fork download
  1. /* External definitions for job-shop model. */
  2.  
  3. #include "simlib.h" /* Required for use of simlib.c. */
  4.  
  5. #define EVENT_ARRIVAL 1 /* Event type for arrival of a job to the
  6. system. */
  7. #define EVENT_DEPARTURE 2 /* Event type for departure of a job from a
  8. particular station. */
  9. #define EVENT_END_SIMULATION 3 /* Event type for end of the simulation. */
  10. #define STREAM_INTERARRIVAL 1 /* Random-number stream for interarrivals. */
  11. #define STREAM_JOB_TYPE 2 /* Random-number stream for job types. */
  12. #define STREAM_SERVICE 3 /* Random-number stream for service times. */
  13. #define MAX_NUM_STATIONS 5 /* Maximum number of stations. */
  14. #define MAX_NUM_JOB_TYPES 3 /* Maximum number of job types. */
  15.  
  16. /* Declare non-simlib global variables. */
  17.  
  18. int num_stations, num_job_types, i, j, num_machines[MAX_NUM_STATIONS + 1],
  19. num_tasks[MAX_NUM_JOB_TYPES +1],
  20. route[MAX_NUM_JOB_TYPES +1][MAX_NUM_STATIONS + 1],
  21. num_machines_busy[MAX_NUM_STATIONS + 1], job_type, task;
  22. float mean_interarrival, length_simulation, prob_distrib_job_type[26],
  23. mean_service[MAX_NUM_JOB_TYPES +1][ MAX_NUM_STATIONS + 1];
  24. FILE *infile, *outfile;
  25.  
  26. /* Declare non-simlib functions. */
  27.  
  28. void arrive(int new_job);
  29. void depart(void);
  30. void report(void);
  31.  
  32.  
  33. main() /* Main function. */
  34. {
  35. /* Open input and output files. */
  36.  
  37. infile = fopen("jobshop.in", "r");
  38. outfile = fopen("jobshop.out", "w");
  39.  
  40. /* Read input parameters. */
  41.  
  42. fscanf(infile, "%d %d %f %f", &num_stations, &num_job_types,
  43. &mean_interarrival, &length_simulation);
  44. for (j = 1; j <= num_stations; ++j)
  45. fscanf(infile, "%d", &num_machines[j]);
  46. for (i = 1; i <= num_job_types; ++i)
  47. fscanf(infile, "%d", &num_tasks[i]);
  48. for (i = 1; i <= num_job_types; ++i) {
  49. for (j = 1; j <= num_tasks[i]; ++j)
  50. fscanf(infile, "%d", &route[i][j]);
  51. for (j = 1; j <= num_tasks[i]; ++j)
  52. fscanf(infile, "%f", &mean_service[i][j]);
  53. }
  54. for (i = 1; i <= num_job_types; ++i)
  55. fscanf(infile, "%f", &prob_distrib_job_type[i]);
  56.  
  57. /* Write report heading and input parameters. */
  58.  
  59. fprintf(outfile, "Job-shop model\n\n");
  60. fprintf(outfile, "Number of work stations%21d\n\n", num_stations);
  61. fprintf(outfile, "Number of machines in each station ");
  62. for (j = 1; j <= num_stations; ++j)
  63. fprintf(outfile, "%5d", num_machines[j]);
  64. fprintf(outfile, "\n\nNumber of job types%25d\n\n", num_job_types);
  65. fprintf(outfile, "Number of tasks for each job type ");
  66. for (i = 1; i <= num_job_types; ++i)
  67. fprintf(outfile, "%5d", num_tasks[i]);
  68. fprintf(outfile, "\n\nDistribution function of job types ");
  69. for (i = 1; i <= num_job_types; ++i)
  70. fprintf(outfile, "%8.3f", prob_distrib_job_type[i]);
  71. fprintf(outfile, "\n\nMean interarrival time of jobs%14.2f hours\n\n",
  72. mean_interarrival);
  73. fprintf(outfile, "Length of the simulation%20.1f eight-hour days\n\n\n",
  74. length_simulation);
  75. fprintf(outfile, "Job type Work stations on route");
  76. for (i = 1; i <= num_job_types; ++i) {
  77. fprintf(outfile, "\n\n%4d ", i);
  78. for (j = 1; j <= num_tasks[i]; ++j)
  79. fprintf(outfile, "%5d", route[i][j]);
  80. }
  81. fprintf(outfile, "\n\n\nJob type ");
  82. fprintf(outfile, "Mean service time (in hours) for successive tasks");
  83. for (i = 1; i <= num_job_types; ++i) {
  84. fprintf(outfile, "\n\n%4d ", i);
  85. for (j = 1; j <= num_tasks[i]; ++j)
  86. fprintf(outfile, "%9.2f", mean_service[i][j]);
  87. }
  88.  
  89. /* Initialize all machines in all stations to the idle state. */
  90.  
  91. for (j = 1; j <= num_stations; ++j)
  92. num_machines_busy[j] = 0;
  93.  
  94. /* Initialize simlib */
  95.  
  96. init_simlib();
  97.  
  98. /* Set maxatr = max(maximum number of attributes per record, 4) */
  99.  
  100. maxatr = 4; /* NEVER SET maxatr TO BE SMALLER THAN 4. */
  101.  
  102. /* Schedule the arrival of the first job. */
  103.  
  104. event_schedule(expon(mean_interarrival, STREAM_INTERARRIVAL),
  105. EVENT_ARRIVAL);
  106.  
  107. /* Schedule the end of the simulation. (This is needed for consistency of
  108.   units.) */
  109.  
  110. event_schedule(8 * length_simulation, EVENT_END_SIMULATION);
  111.  
  112. /* Run the simulation until it terminates after an end-simulation event
  113.   (type EVENT_END_SIMULATION) occurs. */
  114.  
  115. do {
  116.  
  117. /* Determine the next event. */
  118.  
  119. timing();
  120.  
  121. /* Invoke the appropriate event function. */
  122.  
  123. switch (next_event_type) {
  124. case EVENT_ARRIVAL:
  125. arrive(1);
  126. break;
  127. case EVENT_DEPARTURE:
  128. depart();
  129. break;
  130. case EVENT_END_SIMULATION:
  131. report();
  132. break;
  133. }
  134.  
  135. /* If the event just executed was not the end-simulation event (type
  136.   EVENT_END_SIMULATION), continue simulating. Otherwise, end the
  137.   simulation. */
  138.  
  139. } while (next_event_type != EVENT_END_SIMULATION);
  140.  
  141. fclose(infile);
  142. fclose(outfile);
  143.  
  144. return 0;
  145. }
  146.  
  147.  
  148. void arrive(int new_job) /* Function to serve as both an arrival event of a job
  149.   to the system, as well as the non-event of a job's
  150.   arriving to a subsequent station along its
  151.   route. */
  152. {
  153. int station;
  154.  
  155. /* If this is a new arrival to the system, generate the time of the next
  156.   arrival and determine the job type and task number of the arriving
  157.   job. */
  158.  
  159.  
  160. if (new_job == 1) {
  161.  
  162. event_schedule(sim_time + expon(mean_interarrival, STREAM_INTERARRIVAL),
  163. EVENT_ARRIVAL);
  164. job_type = random_integer(prob_distrib_job_type, STREAM_JOB_TYPE);
  165. task = 1;
  166. }
  167.  
  168. /* Determine the station from the route matrix. */
  169.  
  170. station = route[job_type][task];
  171.  
  172. /* Check to see whether all machines in this station are busy. */
  173.  
  174. if (num_machines_busy[station] == num_machines[station]) {
  175.  
  176. /* All machines in this station are busy, so place the arriving job at
  177.   the end of the appropriate queue. Note that the following data are
  178.   stored in the record for each job:
  179.   1. Time of arrival to this station.
  180.   2. Job type.
  181.   3. Current task number. */
  182.  
  183. transfer[1] = sim_time;
  184. transfer[2] = job_type;
  185. transfer[3] = task;
  186. list_file(LAST, station);
  187. }
  188.  
  189. else {
  190.  
  191. /* A machine in this station is idle, so start service on the arriving
  192.   job (which has a delay of zero). */
  193.  
  194. sampst(0.0, station); /* For station. */
  195. sampst(0.0, num_stations + job_type); /* For job type. */
  196. ++num_machines_busy[station];
  197. timest((float) num_machines_busy[station], station);
  198.  
  199. /* Schedule a service completion. Note defining attributes beyond the
  200.   first two for the event record before invoking event_schedule. */
  201.  
  202. transfer[3] = job_type;
  203. transfer[4] = task;
  204. event_schedule(sim_time
  205. + erlang(2, mean_service[job_type][task],
  206. STREAM_SERVICE),
  207. EVENT_DEPARTURE);
  208. }
  209. }
  210.  
  211.  
  212. void depart(void) /* Event function for departure of a job from a particular
  213.   station. */
  214. {
  215. int station, job_type_queue, task_queue;
  216.  
  217. /* Determine the station from which the job is departing. */
  218.  
  219. job_type = transfer[3];
  220. task = transfer[4];
  221. station = route[job_type][task];
  222.  
  223. /* Check to see whether the queue for this station is empty. */
  224.  
  225. if (list_size[station] == 0) {
  226.  
  227. /* The queue for this station is empty, so make a machine in this
  228.   station idle. */
  229.  
  230. --num_machines_busy[station];
  231. timest((float) num_machines_busy[station], station);
  232. }
  233.  
  234. else {
  235.  
  236. /* The queue is nonempty, so start service on first job in queue. */
  237.  
  238. list_remove(FIRST, station);
  239.  
  240. /* Tally this delay for this station. */
  241.  
  242. sampst(sim_time - transfer[1], station);
  243.  
  244. /* Tally this same delay for this job type. */
  245.  
  246. job_type_queue = transfer[2];
  247. task_queue = transfer[3];
  248. sampst(sim_time - transfer[1], num_stations + job_type_queue);
  249.  
  250. /* Schedule end of service for this job at this station. Note defining
  251.   attributes beyond the first two for the event record before invoking
  252.   event_schedule. */
  253.  
  254. transfer[3] = job_type_queue;
  255. transfer[4] = task_queue;
  256. event_schedule(sim_time
  257. + erlang(2, mean_service[job_type_queue][task_queue],
  258. STREAM_SERVICE),
  259. EVENT_DEPARTURE);
  260. }
  261.  
  262. /* If the current departing job has one or more tasks yet to be done, send
  263.   the job to the next station on its route. */
  264.  
  265. if (task < num_tasks[job_type]) {
  266. ++task;
  267. arrive(2);
  268. }
  269. }
  270.  
  271.  
  272. void report(void) /* Report generator function. */
  273. {
  274. int i;
  275. float overall_avg_job_tot_delay, avg_job_tot_delay, sum_probs;
  276.  
  277. /* Compute the average total delay in queue for each job type and the
  278.   overall average job total delay. */
  279.  
  280. fprintf(outfile, "\n\n\n\nJob type Average total delay in queue");
  281. overall_avg_job_tot_delay = 0.0;
  282. sum_probs = 0.0;
  283. for (i = 1; i <= num_job_types; ++i) {
  284. avg_job_tot_delay = sampst(0.0, -(num_stations + i)) * num_tasks[i];
  285. fprintf(outfile, "\n\n%4d%27.3f", i, avg_job_tot_delay);
  286. overall_avg_job_tot_delay += (prob_distrib_job_type[i] - sum_probs)
  287. * avg_job_tot_delay;
  288. sum_probs = prob_distrib_job_type[i];
  289. }
  290. fprintf(outfile, "\n\nOverall average job total delay =%10.3f\n",
  291. overall_avg_job_tot_delay);
  292.  
  293. /* Compute the average number in queue, the average utilization, and the
  294.   average delay in queue for each station. */
  295.  
  296. fprintf(outfile,
  297. "\n\n\n Work Average number Average Average delay");
  298. fprintf(outfile,
  299. "\nstation in queue utilization in queue");
  300. for (j = 1; j <= num_stations; ++j)
  301. fprintf(outfile, "\n\n%4d%17.3f%17.3f%17.3f", j, filest(j),
  302. timest(0.0, -j) / num_machines[j], sampst(0.0, -j));
  303. }
  304.  
  305.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: illegal character: '#'
