fork(2) download
  1. /* This is simlib.c (adapted from SUPERSIMLIB, written by Gregory Glockner). */
  2.  
  3. /* Include files. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include "simlibdefs.h"
  9.  
  10. /* Declare simlib global variables. */
  11.  
  12. int *list_rank, *list_size, next_event_type, maxatr = 0, maxlist = 0;
  13. float *transfer, sim_time, prob_distrib[26];
  14. struct master {
  15. float *value;
  16. struct master *pr;
  17. struct master *sr;
  18. } **head, **tail;
  19.  
  20. /* Declare simlib functions. */
  21.  
  22. void init_simlib(void);
  23. void list_file(int option, int list);
  24. void list_remove(int option, int list);
  25. void timing(void);
  26. void event_schedule(float time_of_event, int type_of_event);
  27. int event_cancel(int event_type);
  28. float sampst(float value, int variable);
  29. float timest(float value, int variable);
  30. float filest(int list);
  31. void out_sampst(FILE *unit, int lowvar, int highvar);
  32. void out_timest(FILE *unit, int lowvar, int highvar);
  33. void out_filest(FILE *unit, int lowlist, int highlist);
  34. void pprint_out(FILE *unit, int i);
  35. float expon(float mean, int stream);
  36. int random_integer(float prob_distrib[], int stream);
  37. float uniform(float a, float b, int stream);
  38. float erlang(int m, float mean, int stream);
  39. float lcgrand(int stream);
  40. void lcgrandst(long zset, int stream);
  41. long lcgrandgt(int stream);
  42.  
  43.  
  44. void init_simlib()
  45. {
  46.  
  47. /* Initialize simlib.c. List LIST_EVENT is reserved for event list, ordered by
  48.   event time. init_simlib must be called from main by user. */
  49.  
  50. int list, listsize;
  51.  
  52. if (maxlist < 1) maxlist = MAX_LIST;
  53. listsize = maxlist + 1;
  54.  
  55. /* Initialize system attributes. */
  56.  
  57. sim_time = 0.0;
  58. if (maxatr < 4) maxatr = MAX_ATTR;
  59.  
  60. /* Allocate space for the lists. */
  61.  
  62. list_rank = (int *) calloc(listsize, sizeof(int));
  63. list_size = (int *) calloc(listsize, sizeof(int));
  64. head = (struct master **) calloc(listsize, sizeof(struct master *));
  65. tail = (struct master **) calloc(listsize, sizeof(struct master *));
  66. transfer = (float *) calloc(maxatr + 1, sizeof(float));
  67.  
  68. /* Initialize list attributes. */
  69.  
  70. for(list = 1; list <= maxlist; ++list) {
  71. head [list] = NULL;
  72. tail [list] = NULL;
  73. list_size[list] = 0;
  74. list_rank[list] = 0;
  75. }
  76.  
  77. /* Set event list to be ordered by event time. */
  78.  
  79. list_rank[LIST_EVENT] = EVENT_TIME;
  80.  
  81. /* Initialize statistical routines. */
  82.  
  83. sampst(0.0, 0);
  84. timest(0.0, 0);
  85. }
  86.  
  87.  
  88. void list_file(int option, int list)
  89. {
  90.  
  91. /* Place transfr into list "list".
  92.   Update timest statistics for the list.
  93.   option = FIRST place at start of list
  94.   LAST place at end of list
  95.   INCREASING place in increasing order on attribute list_rank(list)
  96.   DECREASING place in decreasing order on attribute list_rank(list)
  97.   (ties resolved by FIFO) */
  98.  
  99. struct master *row, *ahead, *behind, *ihead, *itail;
  100. int item, postest;
  101.  
  102. /* If the list value is improper, stop the simulation. */
  103.  
  104. if(!((list >= 0) && (list <= MAX_LIST))) {
  105. printf("\nInvalid list %d for list_file at time %f\n", list, sim_time);
  106. exit(1);
  107. }
  108.  
  109. /* Increment the list size. */
  110.  
  111. list_size[list]++;
  112.  
  113. /* If the option value is improper, stop the simulation. */
  114.  
  115. if(!((option >= 1) && (option <= DECREASING))) {
  116. printf(
  117. "\n%d is an invalid option for list_file on list %d at time %f\n",
  118. option, list, sim_time);
  119. exit(1);
  120. }
  121.  
  122. /* If this is the first record in this list, just make space for it. */
  123.  
  124. if(list_size[list] == 1) {
  125.  
  126. row = (struct master *) malloc(sizeof(struct master));
  127. head[list] = row ;
  128. tail[list] = row ;
  129. (*row).pr = NULL;
  130. (*row).sr = NULL;
  131. }
  132.  
  133. else { /* There are other records in the list. */
  134.  
  135. /* Check the value of option. */
  136.  
  137. if ((option == INCREASING) || (option == DECREASING)) {
  138. item = list_rank[list];
  139. if(!((item >= 1) && (item <= maxatr))) {
  140. printf(
  141. "%d is an improper value for rank of list %d at time %f\n",
  142. item, list, sim_time) ;
  143. exit(1);
  144. }
  145.  
  146. row = head[list];
  147. behind = NULL; /* Dummy value for the first iteration. */
  148.  
  149. /* Search for the correct location. */
  150.  
  151. if (option == INCREASING) {
  152. postest = (transfer[item] >= (*row).value[item]);
  153. while (postest) {
  154. behind = row;
  155. row = (*row).sr;
  156. postest = (behind != tail[list]);
  157. if (postest)
  158. postest = (transfer[item] >= (*row).value[item]);
  159. }
  160. }
  161.  
  162. else {
  163.  
  164. postest = (transfer[item] <= (*row).value[item]);
  165. while (postest) {
  166. behind = row;
  167. row = (*row).sr;
  168. postest = (behind != tail[list]);
  169. if (postest)
  170. postest = (transfer[item] <= (*row).value[item]);
  171. }
  172. }
  173.  
  174. /* Check to see if position is first or last. If so, take care of
  175.   it below. */
  176.  
  177. if (row == head[list])
  178.  
  179. option = FIRST;
  180.  
  181. else
  182.  
  183. if (behind == tail[list])
  184.  
  185. option = LAST;
  186.  
  187. else { /* Insert between preceding and succeeding records. */
  188.  
  189. ahead = (*behind).sr;
  190. row = (struct master *)
  191. malloc(sizeof(struct master));
  192. (*row).pr = behind;
  193. (*behind).sr = row;
  194. (*ahead).pr = row;
  195. (*row).sr = ahead;
  196. }
  197. } /* End if inserting in increasing or decreasing order. */
  198.  
  199. if (option == FIRST) {
  200. row = (struct master *) malloc(sizeof(struct master));
  201. ihead = head[list];
  202. (*ihead).pr = row;
  203. (*row).sr = ihead;
  204. (*row).pr = NULL;
  205. head[list] = row;
  206. }
  207. if (option == LAST) {
  208. row = (struct master *) malloc(sizeof(struct master));
  209. itail = tail[list];
  210. (*row).pr = itail;
  211. (*itail).sr = row;
  212. (*row).sr = NULL;
  213. tail[list] = row;
  214. }
  215. }
  216.  
  217. /* Copy the data. */
  218.  
  219. (*row).value = transfer;
  220.  
  221. /* Make room for new transfer. */
  222.  
  223. transfer = (float *) calloc(maxatr + 1, sizeof(float));
  224.  
  225. /* Update the area under the number-in-list curve. */
  226.  
  227. timest((float)list_size[list], TIM_VAR + list);
  228. }
  229.  
  230.  
  231. void list_remove(int option, int list)
  232. {
  233.  
  234. /* Remove a record from list "list" and copy attributes into transfer.
  235.   Update timest statistics for the list.
  236.   option = FIRST remove first record in the list
  237.   LAST remove last record in the list */
  238.  
  239. struct master *row, *ihead, *itail;
  240.  
  241. /* If the list value is improper, stop the simulation. */
  242.  
  243. if(!((list >= 0) && (list <= MAX_LIST))) {
  244. printf("\nInvalid list %d for list_remove at time %f\n",
  245. list, sim_time);
  246. exit(1);
  247. }
  248.  
  249. /* If the list is empty, stop the simulation. */
  250.  
  251. if(list_size[list] <= 0) {
  252. printf("\nUnderflow of list %d at time %f\n", list, sim_time);
  253. exit(1);
  254. }
  255.  
  256. /* Decrement the list size. */
  257.  
  258. list_size[list]--;
  259.  
  260. /* If the option value is improper, stop the simulation. */
  261.  
  262. if(!(option == FIRST || option == LAST)) {
  263. printf(
  264. "\n%d is an invalid option for list_remove on list %d at time %f\n",
  265. option, list, sim_time);
  266. exit(1);
  267. }
  268.  
  269. if(list_size[list] == 0) {
  270.  
  271. /* There is only 1 record, so remove it. */
  272.  
  273. row = head[list];
  274. head[list] = NULL;
  275. tail[list] = NULL;
  276. }
  277.  
  278. else {
  279.  
  280. /* There is more than 1 record, so remove according to the desired
  281.   option. */
  282.  
  283. switch(option) {
  284.  
  285. /* Remove the first record in the list. */
  286.  
  287. case FIRST:
  288. row = head[list];
  289. ihead = (*row).sr;
  290. (*ihead).pr = NULL;
  291. head[list] = ihead;
  292. break;
  293.  
  294. /* Remove the last record in the list. */
  295.  
  296. case LAST:
  297. row = tail[list];
  298. itail = (*row).pr;
  299. (*itail).sr = NULL;
  300. tail[list] = itail;
  301. break;
  302. }
  303. }
  304.  
  305. /* Copy the data and free memory. */
  306.  
  307. free((char *)transfer);
  308. transfer = (*row).value;
  309. free((char *)row);
  310.  
  311. /* Update the area under the number-in-list curve. */
  312.  
  313. timest((float)list_size[list], TIM_VAR + list);
  314. }
  315.  
  316.  
  317. void timing()
  318. {
  319.  
  320. /* Remove next event from event list, placing its attributes in transfer.
  321.   Set sim_time (simulation time) to event time, transfer[1].
  322.   Set next_event_type to this event type, transfer[2]. */
  323.  
  324. /* Remove the first event from the event list and put it in transfer[]. */
  325.  
  326. list_remove(FIRST, LIST_EVENT);
  327.  
  328. /* Check for a time reversal. */
  329.  
  330. if(transfer[EVENT_TIME] < sim_time) {
  331. printf(
  332. "\nAttempt to schedule event type %f for time %f at time %f\n",
  333. transfer[EVENT_TYPE], transfer[EVENT_TIME], sim_time);
  334. exit(1);
  335. }
  336.  
  337. /* Advance the simulation clock and set the next event type. */
  338.  
  339. sim_time = transfer[EVENT_TIME];
  340. next_event_type = transfer[EVENT_TYPE];
  341. }
  342.  
  343.  
  344. void event_schedule(float time_of_event, int type_of_event)
  345. {
  346.  
  347. /* Schedule an event at time event_time of type event_type. If attributes
  348.   beyond the first two (reserved for the event time and the event type) are
  349.   being used in the event list, it is the user's responsibility to place their
  350.   values into the transfer array before invoking event_schedule. */
  351.  
  352. transfer[EVENT_TIME] = time_of_event;
  353. transfer[EVENT_TYPE] = type_of_event;
  354. list_file(INCREASING, LIST_EVENT);
  355. }
  356.  
  357.  
  358. int event_cancel(int event_type)
  359. {
  360.  
  361. /* Remove the first event of type event_type from the event list, leaving its
  362.   attributes in transfer. If something is cancelled, event_cancel returns 1;
  363.   if no match is found, event_cancel returns 0. */
  364.  
  365. struct master *row, *ahead, *behind;
  366. static float high, low, value;
  367.  
  368. /* If the event list is empty, do nothing and return 0. */
  369.  
  370. if(list_size[LIST_EVENT] == 0) return 0;
  371.  
  372. /* Search the event list. */
  373.  
  374. row = head[LIST_EVENT];
  375. low = event_type - EPSILON;
  376. high = event_type + EPSILON;
  377. value = (*row).value[EVENT_TYPE] ;
  378.  
  379. while (((value <= low) || (value >= high)) && (row != tail[LIST_EVENT])) {
  380. row = (*row).sr;
  381. value = (*row).value[EVENT_TYPE];
  382. }
  383.  
  384. /* Check to see if this is the end of the event list. */
  385.  
  386. if (row == tail[LIST_EVENT]) {
  387.  
  388. /* Double check to see that this is a match. */
  389.  
  390. if ((value > low) && (value < high)) {
  391. list_remove(LAST, LIST_EVENT);
  392. return 1;
  393. }
  394.  
  395. else /* no match */
  396. return 0;
  397. }
  398.  
  399. /* Check to see if this is the head of the list. If it is at the head, then
  400.   it MUST be a match. */
  401.  
  402. if (row == head[LIST_EVENT]) {
  403. list_remove(FIRST, LIST_EVENT);
  404. return 1;
  405. }
  406.  
  407. /* Else remove this event somewhere in the middle of the event list. */
  408.  
  409. /* Update pointers. */
  410.  
  411. ahead = (*row).sr;
  412. behind = (*row).pr;
  413. (*behind).sr = ahead;
  414. (*ahead).pr = behind;
  415.  
  416. /* Decrement the size of the event list. */
  417.  
  418. list_size[LIST_EVENT]--;
  419.  
  420. /* Copy and free memory. */
  421.  
  422. free((char *)transfer); /* Free the old transfer. */
  423. transfer = (*row).value; /* Transfer the data. */
  424. free((char *)row); /* Free the space vacated by row. */
  425.  
  426. /* Update the area under the number-in-event-list curve. */
  427.  
  428. timest((float)list_size[LIST_EVENT], TIM_VAR + LIST_EVENT);
  429. return 1;
  430. }
  431.  
  432.  
  433. float sampst(float value, int variable)
  434. {
  435.  
  436. /* Initialize, update, or report statistics on discrete-time processes:
  437.   sum/average, max (default -1E30), min (default 1E30), number of observations
  438.   for sampst variable "variable", where "variable":
  439.   = 0 initializes accumulators
  440.   > 0 updates sum, count, min, and max accumulators with new observation
  441.   < 0 reports stats on variable "variable" and returns them in transfer:
  442.   [1] = average of observations
  443.   [2] = number of observations
  444.   [3] = maximum of observations
  445.   [4] = minimum of observations */
  446.  
  447. static int ivar, num_observations[SVAR_SIZE];
  448. static float max[SVAR_SIZE], min[SVAR_SIZE], sum[SVAR_SIZE];
  449.  
  450. /* If the variable value is improper, stop the simulation. */
  451.  
  452. if(!(variable >= -MAX_SVAR) && (variable <= MAX_SVAR)) {
  453. printf("\n%d is an improper value for a sampst variable at time %f\n",
  454. variable, sim_time);
  455. exit(1);
  456. }
  457.  
  458. /* Execute the desired option. */
  459.  
  460. if(variable > 0) { /* Update. */
  461. sum[variable] += value;
  462. if(value > max[variable]) max[variable] = value;
  463. if(value < min[variable]) min[variable] = value;
  464. num_observations[variable]++;
  465. return 0.0;
  466. }
  467.  
  468. if(variable < 0) { /* Report summary statistics in transfer. */
  469. ivar = -variable;
  470. transfer[2] = (float) num_observations[ivar];
  471. transfer[3] = max[ivar];
  472. transfer[4] = min[ivar];
  473. if(num_observations[ivar] == 0)
  474. transfer[1] = 0.0;
  475. else
  476. transfer[1] = sum[ivar] / transfer[2];
  477. return transfer[1];
  478. }
  479.  
  480. /* Initialize the accumulators. */
  481.  
  482. for(ivar=1; ivar <= MAX_SVAR; ++ivar) {
  483. sum[ivar] = 0.0;
  484. max[ivar] = -INFINITY;
  485. min[ivar] = INFINITY;
  486. num_observations[ivar] = 0;
  487. }
  488. }
  489.  
  490.  
  491. float timest(float value, int variable)
  492. {
  493.  
  494. /* Initialize, update, or report statistics on continuous-time processes:
  495.   integral/average, max (default -1E30), min (default 1E30)
  496.   for timest variable "variable", where "variable":
  497.   = 0 initializes counters
  498.   > 0 updates area, min, and max accumulators with new level of variable
  499.   < 0 reports stats on variable "variable" and returns them in transfer:
  500.   [1] = time-average of variable updated to the time of this call
  501.   [2] = maximum value variable has attained
  502.   [3] = minimum value variable has attained
  503.   Note that variables TIM_VAR + 1 through TVAR_SIZE are used for automatic
  504.   record keeping on the length of lists 1 through MAX_LIST. */
  505.  
  506. int ivar;
  507. static float area[TVAR_SIZE], max[TVAR_SIZE], min[TVAR_SIZE],
  508. preval[TVAR_SIZE], tlvc[TVAR_SIZE], treset;
  509.  
  510. /* If the variable value is improper, stop the simulation. */
  511.  
  512. if(!(variable >= -MAX_TVAR) && (variable <= MAX_TVAR)) {
  513. printf("\n%d is an improper value for a timest variable at time %f\n",
  514. variable, sim_time);
  515. exit(1);
  516. }
  517.  
  518. /* Execute the desired option. */
  519.  
  520. if(variable > 0) { /* Update. */
  521. area[variable] += (sim_time - tlvc[variable]) * preval[variable];
  522. if(value > max[variable]) max[variable] = value;
  523. if(value < min[variable]) min[variable] = value;
  524. preval[variable] = value;
  525. tlvc[variable] = sim_time;
  526. return 0.0;
  527. }
  528.  
  529. if(variable < 0) { /* Report summary statistics in transfer. */
  530. ivar = -variable;
  531. area[ivar] += (sim_time - tlvc[ivar]) * preval[ivar];
  532. tlvc[ivar] = sim_time;
  533. transfer[1] = area[ivar] / (sim_time - treset);
  534. transfer[2] = max[ivar];
  535. transfer[3] = min[ivar];
  536. return transfer[1];
  537. }
  538.  
  539. /* Initialize the accumulators. */
  540.  
  541. for(ivar = 1; ivar <= MAX_TVAR; ++ivar) {
  542. area[ivar] = 0.0;
  543. max[ivar] = -INFINITY;
  544. min[ivar] = INFINITY;
  545. preval[ivar] = 0.0;
  546. tlvc[ivar] = sim_time;
  547. }
  548. treset = sim_time;
  549. }
  550.  
  551.  
  552. float filest(int list)
  553. {
  554.  
  555. /* Report statistics on the length of list "list" in transfer:
  556.   [1] = time-average of list length updated to the time of this call
  557.   [2] = maximum length list has attained
  558.   [3] = minimum length list has attained
  559.   This uses timest variable TIM_VAR + list. */
  560.  
  561. return timest(0.0, -(TIM_VAR + list));
  562. }
  563.  
  564.  
  565. void out_sampst(FILE *unit, int lowvar, int highvar)
  566. {
  567.  
  568. /* Write sampst statistics for variables lowvar through highvar on file
  569.   "unit". */
  570.  
  571. int ivar, iatrr;
  572.  
  573. if(lowvar>highvar || lowvar > MAX_SVAR || highvar > MAX_SVAR) return;
  574.  
  575. fprintf(unit, "\n sampst Number");
  576. fprintf(unit, "\nvariable of");
  577. fprintf(unit, "\n number Average values Maximum");
  578. fprintf(unit, " Minimum");
  579. fprintf(unit, "\n___________________________________");
  580. fprintf(unit, "_____________________________________");
  581. for(ivar = lowvar; ivar <= highvar; ++ivar) {
  582. fprintf(unit, "\n\n%5d", ivar);
  583. sampst(0.00, -ivar);
  584. for(iatrr = 1; iatrr <= 4; ++iatrr) pprint_out(unit, iatrr);
  585. }
  586. fprintf(unit, "\n___________________________________");
  587. fprintf(unit, "_____________________________________\n\n\n");
  588. }
  589.  
  590.  
  591. void out_timest(FILE *unit, int lowvar, int highvar)
  592. {
  593.  
  594. /* Write timest statistics for variables lowvar through highvar on file
  595.   "unit". */
  596.  
  597. int ivar, iatrr;
  598.  
  599. if(lowvar > highvar || lowvar > TIM_VAR || highvar > TIM_VAR ) return;
  600.  
  601.  
  602. fprintf(unit, "\n timest");
  603. fprintf(unit, "\n variable Time");
  604. fprintf(unit, "\n number average Maximum Minimum");
  605. fprintf(unit, "\n________________________________________________________");
  606. for(ivar = lowvar; ivar <= highvar; ++ivar) {
  607. fprintf(unit, "\n\n%5d", ivar);
  608. timest(0.00, -ivar);
  609. for(iatrr = 1; iatrr <= 3; ++iatrr) pprint_out(unit, iatrr);
  610. }
  611. fprintf(unit, "\n________________________________________________________");
  612. fprintf(unit, "\n\n\n");
  613. }
  614.  
  615.  
  616. void out_filest(FILE *unit, int lowlist, int highlist)
  617. {
  618.  
  619. /* Write timest list-length statistics for lists lowlist through highlist on
  620.   file "unit". */
  621.  
  622. int list, iatrr;
  623.  
  624. if(lowlist > highlist || lowlist > MAX_LIST || highlist > MAX_LIST) return;
  625.  
  626. fprintf(unit, "\n File Time");
  627. fprintf(unit, "\n number average Maximum Minimum");
  628. fprintf(unit, "\n_______________________________________________________");
  629. for(list = lowlist; list <= highlist; ++list) {
  630. fprintf(unit, "\n\n%5d", list);
  631. filest(list);
  632. for(iatrr = 1; iatrr <= 3; ++iatrr) pprint_out(unit, iatrr);
  633. }
  634. fprintf(unit, "\n_______________________________________________________");
  635. fprintf(unit, "\n\n\n");
  636. }
  637.  
  638.  
  639. void pprint_out(FILE *unit, int i) /* Write ith entry in transfer to file
  640.   "unit". */
  641. {
  642. if(transfer[i] == -1e30 || transfer[i] == 1e30)
  643. fprintf(unit," %#15.6G ", 0.00);
  644. else
  645. fprintf(unit," %#15.6G ", transfer[i]);
  646. }
  647.  
  648.  
  649. float expon(float mean, int stream) /* Exponential variate generation
  650.   function. */
  651. {
  652. return -mean * log(lcgrand(stream));
  653.  
  654. }
  655.  
  656.  
  657. int random_integer(float prob_distrib[], int stream) /* Discrete-variate
  658.   generation function. */
  659. {
  660. int i;
  661. float u;
  662.  
  663. u = lcgrand(stream);
  664.  
  665. for (i = 1; u >= prob_distrib[i]; ++i)
  666. ;
  667. return i;
  668. }
  669.  
  670.  
  671. float uniform(float a, float b, int stream) /* Uniform variate generation
  672.   function. */
  673. {
  674. return a + lcgrand(stream) * (b - a);
  675. }
  676.  
  677.  
  678. float erlang(int m, float mean, int stream) /* Erlang variate generation
  679.   function. */
  680. {
  681. int i;
  682. float mean_exponential, sum;
  683.  
  684. mean_exponential = mean / m;
  685. sum = 0.0;
  686. for (i = 1; i <= m; ++i)
  687. sum += expon(mean_exponential, stream);
  688. return sum;
  689. }
  690.  
  691.  
  692. /* Prime modulus multiplicative linear congruential generator
  693.  
  694.   Z[i] = (630360016 * Z[i-1]) (mod(pow(2,31) - 1)), based on Marse and
  695.   Roberts' portable FORTRAN random-number generator UNIRAN. Multiple
  696.   (100) streams are supported, with seeds spaced 100,000 apart.
  697.   Throughout, input argument "stream" must be an int giving the
  698.   desired stream number. The header file lcgrand.h must be included in
  699.   the calling program (#include "lcgrand.h") before using these
  700.   functions.
  701.  
  702.   Usage: (Three functions)
  703.  
  704.   1. To obtain the next U(0,1) random number from stream "stream,"
  705.   execute
  706.   u = lcgrand(stream);
  707.   where lcgrand is a float function. The float variable u will
  708.   contain the next random number.
  709.  
  710.   2. To set the seed for stream "stream" to a desired value zset,
  711.   execute
  712.   lcgrandst(zset, stream);
  713.   where lcgrandst is a void function and zset must be a long set to
  714.   the desired seed, a number between 1 and 2147483646 (inclusive).
  715.   Default seeds for all 100 streams are given in the code.
  716.  
  717.   3. To get the current (most recently used) integer in the sequence
  718.   being generated for stream "stream" into the long variable zget,
  719.   execute
  720.   zget = lcgrandgt(stream);
  721.   where lcgrandgt is a long function. */
  722.  
  723. /* Define the constants. */
  724.  
  725. #define MODLUS 2147483647
  726. #define MULT1 24112
  727. #define MULT2 26143
  728.  
  729. /* Set the default seeds for all 100 streams. */
  730.  
  731. static long zrng[] =
  732. { 1,
  733. 1973272912, 281629770, 20006270,1280689831,2096730329,1933576050,
  734. 913566091, 246780520,1363774876, 604901985,1511192140,1259851944,
  735. 824064364, 150493284, 242708531, 75253171,1964472944,1202299975,
  736. 233217322,1911216000, 726370533, 403498145, 993232223,1103205531,
  737. 762430696,1922803170,1385516923, 76271663, 413682397, 726466604,
  738. 336157058,1432650381,1120463904, 595778810, 877722890,1046574445,
  739. 68911991,2088367019, 748545416, 622401386,2122378830, 640690903,
  740. 1774806513,2132545692,2079249579, 78130110, 852776735,1187867272,
  741. 1351423507,1645973084,1997049139, 922510944,2045512870, 898585771,
  742. 243649545,1004818771, 773686062, 403188473, 372279877,1901633463,
  743. 498067494,2087759558, 493157915, 597104727,1530940798,1814496276,
  744. 536444882,1663153658, 855503735, 67784357,1432404475, 619691088,
  745. 119025595, 880802310, 176192644,1116780070, 277854671,1366580350,
  746. 1142483975,2026948561,1053920743, 786262391,1792203830,1494667770,
  747. 1923011392,1433700034,1244184613,1147297105, 539712780,1545929719,
  748. 190641742,1645390429, 264907697, 620389253,1502074852, 927711160,
  749. 364849192,2049576050, 638580085, 547070247 };
  750.  
  751. /* Generate the next random number. */
  752.  
  753. float lcgrand(int stream)
  754. {
  755. long zi, lowprd, hi31;
  756.  
  757. zi = zrng[stream];
  758. lowprd = (zi & 65535) * MULT1;
  759. hi31 = (zi >> 16) * MULT1 + (lowprd >> 16);
  760. zi = ((lowprd & 65535) - MODLUS) +
  761. ((hi31 & 32767) << 16) + (hi31 >> 15);
  762. if (zi < 0) zi += MODLUS;
  763. lowprd = (zi & 65535) * MULT2;
  764. hi31 = (zi >> 16) * MULT2 + (lowprd >> 16);
  765. zi = ((lowprd & 65535) - MODLUS) +
  766. ((hi31 & 32767) << 16) + (hi31 >> 15);
  767. if (zi < 0) zi += MODLUS;
  768. zrng[stream] = zi;
  769. return (zi >> 7 | 1) / 16777216.0;
  770. }
  771.  
  772.  
  773. void lcgrandst (long zset, int stream) /* Set the current zrng for stream
  774.   "stream" to zset. */
  775. {
  776. zrng[stream] = zset;
  777. }
  778.  
  779.  
  780. long lcgrandgt (int stream) /* Return the current zrng for stream "stream". */
  781. {
  782. return zrng[stream];
  783. }
  784.  
  785.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: illegal character: '#'
