diff --git a/src/main/java/org/fujaba/graphengine/GraphEngine.java b/src/main/java/org/fujaba/graphengine/GraphEngine.java index 9aef7ff..4e96b9d 100644 --- a/src/main/java/org/fujaba/graphengine/GraphEngine.java +++ b/src/main/java/org/fujaba/graphengine/GraphEngine.java @@ -6,6 +6,8 @@ import java.util.ArrayList; import java.util.HashMap; +import org.fujaba.graphengine.algorithm.Algorithm; +import org.fujaba.graphengine.algorithm.adapter.AlgorithmAdapter; import org.fujaba.graphengine.graph.Graph; import org.fujaba.graphengine.graph.Node; import org.fujaba.graphengine.graph.adapter.GraphAdapter; @@ -102,7 +104,8 @@ public static Gson getGson() { .registerTypeAdapter(PatternNode.class, new PatternNodeAdapter()) .registerTypeAdapter(PatternGraph.class, new PatternGraphAdapter()) .registerTypeAdapter(NodeSortTree.class, new NodeSortTreeAdapter()) -// .setPrettyPrinting() + .registerTypeAdapter(Algorithm.class, new AlgorithmAdapter()) + .setPrettyPrinting() // .serializeNulls() .create(); } diff --git a/src/main/java/org/fujaba/graphengine/algorithm/Algorithm.java b/src/main/java/org/fujaba/graphengine/algorithm/Algorithm.java index 139b4dd..5dd7bf2 100644 --- a/src/main/java/org/fujaba/graphengine/algorithm/Algorithm.java +++ b/src/main/java/org/fujaba/graphengine/algorithm/Algorithm.java @@ -1,12 +1,20 @@ package org.fujaba.graphengine.algorithm; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; +import org.fujaba.graphengine.GraphEngine; import org.fujaba.graphengine.Match; import org.fujaba.graphengine.PatternEngine; import org.fujaba.graphengine.graph.Graph; import org.fujaba.graphengine.pattern.PatternGraph; +import com.google.gson.JsonIOException; +import com.google.gson.JsonSyntaxException; + public class Algorithm { private String name; @@ -21,9 +29,28 @@ public Algorithm(String name) { this.repeating = false; } + public static Algorithm loadFrom(String path) throws JsonSyntaxException, JsonIOException, FileNotFoundException { + return GraphEngine.getGson().fromJson(new FileReader(path), Algorithm.class); + } + + public Algorithm saveTo(String path) throws JsonIOException, IOException { + FileWriter fw = new FileWriter(path); + GraphEngine.getGson().toJson(this, fw); + fw.flush(); + fw.close(); + return this; + } + public Application process(Graph input) { Graph output = input; if (atomicAlgorithm != null) { + +// String test = GraphEngine.getGson().toJson(atomicAlgorithm); +// System.err.println(test); +// PatternGraph testPG = GraphEngine.getGson().fromJson(test, PatternGraph.class); +// test = GraphEngine.getGson().toJson(testPG); +// System.err.println(test + "\n"); + while (true) { ArrayList matches = PatternEngine.matchPattern(output, atomicAlgorithm, true); if (matches.size() > 0) { @@ -105,5 +132,9 @@ public Algorithm setRepeating(boolean repeating) { this.repeating = repeating; return this; } + + public String toString() { + return GraphEngine.getGson().toJson(this); + } } diff --git a/src/main/java/org/fujaba/graphengine/algorithm/adapter/AlgorithmAdapter.java b/src/main/java/org/fujaba/graphengine/algorithm/adapter/AlgorithmAdapter.java new file mode 100644 index 0000000..3b61f72 --- /dev/null +++ b/src/main/java/org/fujaba/graphengine/algorithm/adapter/AlgorithmAdapter.java @@ -0,0 +1,70 @@ +package org.fujaba.graphengine.algorithm.adapter; + +import java.io.IOException; + +import org.fujaba.graphengine.GraphEngine; +import org.fujaba.graphengine.algorithm.Algorithm; +import org.fujaba.graphengine.pattern.PatternGraph; +import org.fujaba.graphengine.pattern.adapter.PatternGraphAdapter; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +public class AlgorithmAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Algorithm algorithm) throws IOException { + PatternGraphAdapter patternGraphAdapter = new PatternGraphAdapter(); + out.beginObject(); + out.name("name").value(algorithm.getName()); + if (algorithm.isRepeating()) { + out.name("repeating").value(algorithm.isRepeating()); + } + if (algorithm.getAtomicAlgorithm() != null) { +// out.name("atomic").value(GraphEngine.getGson().toJson(algorithm.getAtomicAlgorithm())); + out.name("atomic"); + patternGraphAdapter.write(out, algorithm.getAtomicAlgorithm()); + } + if (algorithm.getAlgorithmSteps().size() > 0) { + out.name("steps"); + out.beginArray(); + for (Algorithm subAlgorithm: algorithm.getAlgorithmSteps()) { + write(out, subAlgorithm); + } + out.endArray(); + } + out.endObject(); + } + + @Override + public Algorithm read(JsonReader in) throws IOException { + PatternGraphAdapter patternGraphAdapter = new PatternGraphAdapter(); + final Algorithm algorithm = new Algorithm(""); + in.beginObject(); + while (in.hasNext()) { + switch (in.nextName()) { + case "name": + algorithm.setName(in.nextString()); + break; + case "repeating": + algorithm.setRepeating(in.nextBoolean()); + break; + case "atomic": +// algorithm.setAtomicAlgorithm(GraphEngine.getGson().fromJson(in.nextString(), PatternGraph.class)); + algorithm.setAtomicAlgorithm(patternGraphAdapter.read(in)); + break; + case "steps": + in.beginArray(); + while (in.hasNext()) { + algorithm.addAlgorithmStep(read(in)); + } + in.endArray(); + break; + } + } + in.endObject(); + return algorithm; + } + +} diff --git a/src/main/java/org/fujaba/graphengine/pattern/adapter/PatternGraphAdapter.java b/src/main/java/org/fujaba/graphengine/pattern/adapter/PatternGraphAdapter.java index a030c03..dbf7e06 100644 --- a/src/main/java/org/fujaba/graphengine/pattern/adapter/PatternGraphAdapter.java +++ b/src/main/java/org/fujaba/graphengine/pattern/adapter/PatternGraphAdapter.java @@ -149,7 +149,7 @@ public PatternGraph readWithManager(JsonReader in, IdManager idManager) throws I } } } - attribute.setValue(in.nextString()); +// attribute.setValue(in.nextString()); break; } } @@ -165,26 +165,28 @@ public PatternGraph readWithManager(JsonReader in, IdManager idManager) throws I edgesToBuildAction.put(sourceId, new HashMap>()); while (in.hasNext()) { in.beginObject(); - PatternEdge edge = new PatternEdge().setSource(node); + String action = "=="; + String name = ""; + Long target = (long)-1; while (in.hasNext()) { switch (in.nextName()) { case "action": - edge.setAction(in.nextString()); + action = in.nextString(); break; case "name": - edge.setName(in.nextString()); + name = in.nextString(); break; case "target": - edge.setTarget((PatternNode)idManager.getObject(in.nextLong())); + target = in.nextLong(); break; } } - if (!edgesToBuild.get(sourceId).containsKey(edge.getName())) { - edgesToBuild.get(sourceId).put(edge.getName(), new ArrayList()); - edgesToBuildAction.get(sourceId).put(edge.getName(), new ArrayList()); + if (!edgesToBuild.get(sourceId).containsKey(name)) { + edgesToBuild.get(sourceId).put(name, new ArrayList()); + edgesToBuildAction.get(sourceId).put(name, new ArrayList()); } - edgesToBuild.get(sourceId).get(edge.getName()).add(idManager.getId(edge.getTarget())); - edgesToBuildAction.get(sourceId).get(edge.getName()).add(edge.getAction()); + edgesToBuild.get(sourceId).get(name).add(target); + edgesToBuildAction.get(sourceId).get(name).add(action); in.endObject(); } in.endArray(); diff --git a/src/main/resources/ttc2017-state-task-main.algorithm.yage.json b/src/main/resources/ttc2017-state-task-main.algorithm.yage.json new file mode 100644 index 0000000..efe0366 --- /dev/null +++ b/src/main/resources/ttc2017-state-task-main.algorithm.yage.json @@ -0,0 +1,876 @@ +{ + "name": "TTC 2017 State Case", + "steps": [ + { + "name": "prepare data", + "steps": [ + { + "name": "GTR: new initial state", + "atomic": { + "name": "new initial state", + "nodes": [ + { + "expression": "#{initial}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "-", + "name": "initial" + } + ], + "edges": [] + }, + { + "action": "+", + "id": 1, + "attributes": [ + { + "action": "+", + "name": "newInitial", + "value": true + } + ], + "edges": [ + { + "action": "+", + "name": "ε", + "target": 0 + } + ] + }, + { + "expression": "#{newInitial}", + "action": "!\u003d", + "id": 2, + "attributes": [], + "edges": [] + } + ] + } + }, + { + "name": "GTR: adding to the existing new initial state", + "repeating": true, + "atomic": { + "name": "adding to the existing new initial state", + "nodes": [ + { + "expression": "#{initial}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "-", + "name": "initial" + } + ], + "edges": [] + }, + { + "expression": "#{newInitial}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "+", + "name": "ε", + "target": 0 + } + ] + } + ] + } + }, + { + "name": "GTR: new final state", + "atomic": { + "name": "new final state", + "nodes": [ + { + "expression": "#{final}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "-", + "name": "final" + } + ], + "edges": [ + { + "action": "+", + "name": "ε", + "target": 1 + } + ] + }, + { + "action": "+", + "id": 1, + "attributes": [ + { + "action": "+", + "name": "newFinal", + "value": true + } + ], + "edges": [] + }, + { + "expression": "#{newFinal}", + "action": "!\u003d", + "id": 2, + "attributes": [], + "edges": [] + } + ] + } + }, + { + "name": "GTR: adding to the existing new final state", + "repeating": true, + "atomic": { + "name": "adding to the existing new final state", + "nodes": [ + { + "expression": "#{final}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "-", + "name": "final" + } + ], + "edges": [ + { + "action": "+", + "name": "ε", + "target": 1 + } + ] + }, + { + "expression": "#{newFinal}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [] + } + ] + } + }, + { + "name": "GTR: merge multiple labels between the same two nodes", + "repeating": true, + "atomic": { + "name": "merge multiple labels between the same two nodes", + "nodes": [ + { + "action": "\u003d\u003d", + "id": 0, + "attributes": [], + "edges": [ + { + "action": "-", + "name": "#{x}, #{y}", + "target": 1 + }, + { + "action": "+", + "name": "#{x} + \u0027+\u0027 + #{y}", + "target": 1 + } + ] + }, + { + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [] + } + ] + } + } + ] + }, + { + "name": "eliminate state", + "repeating": true, + "steps": [ + { + "name": "GTR: mark state for elimination", + "atomic": { + "name": "mark state for elimination", + "nodes": [ + { + "action": "\u003d\u003d", + "id": 0, + "attributes": [], + "edges": [] + }, + { + "expression": "!(#{newFinal} || #{newInitial} || #{eliminate})", + "action": "\u003d\u003d", + "id": 1, + "attributes": [ + { + "action": "+", + "name": "eliminate", + "value": true + } + ], + "edges": [] + }, + { + "action": "\u003d\u003d", + "id": 2, + "attributes": [], + "edges": [] + }, + { + "expression": "#{eliminate}", + "action": "!\u003d", + "id": 3, + "attributes": [], + "edges": [] + } + ] + } + }, + { + "name": "handle source node", + "repeating": true, + "steps": [ + { + "name": "GTR: mark current working state (p-\u003ek-\u003eq)", + "atomic": { + "name": "mark current working state (p-\u003ek-\u003eq)", + "nodes": [ + { + "expression": "#{current}", + "action": "!\u003d", + "id": 0, + "attributes": [], + "edges": [] + }, + { + "expression": "!(#{current}) \u0026\u0026 !(#{past})", + "action": "\u003d\u003d", + "id": 1, + "attributes": [ + { + "action": "+", + "name": "current", + "value": true + } + ], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{a}", + "target": 2 + } + ] + }, + { + "expression": "#{eliminate} \u003d\u003d 1", + "action": "\u003d\u003d", + "id": 2, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{b}", + "target": 3 + } + ] + }, + { + "action": "\u003d\u003d", + "id": 3, + "attributes": [], + "edges": [] + } + ] + } + }, + { + "name": "GTR: mark current working state (p\u003c-\u003ek)", + "atomic": { + "name": "mark current working state (p\u003c-\u003ek)", + "nodes": [ + { + "expression": "#{current}", + "action": "!\u003d", + "id": 0, + "attributes": [], + "edges": [] + }, + { + "expression": "!(#{current}) \u0026\u0026 !(#{past})", + "action": "\u003d\u003d", + "id": 1, + "attributes": [ + { + "action": "+", + "name": "current", + "value": true + } + ], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{a}", + "target": 2 + } + ] + }, + { + "expression": "#{eliminate} \u003d\u003d 1", + "action": "\u003d\u003d", + "id": 2, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{b}", + "target": 1 + } + ] + } + ] + } + }, + { + "name": "redirect route", + "repeating": true, + "steps": [ + { + "name": "GTR: prepare elimination of state (with pq, pk, kk, kq)", + "repeating": true, + "atomic": { + "name": "prepare elimination of state (with pq, pk, kk, kq)", + "nodes": [ + { + "expression": "#{current}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{pk}", + "target": 1 + }, + { + "action": "-", + "name": "#{pq}", + "target": 2 + }, + { + "action": "+", + "name": "\u0027(\u0027 + #{pq} + \u0027)+((\u0027 + #{pk} + \u0027)(\u0027 + #{kk} + \u0027)*(\u0027 + #{kq} + \u0027))\u0027", + "target": 2 + } + ] + }, + { + "expression": "#{eliminate}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{kq}", + "target": 2 + }, + { + "action": "\u003d\u003d", + "name": "#{kk}", + "target": 1 + } + ] + }, + { + "expression": "!(#{used})", + "action": "\u003d\u003d", + "id": 2, + "attributes": [ + { + "action": "+", + "name": "used", + "value": true + } + ], + "edges": [] + } + ] + } + }, + { + "name": "GTR: prepare elimination of state (with just pk, kk, kq)", + "repeating": true, + "atomic": { + "name": "prepare elimination of state (with just pk, kk, kq)", + "nodes": [ + { + "expression": "#{current}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{pk}", + "target": 1 + }, + { + "action": "+", + "name": "\u0027(\u0027 + #{pk} + \u0027)(\u0027 + #{kk} + \u0027)*(\u0027 + #{kq} + \u0027)\u0027", + "target": 2 + } + ] + }, + { + "expression": "#{eliminate}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{kk}", + "target": 1 + }, + { + "action": "\u003d\u003d", + "name": "#{kq}", + "target": 2 + } + ] + }, + { + "expression": "!(#{used})", + "action": "\u003d\u003d", + "id": 2, + "attributes": [ + { + "action": "+", + "name": "used", + "value": true + } + ], + "edges": [] + } + ] + } + }, + { + "name": "GTR: prepare elimination of state (with just pq, pk, kq)", + "repeating": true, + "atomic": { + "name": "prepare elimination of state (with just pq, pk, kq)", + "nodes": [ + { + "expression": "#{current}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{pk}", + "target": 1 + }, + { + "action": "-", + "name": "#{pq}", + "target": 2 + }, + { + "action": "+", + "name": "\u0027(\u0027 + #{pq} + \u0027)+((\u0027 + #{pk} + \u0027)(\u0027 + #{kq} + \u0027))\u0027", + "target": 2 + } + ] + }, + { + "expression": "#{eliminate}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{kq}", + "target": 2 + } + ] + }, + { + "expression": "!(#{used})", + "action": "\u003d\u003d", + "id": 2, + "attributes": [ + { + "action": "+", + "name": "used", + "value": true + } + ], + "edges": [] + } + ] + } + }, + { + "name": "GTR: prepare elimination of state (with just pk, kq)", + "repeating": true, + "atomic": { + "name": "prepare elimination of state (with just pk, kq)", + "nodes": [ + { + "expression": "#{current}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{pk}", + "target": 1 + }, + { + "action": "+", + "name": "\u0027(\u0027 + #{pk} + \u0027)(\u0027 + #{kq} + \u0027)\u0027", + "target": 2 + } + ] + }, + { + "expression": "#{eliminate}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{kq}", + "target": 2 + } + ] + }, + { + "expression": "!(#{used})", + "action": "\u003d\u003d", + "id": 2, + "attributes": [ + { + "action": "+", + "name": "used", + "value": true + } + ], + "edges": [] + } + ] + } + }, + { + "name": "GTR: prepare elimination of state (with pp, pk, kk, kp)", + "repeating": true, + "atomic": { + "name": "prepare elimination of state (with pp, pk, kk, kp)", + "nodes": [ + { + "expression": "#{current} \u0026\u0026 !(#{used})", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "+", + "name": "used", + "value": true + } + ], + "edges": [ + { + "action": "-", + "name": "#{pp}", + "target": 0 + }, + { + "action": "\u003d\u003d", + "name": "#{pk}", + "target": 1 + }, + { + "action": "+", + "name": "\u0027((\u0027 + #{pp} + \u0027)*((\u0027 + #{pk} + \u0027)(\u0027 + #{kk} + \u0027)*(\u0027 + #{kp} + \u0027))*)*\u0027", + "target": 0 + } + ] + }, + { + "expression": "#{eliminate}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{kk}", + "target": 1 + }, + { + "action": "\u003d\u003d", + "name": "#{kp}", + "target": 0 + } + ] + } + ] + } + }, + { + "name": "GTR: prepare elimination of state (with just pp, pk, kp)", + "repeating": true, + "atomic": { + "name": "prepare elimination of state (with just pp, pk, kp)", + "nodes": [ + { + "expression": "#{current} \u0026\u0026 !(#{used})", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "+", + "name": "used", + "value": true + } + ], + "edges": [ + { + "action": "-", + "name": "#{pp}", + "target": 0 + }, + { + "action": "\u003d\u003d", + "name": "#{pk}", + "target": 1 + }, + { + "action": "+", + "name": "\u0027((\u0027 + #{pp} + \u0027)*((\u0027 + #{pk} + \u0027)(\u0027 + #{kp} + \u0027))*)*\u0027", + "target": 0 + } + ] + }, + { + "expression": "#{eliminate}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{kp}", + "target": 0 + } + ] + } + ] + } + }, + { + "name": "GTR: prepare elimination of state (with just pk, kk, kp)", + "repeating": true, + "atomic": { + "name": "prepare elimination of state (with just pk, kk, kp)", + "nodes": [ + { + "expression": "#{current} \u0026\u0026 !(#{used})", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "+", + "name": "used", + "value": true + } + ], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{pk}", + "target": 1 + }, + { + "action": "+", + "name": "\u0027((\u0027 + #{pk} + \u0027)(\u0027 + #{kk} + \u0027)*(\u0027 + #{kp} + \u0027))*\u0027", + "target": 0 + } + ] + }, + { + "expression": "#{eliminate}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{kk}", + "target": 1 + }, + { + "action": "\u003d\u003d", + "name": "#{kp}", + "target": 0 + } + ] + } + ] + } + }, + { + "name": "GTR: prepare elimination of state (with just pk, kp)", + "repeating": true, + "atomic": { + "name": "prepare elimination of state (with just pk, kp)", + "nodes": [ + { + "expression": "#{current} \u0026\u0026 !(#{used})", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "+", + "name": "used", + "value": true + } + ], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{pk}", + "target": 1 + }, + { + "action": "+", + "name": "\u0027((\u0027 + #{pk} + \u0027)(\u0027 + #{kp} + \u0027))*\u0027", + "target": 0 + } + ] + }, + { + "expression": "#{eliminate}", + "action": "\u003d\u003d", + "id": 1, + "attributes": [], + "edges": [ + { + "action": "\u003d\u003d", + "name": "#{kp}", + "target": 0 + } + ] + } + ] + } + } + ] + }, + { + "name": "GTR: remove mark of current working state", + "atomic": { + "name": "remove mark of current working state", + "nodes": [ + { + "expression": "#{current}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "-", + "name": "current" + }, + { + "action": "+", + "name": "past", + "value": true + } + ], + "edges": [] + } + ] + } + }, + { + "name": "GTR: remove mark of used state", + "repeating": true, + "atomic": { + "name": "remove mark of used state", + "nodes": [ + { + "expression": "#{used}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "-", + "name": "used" + } + ], + "edges": [] + } + ] + } + } + ] + }, + { + "name": "GTR: eliminate state itself", + "atomic": { + "name": "eliminate state itself", + "nodes": [ + { + "expression": "#{eliminate}", + "action": "-", + "id": 0, + "attributes": [], + "edges": [] + } + ] + } + }, + { + "name": "GTR: remove mark of past working state", + "repeating": true, + "atomic": { + "name": "remove mark of past working state", + "nodes": [ + { + "expression": "#{past}", + "action": "\u003d\u003d", + "id": 0, + "attributes": [ + { + "action": "-", + "name": "past" + } + ], + "edges": [] + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/src/test/java/org/fujaba/graphengine/unitTests/TestTTCStateCase.java b/src/test/java/org/fujaba/graphengine/unitTests/TestTTCStateCase.java index eb4ebc2..78a865c 100644 --- a/src/test/java/org/fujaba/graphengine/unitTests/TestTTCStateCase.java +++ b/src/test/java/org/fujaba/graphengine/unitTests/TestTTCStateCase.java @@ -1,5 +1,6 @@ package org.fujaba.graphengine.unitTests; +import java.io.IOException; import java.util.ArrayList; import java.util.regex.Pattern; @@ -16,6 +17,8 @@ import org.junit.Assert; import org.junit.Test; +import com.google.gson.JsonIOException; + public class TestTTCStateCase { public static final String taskMainPath = "src/main/resources/ExperimentalData/testdata/emf/task-main/"; @@ -48,22 +51,30 @@ public class TestTTCStateCase { @Test public void testSolvingTTC2017StateEliminationCaseWithAlgorithm() { - Algorithm algorithmStateCaseTTC2017 = getStateCaseAlgorithmTTC2017(); +// Algorithm algorithmStateCaseTTC2017 = getStateCaseAlgorithmTTC2017(); + Algorithm algorithmStateCaseTTC2017 = null; + try { + String path = "src/main/resources/ttc2017-state-task-main.algorithm.yage.json"; + getStateCaseAlgorithmTTC2017().saveTo(path); + algorithmStateCaseTTC2017 = Algorithm.loadFrom(path); + } catch (Throwable t) { + t.printStackTrace(); + } for (String fileName: fileNamesTaskMain) { System.out.println("TTC2017 State Elimination: " + fileName + "..."); long beginTime = System.nanoTime(); Graph g = TTCStateCaseGraphLoader.load(taskMainPath + fileName); // get data // System.err.println(g); Graph result = algorithmStateCaseTTC2017.process(g).getOutput(); - long endTime = System.nanoTime(); -// System.err.println(result); - System.out.println("Done after " + ((endTime - beginTime) / 1e9) + " seconds."); String resultStringRaw = ""; for (String s: result.getNodes().get(0).getEdges().keySet()) { resultStringRaw = s; } String resultString = resultStringRaw.replaceAll(Pattern.quote("(ε)"), ""); - System.out.println(resultString + "\n"); + System.out.println(resultString); + long endTime = System.nanoTime(); +// System.err.println(result); + System.out.println("Done after " + ((endTime - beginTime) / 1e9) + " seconds.\n"); } }