#include "simlib.h"              /* Required for use of simlib.c. */
^
Main.java:3: error: class, interface, or enum expected
#include "simlib.h"              /* Required for use of simlib.c. */
         ^
Main.java:5: error: illegal character: '#'
#define EVENT_ARRIVAL         1  /* Event type for arrival of a job to the
^
Main.java:7: error: illegal character: '#'
#define EVENT_DEPARTURE       2  /* Event type for departure of a job from a
^
Main.java:9: error: illegal character: '#'
#define EVENT_END_SIMULATION  3  /* Event type for end of the simulation. */
^
Main.java:10: error: illegal character: '#'
#define STREAM_INTERARRIVAL   1  /* Random-number stream for interarrivals. */
^
Main.java:11: error: illegal character: '#'
#define STREAM_JOB_TYPE       2  /* Random-number stream for job types. */
^
Main.java:12: error: illegal character: '#'
#define STREAM_SERVICE        3  /* Random-number stream for service times. */
^
Main.java:13: error: illegal character: '#'
#define MAX_NUM_STATIONS      5  /* Maximum number of stations. */
^
Main.java:14: error: illegal character: '#'
#define MAX_NUM_JOB_TYPES     3  /* Maximum number of job types. */
^
Main.java:22: error: class, interface, or enum expected
float mean_interarrival, length_simulation, prob_distrib_job_type[26],
^
Main.java:24: error: class, interface, or enum expected
FILE  *infile, *outfile;
^
Main.java:28: error: class, interface, or enum expected
void  arrive(int new_job);
^
Main.java:29: error: class, interface, or enum expected
void  depart(void);
^
Main.java:30: error: class, interface, or enum expected
void  report(void);
^
Main.java:33: error: class, interface, or enum expected
main()  /* Main function. */
^
Main.java:38: error: class, interface, or enum expected
    outfile = fopen("jobshop.out", "w");
    ^