#include <stdio.h>
^
Main.java:5: error: class, interface, or enum expected
#include <stdio.h>
         ^
Main.java:6: error: illegal character: '#'
#include <stdlib.h>
^
Main.java:7: error: illegal character: '#'
#include <math.h>
^
Main.java:8: error: illegal character: '#'
#include "simlibdefs.h"
^
Main.java:13: error: class, interface, or enum expected
float  *transfer, sim_time, prob_distrib[26];
^
Main.java:14: error: class, interface, or enum expected
struct master {
^
Main.java:16: error: class, interface, or enum expected
    struct master *pr;
    ^
Main.java:17: error: class, interface, or enum expected
    struct master *sr;
    ^
Main.java:18: error: class, interface, or enum expected
} **head, **tail;
^
Main.java:22: error: class, interface, or enum expected
void  init_simlib(void);
^
Main.java:23: error: class, interface, or enum expected
void  list_file(int option, int list);
^
Main.java:24: error: class, interface, or enum expected
void  list_remove(int option, int list);
^
Main.java:25: error: class, interface, or enum expected
void  timing(void);
^
Main.java:26: error: class, interface, or enum expected
void  event_schedule(float time_of_event, int type_of_event);
^
Main.java:27: error: class, interface, or enum expected
int   event_cancel(int event_type);
^
Main.java:28: error: class, interface, or enum expected
float sampst(float value, int variable);
^
Main.java:29: error: class, interface, or enum expected
float timest(float value, int variable);
^
Main.java:30: error: class, interface, or enum expected
float filest(int list);
^
Main.java:31: error: class, interface, or enum expected
void  out_sampst(FILE *unit, int lowvar, int highvar);
^
Main.java:32: error: class, interface, or enum expected
void  out_timest(FILE *unit, int lowvar, int highvar);
^
Main.java:33: error: class, interface, or enum expected
void  out_filest(FILE *unit, int lowlist, int highlist);
^
Main.java:34: error: class, interface, or enum expected
void  pprint_out(FILE *unit, int i);
^
Main.java:35: error: class, interface, or enum expected
float expon(float mean, int stream);
^
Main.java:36: error: class, interface, or enum expected
int   random_integer(float prob_distrib[], int stream);
^
Main.java:37: error: class, interface, or enum expected
float uniform(float a, float b, int stream);
^
Main.java:38: error: class, interface, or enum expected
float erlang(int m, float mean, int stream);
^
Main.java:39: error: class, interface, or enum expected
float lcgrand(int stream);
^
Main.java:40: error: class, interface, or enum expected
void  lcgrandst(long zset, int stream);
^
Main.java:41: error: class, interface, or enum expected
long  lcgrandgt(int stream);
^
Main.java:44: error: class, interface, or enum expected
void init_simlib()
^
Main.java:52: error: class, interface, or enum expected
    if (maxlist < 1) maxlist = MAX_LIST;
    ^
