This example will show how a function can be used to define and simulate a number of different configurations of a model.
This net can be found in <cpntoolsdir>/Samples/QueueSystem/QueueSystemConfigs.cpn where <cpntoolsdir> is the directory in which CPN Tools is installed.
The net can also be downloaded here.
It is often necessary to analyze and compare the behavior of different configurations of a model. It is always possible to change the configuration of a model by manually editing declarations, net structure, and/or net inscriptions. However, it can be quite time consuming to make manual changes to a model, particularly if the changes require that a syntax check has to be done for large parts of the model, and/or if many different configurations have to be defined and investigated.
In the Queue system example, there are several model parameters that affect the behavior of the system, including:
In this example, we will consider model configurations in which the distribution of inter-arrival times and the queuing strategy will not be changed. As for the Queue system example example net, the inter-arrival times for jobs is exponentially distributed with a mean inter-arrival time of 100 time units, and the queuing strategy is first-in-first-out (FIFO).
In contrast to the Queue system example example net, this example will geared towards investigating model configurations in which the following parameters vary: the number of servers, the average processing time, and the probability distribution of processing times. Each configuration will have either one server with relatively fast processing times, or two servers with slower processing times. And the processing times will be either exponentially distributed or uniformly distributed integers.
Many of the declarations for this net are the same as the net for the Queue system example. The following declarations are unique for this example, and they are briefly explained below.
colset ProcDist = with DISCRETE | EXP; globref num_of_servers = 4; globref avg_proc_time = 360; globref procdist = EXP; fun initServers() = (!num_of_servers)`server; fun genProcTime() = case !procdist of EXP => expTime(!avg_proc_time) | DISCRETE => discrete (!avg_proc_time - 10, !avg_proc_time + 10) fun simulateConfigs(n:int) = let fun setOneServer() = (num_of_servers:=1; avg_proc_time:=90) fun setTwoServers() = (num_of_servers:=2; avg_proc_time:=180) in procdist := EXP; setOneServer(); CPN'Replications.nreplications n; setTwoServers(); CPN'Replications.nreplications n; procdist := DISCRETE; setOneServer(); CPN'Replications.nreplications n; setTwoServers(); CPN'Replications.nreplications n end
Values from the
The reference variables
It is important to note that the contents of the reference variables are never changed when transitions occur in the model. The values of these variables should only be changed immediately before a simulation is started.
This model contains 3 pages with net structure: System, Arrivals, and Server. The System and Arrivals pages are the same as in the Queue system example example.
The Server page for this example is somewhat different than the Server page in the Queue system example example, and it looks like this:
The Init place and transition are used to initialize the number of servers represented in the system. These nodes are used for technical reasons, as described in the help page for model parameters. The Init transition is only enabled at the beginning of a simulation, and it can only occur once during a simulation. When it occurs, the
Four monitors have been defined for the model:
The Queue Length monitor is a list length data collector monitor that measures the length of the list on place Queue. This monitor is similar to the List_length_dc_System'Queue_1 monitor described on the help page for Queue system queue length.
The Queue Delay monitor is a generic data collector monitor that measures the amount of time that a job spent in a queue. Queue delay is measured each time the Start transition occurs. This monitor is the same as the Queue Delay monitor described on the help page for Queue system queue delay.
The ParameterValues monitor is a write-in-file monitor. It will update a file once during a simulation when the Init transition on the Server page occurs. The monitor's observation function is defined to generate a string containing information about the current values of the three reference variables:
fun obs (bindelem) = "Number of servers: "^(Int.toString(!num_of_servers))^ "\nAverage processing time: "^(Int.toString(!avg_proc_time))^ "\nDistribution of processing times: "^ProcDist.mkstr(!procdist)
The One Hundred Queue Delays monitor is a breakpoint monitor that is defined to stop a simulation after 100 jobs have been removed from the queue. This monitor is similar to the OneHundred_QueueDelays monitor described on the help page for Queue System Miscellaneous Monitors.
Simulations of each of these four configurations can be run by applying the Evaluate ML tool to an auxiliary text containing a CPN ML expression that calls the