Tips'n'Tricks
Binding of Variables in SimulatorA CPN variable which cannot be bound from the values of input token, guard, or output patterns can be expanded - all values are tried out - if at least one of the following conditions are fulfilled:
CPN'ExpandLimit := 500; re 2) If the color set has a finite number of elements you can declare ms. The following color sets are finite:
Random Value GeneratorsThere exist several techniques for getting random values in Design/CPN.
How to Speed Up Your Syntax CheckWhen you change a declaration in the Global Declaration Node of a CPN diagram, Design/CPN 3.0 must recheck and reswitch the entire diagram from scratch. To save time you can use the Temporary Declaration Node and the ML Evaluate command.The Temporary Declaration Node allow you to add new declarations to your CPN diagram without rechecking and reswitching the entire diagram. This is, e.g., very useful if you want to add a NEW colour set or a variable/function which you forgot. When the contents of the Temporary Declaration Node becomes to large it is time to move the most stable declarations into the Global Declaration Node. See also Trouble with the Declaration Nodes on the Common Problems page. The ML Evaluate command allows you to evaluate Standard ML code in your diagram. The Standard ML code is usually written in an auxiliary node, but it ML Evaluate can also be used for arc expressions and guards (provided that you give the variables a value before you evaluate the net inscriptions). ML Evaluate is excellent for making complex ML code. It allows you to syntax check and debug ML code, without changing the Global Declaration Node, i.e., without making a full recheck and reswitch. This means that you can save a lot of time, because errors can be detected and corrected in seconds. Like Temporary Declaration Nodes you should use ML Evaluate with great care. NEVER use ML Evaluate to change an existing declaration (Design/CPN will NOT recheck and reswitch the net inscriptions where the declaration is used). If you make a syntax check from scratch, the results of using ML Evaluate is lost, and hence you must reevaluate the declarations which you made by means of ML Evaluate It can often be difficult, even for experienced users, to find when it is safe to use Temporary Declaration Nodes and the ML Evaluate command. If your model starts to "behave strange", we recommend to move everything from the Temporary Declaration Node and everything which you declared by means of ML Evaluate into the Global Declaration Node and make a new syntax check and switch -- from scratch. Overlay GraphicsIt is possible to create a special diagram page, the so called Master page, where its graphics will appear on every printed page. Furthermore, there are simple macros for printing out the page name, page number, date, and time on each page. This is useful if you wish to have, e.g., a fancy header on every page printed. (The graphics on the Master page is not visible in the Design/CPN editor, only on printed pages.)A Master page is created as follows:
Page <<p>> Name <<n>> Date <<d>> Time <<t>>On each printed page you will now see the current page number, page name, date, and timestamp. Note that on the Mac "<<" and ">>" are each one single character. The Backup Diagram FilesWhen Design/CPN saves a diagram, a number of backup files are created in order to handle fatal situations during a save (e.g., crash or full disk). Assume that you save a diagram and name it "myDiagram". When save is done, successful or not, then the following situations are possible:
The table column "Recovery files" shows which files you need in order to recover the old version of the diagram. E.g., if recovery is "myDiagram.tmp" and "myDiagram.DB" (last row), then you need to rename "myDiagram.tmp" to "myDiagram" and "myDiagram.DB" to "myDiagram.DB" (i.e., do nothing), because a diagram consists of a graphics part ("myDiagram") and a database part ("myDiagram.DB"). | ||||||||||||||||
How to Produce PostScript OutputThis tip is for UNIX users. On the Macintosh you just need check the option "Print to File" which is standard in most print dialogs.
Instead of printing your diagram on a PostScript printer
you can create a PostScript file of your diagram. The shell environment
variable called setenv DesignPrintCommand "cat > /users/foo/CPNPrintOutput.ps"From the same shell window start Design/CPN (while running, the tool does not identify changes of the environment variables). The next time you print, the output will be saved in the file CPNPrintOutput.ps in your home directory.
You may wish to look through the
If you have "printed" only one diagram page, then the PostScript file can be
converted to Encapsulated Postscript by means of many different
utilities. One example is to use the Be careful that your diagram graphics is within the page boundary. Otherwise parts of your figure will be clipped (in normal output form). Arbitrary ML Data-types as Colour SetsThe colour set declarations of Design/CPN, as described in the reference manual, are a subset of Standard ML's types. Design/CPN does not support directly in the syntax, e.g., recursive types. However, if the user provides a few extra functions, it is possible to declare such advanced colour sets. In the following we describe what is required in order to use the full expressiveness of the Standard ML type declaration system.User declared advanced colour sets must fulfil the following requirements:
ran is used in interactive simulations when
binding free variables of a type with many elements. If neither
free variables of the type nor interactive simulations are used, then
just define a dummy ran function - remember that it still needs to be of the
type above.
Below find an example where the user declares an advanced colour set, which
is the recursive tree type, Contents of the global declaration node:
The colour set If a declare clause is added as:
color Tree = T with (my_lt, my_random, my_mkst_col)
declare ran,lt,mkst_col,mkst_ms;
then the following function names will be declared by Design/CPN and
made available for the user:
ran'Tree lt'Tree mkst_col'Tree mkst_ms'Tree CPN FAM Memory Usage on MacintoshAs there is no initial dynamic memory allocation for applications on the Macintosh it can sometimes be hard to determine the most appropriate application start-up memory size.For the Design/CPN ML engine on the Macintosh - the CPN FAM - it can especially be difficult as its memory usage is highly dependent on the complexity of the model. Often you may see the message "CPN FAM could not be started" or experience surprisingly slow simulations. If you have succeeded in starting the ML engine, e.g., for syntax checking or simulation, then you can look at the output from the CPN FAM in order to get indications about whether the CPN FAM needs more memory. To see this output you should bring the CPN FAM window to the front. Observer text that looks approximately as follows (generated by the garbage collector): [GC: [Using compacting GC] Marking...relocating...moving...72% (2186/3016 Kbytes) used. Space used (in bytes) States 64, Processes 48, Rec(1) 467656, Rec(2) 400404, Rec(N) 548784, Strings/Numbers 221592, Variants 177344, Bytecodes 327228, Stacks 96000]In this example the interesting number is "72%". If you see this number go above 90% it is a good indication of that you need to increase the memory size of the CPN FAM. In general we recommend that the CPN FAM should have at least 4-5000 kb - and more if available - typically 6-8000 kb. Identification of Page InstancesIn the CPN book of Jensen (volume 1) it is described how to use an ML-function,inst(), in order to identify a page instance.
Unfortunately, this function is not implemented in Design/CPN.
As an alternative, one can make a socket place on the super-page which contains an integer value. On the sub-page, the corresponding port node can be used to make a copy of the integer token, increment the value, and put the integer token back again on the port place. In this way, each instance of the sub-page will get a unique identifier value for further use. Instead of the port-socket technique, one can also use a global (or page) fusion place for the same purpose. One should just ensure that the page instances in question can access and update a shared value atomically. Deleting Arc-selection PointsYou probably already know that arc-selection points can be added by dragging a selection point on straight segments. (This holds also for connectors, polygons, and lines.) But how is an arc-selection point deleted? With the mouse pointer, select an arc-selection point and keep the button down while pressing the space bar on the keyboard. Then the currently selected point will disappear.How to Get Fresh DefaultsShould you need to reset you defaults you can always erase the file called ".CPNSettings" in your home directory (or system folder on the Mac). The next time you start Design/CPN you'll see the dialog message ".CPNSettings file not found (or unreadable). Create new .CPNSettings file?". If you press "OK" the tool will create a fresh CPNSettings file with reset defaults.Note that existing diagrams will not automatically inherit new defaults. If you need to transfer these defaults to your diagram you also have to load your diagram and then invoke Copy Defaults via the Set menu and then select System-> Diagram. Reading multi-sets from a fileTry the following example for reading multi-set parameters from a file (see also the Simple Protocol example):
Global declaration:
color MYCOLOR=with aa | bb | cc declare input_ms;
var result:MYCOLOR ms;
Code segment:
output result;
action
let
val infile=TextIO.openIn(DSFile_NameDialog
{prompt="Select file",
okButtonLabel="Load",
path="",
writeBox=false});
val message=input_ms'MYCOLOR(infile)
in
TextIO.closeIn(infile);
message
end handle _ => empty;
Input file:
% This is a comment which is ignored
1`aa++
2`bb++
5`cc
There are also functions for output of colours (token values) and multi-sets.
For more information see the online Reference Manual on page 37-9, 41-5, 41-8, and 41-9.
| ||||||||||||||||
Last modified: Tue Jun 3 09:57:10 2003 -- Design/CPN Online admin |