diff options
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend')
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend index be641c87..ff0e1d03 100644 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend | |||
@@ -5,6 +5,7 @@ import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | |||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | 5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration |
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | 6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace |
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor | 7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor |
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | 9 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput |
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | 10 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type |
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | 11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem |
@@ -17,6 +18,7 @@ import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor | |||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | 18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic |
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml | 20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml |
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DebugConfiguration | ||
20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | 22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner |
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | 23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration |
22 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser | 24 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser |
@@ -41,7 +43,6 @@ import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | |||
41 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | 43 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup |
42 | import org.eclipse.viatra.query.runtime.api.IQueryGroup | 44 | import org.eclipse.viatra.query.runtime.api.IQueryGroup |
43 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine | 45 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine |
44 | import queries.Case_study_A | ||
45 | 46 | ||
46 | class GeneratePledgeModels { | 47 | class GeneratePledgeModels { |
47 | def static void main(String[] args) { | 48 | def static void main(String[] args) { |
@@ -57,7 +58,7 @@ class GeneratePledgeModels { | |||
57 | val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) | 58 | val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) |
58 | val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) | 59 | val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) |
59 | val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic | 60 | val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic |
60 | 61 | ||
61 | // Workspace setup | 62 | // Workspace setup |
62 | val Date date = new Date(System.currentTimeMillis) | 63 | val Date date = new Date(System.currentTimeMillis) |
63 | val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | 64 | val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); |
@@ -65,84 +66,82 @@ class GeneratePledgeModels { | |||
65 | 66 | ||
66 | val inputs = new FileSystemWorkspace('''inputs/''', "") | 67 | val inputs = new FileSystemWorkspace('''inputs/''', "") |
67 | val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") | 68 | val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") |
69 | val debug = new FileSystemWorkspace('''output/''' + formattedDate + '''/debug/''', "") | ||
68 | workspace.initAndClear | 70 | workspace.initAndClear |
69 | 71 | ||
70 | println("Input and output workspaces are created") | 72 | println("Input and output workspaces are created") |
71 | 73 | ||
72 | // print(TaxationPackage.eINSTANCE.getEClassifiers.filter(EClass).toList.get(0)) | 74 | // print(TaxationPackage.eINSTANCE.getEClassifiers.filter(EClass).toList.get(0)) |
73 | |||
74 | //* | 75 | //* |
75 | val metamodel = loadMetamodel(TaxationPackage.eINSTANCE) | 76 | val metamodel = loadMetamodel(TaxationPackage.eINSTANCE) |
76 | val partialModel = loadPartialModel(inputs, "Household.xmi") | 77 | val partialModel = loadPartialModel(inputs, "Household.xmi") |
77 | val queries = loadQueries(metamodel, Case_study_A.instance) | 78 | // val queries = loadQueries(metamodel, Case_study_A.instance) |
78 | /*/ | 79 | /*/ |
79 | val metamodel = loadMetamodel(FamilytreePackage.eINSTANCE) | 80 | val metamodel = loadMetamodel(FamilytreePackage.eINSTANCE) |
80 | // val partialModel = loadPartialModel(inputs, "yakindu/Yakindu.xmi") | 81 | // val partialModel = loadPartialModel(inputs, "yakindu/Yakindu.xmi") |
81 | val queries = loadQueries(metamodel, FamilyTreeConstraints.instance) | 82 | val queries = loadQueries(metamodel, FamilyTreeConstraints.instance) |
82 | //*/ | 83 | // */ |
83 | println("DSL loaded") | 84 | println("DSL loaded") |
84 | 85 | ||
85 | val SIZE = 10 | 86 | val SIZE = 2 |
86 | var REPS = 1 | 87 | var REPS = 1 |
87 | val RUNTIME = 600 | 88 | val RUNTIME = 600 |
88 | 89 | ||
89 | // ///////////////////////// | 90 | // ///////////////////////// |
90 | // Prepare Problem | 91 | // Prepare Problem |
91 | val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) | 92 | val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) |
92 | var problem = modelGenerationProblem.output | 93 | var problem = modelGenerationProblem.output |
93 | 94 | ||
94 | // val modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) | 95 | // val modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) |
95 | // problem = modelExtensionProblem.output | 96 | // problem = modelExtensionProblem.output |
96 | 97 | // val validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelGenerationProblem, | |
97 | val validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelGenerationProblem, | 98 | // new Viatra2LogicConfiguration) |
98 | new Viatra2LogicConfiguration) | 99 | // problem = validModelExtensionProblem.output |
99 | problem = validModelExtensionProblem.output | 100 | debug.writeModel(problem, "problem.logicproblem") |
100 | |||
101 | workspace.writeModel(problem, "problem.logicproblem") | ||
102 | println("Problem created") | 101 | println("Problem created") |
103 | 102 | // End Prepare Problem | |
103 | // ///////////////////////// | ||
104 | for (var i = 0; i < REPS; i++) { | 104 | for (var i = 0; i < REPS; i++) { |
105 | 105 | ||
106 | println("Run #" + i + ":") | ||
107 | |||
108 | var ViatraReasoner reasoner = new ViatraReasoner | 106 | var ViatraReasoner reasoner = new ViatraReasoner |
109 | 107 | ||
110 | // ///////////////////////////////////////////////////// | 108 | // ///////////////////////////////////////////////////// |
111 | // Define Config File | 109 | // Define Config File |
112 | val knownIntegers = new TreeSet<Integer> | 110 | val knownIntegers = new TreeSet<Integer> |
113 | knownIntegers.addAll(0) | 111 | knownIntegers.addAll(0) |
114 | 112 | ||
115 | val knownReals = new TreeSet<BigDecimal> | 113 | val knownReals = new TreeSet<BigDecimal> |
116 | knownReals.addAll(new BigDecimal("0.0")) | 114 | knownReals.addAll(new BigDecimal("0.0")) |
117 | 115 | ||
118 | val knownStrings = new TreeSet<String> | 116 | val knownStrings = new TreeSet<String> |
119 | knownStrings.addAll("r0", "r1", "r2") | 117 | knownStrings.addAll("r0", "r1", "r2") |
120 | 118 | ||
121 | |||
122 | val solverConfig = new ViatraReasonerConfiguration => [ | 119 | val solverConfig = new ViatraReasonerConfiguration => [ |
120 | it.documentationLevel = DocumentationLevel::FULL | ||
121 | it.debugCongiguration = new DebugConfiguration => [logging = true] | ||
123 | it.runtimeLimit = RUNTIME | 122 | it.runtimeLimit = RUNTIME |
124 | it.typeScopes.maxNewElements = SIZE | 123 | // it.typeScopes.maxNewElements = SIZE |
125 | // it.typeScopes.minNewElements = SIZE | 124 | // it.typeScopes.minNewElements = 3 |
126 | if(!knownIntegers.isEmpty) it.typeScopes.knownIntegers = knownIntegers | 125 | if(!knownIntegers.isEmpty) it.typeScopes.knownIntegers = knownIntegers |
127 | if(!knownReals.isEmpty) it.typeScopes.knownReals = knownReals | 126 | if(!knownReals.isEmpty) it.typeScopes.knownReals = knownReals |
128 | // if(!knownStrings.isEmpty) it.typeScopes.knownStrings = knownStrings | 127 | // if(!knownStrings.isEmpty) it.typeScopes.knownStrings = knownStrings |
129 | ] | 128 | ] |
130 | 129 | ||
130 | println("Run #" + i + ":") | ||
131 | val startTime = System.currentTimeMillis | 131 | val startTime = System.currentTimeMillis |
132 | var solution = reasoner.solve(problem, solverConfig, workspace) | 132 | var solution = reasoner.solve(problem, solverConfig, debug) |
133 | val totalTime = System.currentTimeMillis-startTime | 133 | val totalTime = System.currentTimeMillis - startTime |
134 | 134 | ||
135 | println(" Problem Solved") | 135 | println(" Problem Solved") |
136 | solution.writeStats(totalTime) | 136 | solution.writeStats(totalTime, solverConfig) |
137 | 137 | ||
138 | if (solution instanceof ModelResult) { | 138 | if (solution instanceof ModelResult) { |
139 | solution.writeRepresentation(workspace, i) | 139 | solution.writeRepresentation(workspace, i) |
140 | // solution.writeInterpretation(logic2Ecore, workspace, i, reasoner, modelGenerationProblem) | 140 | solution.writeInterpretation(logic2Ecore, workspace, i, reasoner, modelGenerationProblem) |
141 | println(" Solution saved and visualised") | 141 | println(" Solution saved and visualised") |
142 | } else | 142 | } else |
143 | println(" Returned: " + solution.class.simpleName.toString) | 143 | println(" Returned: " + solution.class.simpleName.toString) |
144 | 144 | ||
145 | |||
146 | // println("Stats Created") | 145 | // println("Stats Created") |
147 | // Run Garbage Collector | 146 | // Run Garbage Collector |
148 | val Runtime r = Runtime.getRuntime(); | 147 | val Runtime r = Runtime.getRuntime(); |
@@ -230,13 +229,16 @@ class GeneratePledgeModels { | |||
230 | } | 229 | } |
231 | } | 230 | } |
232 | 231 | ||
233 | def static writeStats(LogicResult solution, long time) { | 232 | def static writeStats(LogicResult solution, long time, ViatraReasonerConfiguration config) { |
234 | val stats = solution.statistics | 233 | val stats = solution.statistics |
235 | println(" Statistics:") | 234 | println(" Statistics:") |
236 | // for (e : stats.entries.filter[name.substring(0, 9) == "_Solution"]) { | 235 | // for (e : stats.entries.filter[name.substring(0, 9) == "_Solution"]) { |
237 | // println(" " + e.name + ": " + (e as IntStatisticEntry).value + " ms") | 236 | // println(" " + e.name + ": " + (e as IntStatisticEntry).value + " ms") |
238 | // } | 237 | // } |
239 | println(" \"solve\" time: " + time as double/1000 + " s") | 238 | println( |
239 | " #new nodes : [" + config.typeScopes.minNewElements + ".." + | ||
240 | (if(config.typeScopes.maxNewElements == 2147483647) "*" else config.typeScopes.maxNewElements) + "]") | ||
241 | println(" \"solve\" time: " + time as double / 1000 + " s") | ||
240 | 242 | ||
241 | // println("<<End Statistics>>") | 243 | // println("<<End Statistics>>") |
242 | } | 244 | } |