From: Mike Becker Date: Sun, 8 Dec 2019 10:10:46 +0000 (+0100) Subject: fixes non-deterministic selection of enabled transitions X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=petrinet.git fixes non-deterministic selection of enabled transitions --- diff --git a/pom.xml b/pom.xml index 4c2b205..e4b00f0 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 de.yasc.example petrinet @@ -10,4 +11,23 @@ 11 11 + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + java + + + + + de.yasc.example.petrinet.Main + + + + \ No newline at end of file diff --git a/src/main/java/de/yasc/example/petrinet/Petrinet.java b/src/main/java/de/yasc/example/petrinet/Petrinet.java index f8882f2..994a037 100644 --- a/src/main/java/de/yasc/example/petrinet/Petrinet.java +++ b/src/main/java/de/yasc/example/petrinet/Petrinet.java @@ -74,7 +74,7 @@ public final class Petrinet { if (enabledTransitions.isEmpty()) { return false; } else { - transitions.get(prng.nextInt(enabledTransitions.size())).fire(); + enabledTransitions.get(prng.nextInt(enabledTransitions.size())).fire(); return true; } } @@ -92,7 +92,7 @@ public final class Petrinet { public Integer[] getMarking() { final var marking = new ArrayList(); for (int p = 0 ; p < places.length ; p++) { - Collections.nCopies(places[p].tokens, p).forEach(marking::add); + marking.addAll(Collections.nCopies(places[p].tokens, p)); } return marking.toArray(new Integer[0]); }