From f0a68c73acc49e71cce979a693992641249eb65e Mon Sep 17 00:00:00 2001
From: apvrille <ludovic.apvrille@eurecom.fr>
Date: Thu, 11 Jan 2018 17:47:46 +0100
Subject: [PATCH] Another optimization of minimization

---
 ...croWaveOven_SafetySecurity_fullMethodo.xml |  6 +-
 src/main/java/ui/graph/AUTBlock.java          |  7 ++
 src/main/java/ui/graph/AUTGraph.java          | 18 +++--
 src/main/java/ui/graph/AUTPartition.java      | 73 +++++++++++--------
 src/main/java/ui/graph/AUTSplitter.java       | 11 +++
 5 files changed, 76 insertions(+), 39 deletions(-)

diff --git a/modeling/AVATAR/MicroWaveOven_SafetySecurity_fullMethodo.xml b/modeling/AVATAR/MicroWaveOven_SafetySecurity_fullMethodo.xml
index 120a55c16f..88478a23c6 100644
--- a/modeling/AVATAR/MicroWaveOven_SafetySecurity_fullMethodo.xml
+++ b/modeling/AVATAR/MicroWaveOven_SafetySecurity_fullMethodo.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 
-<TURTLEGMODELING version="0.99-beta4">
+<TURTLEGMODELING version="1.0beta">
 
 <Modeling type="Avatar Methodology" nameTab="Methodology" >
 <AvatarMethodologyDiagramPanel name="AVATAR_Methodology" minX="10" maxX="1400" minY="10" maxY="900" zoom="1.0" >
@@ -5281,7 +5281,7 @@ or by a maintenance station
 <MainCode value=""/>
 <MainCode value="}"/>
 <Optimized value="true" />
-<Validated value="" />
+<Validated value="ObserverProp1;RemotelyControlledMicrowave;RemoteControl;MicroWaveOven;Bell;ControlPanel;Controller;Magnetron;Door;WirelessInterface;" />
 <Ignored value="" />
 
 <CONNECTOR type="5002" id="2890" >
@@ -10109,7 +10109,7 @@ or by a maintenance station
 <MainCode value=""/>
 <MainCode value="}"/>
 <Optimized value="true" />
-<Validated value="" />
+<Validated value="ObserverProp1;RemotelyControlledMicrowave;MicroWaveOven;Door;Magnetron;Controller;ControlPanel;Bell;" />
 <Ignored value="" />
 
 <CONNECTOR type="5002" id="4993" >
diff --git a/src/main/java/ui/graph/AUTBlock.java b/src/main/java/ui/graph/AUTBlock.java
index b76a1bdb42..583de0e0c9 100755
--- a/src/main/java/ui/graph/AUTBlock.java
+++ b/src/main/java/ui/graph/AUTBlock.java
@@ -66,6 +66,13 @@ public class AUTBlock  implements Comparable<AUTBlock> {
         states.add(_st);
     }
 
