fixes non-deterministic selection of enabled transitions master
authorMike Becker <universe@uap-core.de>
Sun, 8 Dec 2019 10:10:46 +0000 (11:10 +0100)
committerMike Becker <universe@uap-core.de>
Sun, 8 Dec 2019 10:10:46 +0000 (11:10 +0100)
pom.xml
src/main/java/de/yasc/example/petrinet/Petrinet.java

diff --git a/pom.xml b/pom.xml
index 4c2b205..e4b00f0 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>de.yasc.example</groupId>
     <artifactId>petrinet</artifactId>
         <maven.compiler.source>11</maven.compiler.source>
         <maven.compiler.target>11</maven.compiler.target>
     </properties>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>exec-maven-plugin</artifactId>
+                <version>1.6.0</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>java</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <mainClass>de.yasc.example.petrinet.Main</mainClass>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>
\ No newline at end of file
index f8882f2..994a037 100644 (file)
@@ -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<Integer>();
         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]);
     }