Main.java:42: error: class, interface, or enum expected
    fscanf(infile, "%d %d %f %f", &num_stations, &num_job_types,
    ^
Main.java:44: error: class, interface, or enum expected
    for (j = 1; j <= num_stations; ++j)
    ^
Main.java:44: error: class, interface, or enum expected
    for (j = 1; j <= num_stations; ++j)
                ^
Main.java:44: error: class, interface, or enum expected
    for (j = 1; j <= num_stations; ++j)
                                   ^
Main.java:46: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
    ^
Main.java:46: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
                ^
Main.java:46: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
                                    ^
Main.java:48: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
    ^
Main.java:48: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
                ^
Main.java:48: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
                                    ^
Main.java:49: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
                    ^
Main.java:49: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
                                       ^
Main.java:51: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
        ^
Main.java:51: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
                    ^
Main.java:51: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
                                       ^
Main.java:53: error: class, interface, or enum expected
    }
    ^
Main.java:54: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
                ^
Main.java:54: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
                                    ^
Main.java:59: error: class, interface, or enum expected
    fprintf(outfile, "Job-shop model\n\n");
    ^
Main.java:60: error: class, interface, or enum expected
    fprintf(outfile, "Number of work stations%21d\n\n", num_stations);
    ^
Main.java:61: error: class, interface, or enum expected
    fprintf(outfile, "Number of machines in each station     ");
    ^
