Dining Philosophers
Dining Philosophers example that allows you to draw the state-space using low-level functions Examples


Purpose of this Example

This example assumes that you have gone through the Hello World example.

The Model

For a description of the model, please refer to the description in CPN Tools' help pages.

The model has not been altered, but a page with queries has been added , which can be used to draw the state-space once calculated.

dining_philosophers_screenshot.gif

Declarations

dining_philosophers_declarations.gif

The only thing differing from the Hello World example is that we create an instance of the Graph object rather than the GetString and ShowString objects.

Queries

dining_philosophers_queries.gif

The Queries page contains 4 queries.

The EvalAllNodes and EvalAllArcs functions evaluate a function for all nodes/arcs in the state-space (refer to CPN Tools' state-space manual chapter 5 for more information).

We can create a new node in the Graph by calling createNode with the name of the new node. We compose this function with st_Node, which give a textual representation of a node. All in all the parameter to ''"EvalAllNodes"" is a function that, given a node from the state-space, creates a node in the Graph named by a textual representation of the state-space node.

Similarily, createArc creates an arc between two nodes (given their name) with a custom label, which is given as the third parameter (in this case the empty string).

The third query allows you to automatically layout the graph, and the fourth query allows you to export the graph in a format loadable by Graphviz.

Simulation

dining_philosophers_viewer1.gif dining_philosophers_2.gif dining_philosophers_3.gif dining_philosophers_layout.gif dining_philosophers_4.gif dining_philosophers_5.gif dining_philosophers_export.gif

Download

Next Step

You should now take a look at the Distributed Database example, which uses more highlevel functions.

Version 16, Mon 12 Jun 2006 13:14:16 [tveon] - created Tue 20 Jul 2004 09:06:29 [mw]