Saturday, September 7, 2013

NUMERICAL COMPUTATION TECHNIQUE - DISCRETE MODEL

Note:-  The example given in the book "System Simulation" by  Geoffrey Gordon (Second Edition -Section 3.7, Page 48- has been simulated. The following assumptions are made:

1.  Maximum number of jobs coming in a day is not more than 25.
2.  All unfinished jobs will be transferred to the next day.
3. The clerk  takes a five minutes break if, at the time he finishes a job, it is an hour or more since he began work or since he last had a break. He works for 8 hours in a day ( i.e. 480 minutes). If the working time required to finish the last job crosses the closing hours, he will leave the office only after finishing it.
4.  Working time of any job is not more than 90 minutes.
5. Simulation can be done for any number of days as per the user's requirement

OUTPUT

The first column is the starting time (st) of a new job. Second column is the working time (wt) for that job. Third column is the finishing time (ft) of that job.Fourth column contains the cumulative time (ct) since work started or since the last break. Fifth column contains (job) the number of jobs yet to be finished after the last job.


#include < stdio.h >
#include < conio.h >
#include < math.h >
#include < stdlib.h >
void main()
  {
    int st=0,wt=0,ft=0,ct=0,job=0,day=1,j,k,idle=0;
    clrscr();
    printf("\n\nEnter the number of days to be processed\n\n");
    scanf("%d",&k);
    randomize();
    job=rand()%25;
    while(day<=k)
    {
     printf("\nDAY = %d\n\n",day);
     printf("Total number of jobs for  day %d=%d\n\n", day,job);
     while(job>0 && ft<=480)
  {
    wt=rand()%90;
    ft=st+wt;
    ct=ct+wt;
    job=job-1;
    printf("%d,  %d,  %d,  %d,  %d \n\n", st,wt,ft,ct,job);
    if(ct>=60)
    ct=0;
    st=ft;
    if(ct==0)
    st=st+5;
    if(st>=480)
    break;
  }

printf("Number of jobs unattended on  day %d = %d\n\n",day,job);
if (ft<=480)
idle=idle+(480-ft);
day=day+1;
j=rand()%25;
if(day<=k)
printf("Number of new jobs on day %d=%d\n\n",day,j);
job=job+j;
st=0;
wt=0;
ft=0;
ct=0;
getch();
    }
   printf("Total number of jobs pending after %d days=%d \n\n",day-1,job-j);
   printf("Total idle time = %d\n\n",idle);
   getch();
  }



OUTPUT


 Enter the number of days to be processed

5

DAY = 1

Total number of jobs for  day 1=24

0,  81,  81,  81,  23

86,  58,  144,  58,  22

144,  15,  159,  73,  21

164,  31,  195,  31,  20

195,  82,  277,  113,  19

282,  72,  354,  72,  18

359,  89,  448,  89,  17

453,  9,  462,  9,  16

462,  7,  469,  16,  15

469,  74,  543,  90,  14

Number of jobs unattended on  day 1 = 14

Number of new jobs on day 2=3


DAY = 2

Total number of jobs for  day 2=17

0,  75,  75,  75,  16

80,  85,  165,  85,  15

170,  18,  188,  18,  14

188,  53,  241,  71,  13

246,  30,  276,  30,  12

276,  36,  312,  66,  11

317,  56,  373,  56,  10

373,  67,  440,  123,  9

445,  75,  520,  75,  8

Number of jobs unattended on  day 2 = 8

Number of new jobs on day 3=20


DAY = 3

Total number of jobs for  day 3=28

0,  21,  21,  21,  27

21,  82,  103,  103,  26

108,  1,  109,  1,  25

109,  45,  154,  46,  24

154,  73,  227,  119,  23

232,  3,  235,  3,  22

235,  76,  311,  79,  21

316,  11,  327,  11,  20

327,  71,  398,  82,  19

403,  10,  413,  10,  18

413,  11,  424,  21,  17

424,  84,  508,  105,  16

Number of jobs unattended on  day 3 = 16

Number of new jobs on day 4=6


DAY = 4

Total number of jobs for  day 4=22

0,  32,  32,  32,  21

32,  77,  109,  109,  20

114,  4,  118,  4,  19

118,  47,  165,  51,  18

165,  35,  200,  86,  17

205,  8,  213,  8,  16

213,  1,  214,  9,  15

214,  55,  269,  64,  14

274,  66,  340,  66,  13

345,  81,  426,  81,  12

431,  84,  515,  84,  11

Number of jobs unattended on  day 4 = 11

Number of new jobs on day 5=10


DAY = 5

Total number of jobs for  day 5=21

0,  28,  28,  28,  20

28,  34,  62,  62,  19

67,  61,  128,  61,  18

133,  84,  217,  84,  17

222,  61,  283,  61,  16

288,  36,  324,  36,  15

324,  17,  341,  53,  14

341,  17,  358,  70,  13

363,  32,  395,  32,  12

395,  27,  422,  59,  11

422,  37,  459,  96,  10

464,  28,  492,  28,  9

Number of jobs unattended on  day 5 = 9

Total number of jobs pending after 5 days=9

Total idle time = 0



No comments: