From fd0fe9f3aa5253f7636ab71995ff4e368f31cd1d Mon Sep 17 00:00:00 2001 From: hoechp Date: Tue, 30 May 2017 23:13:18 +0200 Subject: [PATCH] #36 i wish i had more time and all, but it's now 'ready', i guess... --- .../org/fujaba/graphengine/GraphEngine.java | 2 +- ...tc2017-state-task-main.algorithm.yage.json | 877 +--------------- .../{Evalution.java => TTCEvalution.java} | 58 +- .../unitTests/TestTTCStateCase.java | 971 +++++++++--------- 4 files changed, 505 insertions(+), 1403 deletions(-) rename src/test/java/org/fujaba/graphengine/unitTests/{Evalution.java => TTCEvalution.java} (59%) diff --git a/src/main/java/org/fujaba/graphengine/GraphEngine.java b/src/main/java/org/fujaba/graphengine/GraphEngine.java index 5a960f3..c081204 100644 --- a/src/main/java/org/fujaba/graphengine/GraphEngine.java +++ b/src/main/java/org/fujaba/graphengine/GraphEngine.java @@ -103,7 +103,7 @@ public static Gson getGson() { .registerTypeAdapter(PatternGraph.class, new PatternGraphAdapter()) .registerTypeAdapter(NodeSortTree.class, new NodeSortTreeAdapter()) .registerTypeAdapter(Algorithm.class, new AlgorithmAdapter()) - .setPrettyPrinting() +// .setPrettyPrinting() // .serializeNulls() .create(); } diff --git a/src/main/resources/ttc2017-state-task-main.algorithm.yage.json b/src/main/resources/ttc2017-state-task-main.algorithm.yage.json index efe0366..1ffb6a6 100644 --- a/src/main/resources/ttc2017-state-task-main.algorithm.yage.json +++ b/src/main/resources/ttc2017-state-task-main.algorithm.yage.json @@ -1,876 +1 @@ -{ - "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 +{"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/Evalution.java b/src/test/java/org/fujaba/graphengine/unitTests/TTCEvalution.java similarity index 59% rename from src/test/java/org/fujaba/graphengine/unitTests/Evalution.java rename to src/test/java/org/fujaba/graphengine/unitTests/TTCEvalution.java index 9883a4f..fc9e65a 100644 --- a/src/test/java/org/fujaba/graphengine/unitTests/Evalution.java +++ b/src/test/java/org/fujaba/graphengine/unitTests/TTCEvalution.java @@ -13,17 +13,17 @@ import org.fujaba.graphengine.stateelimination.TTCStateCaseGraphLoader; import org.junit.Test; -public class Evalution { +public class TTCEvalution { public static final String taskMainPath = "src/main/resources/ExperimentalData/testdata/emf/task-main/"; public static String positivePath = "src/main/resources/EvaluationFramework/testdata/acceptedWords/"; public static String negativePath = "src/main/resources/EvaluationFramework/testdata/notAcceptedWords/"; -// @Test + @Test public void evaluateResults() { - // the following already 'freezes' the CPU, because a long RegExp take its time... +// // the following already almost 'freezes' the CPU, because a long RegExp take its time... // String s1 = "s7s30s47s49s0s7s30s47s49s0s10s26s46s49s0s4s19s42s49s0s16s21s41s49s0s8s29s48s59"; // String s2 = "(((((((((((((((s1)(s17))(s33))(s49))|((((s10)(s26))(s46))(s49)))|((((s13)(s23))(s38))(s49)))|((((s7)(s30))(s47))(s49)))|((((s16)(s21))(s41))(s49)))|((((s4)(s19))(s42))(s49)))(s0))*)*(((((s6)(s32))(s35))(s53))(s0))*)*)*(((((s11)(s28))(s43))(s56))(s0))*)*)*(((((((((((((s2)(s18))(s34))(s50))(s60))|(((((s5)(s31))(s37))(s55))(s60)))|(((((s15)(s22))(s39))(s51))(s60)))|(((((s3)(s20))(s40))(s52))(s60)))|(((((s14)(s24))(s36))(s54))(s60)))|(((((s12)(s27))(s44))(s57))(s60)))|(((((s9)(s25))(s45))(s58))(s60)))|(((((s8)(s29))(s48))(s59))(s60)))(s60)*)"; // System.out.println(s1.matches(s2)); @@ -32,16 +32,16 @@ public void evaluateResults() { System.out.println("TTC2017 State Elimination: " + fileName + "..."); long beginTime = System.nanoTime(); Graph g = TTCStateCaseGraphLoader.load(taskMainPath + fileName); // get data - Graph result = TestTTCStateCase.solveGraph(g); // solve problem + Graph result = TestTTCStateCase.getStateCaseAlgorithmTTC2017().process(g).getOutput(); // solve problem long endTime = System.nanoTime(); - 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("(ε)"), ""); resultString = resultString.replaceAll(Pattern.quote("ε"), ""); - System.out.println(resultString + "\n"); + System.out.println(resultString); + System.out.println("Done after " + ((endTime - beginTime) / 1e9) + " seconds.\n"); String baseFileName = fileName.substring(0, fileName.length() - 4); @@ -69,9 +69,12 @@ private String testWords(String regex, String acceptedWordsFile, boolean accept) reader = new BufferedReader(new FileReader(acceptedWordsFile)); while((word = reader.readLine()) != null){ totalWords++; + long beginTime = System.nanoTime(); if (word.matches(regex) == accept) { + System.out.println("success after " + (System.nanoTime() - beginTime) / 1e6 + " ms"); passed++; } else { + System.out.println("failed after " + (System.nanoTime() - beginTime) / 1e6 + " ms"); System.err.println(word); System.err.println("did" + (accept ? "n't" : "") + " match"); System.err.println(regex); @@ -84,47 +87,4 @@ private String testWords(String regex, String acceptedWordsFile, boolean accept) return passed + "/" + totalWords; } - @Test - public void testStuff() { - // TODO: remove debug - PatternGraph pattern = getStochasticPrepareStateWithPqPkKkKqPattern(); - Graph graph = new Graph(); - Node p = new Node().setAttribute("current", true); - Node k = new Node().setAttribute("eliminate", true); - Node q = new Node(); - graph.addNode(p, k, q); - p.addEdge("a[0.2]", q); - p.addEdge("b[0.3]", k); - k.addEdge("c[0.5]", k); - k.addEdge("d[0.7]", q); - - Algorithm alg = new Algorithm("test"); - alg.addAlgorithmStep(pattern, false); - - graph = alg.process(graph).getOutput(); - - System.out.println(graph); - - } - - public static PatternGraph getStochasticPrepareStateWithPqPkKkKqPattern() { // #2.3.1 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with pq, pk, kk, kq)"); - PatternNode p = new PatternNode("#{current}"); - PatternNode k = new PatternNode("#{eliminate}"); - PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - gtr.addPatternNode(p, k, q); - /* CASE 1: there's pq, pk, kk and kq */ - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kq}", q); - k.addPatternEdge("==", "#{kk}", k); - p.addPatternEdge("-", "#{pq}", q); - - String extractedEdge = "substring(#{pq}, 0, indexOf(#{pq}, '[', length(#{pq}) - 5))"; - String extractedProb = "substring(#{pq}, indexOf(#{pq}, '[', length(#{pq}) - 5) + 1, length(#{pq}) - 1)"; - - p.addPatternEdge("+", "'(' + substring(#{pq}, 0, indexOf(#{pq}, '[', length(#{pq}) - 5)) + '[500])+((' + substring(#{pk}, 0, indexOf(#{pk}, '[', length(#{pk}) - 5)) + ')(' + substring(#{kk}, 0, indexOf(#{kk}, '[', length(#{kk}) - 5)) + ')*[' + substring(#{kk}, indexOf(#{kk}, '[', length(#{kk}) - 5) + 1, length(#{kk}) - 1) + '](' + substring(#{kq}, 0, indexOf(#{kq}, '[', length(#{kq}) - 5)) + ')[500])'", q); - return gtr; - } - } diff --git a/src/test/java/org/fujaba/graphengine/unitTests/TestTTCStateCase.java b/src/test/java/org/fujaba/graphengine/unitTests/TestTTCStateCase.java index d4c2a26..0d76898 100644 --- a/src/test/java/org/fujaba/graphengine/unitTests/TestTTCStateCase.java +++ b/src/test/java/org/fujaba/graphengine/unitTests/TestTTCStateCase.java @@ -1,14 +1,9 @@ package org.fujaba.graphengine.unitTests; -import java.util.ArrayList; import java.util.regex.Pattern; -import org.fujaba.graphengine.GraphEngine; -import org.fujaba.graphengine.Match; -import org.fujaba.graphengine.PatternEngine; import org.fujaba.graphengine.algorithm.Algorithm; import org.fujaba.graphengine.graph.Graph; -import org.fujaba.graphengine.graph.Node; import org.fujaba.graphengine.pattern.PatternAttribute; import org.fujaba.graphengine.pattern.PatternGraph; import org.fujaba.graphengine.pattern.PatternNode; @@ -18,24 +13,26 @@ public class TestTTCStateCase { + private static Algorithm algorithm = null; + private static Algorithm algorithmPrepare = null; public static final String taskMainPath = "src/main/resources/ExperimentalData/testdata/emf/task-main/"; public static final String[] fileNamesTaskMain = { "leader3_2.xmi", "leader4_2.xmi", "leader3_3.xmi", -// "leader5_2.xmi", -// "leader3_4.xmi", -// "leader3_5.xmi", -// "leader4_3.xmi", -// "leader6_2.xmi", -// "leader3_6.xmi", -// "leader4_4.xmi", -// "leader5_3.xmi", -// "leader3_8.xmi", -// "leader4_5.xmi", -// "leader6_3.xmi", -// "leader4_6.xmi", -// "leader5_4.xmi", + "leader5_2.xmi", + "leader3_4.xmi", + "leader3_5.xmi", + "leader4_3.xmi", + "leader6_2.xmi", + "leader3_6.xmi", + "leader4_4.xmi", + "leader5_3.xmi", + "leader3_8.xmi", + "leader4_5.xmi", + "leader6_3.xmi", + "leader4_6.xmi", + "leader5_4.xmi", // biggest input graph it scales up to is leader5_4.xmi // "leader5_5.xmi", // "leader6_4.xmi", // "leader6_5.xmi" @@ -47,240 +44,283 @@ public class TestTTCStateCase { }; @Test - public void testSolvingTTC2017StateEliminationCaseWithAlgorithm() { -// Algorithm algorithmStateCaseTTC2017 = getStateCaseAlgorithmTTC2017(); + public void testSolvingTTC2017StateEliminationCaseWithGraphTransformationAlgorithm() { + + // start with task-extension1, because it's quicker: + + // load model: + Graph g = TTCStateCaseGraphLoader.load(taskExtension1Path + "zeroconf.xmi", false); + // convert graph (so it's uniform) + Graph result = getStateCasePreparationAlgorithmTTC2017().process(g).getOutput(); + // print result (contains just one initial state and one final state) + System.out.println("converted graph for extension 1:\n" + result + "\n"); + + // now task-main: + + testSolvingTTC2017StateEliminationCaseWithAlgorithm(taskMainPath, fileNamesTaskMain); + + } + + private void testSolvingTTC2017StateEliminationCaseWithAlgorithm(String taskPath, String[] fileNamesTask) { Algorithm algorithmStateCaseTTC2017 = null; try { + // construct the algorithm, save it to a file and load it again: 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) { + for (String fileName: fileNamesTask) { + // handle test case System.out.println("TTC2017 State Elimination: " + fileName + "..."); + // start time measure long beginTime = System.nanoTime(); - Graph g = TTCStateCaseGraphLoader.load(taskMainPath + fileName, false); // get data -// System.err.println(g); + // load graph + Graph g = TTCStateCaseGraphLoader.load(taskPath + fileName, false); + // run algorithm Graph result = algorithmStateCaseTTC2017.process(g).getOutput(); + // extract resulting string String resultStringRaw = ""; for (String s: result.getNodes().get(0).getEdges().keySet()) { resultStringRaw = s; } + // remove references to 'empty' edges String resultString = resultStringRaw.replaceAll(Pattern.quote("(ε)"), ""); + // print final result System.out.println(resultString); + // stop time measure long endTime = System.nanoTime(); -// System.err.println(result); + // print time measure System.out.println("Done after " + ((endTime - beginTime) / 1e9) + " seconds.\n"); } } - @Test - public void testSolvingTTC2017StateEliminationCase() { - for (String fileName: fileNamesTaskMain) { - System.out.println("TTC2017 State Elimination: " + fileName + "..."); - long beginTime = System.nanoTime(); - Graph g = TTCStateCaseGraphLoader.load(taskMainPath + fileName); // get data - Graph result = solveGraph(g); // solve problem - long endTime = System.nanoTime(); - 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"); - } - } +// @Test +// public void testSolvingTTC2017StateEliminationCase() { +// for (String fileName: fileNamesTaskMain) { +// System.out.println("TTC2017 State Elimination: " + fileName + "..."); +// long beginTime = System.nanoTime(); +// Graph g = TTCStateCaseGraphLoader.load(taskMainPath + fileName); // get data +// Graph result = solveGraph(g); // solve problem +// long endTime = System.nanoTime(); +// 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"); +// } +// } +// +// @Test +// public void testSolvingTTC2017StateEliminationCaseExtension1() { +// for (String fileName: fileNamesTaskExtension1) { +// System.out.println("TTC2017 State Elimination (Extension 1): " + fileName + "..."); +// long beginTime = System.nanoTime(); +// Graph g = TTCStateCaseGraphLoader.load(taskExtension1Path + fileName); // get data +// Graph result = solveGraph(g); // solve problem +// long endTime = System.nanoTime(); +// 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"); +// } +// +// } - @Test - public void testSolvingTTC2017StateEliminationCaseExtension1() { - for (String fileName: fileNamesTaskExtension1) { - System.out.println("TTC2017 State Elimination (Extension 1): " + fileName + "..."); - long beginTime = System.nanoTime(); - Graph g = TTCStateCaseGraphLoader.load(taskExtension1Path + fileName); // get data - Graph result = solveGraph(g); // solve problem - long endTime = System.nanoTime(); - 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"); + public static Algorithm getStateCasePreparationAlgorithmTTC2017() { + + if (algorithmPrepare == null) { + + Algorithm prepareData = new Algorithm("prepare data"); + + prepareData.addAlgorithmStep(getNewInitialPattern()); + prepareData.addAlgorithmStep(getAddToInitialPattern(), true); + prepareData.addAlgorithmStep(getNewFinalPattern()); + prepareData.addAlgorithmStep(getAddToFinalPattern(), true); + prepareData.addAlgorithmStep(getMergeEdgesPattern(), true); + + algorithmPrepare = prepareData; + } + return algorithmPrepare; } public static Algorithm getStateCaseAlgorithmTTC2017() { - Algorithm stateCaseTTC2017 = new Algorithm("TTC 2017 State Case"); - - Algorithm prepareData = new Algorithm("prepare data"); - Algorithm eliminateState = new Algorithm("eliminate state"); - Algorithm handleSourceNode = new Algorithm("handle source node"); - Algorithm redirectRoute = new Algorithm("redirect route"); - - stateCaseTTC2017.addAlgorithmStep(prepareData); - prepareData.addAlgorithmStep(getNewInitialPattern()); - prepareData.addAlgorithmStep(getAddToInitialPattern(), true); - prepareData.addAlgorithmStep(getNewFinalPattern()); - prepareData.addAlgorithmStep(getAddToFinalPattern(), true); - prepareData.addAlgorithmStep(getMergeEdgesPattern(), true); - stateCaseTTC2017.addAlgorithmStep(eliminateState, true); - eliminateState.addAlgorithmStep(getMarkStateForEliminationPattern()); - eliminateState.addAlgorithmStep(handleSourceNode, true); - handleSourceNode.addAlgorithmStep(getMarkWithCurrentPattern()); - handleSourceNode.addAlgorithmStep(getMarkFallbackWithCurrentPattern()); - handleSourceNode.addAlgorithmStep(redirectRoute, true); - redirectRoute.addAlgorithmStep(getPrepareStateWithPqPkKkKqPattern(), true); - redirectRoute.addAlgorithmStep(getPrepareStateWithPkKkKqPattern(), true); - redirectRoute.addAlgorithmStep(getPrepareStateWithPqPkKqPattern(), true); - redirectRoute.addAlgorithmStep(getPrepareStateWithPkKqPattern(), true); - redirectRoute.addAlgorithmStep(getPrepareStateWithPpPkKkKpPattern(), true); - redirectRoute.addAlgorithmStep(getPrepareStateWithPpPkKpPattern(), true); - redirectRoute.addAlgorithmStep(getPrepareStateWithPkKkKpPattern(), true); - redirectRoute.addAlgorithmStep(getPrepareStateWithPkKpPattern(), true); - handleSourceNode.addAlgorithmStep(getUnmarkCurrentPattern()); - handleSourceNode.addAlgorithmStep(getRemoveMarksPattern(), true); - eliminateState.addAlgorithmStep(getEliminateMarkedStatePattern()); - eliminateState.addAlgorithmStep(getUnmarkPastPattern(), true); - - return stateCaseTTC2017; - } - - public static Algorithm getStochasticStateCaseAlgorithmTTC2017() { - - Algorithm stateCaseTTC2017 = new Algorithm("TTC 2017 State Case"); - - Algorithm prepareData = new Algorithm("prepare data"); - Algorithm eliminateState = new Algorithm("eliminate state"); - Algorithm handleSourceNode = new Algorithm("handle source node"); - Algorithm redirectRoute = new Algorithm("redirect route"); + if (algorithm == null) { + + Algorithm stateCaseTTC2017 = new Algorithm("TTC 2017 State Case"); + + Algorithm eliminateState = new Algorithm("eliminate state"); + Algorithm handleSourceNode = new Algorithm("handle source node"); + Algorithm redirectRoute = new Algorithm("redirect route"); + + stateCaseTTC2017.addAlgorithmStep(getStateCasePreparationAlgorithmTTC2017()); + stateCaseTTC2017.addAlgorithmStep(eliminateState, true); + eliminateState.addAlgorithmStep(getMarkStateForEliminationPattern()); + eliminateState.addAlgorithmStep(handleSourceNode, true); + handleSourceNode.addAlgorithmStep(getMarkWithCurrentPattern()); + handleSourceNode.addAlgorithmStep(getMarkFallbackWithCurrentPattern()); + handleSourceNode.addAlgorithmStep(redirectRoute, true); + redirectRoute.addAlgorithmStep(getPrepareStateWithPqPkKkKqPattern(), true); + redirectRoute.addAlgorithmStep(getPrepareStateWithPkKkKqPattern(), true); + redirectRoute.addAlgorithmStep(getPrepareStateWithPqPkKqPattern(), true); + redirectRoute.addAlgorithmStep(getPrepareStateWithPkKqPattern(), true); + redirectRoute.addAlgorithmStep(getPrepareStateWithPpPkKkKpPattern(), true); + redirectRoute.addAlgorithmStep(getPrepareStateWithPpPkKpPattern(), true); + redirectRoute.addAlgorithmStep(getPrepareStateWithPkKkKpPattern(), true); + redirectRoute.addAlgorithmStep(getPrepareStateWithPkKpPattern(), true); + handleSourceNode.addAlgorithmStep(getUnmarkCurrentPattern()); + handleSourceNode.addAlgorithmStep(getRemoveMarksPattern(), true); + eliminateState.addAlgorithmStep(getEliminateMarkedStatePattern()); + eliminateState.addAlgorithmStep(getUnmarkPastPattern(), true); + + algorithm = stateCaseTTC2017; + + } - stateCaseTTC2017.addAlgorithmStep(prepareData); - prepareData.addAlgorithmStep(getNewInitialPattern()); - prepareData.addAlgorithmStep(getAddToInitialPattern(), true); - prepareData.addAlgorithmStep(getNewFinalPattern()); - prepareData.addAlgorithmStep(getAddToFinalPattern(), true); - prepareData.addAlgorithmStep(getMergeEdgesPattern(), true); - stateCaseTTC2017.addAlgorithmStep(eliminateState, true); - eliminateState.addAlgorithmStep(getMarkStateForEliminationPattern()); - eliminateState.addAlgorithmStep(handleSourceNode, true); - handleSourceNode.addAlgorithmStep(getMarkWithCurrentPattern()); - handleSourceNode.addAlgorithmStep(getMarkFallbackWithCurrentPattern()); - handleSourceNode.addAlgorithmStep(redirectRoute, true); - redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPqPkKkKqPattern(), true); - redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPkKkKqPattern(), true); - redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPqPkKqPattern(), true); - redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPkKqPattern(), true); - redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPpPkKkKpPattern(), true); - redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPpPkKpPattern(), true); - redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPkKkKpPattern(), true); - redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPkKpPattern(), true); - handleSourceNode.addAlgorithmStep(getUnmarkCurrentPattern()); - handleSourceNode.addAlgorithmStep(getRemoveMarksPattern(), true); - eliminateState.addAlgorithmStep(getEliminateMarkedStatePattern()); - eliminateState.addAlgorithmStep(getUnmarkPastPattern(), true); - - return stateCaseTTC2017; + return algorithm; } - public static Graph solveGraph(Graph g) { - PatternGraph gtr_1_1 = getNewInitialPattern(); - PatternGraph gtr_1_1_b = getAddToInitialPattern(); - PatternGraph gtr_1_2 = getNewFinalPattern(); - PatternGraph gtr_1_3 = getAddToFinalPattern(); - PatternGraph gtr_1_4 = getMergeEdgesPattern(); - PatternGraph gtr_2_1 = getMarkStateForEliminationPattern(); - PatternGraph gtr_2_2_1 = getMarkWithCurrentPattern(); - PatternGraph gtr_2_2_2 = getMarkFallbackWithCurrentPattern(); - PatternGraph gtr_2_3_1 = getPrepareStateWithPqPkKkKqPattern(); - PatternGraph gtr_2_3_2 = getPrepareStateWithPkKkKqPattern(); - PatternGraph gtr_2_3_3 = getPrepareStateWithPqPkKqPattern(); - PatternGraph gtr_2_3_4 = getPrepareStateWithPkKqPattern(); - PatternGraph gtr_2_3_5 = getPrepareStateWithPpPkKkKpPattern(); - PatternGraph gtr_2_3_6 = getPrepareStateWithPpPkKpPattern(); - PatternGraph gtr_2_3_7 = getPrepareStateWithPkKkKpPattern(); - PatternGraph gtr_2_3_8 = getPrepareStateWithPkKpPattern(); - PatternGraph gtr_2_4 = getUnmarkCurrentPattern(); - PatternGraph gtr_2_5 = getRemoveMarksPattern(); - PatternGraph gtr_2_6 = getEliminateMarkedStatePattern(); - PatternGraph gtr_2_7 = getUnmarkPastPattern(); - - /* - * How to loop: - * - * #1.1 - * #1.1 b) - * #1.2 - * #1.3 - * #1.4 - * #2.1 // mark k (as elimination) - * #2.2.1 // mark p (as current) - * #2.2.2 // mark p (as current) - * #2.3.1 // mark q (as used) - * #2.3.2 // mark q (as used) - * #2.3.3 // mark q (as used) - * #2.3.4 // mark q (as used) - * #2.3.5 // mark q (as used) - * #2.3.6 // mark q (as used) - * #2.3.7 // mark q (as used) - * #2.3.8 // mark q (as used) - * #2.4 // mark p (as past) - * #2.5 // unmark q - * #2.6 - * #2.7 - * - */ - - - g = applyGTR(g, gtr_1_1, true); - g = applyGTR(g, gtr_1_1_b); - g = applyGTR(g, gtr_1_2, true); - g = applyGTR(g, gtr_1_3); - g = applyGTR(g, gtr_1_4); - while (true) { -// Graph copy1 = g.clone(); - Graph ref1 = g; - g = applyGTR(g, gtr_2_1, true); - while (true) { -// Graph copy2 = g.clone(); - Graph ref2 = g; - g = applyGTR(g, gtr_2_2_1, true); - g = applyGTR(g, gtr_2_2_2, true); - while (true) { -// Graph copy3 = g.clone(); - Graph ref3 = g; - g = applyGTR(g, gtr_2_3_1); - g = applyGTR(g, gtr_2_3_2); - g = applyGTR(g, gtr_2_3_3); - g = applyGTR(g, gtr_2_3_4); - g = applyGTR(g, gtr_2_3_5); - g = applyGTR(g, gtr_2_3_6); - g = applyGTR(g, gtr_2_3_7); - g = applyGTR(g, gtr_2_3_8); -// if (GraphEngine.isIsomorphTo(g, copy3)) { - if (g == ref3) { - break; - } - } - g = applyGTR(g, gtr_2_4, true); - g = applyGTR(g, gtr_2_5); -// if (GraphEngine.isIsomorphTo(g, copy2)) { - if (g == ref2) { - break; - } - } - g = applyGTR(g, gtr_2_6, true); - g = applyGTR(g, gtr_2_7); -// if (GraphEngine.isIsomorphTo(g, copy1)) { - if (g == ref1) { - break; - } - } - return g; - } +// public static Algorithm getStochasticStateCaseAlgorithmTTC2017() { +// +// Algorithm stateCaseTTC2017 = new Algorithm("TTC 2017 State Case"); +// +// Algorithm prepareData = new Algorithm("prepare data"); +// Algorithm eliminateState = new Algorithm("eliminate state"); +// Algorithm handleSourceNode = new Algorithm("handle source node"); +// Algorithm redirectRoute = new Algorithm("redirect route"); +// +// stateCaseTTC2017.addAlgorithmStep(prepareData); +// prepareData.addAlgorithmStep(getNewInitialPattern()); +// prepareData.addAlgorithmStep(getAddToInitialPattern(), true); +// prepareData.addAlgorithmStep(getNewFinalPattern()); +// prepareData.addAlgorithmStep(getAddToFinalPattern(), true); +// prepareData.addAlgorithmStep(getMergeEdgesPattern(), true); +// stateCaseTTC2017.addAlgorithmStep(eliminateState, true); +// eliminateState.addAlgorithmStep(getMarkStateForEliminationPattern()); +// eliminateState.addAlgorithmStep(handleSourceNode, true); +// handleSourceNode.addAlgorithmStep(getMarkWithCurrentPattern()); +// handleSourceNode.addAlgorithmStep(getMarkFallbackWithCurrentPattern()); +// handleSourceNode.addAlgorithmStep(redirectRoute, true); +// redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPqPkKkKqPattern(), true); +// redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPkKkKqPattern(), true); +// redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPqPkKqPattern(), true); +// redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPkKqPattern(), true); +// redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPpPkKkKpPattern(), true); +// redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPpPkKpPattern(), true); +// redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPkKkKpPattern(), true); +// redirectRoute.addAlgorithmStep(getStochasticPrepareStateWithPkKpPattern(), true); +// handleSourceNode.addAlgorithmStep(getUnmarkCurrentPattern()); +// handleSourceNode.addAlgorithmStep(getRemoveMarksPattern(), true); +// eliminateState.addAlgorithmStep(getEliminateMarkedStatePattern()); +// eliminateState.addAlgorithmStep(getUnmarkPastPattern(), true); +// +// return stateCaseTTC2017; +// } +// +// public static Graph solveGraph(Graph g) { +// PatternGraph gtr_1_1 = getNewInitialPattern(); +// PatternGraph gtr_1_1_b = getAddToInitialPattern(); +// PatternGraph gtr_1_2 = getNewFinalPattern(); +// PatternGraph gtr_1_3 = getAddToFinalPattern(); +// PatternGraph gtr_1_4 = getMergeEdgesPattern(); +// PatternGraph gtr_2_1 = getMarkStateForEliminationPattern(); +// PatternGraph gtr_2_2_1 = getMarkWithCurrentPattern(); +// PatternGraph gtr_2_2_2 = getMarkFallbackWithCurrentPattern(); +// PatternGraph gtr_2_3_1 = getPrepareStateWithPqPkKkKqPattern(); +// PatternGraph gtr_2_3_2 = getPrepareStateWithPkKkKqPattern(); +// PatternGraph gtr_2_3_3 = getPrepareStateWithPqPkKqPattern(); +// PatternGraph gtr_2_3_4 = getPrepareStateWithPkKqPattern(); +// PatternGraph gtr_2_3_5 = getPrepareStateWithPpPkKkKpPattern(); +// PatternGraph gtr_2_3_6 = getPrepareStateWithPpPkKpPattern(); +// PatternGraph gtr_2_3_7 = getPrepareStateWithPkKkKpPattern(); +// PatternGraph gtr_2_3_8 = getPrepareStateWithPkKpPattern(); +// PatternGraph gtr_2_4 = getUnmarkCurrentPattern(); +// PatternGraph gtr_2_5 = getRemoveMarksPattern(); +// PatternGraph gtr_2_6 = getEliminateMarkedStatePattern(); +// PatternGraph gtr_2_7 = getUnmarkPastPattern(); +// +// /* +// * How to loop: +// * +// * #1.1 +// * #1.1 b) +// * #1.2 +// * #1.3 +// * #1.4 +// * #2.1 // mark k (as elimination) +// * #2.2.1 // mark p (as current) +// * #2.2.2 // mark p (as current) +// * #2.3.1 // mark q (as used) +// * #2.3.2 // mark q (as used) +// * #2.3.3 // mark q (as used) +// * #2.3.4 // mark q (as used) +// * #2.3.5 // mark q (as used) +// * #2.3.6 // mark q (as used) +// * #2.3.7 // mark q (as used) +// * #2.3.8 // mark q (as used) +// * #2.4 // mark p (as past) +// * #2.5 // unmark q +// * #2.6 +// * #2.7 +// * +// */ +// +// +// g = applyGTR(g, gtr_1_1, true); +// g = applyGTR(g, gtr_1_1_b); +// g = applyGTR(g, gtr_1_2, true); +// g = applyGTR(g, gtr_1_3); +// g = applyGTR(g, gtr_1_4); +// while (true) { +//// Graph copy1 = g.clone(); +// Graph ref1 = g; +// g = applyGTR(g, gtr_2_1, true); +// while (true) { +//// Graph copy2 = g.clone(); +// Graph ref2 = g; +// g = applyGTR(g, gtr_2_2_1, true); +// g = applyGTR(g, gtr_2_2_2, true); +// while (true) { +//// Graph copy3 = g.clone(); +// Graph ref3 = g; +// g = applyGTR(g, gtr_2_3_1); +// g = applyGTR(g, gtr_2_3_2); +// g = applyGTR(g, gtr_2_3_3); +// g = applyGTR(g, gtr_2_3_4); +// g = applyGTR(g, gtr_2_3_5); +// g = applyGTR(g, gtr_2_3_6); +// g = applyGTR(g, gtr_2_3_7); +// g = applyGTR(g, gtr_2_3_8); +//// if (GraphEngine.isIsomorphTo(g, copy3)) { +// if (g == ref3) { +// break; +// } +// } +// g = applyGTR(g, gtr_2_4, true); +// g = applyGTR(g, gtr_2_5); +//// if (GraphEngine.isIsomorphTo(g, copy2)) { +// if (g == ref2) { +// break; +// } +// } +// g = applyGTR(g, gtr_2_6, true); +// g = applyGTR(g, gtr_2_7); +//// if (GraphEngine.isIsomorphTo(g, copy1)) { +// if (g == ref1) { +// break; +// } +// } +// return g; +// } @Test public void testLoadingTTCStateCaseData() { @@ -288,31 +328,8 @@ public void testLoadingTTCStateCaseData() { /* * just loading models and count nodes: */ - String taskMainPath = "src/main/resources/ExperimentalData/testdata/emf/task-main/"; - - String[] fileNames = { - "leader3_2.xmi", - "leader4_2.xmi", - "leader3_3.xmi", - "leader5_2.xmi", - "leader3_4.xmi", - "leader3_5.xmi", - "leader4_3.xmi", - "leader6_2.xmi", - "leader3_6.xmi", - "leader4_4.xmi", - "leader5_3.xmi", - "leader3_8.xmi", - "leader4_5.xmi", - "leader6_3.xmi", - "leader4_6.xmi", - "leader5_4.xmi", - "leader5_5.xmi", - "leader6_4.xmi", - "leader6_5.xmi" - }; - for (String fileName: fileNames) { + for (String fileName: fileNamesTaskMain) { g = TTCStateCaseGraphLoader.load(taskMainPath + fileName); System.out.println(fileName + ": " + g.getNodes().size()); } @@ -345,117 +362,117 @@ public void testLoadingTTCStateCaseData() { Assert.assertEquals(335, g.getNodes().size()); } - @Test - public void testSomeIsolatedGTR() { - - PatternGraph gtr_1_1 = getNewInitialPattern(); - PatternGraph gtr_1_2 = getNewFinalPattern(); - PatternGraph gtr_1_3 = getAddToFinalPattern(); - PatternGraph gtr_1_4 = getMergeEdgesPattern(); -// PatternGraph gtr_2_1 = getMarkStateForEliminationPattern(); -// PatternGraph gtr_2_2 = getMarkWithCurrentPattern(); -// PatternGraph gtr_2_3_1 = getPrepareStateWithPqPkKkKqPattern(); - PatternGraph gtr_2_3_2 = getPrepareStateWithPkKkKqPattern(); -// PatternGraph gtr_2_3_3 = getPrepareStateWithPqPkKqPattern(); -// PatternGraph gtr_2_3_4 = getPrepareStateWithPkKqPattern(); -// PatternGraph gtr_2_4 = getUnmarkCurrentPattern(); -// PatternGraph gtr_2_5 = getRemoveMarksPattern(); -// PatternGraph gtr_2_6 = getEliminateMarkedStatePattern(); -// PatternGraph gtr_2_7 = getUnmarkPastPattern(); - - ArrayList matches; - Graph result; - - Graph g_1_1 = new Graph(); - Node n_1_1 = new Node().setAttribute("initial", true); - g_1_1.addNode(n_1_1); - matches = PatternEngine.matchPattern(g_1_1, gtr_1_1, true); - Assert.assertEquals(1, matches.size()); - result = PatternEngine.applyMatch(matches.get(0)); - Assert.assertTrue(!GraphEngine.isIsomorphTo(g_1_1, result)); - - Graph g_1_2 = new Graph(); - Node n_1_2_a = new Node().setAttribute("final", true); - Node n_1_2_b = new Node().setAttribute("final", true); - g_1_2.addNode(n_1_2_a, n_1_2_b); - matches = PatternEngine.matchPattern(g_1_2, gtr_1_2, false); - Assert.assertEquals(2, matches.size()); - matches = PatternEngine.matchPattern(g_1_2, gtr_1_2, true); - Assert.assertEquals(1, matches.size()); - result = PatternEngine.applyMatch(matches.get(0)); - Assert.assertTrue(!GraphEngine.isIsomorphTo(g_1_2, result)); - g_1_2 = result; - matches = PatternEngine.matchPattern(g_1_2, gtr_1_2, false); - Assert.assertEquals(0, matches.size()); - - Graph g_1_3 = g_1_2; - matches = PatternEngine.matchPattern(g_1_3, gtr_1_3, false); - Assert.assertEquals(1, matches.size()); - result = PatternEngine.applyMatch(matches.get(0)); - Assert.assertTrue(!GraphEngine.isIsomorphTo(g_1_3, result)); - - Graph g_1_4 = new Graph(); - Node n_1_4_a = new Node(); - Node n_1_4_b = new Node(); - g_1_4.addNode(n_1_4_a, n_1_4_b); - n_1_4_a.addEdge("a", n_1_4_b); - n_1_4_a.addEdge("b", n_1_4_b); - n_1_4_a.addEdge("c", n_1_4_b); - matches = PatternEngine.matchPattern(g_1_4, gtr_1_4, false); - Assert.assertEquals(1, matches.size()); - result = PatternEngine.applyMatch(matches.get(0)); - Assert.assertTrue(!GraphEngine.isIsomorphTo(g_1_4, result)); - g_1_4 = result; - matches = PatternEngine.matchPattern(g_1_4, gtr_1_4, false); - Assert.assertEquals(1, matches.size()); - result = PatternEngine.applyMatch(matches.get(0)); - - Graph g_2_3_2 = new Graph(); - Node n_2_3_2_p = new Node().setAttribute("current", true); - Node n_2_3_2_k = new Node().setAttribute("eliminate", true); - Node n_2_3_2_q = new Node(); - g_2_3_2.addNode(n_2_3_2_p, n_2_3_2_k, n_2_3_2_q); - n_2_3_2_p.addEdge("a", n_2_3_2_k); - n_2_3_2_k.addEdge("b", n_2_3_2_k); - n_2_3_2_k.addEdge("c", n_2_3_2_q); - matches = PatternEngine.matchPattern(g_2_3_2, gtr_2_3_2, false); - Assert.assertEquals(1, matches.size()); - result = PatternEngine.applyMatch(matches.get(0)); - System.out.println(g_2_3_2); - System.out.println(result); - - } - - @Test - public void testSomeProblematicGTR() { - String gtrString = "{\"nodes\":[{\"id\":0,\"attributes\":{\"current\":true},\"edges\":[{\"((((((((s2)(s10))(s18))(s25))+((((s6)(s14))(s20))(s25)))+((((s5)(s13))(s23))(s25)))+((((s4)(s15))(s24))(s25)))+((((s7)(s12))(s21))(s25)))+((((s3)(s16))(s19))(s25))\":[1]},{\"((s8)(s11))(s22)\":[2]}]},{\"id\":2,\"attributes\":{\"eliminate\":true},\"edges\":[{\"s0\":[0]}]},{\"id\":1,\"attributes\":{},\"edges\":[{\"s25\":[1]},{\"ε\":[3]}]},{\"id\":4,\"attributes\":{\"newInitial\":true},\"edges\":[{\"ε\":[0]}]},{\"id\":3,\"attributes\":{\"newFinal\":true},\"edges\":[]}]}"; - Graph g = GraphEngine.getGson().fromJson(gtrString, Graph.class); - PatternGraph gtr = getPrepareStateWithPkKpPattern(); - - ArrayList matches = PatternEngine.matchPattern(g, gtr, true); - Assert.assertTrue(matches.size() > 0); - - Graph result = applyGTR(g, gtr); - Assert.assertTrue(!GraphEngine.isIsomorphTo(g, result)); - } - - public static Graph applyGTR(Graph g, PatternGraph gtr) { - return applyGTR(g, gtr, false); - } - - public static Graph applyGTR(Graph g, PatternGraph gtr, boolean single) { - boolean foundOne = false; - do { - foundOne = false; - ArrayList matches = PatternEngine.matchPattern(g, gtr, true); - if (matches.size() > 0) { - foundOne = true; - g = PatternEngine.applyMatch(matches.get(0)); -// System.out.println(gtr.getName() + ":\n" + g + "\n"); - } - } while (!single && foundOne); - return g; - } +// @Test +// public void testSomeIsolatedGTR() { +// +// PatternGraph gtr_1_1 = getNewInitialPattern(); +// PatternGraph gtr_1_2 = getNewFinalPattern(); +// PatternGraph gtr_1_3 = getAddToFinalPattern(); +// PatternGraph gtr_1_4 = getMergeEdgesPattern(); +//// PatternGraph gtr_2_1 = getMarkStateForEliminationPattern(); +//// PatternGraph gtr_2_2 = getMarkWithCurrentPattern(); +//// PatternGraph gtr_2_3_1 = getPrepareStateWithPqPkKkKqPattern(); +// PatternGraph gtr_2_3_2 = getPrepareStateWithPkKkKqPattern(); +//// PatternGraph gtr_2_3_3 = getPrepareStateWithPqPkKqPattern(); +//// PatternGraph gtr_2_3_4 = getPrepareStateWithPkKqPattern(); +//// PatternGraph gtr_2_4 = getUnmarkCurrentPattern(); +//// PatternGraph gtr_2_5 = getRemoveMarksPattern(); +//// PatternGraph gtr_2_6 = getEliminateMarkedStatePattern(); +//// PatternGraph gtr_2_7 = getUnmarkPastPattern(); +// +// ArrayList matches; +// Graph result; +// +// Graph g_1_1 = new Graph(); +// Node n_1_1 = new Node().setAttribute("initial", true); +// g_1_1.addNode(n_1_1); +// matches = PatternEngine.matchPattern(g_1_1, gtr_1_1, true); +// Assert.assertEquals(1, matches.size()); +// result = PatternEngine.applyMatch(matches.get(0)); +// Assert.assertTrue(!GraphEngine.isIsomorphTo(g_1_1, result)); +// +// Graph g_1_2 = new Graph(); +// Node n_1_2_a = new Node().setAttribute("final", true); +// Node n_1_2_b = new Node().setAttribute("final", true); +// g_1_2.addNode(n_1_2_a, n_1_2_b); +// matches = PatternEngine.matchPattern(g_1_2, gtr_1_2, false); +// Assert.assertEquals(2, matches.size()); +// matches = PatternEngine.matchPattern(g_1_2, gtr_1_2, true); +// Assert.assertEquals(1, matches.size()); +// result = PatternEngine.applyMatch(matches.get(0)); +// Assert.assertTrue(!GraphEngine.isIsomorphTo(g_1_2, result)); +// g_1_2 = result; +// matches = PatternEngine.matchPattern(g_1_2, gtr_1_2, false); +// Assert.assertEquals(0, matches.size()); +// +// Graph g_1_3 = g_1_2; +// matches = PatternEngine.matchPattern(g_1_3, gtr_1_3, false); +// Assert.assertEquals(1, matches.size()); +// result = PatternEngine.applyMatch(matches.get(0)); +// Assert.assertTrue(!GraphEngine.isIsomorphTo(g_1_3, result)); +// +// Graph g_1_4 = new Graph(); +// Node n_1_4_a = new Node(); +// Node n_1_4_b = new Node(); +// g_1_4.addNode(n_1_4_a, n_1_4_b); +// n_1_4_a.addEdge("a", n_1_4_b); +// n_1_4_a.addEdge("b", n_1_4_b); +// n_1_4_a.addEdge("c", n_1_4_b); +// matches = PatternEngine.matchPattern(g_1_4, gtr_1_4, false); +// Assert.assertEquals(1, matches.size()); +// result = PatternEngine.applyMatch(matches.get(0)); +// Assert.assertTrue(!GraphEngine.isIsomorphTo(g_1_4, result)); +// g_1_4 = result; +// matches = PatternEngine.matchPattern(g_1_4, gtr_1_4, false); +// Assert.assertEquals(1, matches.size()); +// result = PatternEngine.applyMatch(matches.get(0)); +// +// Graph g_2_3_2 = new Graph(); +// Node n_2_3_2_p = new Node().setAttribute("current", true); +// Node n_2_3_2_k = new Node().setAttribute("eliminate", true); +// Node n_2_3_2_q = new Node(); +// g_2_3_2.addNode(n_2_3_2_p, n_2_3_2_k, n_2_3_2_q); +// n_2_3_2_p.addEdge("a", n_2_3_2_k); +// n_2_3_2_k.addEdge("b", n_2_3_2_k); +// n_2_3_2_k.addEdge("c", n_2_3_2_q); +// matches = PatternEngine.matchPattern(g_2_3_2, gtr_2_3_2, false); +// Assert.assertEquals(1, matches.size()); +// result = PatternEngine.applyMatch(matches.get(0)); +// System.out.println(g_2_3_2); +// System.out.println(result); +// +// } +// +// @Test +// public void testSomeProblematicGTR() { +// String gtrString = "{\"nodes\":[{\"id\":0,\"attributes\":{\"current\":true},\"edges\":[{\"((((((((s2)(s10))(s18))(s25))+((((s6)(s14))(s20))(s25)))+((((s5)(s13))(s23))(s25)))+((((s4)(s15))(s24))(s25)))+((((s7)(s12))(s21))(s25)))+((((s3)(s16))(s19))(s25))\":[1]},{\"((s8)(s11))(s22)\":[2]}]},{\"id\":2,\"attributes\":{\"eliminate\":true},\"edges\":[{\"s0\":[0]}]},{\"id\":1,\"attributes\":{},\"edges\":[{\"s25\":[1]},{\"ε\":[3]}]},{\"id\":4,\"attributes\":{\"newInitial\":true},\"edges\":[{\"ε\":[0]}]},{\"id\":3,\"attributes\":{\"newFinal\":true},\"edges\":[]}]}"; +// Graph g = GraphEngine.getGson().fromJson(gtrString, Graph.class); +// PatternGraph gtr = getPrepareStateWithPkKpPattern(); +// +// ArrayList matches = PatternEngine.matchPattern(g, gtr, true); +// Assert.assertTrue(matches.size() > 0); +// +// Graph result = applyGTR(g, gtr); +// Assert.assertTrue(!GraphEngine.isIsomorphTo(g, result)); +// } +// +// public static Graph applyGTR(Graph g, PatternGraph gtr) { +// return applyGTR(g, gtr, false); +// } +// +// public static Graph applyGTR(Graph g, PatternGraph gtr, boolean single) { +// boolean foundOne = false; +// do { +// foundOne = false; +// ArrayList matches = PatternEngine.matchPattern(g, gtr, true); +// if (matches.size() > 0) { +// foundOne = true; +// g = PatternEngine.applyMatch(matches.get(0)); +//// System.out.println(gtr.getName() + ":\n" + g + "\n"); +// } +// } while (!single && foundOne); +// return g; +// } public static PatternGraph getNewInitialPattern() { // #1.1 (single match; don't repeat) - could also be repeated // gtr for new initial state: @@ -697,127 +714,127 @@ public static PatternGraph getUnmarkPastPattern() { // #2.7 return gtr; } - private static String extrEdge(String name) { - return "substring(#{" + name + "}, 0, indexOf(#{" + name + "}, '[', length(#{" + name + "}) - 5))"; - } - private static String extrProb(String name) { - return "substring(#{" + name + "}, indexOf(#{" + name + "}, '[', length(#{" + name + "}) - 5) + 1, length(#{" + name + "}) - 1)"; - } - - public static PatternGraph getStochasticPrepareStateWithPqPkKkKqPattern() { // #2.3.1 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with pq, pk, kk, kq)"); - PatternNode p = new PatternNode("#{current}"); - PatternNode k = new PatternNode("#{eliminate}"); - PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - gtr.addPatternNode(p, k, q); - /* CASE 1: there's pq, pk, kk and kq */ - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kq}", q); - k.addPatternEdge("==", "#{kk}", k); - p.addPatternEdge("-", "#{pq}", q); - p.addPatternEdge("+", "'(' + " + extrEdge("pq") + " + ')[500]+((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kk") + " + ')*[" + extrProb("kk") + "](' + " + extrEdge("kq") + " + '))[500]'", q); - return gtr; - } - - public static PatternGraph getStochasticPrepareStateWithPkKkKqPattern() { // #2.3.2 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pk, kk, kq)"); - PatternNode p = new PatternNode("#{current}"); - PatternNode k = new PatternNode("#{eliminate}"); - PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - gtr.addPatternNode(p, k, q); - /* CASE 2: there's just pk, kk and kq */ - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kk}", k); - k.addPatternEdge("==", "#{kq}", q); - p.addPatternEdge("+", "'(' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kk") + " + ')*[" + extrEdge("kk") + "](' + " + extrEdge("kq") + " + ')[500]'", q); - return gtr; - } - - public static PatternGraph getStochasticPrepareStateWithPqPkKqPattern() { // #2.3.3 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pq, pk, kq)"); - PatternNode p = new PatternNode("#{current}"); - PatternNode k = new PatternNode("#{eliminate}"); - PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - gtr.addPatternNode(p, k, q); - /* CASE 3: there's just pq, pk and kq */ - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kq}", q); - p.addPatternEdge("-", "#{pq}", q); - p.addPatternEdge("+", "'(' + " + extrEdge("pq") + " + ')[500]+((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kq") + " + '))[500]'", q); - return gtr; - } - - public static PatternGraph getStochasticPrepareStateWithPkKqPattern() { // #2.3.4 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pk, kq)"); - PatternNode p = new PatternNode("#{current}"); - PatternNode k = new PatternNode("#{eliminate}"); - PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - gtr.addPatternNode(p, k, q); - /* CASE 4: there's just pk and kq */ - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kq}", q); - p.addPatternEdge("+", "'(' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kq") + " + ')[500]'", q); - return gtr; - } - - public static PatternGraph getStochasticPrepareStateWithPpPkKkKpPattern() { // #2.3.5 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with pp, pk, kk, kp)"); - PatternNode p = new PatternNode("#{current} && !(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - PatternNode k = new PatternNode("#{eliminate}"); - gtr.addPatternNode(p, k); - /* CASE 5: there's pp, pk, kk and kp */ - p.addPatternEdge("-", "#{pp}", p); - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kk}", k); - k.addPatternEdge("==", "#{kp}", p); - p.addPatternEdge("+", "'((' + " + extrEdge("pp") + " + ')*[" + extrProb("pp") + "]((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kk") + " + ')*[" + extrProb("kk") + "](' + " + extrEdge("kp") + " + '))*[1.0])*[1.0]'", p); - return gtr; - } - - public static PatternGraph getStochasticPrepareStateWithPpPkKpPattern() { // #2.3.6 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pp, pk, kp)"); - PatternNode p = new PatternNode("#{current} && !(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - PatternNode k = new PatternNode("#{eliminate}"); - gtr.addPatternNode(p, k); - /* CASE 6: there's just pp, pk and kp */ - p.addPatternEdge("-", "#{pp}", p); - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kp}", p); - p.addPatternEdge("+", "'((' + " + extrEdge("pp") + " + ')*[" + extrProb("pp") + "]((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kp") + " + '))*[1.0])*[1.0]'", p); - return gtr; - } - - public static PatternGraph getStochasticPrepareStateWithPkKkKpPattern() { // #2.3.7 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pk, kk, kp)"); - PatternNode p = new PatternNode("#{current} && !(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - PatternNode k = new PatternNode("#{eliminate}"); - gtr.addPatternNode(p, k); - /* CASE 7: there's just pk, kk and kp */ - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kk}", k); - k.addPatternEdge("==", "#{kp}", p); - p.addPatternEdge("+", "'((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kk") + " + ')*[" + extrProb("kk") + "](' + " + extrEdge("kp") + " + '))*[1.0]'", p); - return gtr; - } - - public static PatternGraph getStochasticPrepareStateWithPkKpPattern() { // #2.3.8 (all matches; don't repeat) - could also be repeated - // gtr for adding new calculated labels - PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pk, kp)"); - PatternNode p = new PatternNode("#{current} && !(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); - PatternNode k = new PatternNode("#{eliminate}"); - gtr.addPatternNode(p, k); - /* CASE 8: there's just pk and kp */ - p.addPatternEdge("==", "#{pk}", k); - k.addPatternEdge("==", "#{kp}", p); - p.addPatternEdge("+", "'((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kp") + " + '))*[1.0]'", p); - return gtr; - } +// private static String extrEdge(String name) { +// return "substring(#{" + name + "}, 0, indexOf(#{" + name + "}, '[', length(#{" + name + "}) - 5))"; +// } +// private static String extrProb(String name) { +// return "substring(#{" + name + "}, indexOf(#{" + name + "}, '[', length(#{" + name + "}) - 5) + 1, length(#{" + name + "}) - 1)"; +// } +// +// public static PatternGraph getStochasticPrepareStateWithPqPkKkKqPattern() { // #2.3.1 (all matches; don't repeat) - could also be repeated +// // gtr for adding new calculated labels +// PatternGraph gtr = new PatternGraph("prepare elimination of state (with pq, pk, kk, kq)"); +// PatternNode p = new PatternNode("#{current}"); +// PatternNode k = new PatternNode("#{eliminate}"); +// PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); +// gtr.addPatternNode(p, k, q); +// /* CASE 1: there's pq, pk, kk and kq */ +// p.addPatternEdge("==", "#{pk}", k); +// k.addPatternEdge("==", "#{kq}", q); +// k.addPatternEdge("==", "#{kk}", k); +// p.addPatternEdge("-", "#{pq}", q); +// p.addPatternEdge("+", "'(' + " + extrEdge("pq") + " + ')[500]+((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kk") + " + ')*[" + extrProb("kk") + "](' + " + extrEdge("kq") + " + '))[500]'", q); +// return gtr; +// } +// +// public static PatternGraph getStochasticPrepareStateWithPkKkKqPattern() { // #2.3.2 (all matches; don't repeat) - could also be repeated +// // gtr for adding new calculated labels +// PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pk, kk, kq)"); +// PatternNode p = new PatternNode("#{current}"); +// PatternNode k = new PatternNode("#{eliminate}"); +// PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); +// gtr.addPatternNode(p, k, q); +// /* CASE 2: there's just pk, kk and kq */ +// p.addPatternEdge("==", "#{pk}", k); +// k.addPatternEdge("==", "#{kk}", k); +// k.addPatternEdge("==", "#{kq}", q); +// p.addPatternEdge("+", "'(' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kk") + " + ')*[" + extrEdge("kk") + "](' + " + extrEdge("kq") + " + ')[500]'", q); +// return gtr; +// } +// +// public static PatternGraph getStochasticPrepareStateWithPqPkKqPattern() { // #2.3.3 (all matches; don't repeat) - could also be repeated +// // gtr for adding new calculated labels +// PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pq, pk, kq)"); +// PatternNode p = new PatternNode("#{current}"); +// PatternNode k = new PatternNode("#{eliminate}"); +// PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); +// gtr.addPatternNode(p, k, q); +// /* CASE 3: there's just pq, pk and kq */ +// p.addPatternEdge("==", "#{pk}", k); +// k.addPatternEdge("==", "#{kq}", q); +// p.addPatternEdge("-", "#{pq}", q); +// p.addPatternEdge("+", "'(' + " + extrEdge("pq") + " + ')[500]+((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kq") + " + '))[500]'", q); +// return gtr; +// } +// +// public static PatternGraph getStochasticPrepareStateWithPkKqPattern() { // #2.3.4 (all matches; don't repeat) - could also be repeated +// // gtr for adding new calculated labels +// PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pk, kq)"); +// PatternNode p = new PatternNode("#{current}"); +// PatternNode k = new PatternNode("#{eliminate}"); +// PatternNode q = new PatternNode("!(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); +// gtr.addPatternNode(p, k, q); +// /* CASE 4: there's just pk and kq */ +// p.addPatternEdge("==", "#{pk}", k); +// k.addPatternEdge("==", "#{kq}", q); +// p.addPatternEdge("+", "'(' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kq") + " + ')[500]'", q); +// return gtr; +// } +// +// public static PatternGraph getStochasticPrepareStateWithPpPkKkKpPattern() { // #2.3.5 (all matches; don't repeat) - could also be repeated +// // gtr for adding new calculated labels +// PatternGraph gtr = new PatternGraph("prepare elimination of state (with pp, pk, kk, kp)"); +// PatternNode p = new PatternNode("#{current} && !(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); +// PatternNode k = new PatternNode("#{eliminate}"); +// gtr.addPatternNode(p, k); +// /* CASE 5: there's pp, pk, kk and kp */ +// p.addPatternEdge("-", "#{pp}", p); +// p.addPatternEdge("==", "#{pk}", k); +// k.addPatternEdge("==", "#{kk}", k); +// k.addPatternEdge("==", "#{kp}", p); +// p.addPatternEdge("+", "'((' + " + extrEdge("pp") + " + ')*[" + extrProb("pp") + "]((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kk") + " + ')*[" + extrProb("kk") + "](' + " + extrEdge("kp") + " + '))*[1.0])*[1.0]'", p); +// return gtr; +// } +// +// public static PatternGraph getStochasticPrepareStateWithPpPkKpPattern() { // #2.3.6 (all matches; don't repeat) - could also be repeated +// // gtr for adding new calculated labels +// PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pp, pk, kp)"); +// PatternNode p = new PatternNode("#{current} && !(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); +// PatternNode k = new PatternNode("#{eliminate}"); +// gtr.addPatternNode(p, k); +// /* CASE 6: there's just pp, pk and kp */ +// p.addPatternEdge("-", "#{pp}", p); +// p.addPatternEdge("==", "#{pk}", k); +// k.addPatternEdge("==", "#{kp}", p); +// p.addPatternEdge("+", "'((' + " + extrEdge("pp") + " + ')*[" + extrProb("pp") + "]((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kp") + " + '))*[1.0])*[1.0]'", p); +// return gtr; +// } +// +// public static PatternGraph getStochasticPrepareStateWithPkKkKpPattern() { // #2.3.7 (all matches; don't repeat) - could also be repeated +// // gtr for adding new calculated labels +// PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pk, kk, kp)"); +// PatternNode p = new PatternNode("#{current} && !(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); +// PatternNode k = new PatternNode("#{eliminate}"); +// gtr.addPatternNode(p, k); +// /* CASE 7: there's just pk, kk and kp */ +// p.addPatternEdge("==", "#{pk}", k); +// k.addPatternEdge("==", "#{kk}", k); +// k.addPatternEdge("==", "#{kp}", p); +// p.addPatternEdge("+", "'((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kk") + " + ')*[" + extrProb("kk") + "](' + " + extrEdge("kp") + " + '))*[1.0]'", p); +// return gtr; +// } +// +// public static PatternGraph getStochasticPrepareStateWithPkKpPattern() { // #2.3.8 (all matches; don't repeat) - could also be repeated +// // gtr for adding new calculated labels +// PatternGraph gtr = new PatternGraph("prepare elimination of state (with just pk, kp)"); +// PatternNode p = new PatternNode("#{current} && !(#{used})").addPatternAttribute(new PatternAttribute().setAction("+").setName("used").setValue(true)); +// PatternNode k = new PatternNode("#{eliminate}"); +// gtr.addPatternNode(p, k); +// /* CASE 8: there's just pk and kp */ +// p.addPatternEdge("==", "#{pk}", k); +// k.addPatternEdge("==", "#{kp}", p); +// p.addPatternEdge("+", "'((' + " + extrEdge("pk") + " + ')(' + " + extrEdge("kp") + " + '))*[1.0]'", p); +// return gtr; +// } } \ No newline at end of file