Main.java:62: error: class, interface, or enum expected
    for (j = 1; j <= num_stations; ++j)
    ^
Main.java:62: error: class, interface, or enum expected
    for (j = 1; j <= num_stations; ++j)
                ^
Main.java:62: error: class, interface, or enum expected
    for (j = 1; j <= num_stations; ++j)
                                   ^
Main.java:64: error: class, interface, or enum expected
    fprintf(outfile, "\n\nNumber of job types%25d\n\n", num_job_types);
    ^
Main.java:65: error: class, interface, or enum expected
    fprintf(outfile, "Number of tasks for each job type      ");
    ^
Main.java:66: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
    ^
Main.java:66: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
                ^
Main.java:66: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
                                    ^
Main.java:68: error: class, interface, or enum expected
    fprintf(outfile, "\n\nDistribution function of job types  ");
    ^
Main.java:69: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
    ^
Main.java:69: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
                ^
Main.java:69: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i)
                                    ^
Main.java:71: error: class, interface, or enum expected
    fprintf(outfile, "\n\nMean interarrival time of jobs%14.2f hours\n\n",
    ^
Main.java:73: error: class, interface, or enum expected
    fprintf(outfile, "Length of the simulation%20.1f eight-hour days\n\n\n",
    ^
Main.java:75: error: class, interface, or enum expected
    fprintf(outfile, "Job type     Work stations on route");
    ^
Main.java:76: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
    ^
Main.java:76: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
                ^
Main.java:76: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
                                    ^
Main.java:78: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
        ^
Main.java:78: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
                    ^
Main.java:78: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
                                       ^
Main.java:80: error: class, interface, or enum expected
    }
    ^
Main.java:82: error: class, interface, or enum expected
    fprintf(outfile, "Mean service time (in hours) for successive tasks");
    ^
Main.java:83: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
    ^
Main.java:83: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
                ^
Main.java:83: error: class, interface, or enum expected
    for (i = 1; i <= num_job_types; ++i) {
                                    ^
Main.java:85: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
        ^
Main.java:85: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
                    ^
Main.java:85: error: class, interface, or enum expected
        for (j = 1; j <= num_tasks[i]; ++j)
                                       ^
Main.java:87: error: class, interface, or enum expected
    }
    ^
Main.java:91: error: class, interface, or enum expected
    for (j = 1; j <= num_stations; ++j)
                ^
Main.java:91: error: class, interface, or enum expected
    for (j = 1; j <= num_stations; ++j)
                                   ^
Main.java:96: error: class, interface, or enum expected
    init_simlib();
    ^
Main.java:100: error: class, interface, or enum expected
    maxatr = 4;  /* NEVER SET maxatr TO BE SMALLER THAN 4. */
    ^
Main.java:104: error: class, interface, or enum expected
    event_schedule(expon(mean_interarrival, STREAM_INTERARRIVAL),
    ^
Main.java:110: error: class, interface, or enum expected
    event_schedule(8 * length_simulation, EVENT_END_SIMULATION);
    ^
Main.java:115: error: class, interface, or enum expected
    do {
    ^
Main.java:123: error: class, interface, or enum expected
        switch (next_event_type) {
        ^
Main.java:126: error: class, interface, or enum expected
                break;
                ^
Main.java:127: error: class, interface, or enum expected
            case EVENT_DEPARTURE:
            ^
Main.java:129: error: class, interface, or enum expected
                break;
                ^
Main.java:130: error: class, interface, or enum expected
            case EVENT_END_SIMULATION:
            ^
Main.java:132: error: class, interface, or enum expected
                break;
                ^
Main.java:133: error: class, interface, or enum expected
        }
        ^
Main.java:141: error: class, interface, or enum expected
    fclose(infile);
    ^
Main.java:142: error: class, interface, or enum expected
    fclose(outfile);
    ^
Main.java:144: error: class, interface, or enum expected
    return 0;
    ^
Main.java:145: error: class, interface, or enum expected
}
^
Main.java:160: error: class, interface, or enum expected
    if (new_job == 1) {
    ^
Main.java:164: error: class, interface, or enum expected
        job_type = random_integer(prob_distrib_job_type, STREAM_JOB_TYPE);
        ^
Main.java:165: error: class, interface, or enum expected
        task     = 1;
        ^
Main.java:166: error: class, interface, or enum expected
    }
    ^
Main.java:174: error: class, interface, or enum expected
    if (num_machines_busy[station] == num_machines[station]) {
    ^
Main.java:184: error: class, interface, or enum expected
        transfer[2] = job_type;
        ^
Main.java:185: error: class, interface, or enum expected
        transfer[3] = task;
        ^
Main.java:186: error: class, interface, or enum expected
        list_file(LAST, station);
        ^
Main.java:187: error: class, interface, or enum expected
    }
    ^
Main.java:195: error: class, interface, or enum expected
        sampst(0.0, num_stations + job_type);              /* For job type. */
        ^
Main.java:196: error: class, interface, or enum expected
        ++num_machines_busy[station];
        ^
Main.java:197: error: class, interface, or enum expected
        timest((float) num_machines_busy[station], station);
        ^
Main.java:202: error: class, interface, or enum expected
        transfer[3] = job_type;
        ^
Main.java:203: error: class, interface, or enum expected
        transfer[4] = task;
        ^
100 errors
stdout
Standard output is empty