First open the "CSPN-Examples\Dinner of philosophers" folder.

Here you can see the components of the netclass. The net itself is stored inside the "Dinner of philosophers.MainPetriNet.vit".
The "Dinner of philosophers.Philosoph.vi" is a subnet inside the main-net. It is reentrant, and can be called several times with different subnet-names.

inheritance
The class has inherited from the "CSPN-NetControl" class. The name of the net is equivalent with the Objectname. The Possibility to instaniate a net twice, or more often exists. Here you simply have to change the objectname.

starting & control
For further advice create a CS-Object of the Net. Therefore you can use the ini.file, placed beside the class.
If you dont know how to create a CS-Object, check the CS-dokumentation first!!

Done? You should see the PetriNet Frontpanel now, already launched, with some controls, and 3 big buttons.
  • The left button "Shutdown Net" does a full cleanup...nothing from the net should be left, if pushed
  • The middle button keeps the control structures alive, and allows the user to edit the net "on the fly".
  • The right one does a pause to the net. All timers do a break and all Net-Objects stop communication. If pushed again the net will continue to work.

What does the net do? The net is a typical example for petri-nets. Three Philosophers are Sitting around a table. Between two of them, always one fork is available (so 3 forks overall). To start eating a philosopher needs two forks. In front of this fact, only one philosopher can eat, while the other two are thinking. The decision which one eats and which is thinking should be performed by the net randomly, so every philosopher gets the same chance to eat.
After eating some seconds, the philosopher drops back the forks, and the game starts once more.

where to edit a net?
Now push the "Stop serving for editing" button, and change to the block diagram.
  • In the second frame of the sequenze(index 1), you can see your PetriNet. The other frames are of minor intrest.
  • Inside the block diagram you can see the 3 forks as boolen places, and the 3 philosophers as sub-nets.
  • The forks are constant-boolean values.
  • open a philosoph sub net and switch to the blockdiagram (the second frame) to see the structure of an philosoph.
  • As expected, he needs two forks to switch to the "is eating" state. After 3 seconds he switchs back to "is thinking" automatically, driven by the timer.
  • If you want to use a subnet take the one inside the "CSPN-Tools" folder, and modify it, to your requirements.
  • On using subnets, you will recognize the direction of the controls of these subnets: All controls are inputs !! The reason for that is, that petri-nets are Biparit graphs. So I decidet to design them so. Transition have only input-ports and places only output Ports. This may confuse you at the beginning, but also prevent you from combining wrong connections inside the net.
  • As you can see there is no control-sequence, which regulates the order, in which the philosophers do eat. The net chooses them completly random (as random as possible, for a computer).

-- AlexanderSchwinn - 06 Aug 2007

This topic: CSframework > WebHome > ProjectsUsingCS > CSObjectNet > CsOnIntroduction > CSPetriNet > CSPNHowTo > Philosophers
Topic revision: 2007-08-07, AlexanderSchwinn
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback | Legal notice | Privacy Policy (german)