Real Time and Transition Priorities in CPN Tools
This post has 452 words. Reading it will take approximately 2 minutes.
loading...
Some months ago, Eric Verbeek and I worked together on adding a couple features to CPN Tools with the primary focus of getting Eric started with maintaining CPN Tools. Today I released a new version of CPN Tools with those features, namely real time stamps and transition priorities. See the demo here:
Note that whenever I mention resources p and q in the first example, I really mean processes p and q. The resources are named R, S, and T.
Just to make it painfully clear: Real time: real, wall clock time/star trek time/bullshit time: fake, transition priorities: real. If you are interested, below is the code I used to generate the fake time stamps using Access/CPN:
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import dk.au.daimi.ascoveco.cpn.engine.highlevel.HighLevelSimulator;
import dk.au.daimi.ascoveco.cpn.engine.proxy.ProxyDaemon;
import dk.au.daimi.ascoveco.cpn.engine.proxy.ProxySimulator;
public class SillyTime {
private static final String[] approx = new String[] { "1", "2",
"Threeish", "Four, I think", "Five or six",
"Not too many", "Not too many", "Think it's about ten",
"Think it's about ten", "Think it's about ten",
"Lost count several steps ago",
"Lost count several steps ago",
"Lost count several steps ago", "Lets say it's 37",
"Lets say it's 37", "Fifty?", "Fifty?",
"Over nine thousaaand!" };
public static void main(final String[] args) throws Exception {
System.out.println("Starting proxy");
final ProxyDaemon pd = ProxyDaemon.getDefaultInstance();
while (true) {
System.out.println("Waiting for CPN Tools");
final ProxySimulator ps = pd.getNext();
System.out.println("Waiting for syntax check");
while (ps.getPetriNet() == null) Thread.sleep(500);
new Thread() {
public void run() {
final HighLevelSimulator simulator = ps.getSimulator();
try {
simulator.evaluate("val SILLY'step = ref \"nothing\";"
+ "fun setWallClockTime() = (SILLY'step := \"wall\");"
+ "fun setInternationalTime() = (SILLY'step := \"star\");"
+ "fun setApproximateTime() = (SILLY'step := \"approx\")");
int last = -1, count = 0;
final Random r = new Random();
while (true) {
final String result = simulator.evaluate("!SILLY'step");
int level = last;
if (result.indexOf("wall") >= 0) level = 1;
if (result.indexOf("star") >= 0) level = 2;
if (result.indexOf("approx") >= 0) level = 3;
count++;
if (level != last) count = 0;
last = level;
if (level == 1) {
simulator.execute();
final SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
final String s = formatter.format(new Date());
simulator.refreshViews(s + " CEDT", simulator.getStep());
}
if (level == 2) {
simulator.execute();
final int main = r.nextInt(10000) + 40000;
final int minor = r.nextInt(10);
simulator.refreshViews("Stardate " + main + "." + minor, simulator.getStep());
}
if (level == 3) {
simulator.execute();
simulator.refreshViews(
approx[Math.min(count, approx.length - 1)],
simulator.getStep());
}
Thread.sleep(1000);
}
} catch (final Exception e) {
}
}
}.start();
}
}
}
Real Time and Transition Priorities in CPN Tools,









