My first program

 

The classic producer consumer system. When you start the Demos system (see the install guide) you will end up with a display that looks as follows:

 

At this point click on File->New and copy in the following program (right click edit->paste, or ctrl-v):

cons workI=1;               //1 second between arrivals*)
cons serviceI=0.5;          //time taken for service

bin(work,0);                //place for stuff

class workarr=
{repeat
 {hold(negexp(workI));      //interval between arrivals
  putB(work,1);             //put the work in a bin
 }
}

class server=
{repeat
 {getB(work,1);             //something to do?
  hold(negexp(serviceI));
 }
}

entity(a,workarr,0);       //start a work generator
entity(s,server,0);        //start a server
hold(500);                 //run for 500 seconds
close;                     //and relax

now pull down Execute->Run, various events will be in the scroll window and the system will stop with:

Now click on the Value button and the display will look as follows:

Left click on the text work (of work=0) and the text s of (s= 1), and you will get graphs showing the levels in the bin and the number of blocked servers. Also click the Dump button to get another copy of the overall statistics:

 

Now click Execute->Run again. As the numbers of work change try left click on the text, you will get something like the following.

If your screen gets overfull try pressing the Trace button twice (second time it will be labeled Value). Notice that the system executes significantly faster in the value mode. Click File->Save

Type in the name you want the file to have and ensure it is highlighted then press accept.

Things to try:

  1. change the values of aRR, or sRR and rerun;
  2. add a copy of the entity(s,server,0); and see what happens;
  3. add a copy the entity(a,worker,0); and see what happens;
  4. change the 500 to let the simulation run longer;
  5. try right clicking on the text label in the value mode.
  6. add the following
    cons servers=2;
    cons loaders=3;
    to the start of your program and replace the two entity commands with
    do servers {entity(s,server,0);}
    do loaders {entity(a,workarr,0);}
    and rerun the program as before;
  7. We want the bin to have limited capacity (say 10). So add
    bin(limit,10);
    after the bin definition and change the workarr class to
    {repeat{hold(arrival);getB(limit,1);putB(work,1);}}
    and the server class to
    {repeat{getB(work,1);hold(service);putB(limit,1);}}
    and run as before.
  8. After the constants at the start of the program add
     var done=0;
    and change the server class to the following: then run as before.
    {repeat{getB(work,1);
     hold(service);
     done:=done+1;
     trace("Work_done=%v",done);
     putB(limit,1);}}
    and run again. Is there anything strange about the various totals?