Main.java:53: error: class, interface, or enum expected
    listsize = maxlist + 1;
    ^
Main.java:57: error: class, interface, or enum expected
    sim_time = 0.0;
    ^
Main.java:58: error: class, interface, or enum expected
    if (maxatr < 4) maxatr = MAX_ATTR;
    ^
Main.java:62: error: class, interface, or enum expected
    list_rank = (int *)            calloc(listsize,   sizeof(int));
    ^
Main.java:63: error: class, interface, or enum expected
    list_size = (int *)            calloc(listsize,   sizeof(int));
    ^
Main.java:64: error: class, interface, or enum expected
    head      = (struct master **) calloc(listsize,   sizeof(struct master *));
    ^
Main.java:65: error: class, interface, or enum expected
    tail      = (struct master **) calloc(listsize,   sizeof(struct master *));
    ^
Main.java:66: error: class, interface, or enum expected
    transfer  = (float *)          calloc(maxatr + 1, sizeof(float));
    ^
Main.java:70: error: class, interface, or enum expected
    for(list = 1; list <= maxlist; ++list) {
    ^
Main.java:70: error: class, interface, or enum expected
    for(list = 1; list <= maxlist; ++list) {
                  ^
Main.java:70: error: class, interface, or enum expected
    for(list = 1; list <= maxlist; ++list) {
                                   ^
Main.java:72: error: class, interface, or enum expected
        tail [list]     = NULL;
        ^
Main.java:73: error: class, interface, or enum expected
        list_size[list] = 0;
        ^
Main.java:74: error: class, interface, or enum expected
        list_rank[list] = 0;
        ^
Main.java:75: error: class, interface, or enum expected
    }
    ^
Main.java:83: error: class, interface, or enum expected
    sampst(0.0, 0);
    ^
Main.java:84: error: class, interface, or enum expected
    timest(0.0, 0);
    ^
Main.java:85: error: class, interface, or enum expected
}
^
Main.java:100: error: class, interface, or enum expected
    int    item, postest;
    ^
Main.java:104: error: class, interface, or enum expected
    if(!((list >= 0) && (list <= MAX_LIST))) {
    ^
Main.java:106: error: class, interface, or enum expected
        exit(1);
        ^
Main.java:107: error: class, interface, or enum expected
    }
    ^
Main.java:115: error: class, interface, or enum expected
    if(!((option >= 1) && (option <= DECREASING))) {
    ^
Main.java:119: error: class, interface, or enum expected
        exit(1);
        ^
Main.java:120: error: class, interface, or enum expected
    }
    ^
Main.java:127: error: class, interface, or enum expected
        head[list] = row ;
        ^
Main.java:128: error: class, interface, or enum expected
        tail[list] = row ;
        ^
Main.java:129: error: class, interface, or enum expected
        (*row).pr  = NULL;
        ^
Main.java:130: error: class, interface, or enum expected
        (*row).sr  = NULL;
        ^
Main.java:131: error: class, interface, or enum expected
    }
    ^