+    public int getHashValue() {
+        if (!hashComputed) {
+            computeHash();
+        }
+        return hashValue;
+    }
+
 
     public String toString() {
         boolean first = true;
diff --git a/src/main/java/ui/graph/AUTGraph.java b/src/main/java/ui/graph/AUTGraph.java
index 326c6e1160..d0a2e458c6 100755
--- a/src/main/java/ui/graph/AUTGraph.java
+++ b/src/main/java/ui/graph/AUTGraph.java
@@ -40,7 +40,8 @@
 package ui.graph;
 
 import myutil.Conversion;
-import myutil.*;
+import myutil.DijkstraState;
+import myutil.GraphAlgorithms;
 import myutil.TraceManager;
 
 import java.io.BufferedReader;
@@ -1088,14 +1089,21 @@ public class AUTGraph implements myutil.Graph {
 
         int maxIte = 1000; // With same nb of partitions
         int nbOfPartitions = w.size();
-        int evolution = 10;
+        int evolution = 20;
+        int hashCode = -1;
 
         AUTPartition currentP;
         while ((w.size() > 0) && (maxIte > 0) && (evolution > 0)) {
+
+            int newHash = w.getHashCode();
+            if (newHash == hashCode) {
+                break;
+            }
+
             if (w.size() == nbOfPartitions) {
-                evolution --;
+                evolution--;
             } else {
-                evolution = 10;
+                evolution = 20;
             }
             nbOfPartitions = w.size();
             maxIte--;
@@ -1258,7 +1266,7 @@ public class AUTGraph implements myutil.Graph {
             }
         }
 
-        //TraceManager.addDev("\nAll done:\n---------");
+        TraceManager.addDev("\nAll done: it: " + maxIte + "\n---------");
         //printConfiguration(partition, w);
         //TraceManager.addDev("------------------");
 
diff --git a/src/main/java/ui/graph/AUTPartition.java b/src/main/java/ui/graph/AUTPartition.java
index 393ab58abf..1494c55a27 100755
--- a/src/main/java/ui/graph/AUTPartition.java
+++ b/src/main/java/ui/graph/AUTPartition.java
@@ -37,28 +37,28 @@
  */
 
 
-
-
 package ui.graph;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.LinkedList;
 
 /**
-   * Class AUTPartition
-   * Creation : 06/01/2017
-   ** @version 1.0 06/01/2017
-   * @author Ludovic APVRILLE
+ * Class AUTPartition
+ * Creation : 06/01/2017
+ * * @version 1.0 06/01/2017
+ *
+ * @author Ludovic APVRILLE
  */
-public class AUTPartition  {
+public class AUTPartition {
+
 
-    
     public ArrayList<AUTBlock> blocks;
     // Blocks are expected to be mutually exclusive
     // in terms of states they contain.
 
     public AUTPartition() {
-	blocks = new ArrayList<AUTBlock>();
+        blocks = new ArrayList<AUTBlock>();
     }
 
     public void addBlock(AUTBlock _bl) {
@@ -66,43 +66,54 @@ public class AUTPartition  {
     }
 
     public void addIfNonEmpty(AUTBlock _b) {
-	if (_b.size() > 0) {
-	    addBlock(_b);
-	}
+        if (_b.size() > 0) {
+            addBlock(_b);
+        }
     }
 
     public String toString() {
-	StringBuffer sb = new StringBuffer("");
-	for(AUTBlock block: blocks) {
-	    sb.append("(" + block.toString() + ")");
-	}
-	return sb.toString();
+        StringBuffer sb = new StringBuffer("");
+        for (AUTBlock block : blocks) {
+            sb.append("(" + block.toString() + ")");
+        }
+        return sb.toString();
     }
 
 
     // List of blocks that has a state that has an
     // output "elt" transition
     public LinkedList<AUTBlock> getI(AUTElement _elt, AUTBlock _b) {
-	LinkedList<AUTBlock> listI = new LinkedList<AUTBlock>();
-	for(AUTBlock b: blocks) {
-	    if (b.hasStateOf(_b)) {
-		listI.add(b);
-	    }
-	}
-	return listI;
+        LinkedList<AUTBlock> listI = new LinkedList<AUTBlock>();
+        for (AUTBlock b : blocks) {
+            if (b.hasStateOf(_b)) {
+                listI.add(b);
+            }
+        }
+        return listI;
     }
 
     public boolean removeBlock(AUTBlock _b) {
-	return blocks.remove(_b);
+        return blocks.remove(_b);
     }
 
     public AUTBlock getBlockWithState(int id) {
-	for(AUTBlock b: blocks) {
-	    if (b.hasState(id)) {
-		return b;
-	    }
-	}
-	return null;
+        for (AUTBlock b : blocks) {
+            if (b.hasState(id)) {
+                return b;
+            }
+        }
+        return null;
+    }
+
+    public int getHashCode() {
+        int []values = new int[blocks.size()];
+        int cpt = 0;
+        for(AUTBlock b: blocks) {
+            values[cpt] = b.getHashValue();
+            cpt ++;
+        }
+        return Arrays.hashCode(values);
+
     }
 
 
diff --git a/src/main/java/ui/graph/AUTSplitter.java b/src/main/java/ui/graph/AUTSplitter.java
index 16bd7f0e7e..a2c9fe6fc2 100755
--- a/src/main/java/ui/graph/AUTSplitter.java
+++ b/src/main/java/ui/graph/AUTSplitter.java
@@ -42,6 +42,7 @@
 package ui.graph;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 
 /**
    * Class AUTSplitter
@@ -74,5 +75,15 @@ public class AUTSplitter  {
 	return partitions.size();
     }
 
+    public int getHashCode() {
+        int[] values = new int[partitions.size()];
+        int cpt = 0;
+        for (AUTPartition p : partitions) {
+            values[cpt] = p.getHashCode();
+            cpt++;
+        }
+        return Arrays.hashCode(values);
+    }
+
 
 }
-- 
GitLab