Skip to content

Commit

Permalink
#31 works flawlessly
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechp committed Mar 5, 2017
1 parent ecea91a commit 2075d80
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import org.fujaba.graphengine.GraphEngine;
import org.fujaba.graphengine.graph.Graph;
Expand Down Expand Up @@ -69,7 +70,26 @@ public Graph normalized(Graph graph) {
nodeSortTreesStrings.add(GraphEngine.getGson().toJson(nst));
}
ArrayList<String> nodeSortTreesCopyStrings = null;
ArrayList<ArrayList<NodeSortTree>> history = new ArrayList<ArrayList<NodeSortTree>>();
while (!nodeSortTreesStrings.equals(nodeSortTreesCopyStrings)) {
int loopCycleIndex = history.indexOf(nodeSortTrees);
if (loopCycleIndex == -1) {
history.add(nodeSortTrees);
} else {
// loop detected
// TODO: GET A SPECIFIC ONE!!!!
ArrayList<NodeSortTree> minList = null;
String minString = "";
for (ArrayList<NodeSortTree> currentList: history) {
// System.out.println(currentList.toString());
if (minList == null || currentList.toString().compareTo(minString) < 0) {
minList = currentList;
minString = currentList.toString();
}
}
nodeSortTrees = minList;
break;
}
nodeSortTreesCopyStrings = (ArrayList<String>)nodeSortTreesStrings.clone();
HashMap<String, ArrayList<NodeSortTree>> mapping = new HashMap<String, ArrayList<NodeSortTree>>();
for (NodeSortTree nst: nodeSortTrees) { // TODO: shouldn't this be done just once initially???
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,10 @@ public void setRootNodeSortTreeNode(NodeSortTreeNode rootNodeSortTreeNode) {
public int compareTo(NodeSortTree o) {
return GraphEngine.getGson().toJson(this).compareTo(GraphEngine.getGson().toJson(o));
}

@Override
public String toString() {
return GraphEngine.getGson().toJson(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;

import org.fujaba.graphengine.GraphEngine;
import org.fujaba.graphengine.graph.Node;

public class NodeSortTreeNode {
Expand Down
91 changes: 52 additions & 39 deletions src/test/java/org/fujaba/graphengine/unitTests/GraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public void testNormalizationNotDoingWickedStuff() {
hell12.addEdge("c", hell3);
hell.addNode(hell1, hell2, hell3, hell4, hell5, hell6, hell7, hell8, hell9, hell10, hell11, hell12);
ArrayList<Graph> hellishSubGraphs = new ArrayList<Graph>();
for (int i = 0; i < 1; ++i) {
for (int i = 0; i < 3; ++i) {
hellishSubGraphs.add(hell.clone());
}
hell.getNodes().clear();
Expand All @@ -566,49 +566,62 @@ public void testNormalizationNotDoingWickedStuff() {
}

// System.out.println();
// String lastSerialization = null;
// for (int i = 0; i < 100; ++i) {
// Collections.shuffle(a.getNodes());
// a = GraphEngine.normalized(a);
// if (lastSerialization == null) {
// lastSerialization = GraphEngine.getGson().toJson(a);
// } else {
// String currentSerialization = GraphEngine.getGson().toJson(a);
// Assert.assertEquals(lastSerialization, currentSerialization);
// lastSerialization = currentSerialization;
// }
String lastSerialization = null;
for (int i = 0; i < 100; ++i) {
Collections.shuffle(a.getNodes());
for (Node n: a.getNodes()) {
for (String key: n.getEdges().keySet()) {
Collections.shuffle(n.getEdges(key));
}
}
a = GraphEngine.normalized(a);
if (lastSerialization == null) {
lastSerialization = GraphEngine.getGson().toJson(a);
} else {
String currentSerialization = GraphEngine.getGson().toJson(a);
Assert.assertEquals(lastSerialization, currentSerialization);
lastSerialization = currentSerialization;
}
// System.out.println(lastSerialization);
// }
}
// System.out.println();
// lastSerialization = null;
// for (int i = 0; i < 100; ++i) {
// Collections.shuffle(b.getNodes());
// b = GraphEngine.normalized(b);
// if (lastSerialization == null) {
// lastSerialization = GraphEngine.getGson().toJson(b);
// } else {
// String currentSerialization = GraphEngine.getGson().toJson(b);
// Assert.assertEquals(lastSerialization, currentSerialization);
// lastSerialization = currentSerialization;
// }
lastSerialization = null;
for (int i = 0; i < 100; ++i) {
Collections.shuffle(b.getNodes());
for (Node n: b.getNodes()) {
for (String key: n.getEdges().keySet()) {
Collections.shuffle(n.getEdges(key));
}
}
b = GraphEngine.normalized(b);
if (lastSerialization == null) {
lastSerialization = GraphEngine.getGson().toJson(b);
} else {
String currentSerialization = GraphEngine.getGson().toJson(b);
Assert.assertEquals(lastSerialization, currentSerialization);
lastSerialization = currentSerialization;
}
// System.out.println(lastSerialization);
// }
//// System.out.println(GraphEngine.getGson().toJson(hell));
//// GraphEngine.prepareGraphAsJsonFileForSigmaJs(hell, "data.json");
}
// System.out.println();
// String lastSerialization = null;
// for (int i = 0; i < 1; ++i) {
// Collections.shuffle(hell.getNodes());
// hell = GraphEngine.normalized(hell);
// if (lastSerialization == null) {
// lastSerialization = GraphEngine.getGson().toJson(hell);
// } else {
// String currentSerialization = GraphEngine.getGson().toJson(hell);
//// Assert.assertEquals(lastSerialization, currentSerialization);
// lastSerialization = currentSerialization;
// }
lastSerialization = null;
for (int i = 0; i < 10; ++i) {
Collections.shuffle(hell.getNodes());
for (Node n: hell.getNodes()) {
for (String key: n.getEdges().keySet()) {
Collections.shuffle(n.getEdges(key));
}
}
hell = GraphEngine.normalized(hell);
if (lastSerialization == null) {
lastSerialization = GraphEngine.getGson().toJson(hell);
} else {
String currentSerialization = GraphEngine.getGson().toJson(hell);
Assert.assertEquals(lastSerialization, currentSerialization);
lastSerialization = currentSerialization;
}
// System.out.println(lastSerialization);
// }
}

}

Expand Down

0 comments on commit 2075d80

Please sign in to comment.