Main.java:139: error: class, interface, or enum expected
            if(!((item >= 1) && (item <= maxatr))) {
            ^
Main.java:143: error: class, interface, or enum expected
                exit(1);
                ^
Main.java:144: error: class, interface, or enum expected
            }
            ^
Main.java:147: error: class, interface, or enum expected
            behind = NULL; /* Dummy value for the first iteration. */
            ^
Main.java:151: error: class, interface, or enum expected
            if (option == INCREASING) {
            ^
Main.java:153: error: class, interface, or enum expected
                while (postest) {
                ^
Main.java:155: error: class, interface, or enum expected
                    row     = (*row).sr;
                    ^
Main.java:156: error: class, interface, or enum expected
                    postest = (behind != tail[list]);
                    ^
Main.java:157: error: class, interface, or enum expected
                    if (postest)
                    ^
Main.java:159: error: class, interface, or enum expected
                }
                ^
Main.java:165: error: class, interface, or enum expected
                while (postest) {
                ^
Main.java:167: error: class, interface, or enum expected
                    row     = (*row).sr;
                    ^
Main.java:168: error: class, interface, or enum expected
                    postest = (behind != tail[list]);
                    ^
Main.java:169: error: class, interface, or enum expected
                    if (postest)
                    ^
Main.java:171: error: class, interface, or enum expected
                }
                ^
Main.java:181: error: class, interface, or enum expected
            else
            ^
Main.java:187: error: class, interface, or enum expected
                else { /* Insert between preceding and succeeding records. */
                ^
Main.java:190: error: class, interface, or enum expected
                    row          = (struct master *)
                    ^
Main.java:192: error: class, interface, or enum expected
                    (*row).pr    = behind;
                    ^
Main.java:193: error: class, interface, or enum expected
                    (*behind).sr = row;
                    ^
Main.java:194: error: class, interface, or enum expected
                    (*ahead).pr  = row;
                    ^
Main.java:195: error: class, interface, or enum expected
                    (*row).sr    = ahead;
                    ^
Main.java:196: error: class, interface, or enum expected
                }
                ^
Main.java:201: error: class, interface, or enum expected
            ihead       = head[list];
            ^
Main.java:202: error: class, interface, or enum expected
            (*ihead).pr = row;
            ^
Main.java:203: error: class, interface, or enum expected
            (*row).sr   = ihead;
            ^
Main.java:204: error: class, interface, or enum expected
            (*row).pr   = NULL;
            ^
Main.java:205: error: class, interface, or enum expected
            head[list]  = row;
            ^
Main.java:206: error: class, interface, or enum expected
        }
        ^
Main.java:209: error: class, interface, or enum expected
            itail       = tail[list];
            ^
Main.java:210: error: class, interface, or enum expected
            (*row).pr   = itail;
            ^
Main.java:211: error: class, interface, or enum expected
            (*itail).sr = row;
            ^
Main.java:212: error: class, interface, or enum expected
            (*row).sr   = NULL;
            ^
Main.java:213: error: class, interface, or enum expected
            tail[list]  = row;
            ^
Main.java:214: error: class, interface, or enum expected
        }
        ^
Main.java:223: error: class, interface, or enum expected
    transfer = (float *) calloc(maxatr + 1, sizeof(float));
    ^
Main.java:227: error: class, interface, or enum expected
    timest((float)list_size[list], TIM_VAR + list);
    ^
Main.java:228: error: class, interface, or enum expected
}
^
100 errors
stdout
Standard output is empty