diff options
author | 2018-02-24 20:56:42 -0500 | |
---|---|---|
committer | 2018-02-24 20:56:42 -0500 | |
commit | 5f1117a84bc3c24ec71d6bcb9d3f2badffca28c2 (patch) | |
tree | 8f0b68af71ae18429c134a533b9951ccd21af558 /Application/hu.bme.mit.inf.dslreasoner.application | |
parent | Application configuration update (diff) | |
download | VIATRA-Generator-5f1117a84bc3c24ec71d6bcb9d3f2badffca28c2.tar.gz VIATRA-Generator-5f1117a84bc3c24ec71d6bcb9d3f2badffca28c2.tar.zst VIATRA-Generator-5f1117a84bc3c24ec71d6bcb9d3f2badffca28c2.zip |
Execution update
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application')
8 files changed, 218 insertions, 38 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend index 635d9dcc..44d9fab0 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend | |||
@@ -5,6 +5,7 @@ import hu.bme.mit.inf.dslreasoner.application.validation.MetamodelValidator | |||
5 | import hu.bme.mit.inf.dslreasoner.application.validation.QueryAndMetamodelValidator | 5 | import hu.bme.mit.inf.dslreasoner.application.validation.QueryAndMetamodelValidator |
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | 6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic |
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | 7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration |
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope | 9 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope |
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.InconsistencyResult | 10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.InconsistencyResult |
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | 11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult |
@@ -14,6 +15,7 @@ import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic | |||
14 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration | 15 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration |
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | 16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic |
16 | import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace | 17 | import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace |
18 | import java.util.Optional | ||
17 | import org.eclipse.emf.common.util.URI | 19 | import org.eclipse.emf.common.util.URI |
18 | 20 | ||
19 | class GenerationTaskExecutor { | 21 | class GenerationTaskExecutor { |
@@ -36,13 +38,17 @@ class GenerationTaskExecutor { | |||
36 | val patternSpecification = scriptExecutor.getPatternSpecification(task.patterns) | 38 | val patternSpecification = scriptExecutor.getPatternSpecification(task.patterns) |
37 | val partialmodelSpecification = scriptExecutor.getPartialModelSpecification(task.partialModel) | 39 | val partialmodelSpecification = scriptExecutor.getPartialModelSpecification(task.partialModel) |
38 | val scopeSpecification = scriptExecutor.getScopeSpecification(task.scope) | 40 | val scopeSpecification = scriptExecutor.getScopeSpecification(task.scope) |
39 | val configurationMap = scriptExecutor.transformToMap( | 41 | |
40 | scriptExecutor.getConfiguration(task.config)) | ||
41 | val messageFile = scriptExecutor.getFileSpecification(task.targetLogFile) | 42 | val messageFile = scriptExecutor.getFileSpecification(task.targetLogFile) |
42 | val debugFolder = scriptExecutor.getFileSpecification(task.debugFolder) | 43 | val debugFolder = scriptExecutor.getFileSpecification(task.debugFolder) |
43 | val outputFolder = scriptExecutor.getFileSpecification(task.getTagetFolder) | 44 | val outputFolder = scriptExecutor.getFileSpecification(task.getTagetFolder) |
44 | val statisticsFile = scriptExecutor.getFileSpecification(task.targetStatisticsFile) | 45 | val statisticsFile = scriptExecutor.getFileSpecification(task.targetStatisticsFile) |
45 | 46 | ||
47 | val configSpecification = scriptExecutor.getConfiguration(task.config) | ||
48 | val configurationMap = scriptExecutor.transformToMap(configSpecification) | ||
49 | val documentationLevel = scriptExecutor.getDocumentation(configSpecification) | ||
50 | val runtieLimit = scriptExecutor.getRuntimeLimit(configSpecification) | ||
51 | val memoryLimit = scriptExecutor.getMemoryLimit(configSpecification) | ||
46 | // 2. create console | 52 | // 2. create console |
47 | 53 | ||
48 | val console = new ScriptConsole(true,true, | 54 | val console = new ScriptConsole(true,true, |
@@ -94,12 +100,16 @@ class GenerationTaskExecutor { | |||
94 | // 5. create a solver and a configuration | 100 | // 5. create a solver and a configuration |
95 | // 5.1 initialize | 101 | // 5.1 initialize |
96 | val solver = solverLoader.loadSolver(task.solver,configurationMap) | 102 | val solver = solverLoader.loadSolver(task.solver,configurationMap) |
97 | val solverConfig = solverLoader.loadSolverConfig(task.solver,configurationMap) | 103 | val solverConfig = solverLoader.loadSolverConfig(task.solver,configurationMap,console) |
98 | val reasonerWorkspace = if(debugFolder!== null) { | 104 | val reasonerWorkspace = if(debugFolder!== null) { |
99 | new ProjectWorkspace(debugFolder.path,"") | 105 | new ProjectWorkspace(debugFolder.path,"") |
100 | } else { | 106 | } else { |
101 | new NullWorkspace | 107 | new NullWorkspace |
102 | } | 108 | } |
109 | reasonerWorkspace.initAndClear | ||
110 | if(documentationLevel.atLeastNormal) { | ||
111 | reasonerWorkspace.writeModel(problem,"generation.logicproblem") | ||
112 | } | ||
103 | 113 | ||
104 | // 5.2 set values that defined directly | 114 | // 5.2 set values that defined directly |
105 | solverConfig.solutionScope = new SolutionScope => [ | 115 | solverConfig.solutionScope = new SolutionScope => [ |
@@ -116,33 +126,55 @@ class GenerationTaskExecutor { | |||
116 | modelGeneration.trace | 126 | modelGeneration.trace |
117 | ) | 127 | ) |
118 | 128 | ||
129 | // 5.3 set resource limits | ||
130 | documentationLevel.ifPresent[solverConfig.documentationLevel = it] | ||
131 | runtieLimit.ifPresent[solverConfig.runtimeLimit = it] | ||
132 | memoryLimit.ifPresent[solverConfig.memoryLimit = it] | ||
133 | |||
119 | // 6. execute the solver on the problem with the configuration | 134 | // 6. execute the solver on the problem with the configuration |
120 | val runs = if(task.runSpecified) { | 135 | // 6.1 calculating the runs |
121 | task.runs | 136 | val runs = if(task.runSpecified) { task.runs } else { 1 } |
122 | } else { | 137 | console.writeMessage("Model generation started") |
123 | 1 | ||
124 | } | ||
125 | console.writeMessage("Start model generation") | ||
126 | 138 | ||
127 | for(run : 1..runs) { | 139 | for(run : 1..runs) { |
128 | val solution = solver.solve(problem,solverConfig,reasonerWorkspace) | 140 | |
141 | // 6.2 For each run, the configuration and the workspace is adjusted | ||
142 | solverLoader.setRunIndex(solverConfig,configurationMap,run,console) | ||
143 | val reasonerWorkspaceForRun = if(runs > 1) { | ||
144 | reasonerWorkspace.subWorkspace('''run«run»''',"") => [initAndClear] | ||
145 | } else { | ||
146 | reasonerWorkspace | ||
147 | } | ||
148 | |||
149 | // 7. Solver call | ||
150 | |||
151 | val solution = solver.solve(problem,solverConfig,reasonerWorkspaceForRun) | ||
152 | |||
129 | console.writeMessage(solution.soutionDescription.toString) | 153 | console.writeMessage(solution.soutionDescription.toString) |
154 | |||
155 | // 8. Solution processing | ||
156 | if(solution instanceof ModelResult) { | ||
157 | // | ||
158 | val interpretations = solver.getInterpretations(solution) | ||
159 | } | ||
160 | |||
130 | } | 161 | } |
162 | console.writeMessage("Model generation finished") | ||
131 | } | 163 | } |
132 | 164 | ||
133 | private def dispatch soutionDescription(InconsistencyResult s) { | 165 | private def dispatch soutionDescription(InconsistencyResult s) { |
134 | if(s.representation.size == 1) { | 166 | if(s.representation.size == 0) { |
135 | '''Problem is inconsistent!''' | 167 | '''Problem is inconsistent, no model is created!''' |
136 | } else { | 168 | } else { |
137 | '''Problem is inconsistent, only «s.representation.size» model can be created!''' | 169 | '''Problem is inconsistent, only «s.representation.size» model«IF s.representation.size>1»s«ENDIF» can be created!''' |
138 | } | 170 | } |
139 | } | 171 | } |
140 | 172 | ||
141 | private def dispatch soutionDescription(ModelResult s) { | 173 | private def dispatch soutionDescription(ModelResult s) { |
142 | if(s.representation.size == 1) { | 174 | if(s.representation.size == 1) { |
143 | '''Problem is consistent!''' | 175 | '''Problem is consistent, a model is generated''' |
144 | } else { | 176 | } else { |
145 | '''Problem is consistent, «s.representation.size» model generated!''' | 177 | '''Problem is consistent, «s.representation.size» models are generated!''' |
146 | } | 178 | } |
147 | } | 179 | } |
148 | 180 | ||
@@ -153,4 +185,12 @@ class GenerationTaskExecutor { | |||
153 | '''Unable to solve problem, but «s.representation.size» model generated!''' | 185 | '''Unable to solve problem, but «s.representation.size» model generated!''' |
154 | } | 186 | } |
155 | } | 187 | } |
188 | |||
189 | private def atLeastNormal(Optional<DocumentationLevel> level) { | ||
190 | if(level.isPresent) { | ||
191 | return (level.get !== DocumentationLevel.NONE) | ||
192 | } else { | ||
193 | return false | ||
194 | } | ||
195 | } | ||
156 | } \ No newline at end of file | 196 | } \ No newline at end of file |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/NullWorkspace.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/NullWorkspace.xtend index 4cc44df3..fd3e7348 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/NullWorkspace.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/NullWorkspace.xtend | |||
@@ -31,7 +31,9 @@ class NullWorkspace extends ReasonerWorkspace{ | |||
31 | protected override Resource getResource(String name) { | 31 | protected override Resource getResource(String name) { |
32 | throw new UnsupportedOperationException(message) | 32 | throw new UnsupportedOperationException(message) |
33 | } | 33 | } |
34 | override public URI writeModel(EObject modelRoot, String name) { } | 34 | override public URI writeModel(EObject modelRoot, String name) { } |
35 | override writeModelToString(EObject modelRoot, String name) { } | ||
36 | |||
35 | override public <RootType extends EObject> RootType reloadModel(Class<RootType> type, String name) { | 37 | override public <RootType extends EObject> RootType reloadModel(Class<RootType> type, String name) { |
36 | throw new UnsupportedOperationException(message) | 38 | throw new UnsupportedOperationException(message) |
37 | } | 39 | } |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend index 24f77754..2dc329a0 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend | |||
@@ -93,12 +93,23 @@ class ScriptConsole implements Closeable { | |||
93 | if (uri === null) { | 93 | if (uri === null) { |
94 | return null | 94 | return null |
95 | } else { | 95 | } else { |
96 | val fileString = uri.toFileString | 96 | if(uri.isFile) { |
97 | val file = new File(fileString) | 97 | val fileString = uri.toFileString |
98 | if (this.cleanFiles && file.exists) { | 98 | val file = new File(fileString) |
99 | file.delete | 99 | if (this.cleanFiles && file.exists) { |
100 | file.delete | ||
101 | } | ||
102 | return file | ||
103 | } else if(uri.isPlatformResource) { | ||
104 | val platformString = uri.toPlatformString(true) | ||
105 | val file = new File(platformString) | ||
106 | if (this.cleanFiles && file.exists) { | ||
107 | file.delete | ||
108 | } | ||
109 | return file | ||
110 | } else { | ||
111 | throw new UnsupportedOperationException('''Unksupported file usi: "«uri»"!''') | ||
100 | } | 112 | } |
101 | return file | ||
102 | } | 113 | } |
103 | } | 114 | } |
104 | 115 | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptExecutor.xtend index c783c9b9..7bd73792 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptExecutor.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptExecutor.xtend | |||
@@ -3,22 +3,29 @@ package hu.bme.mit.inf.dslreasoner.application.execution | |||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigReference | 3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigReference |
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigSpecification | 4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigSpecification |
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | 5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript |
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.CustomEntry | ||
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.DocumentationEntry | ||
8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.FileReference | 9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.FileReference |
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.FileSpecification | 10 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.FileSpecification |
8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GenerationTask | 11 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GenerationTask |
9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GraphPatternReference | 12 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GraphPatternReference |
13 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MemoryEntry | ||
10 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelReference | 14 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelReference |
11 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification | 15 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification |
12 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelReference | 16 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelReference |
13 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelSpecification | 17 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelSpecification |
14 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternSpecification | 18 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternSpecification |
19 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.RuntimeEntry | ||
15 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeReference | 20 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeReference |
16 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeSpecification | 21 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeSpecification |
17 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Task | 22 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Task |
18 | import hu.bme.mit.inf.dslreasoner.application.execution.util.ApplicationConfigurationParser | 23 | import hu.bme.mit.inf.dslreasoner.application.execution.util.ApplicationConfigurationParser |
24 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | ||
19 | import java.util.LinkedHashMap | 25 | import java.util.LinkedHashMap |
26 | import java.util.Optional | ||
20 | import org.eclipse.emf.common.util.URI | 27 | import org.eclipse.emf.common.util.URI |
21 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport | 28 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.DocumentLevelSpecification |
22 | 29 | ||
23 | class ScriptExecutor { | 30 | class ScriptExecutor { |
24 | val parser = new ApplicationConfigurationParser | 31 | val parser = new ApplicationConfigurationParser |
@@ -140,11 +147,55 @@ class ScriptExecutor { | |||
140 | val map = new LinkedHashMap | 147 | val map = new LinkedHashMap |
141 | 148 | ||
142 | if(config != null) { | 149 | if(config != null) { |
143 | for(entry : config.entries) { | 150 | for(entry : config.entries.filter(CustomEntry)) { |
144 | map.put(entry.key,entry.value) | 151 | map.put(entry.key,entry.value) |
145 | } | 152 | } |
146 | } | 153 | } |
147 | 154 | ||
148 | return map | 155 | return map |
149 | } | 156 | } |
157 | def getRuntimeLimit(ConfigSpecification config) { | ||
158 | if(config === null) { | ||
159 | return Optional::empty | ||
160 | } else { | ||
161 | val runtimeEntry = config.entries.filter(RuntimeEntry).head | ||
162 | if(runtimeEntry!==null) { | ||
163 | return Optional::of(runtimeEntry.millisecLimit) | ||
164 | } else { | ||
165 | return Optional::empty | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | def getMemoryLimit(ConfigSpecification config) { | ||
170 | if(config === null) { | ||
171 | return Optional::empty | ||
172 | } else { | ||
173 | val memoryEntry = config.entries.filter(MemoryEntry).head | ||
174 | if(memoryEntry!==null) { | ||
175 | return Optional::of(memoryEntry.megabyteLimit) | ||
176 | } else { | ||
177 | return Optional::empty | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | def getDocumentation(ConfigSpecification config) { | ||
182 | if(config === null) { | ||
183 | return Optional::empty | ||
184 | } else { | ||
185 | val documentationEntry = config.entries.filter(DocumentationEntry).head | ||
186 | if(documentationEntry!==null) { | ||
187 | val DocumentLevelSpecification value = documentationEntry.level | ||
188 | val translatedValue = if(value===DocumentLevelSpecification::FULL) { | ||
189 | DocumentationLevel::FULL | ||
190 | } else if(value===DocumentLevelSpecification::NORMAL) { | ||
191 | DocumentationLevel::NORMAL | ||
192 | } else if(value===DocumentLevelSpecification::NONE) { | ||
193 | DocumentationLevel::NONE | ||
194 | } else { | ||
195 | throw new UnsupportedOperationException('''Unable to translate documentation level "«value»"!''') | ||
196 | } | ||
197 | return Optional::of(translatedValue) | ||
198 | } | ||
199 | } | ||
200 | } | ||
150 | } \ No newline at end of file | 201 | } \ No newline at end of file |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend index dcd89981..9ae1ba6b 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend | |||
@@ -1,13 +1,17 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | 1 | package hu.bme.mit.inf.dslreasoner.application.execution |
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Solver | 3 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloyBackendSolver |
4 | import java.util.Map | ||
5 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolver | 4 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolver |
6 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SMTSolver | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | ||
8 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolverConfiguration | 5 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolverConfiguration |
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Solver | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration | ||
8 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SMTSolver | ||
9 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SmtSolverConfiguration | 9 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SmtSolverConfiguration |
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | 11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration |
12 | import java.util.Map | ||
13 | import java.util.Optional | ||
14 | import org.eclipse.xtext.xbase.lib.Functions.Function1 | ||
11 | 15 | ||
12 | class SolverLoader { | 16 | class SolverLoader { |
13 | def loadSolver(Solver solver, Map<String, String> config) { | 17 | def loadSolver(Solver solver, Map<String, String> config) { |
@@ -18,11 +22,66 @@ class SolverLoader { | |||
18 | } | 22 | } |
19 | } | 23 | } |
20 | 24 | ||
21 | def loadSolverConfig(Solver solver, Map<String, String> config) { | 25 | |
22 | switch(solver) { | 26 | |
23 | case ALLOY_SOLVER: return new AlloySolverConfiguration | 27 | private def <Type> Optional<Type> getAsType( |
24 | case SMT_SOLVER: return new SmtSolverConfiguration | 28 | Map<String, String> config, |
25 | case VIATRA_SOLVER: return new ViatraReasonerConfiguration | 29 | String key, |
30 | ScriptConsole console, | ||
31 | Function1<String,Type> parser, | ||
32 | Class<Type> requestedType) | ||
33 | { | ||
34 | if(config.containsKey(key)) { | ||
35 | val stringValue = config.get(key) | ||
36 | try{ | ||
37 | val parsedValue = parser.apply(stringValue) | ||
38 | return Optional.of(parsedValue) | ||
39 | } catch(Exception e) { | ||
40 | console.writeError('''Unable to parse configuration value for "«key»" to «requestedType.simpleName»!''') | ||
41 | return Optional::empty | ||
42 | } | ||
43 | } else { | ||
44 | return Optional::empty | ||
45 | } | ||
46 | } | ||
47 | private def getAsInteger(Map<String, String> config, String key, ScriptConsole console) { | ||
48 | return getAsType(config,key,console,[x|Integer.parseInt(x)],Integer) | ||
49 | } | ||
50 | private def getAsBoolean(Map<String, String> config, String key, ScriptConsole console) { | ||
51 | return getAsType(config,key,console,[x|Boolean.parseBoolean(x)],Boolean) | ||
52 | } | ||
53 | private def getAsDouble(Map<String, String> config, String key, ScriptConsole console) { | ||
54 | return getAsType(config,key,console,[x|Double.parseDouble(x)],Double) | ||
55 | } | ||
56 | |||
57 | def loadSolverConfig( | ||
58 | Solver solver, | ||
59 | Map<String, String> config, | ||
60 | ScriptConsole console) | ||
61 | { | ||
62 | if(solver === Solver::ALLOY_SOLVER) { | ||
63 | return new AlloySolverConfiguration => [c| | ||
64 | config.getAsInteger("symmetry",console) | ||
65 | .ifPresent[c.symmetry = it] | ||
66 | config.getAsType("solver",console,[x|AlloyBackendSolver::valueOf(x)],AlloyBackendSolver) | ||
67 | .ifPresent[c.solver = it] | ||
68 | ] | ||
69 | } else if(solver === Solver::SMT_SOLVER) { | ||
70 | return new SmtSolverConfiguration => [c| | ||
71 | config.getAsBoolean("fixRandomSeed",console).ifPresent[c.fixRandomSeed = it] | ||
72 | ] | ||
73 | } else if(solver === Solver::VIATRA_SOLVER) { | ||
74 | return new ViatraReasonerConfiguration => [c| | ||
75 | ] | ||
76 | } else { | ||
77 | throw new UnsupportedOperationException('''Unknown solver: «solver»''') | ||
26 | } | 78 | } |
27 | } | 79 | } |
80 | |||
81 | def dispatch void setRunIndex(AlloySolverConfiguration config, Map<String, String> parameters, int runIndex, ScriptConsole console) { | ||
82 | parameters.getAsBoolean("randomise",console).ifPresent[config.randomise = runIndex] | ||
83 | } | ||
84 | def dispatch void setRunIndex(LogicSolverConfiguration config, Map<String, String> parameters, int runIndex, ScriptConsole console) { | ||
85 | |||
86 | } | ||
28 | } \ No newline at end of file | 87 | } \ No newline at end of file |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/ApplicationConfigurationParser.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/ApplicationConfigurationParser.xtend new file mode 100644 index 00000000..ea738c5a --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/ApplicationConfigurationParser.xtend | |||
@@ -0,0 +1,18 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution.util | ||
2 | |||
3 | import org.eclipse.emf.common.util.URI | ||
4 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | ||
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | ||
6 | |||
7 | class ApplicationConfigurationParser { | ||
8 | public def parse(URI uri) { | ||
9 | val rs = new ResourceSetImpl | ||
10 | val res = rs.getResource(uri,true) | ||
11 | val content = res.contents.head | ||
12 | if(content instanceof ConfigurationScript) { | ||
13 | return content | ||
14 | } else { | ||
15 | throw new IllegalArgumentException('''Content is not an ConfigurationScript! (got: «content.class.simpleName»)''') | ||
16 | } | ||
17 | } | ||
18 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend index f85e3dcf..0da42e0f 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend | |||
@@ -3,6 +3,7 @@ package hu.bme.mit.inf.dslreasoner.application.execution.util | |||
3 | import com.google.inject.Guice | 3 | import com.google.inject.Guice |
4 | import com.google.inject.Injector | 4 | import com.google.inject.Injector |
5 | import com.google.inject.Module | 5 | import com.google.inject.Module |
6 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptConsole | ||
6 | import java.util.LinkedHashMap | 7 | import java.util.LinkedHashMap |
7 | import java.util.List | 8 | import java.util.List |
8 | import org.eclipse.emf.common.util.URI | 9 | import org.eclipse.emf.common.util.URI |
@@ -17,13 +18,11 @@ import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandalone | |||
17 | import org.eclipse.viatra.query.patternlanguage.emf.GenmodelExtensionLoader | 18 | import org.eclipse.viatra.query.patternlanguage.emf.GenmodelExtensionLoader |
18 | import org.eclipse.viatra.query.patternlanguage.emf.IGenmodelMappingLoader | 19 | import org.eclipse.viatra.query.patternlanguage.emf.IGenmodelMappingLoader |
19 | import org.eclipse.viatra.query.patternlanguage.emf.eMFPatternLanguage.PatternModel | 20 | import org.eclipse.viatra.query.patternlanguage.emf.eMFPatternLanguage.PatternModel |
21 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.CompoundMetamodelProviderService | ||
22 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | ||
20 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder | 23 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder |
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | 24 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification |
22 | import org.eclipse.xtext.resource.XtextResourceSet | 25 | import org.eclipse.xtext.resource.XtextResourceSet |
23 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptConsole | ||
24 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | ||
25 | import hu.bme.mit.inf.dslreasoner.application.linking.PreloadedMetamodelProvider | ||
26 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.CompoundMetamodelProviderService | ||
27 | 26 | ||
28 | class MyModule extends EMFPatternLanguageRuntimeModule implements Module { | 27 | class MyModule extends EMFPatternLanguageRuntimeModule implements Module { |
29 | def public Class<? extends IAnnotationValidatorLoader> bindAnnotationValidatorLoader() { | 28 | def public Class<? extends IAnnotationValidatorLoader> bindAnnotationValidatorLoader() { |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend index e48b74ba..41a89e6f 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend | |||
@@ -79,7 +79,7 @@ class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | |||
79 | } catch(RuntimeException e){ | 79 | } catch(RuntimeException e){ |
80 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | 80 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) |
81 | } | 81 | } |
82 | if(res!==null && !res.contents.empty) { | 82 | if(res!==null && !res.contents.nullOrEmpty) { |
83 | return #[res.contents.head] | 83 | return #[res.contents.head] |
84 | } else { | 84 | } else { |
85 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | 85 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) |
@@ -88,7 +88,7 @@ class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | |||
88 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | 88 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | private def getNSUri(INode node) { | 92 | private def getNSUri(INode node) { |
93 | try { | 93 | try { |
94 | val convertedValue = valueConverterService.toValue(node.text, | 94 | val convertedValue = valueConverterService.toValue(node.text, |