diff options
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution')
14 files changed, 285 insertions, 330 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/EclipseBasedProgressMonitor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/EclipseBasedProgressMonitor.xtend index be35b64a..df25151c 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/EclipseBasedProgressMonitor.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/EclipseBasedProgressMonitor.xtend | |||
@@ -24,4 +24,4 @@ class EclipseBasedProgressMonitor extends SolverProgressMonitor{ | |||
24 | super.isCancelled() || internalMonitor.isCanceled | 24 | super.isCancelled() || internalMonitor.isCanceled |
25 | } | 25 | } |
26 | 26 | ||
27 | } \ No newline at end of file | 27 | } |
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 aa98e268..c3ba9f81 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 | |||
@@ -2,8 +2,6 @@ package hu.bme.mit.inf.dslreasoner.application.execution | |||
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | 3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript |
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GenerationTask | 4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GenerationTask |
5 | import hu.bme.mit.inf.dslreasoner.application.validation.MetamodelValidator | ||
6 | import hu.bme.mit.inf.dslreasoner.application.validation.QueryAndMetamodelValidator | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | 5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic |
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | 6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration |
9 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | 7 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel |
@@ -35,12 +33,10 @@ class GenerationTaskExecutor { | |||
35 | val scopeLoader = new ScopeLoader | 33 | val scopeLoader = new ScopeLoader |
36 | val statisticsUtil = new StatisticSections2CSV | 34 | val statisticsUtil = new StatisticSections2CSV |
37 | 35 | ||
38 | val metamodelValidator = new MetamodelValidator | ||
39 | val queryAndMetamodelValidator = new QueryAndMetamodelValidator | ||
40 | |||
41 | def executeGenerationTask( | 36 | def executeGenerationTask( |
42 | GenerationTask task, | 37 | GenerationTask task, |
43 | ScriptExecutor scriptExecutor, | 38 | ScriptExecutor scriptExecutor, |
39 | ScriptConsole.Factory scriptConsoleFactory, | ||
44 | IProgressMonitor monitor) | 40 | IProgressMonitor monitor) |
45 | { | 41 | { |
46 | monitor.subTask('''Collecting all resources''') | 42 | monitor.subTask('''Collecting all resources''') |
@@ -62,7 +58,7 @@ class GenerationTaskExecutor { | |||
62 | val memoryLimit = scriptExecutor.getMemoryLimit(configSpecification) | 58 | val memoryLimit = scriptExecutor.getMemoryLimit(configSpecification) |
63 | 59 | ||
64 | // 2. create console | 60 | // 2. create console |
65 | val console = new ScriptConsole(true,false, | 61 | val console = scriptConsoleFactory.createScriptConsole(false, |
66 | if(messageFile!==null) URI.createURI(messageFile.path) else null, | 62 | if(messageFile!==null) URI.createURI(messageFile.path) else null, |
67 | if(debugFolder!==null) URI.createURI('''«debugFolder.path»/errors.txt''') else null, | 63 | if(debugFolder!==null) URI.createURI('''«debugFolder.path»/errors.txt''') else null, |
68 | if(statisticsFile!==null) URI.createURI(statisticsFile.path) else null | 64 | if(statisticsFile!==null) URI.createURI(statisticsFile.path) else null |
@@ -132,11 +128,12 @@ class GenerationTaskExecutor { | |||
132 | // 5. create a solver and a configuration | 128 | // 5. create a solver and a configuration |
133 | // 5.1 initialize | 129 | // 5.1 initialize |
134 | val solver = solverLoader.loadSolver(task.solver,configurationMap) | 130 | val solver = solverLoader.loadSolver(task.solver,configurationMap) |
135 | 131 | val objectiveSpecification = scriptExecutor.getObjectiveSpecification(task.objectives) | |
136 | val solverConfig = solverLoader.loadSolverConfig(task.solver,configurationMap,console) | 132 | val objectiveEntries = objectiveSpecification?.entries ?: emptyList |
133 | val solverConfig = solverLoader.loadSolverConfig(task.solver,configurationMap,objectiveEntries,console) | ||
137 | // 5.2 set values that defined directly | 134 | // 5.2 set values that defined directly |
138 | solverConfig.solutionScope = new SolutionScope => [ | 135 | solverConfig.solutionScope = new SolutionScope => [ |
139 | it.numberOfRequiredSolution = if(task.numberSpecified) { | 136 | it.numberOfRequiredSolutions = if(task.numberSpecified) { |
140 | task.number | 137 | task.number |
141 | } else { | 138 | } else { |
142 | 1 | 139 | 1 |
@@ -303,7 +300,7 @@ class GenerationTaskExecutor { | |||
303 | console.flushStatistics | 300 | console.flushStatistics |
304 | console.writeMessage("Model generation finished") | 301 | console.writeMessage("Model generation finished") |
305 | } catch(Exception e) { | 302 | } catch(Exception e) { |
306 | console.writeError(''' | 303 | console.writeError(''' |
307 | Error occured («e.class.simpleName»): «e.message» | 304 | Error occured («e.class.simpleName»): «e.message» |
308 | «FOR s : e.stackTrace SEPARATOR "\n"» «s»«ENDFOR»''') | 305 | «FOR s : e.stackTrace SEPARATOR "\n"» «s»«ENDFOR»''') |
309 | } | 306 | } |
@@ -349,4 +346,4 @@ class GenerationTaskExecutor { | |||
349 | return false | 346 | return false |
350 | } | 347 | } |
351 | } | 348 | } |
352 | } \ No newline at end of file | 349 | } |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/MetamodelLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/MetamodelLoader.xtend index 5e7f84f0..626329dc 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/MetamodelLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/MetamodelLoader.xtend | |||
@@ -120,4 +120,4 @@ class MetamodelLoader { | |||
120 | // } | 120 | // } |
121 | // return res | 121 | // return res |
122 | // } | 122 | // } |
123 | } \ No newline at end of file | 123 | } |
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 05081581..5e656e8f 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 | |||
@@ -59,4 +59,4 @@ class NullWorkspace extends ReasonerWorkspace{ | |||
59 | throw new UnsupportedOperationException(message) | 59 | throw new UnsupportedOperationException(message) |
60 | } | 60 | } |
61 | override refreshFile(String name) { } | 61 | override refreshFile(String name) { } |
62 | } \ No newline at end of file | 62 | } |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSModule.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSModule.xtend index 1269ec1f..3e598dd6 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSModule.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSModule.xtend | |||
@@ -43,4 +43,4 @@ class PatternLanguageWithRSModule extends EMFPatternLanguageRuntimeModule{ | |||
43 | override Class<? extends ITypeInferrer> bindITypeInferrer() { | 43 | override Class<? extends ITypeInferrer> bindITypeInferrer() { |
44 | return EMFTypeInferrer; | 44 | return EMFTypeInferrer; |
45 | } | 45 | } |
46 | } \ No newline at end of file | 46 | } |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSSetup.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSSetup.xtend index dd5af673..c209cde5 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSSetup.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSSetup.xtend | |||
@@ -12,4 +12,4 @@ class PatternLanguageWithRSSetup extends EMFPatternLanguageStandaloneSetup{ | |||
12 | override Injector createInjector() { | 12 | override Injector createInjector() { |
13 | return Guice::createInjector(new PatternLanguageWithRSModule()); | 13 | return Guice::createInjector(new PatternLanguageWithRSModule()); |
14 | } | 14 | } |
15 | } \ No newline at end of file | 15 | } |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend index cfc91143..5a73845d 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend | |||
@@ -144,4 +144,4 @@ class QueryLoader { | |||
144 | } | 144 | } |
145 | return res | 145 | return res |
146 | } | 146 | } |
147 | } \ No newline at end of file | 147 | } |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend index dcaf74cd..6d6ad85e 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend | |||
@@ -220,4 +220,4 @@ class ScopeLoader { | |||
220 | else return specification.exactNumber | 220 | else return specification.exactNumber |
221 | } | 221 | } |
222 | 222 | ||
223 | } \ No newline at end of file | 223 | } |
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 cfb1f09b..d49a0f2a 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 | |||
@@ -9,128 +9,108 @@ import java.util.LinkedHashSet | |||
9 | import java.util.LinkedList | 9 | import java.util.LinkedList |
10 | import java.util.List | 10 | import java.util.List |
11 | import java.util.Map | 11 | import java.util.Map |
12 | import java.util.concurrent.CompletableFuture | ||
13 | import javax.swing.text.BadLocationException | ||
14 | import org.eclipse.emf.common.util.URI | 12 | import org.eclipse.emf.common.util.URI |
15 | import org.eclipse.jface.text.DocumentEvent | ||
16 | import org.eclipse.jface.text.IDocumentListener | ||
17 | import org.eclipse.swt.graphics.Color | ||
18 | import org.eclipse.ui.console.ConsolePlugin | ||
19 | import org.eclipse.ui.console.MessageConsole | ||
20 | import org.eclipse.ui.console.MessageConsoleStream | ||
21 | import org.eclipse.xtend.lib.annotations.Data | 13 | import org.eclipse.xtend.lib.annotations.Data |
22 | 14 | ||
23 | //import org.eclipse.ui.console.MessageConsole | 15 | abstract class ScriptConsole { |
24 | |||
25 | class ScriptConsole { | ||
26 | /** | ||
27 | * Console is identified with the name of this class. | ||
28 | */ | ||
29 | val final consoleID = ScriptConsole.name | ||
30 | val boolean printToConsole | 16 | val boolean printToConsole |
31 | val MessageConsole runtimeConsole; | ||
32 | val ReasonerWorkspace messageWorkspace; | 17 | val ReasonerWorkspace messageWorkspace; |
33 | val String messageFileName; | 18 | val String messageFileName; |
34 | val ReasonerWorkspace errorWorkspace; | 19 | val ReasonerWorkspace errorWorkspace; |
35 | val String errorFileName; | 20 | val String errorFileName; |
36 | val ReasonerWorkspace statisticsWorkspace; | 21 | val ReasonerWorkspace statisticsWorkspace; |
37 | val String statisticsFileName; | 22 | val String statisticsFileName; |
38 | 23 | val List<String> errorMessagesDuringInitialisation = new LinkedList; | |
24 | |||
39 | val statisticsHeaderBuffer = new LinkedHashSet<String> | 25 | val statisticsHeaderBuffer = new LinkedHashSet<String> |
40 | val statisticsDataBuffer = new LinkedList<Map<String,? extends Object>> | 26 | val statisticsDataBuffer = new LinkedList<Map<String,? extends Object>> |
41 | 27 | ||
42 | static val delimier = ',' | 28 | static val delimier = ',' |
43 | static val empty = "" | 29 | static val empty = "" |
44 | 30 | ||
45 | public new( | 31 | new(boolean printToConsole, boolean cleanFiles, URI messageConsoleURI, URI errorConsoleURI, |
46 | boolean printToRuntimeConsole, | 32 | URI statisticsConsoleURI) { |
47 | boolean cleanFiles, | 33 | this.messageWorkspace = prepareWorkspace(messageConsoleURI, errorMessagesDuringInitialisation) |
48 | URI messageConsoleURI, | ||
49 | URI errorConsoleURI, | ||
50 | URI statisticsConsoleURI) | ||
51 | { | ||
52 | val List<String> errorMessagesDuringInitialisation = new LinkedList | ||
53 | |||
54 | this.messageWorkspace = prepareWorkspace(messageConsoleURI,errorMessagesDuringInitialisation) | ||
55 | this.messageFileName = prepareFileName(messageConsoleURI) | 34 | this.messageFileName = prepareFileName(messageConsoleURI) |
56 | this.errorWorkspace = prepareWorkspace(errorConsoleURI,errorMessagesDuringInitialisation) | 35 | this.errorWorkspace = prepareWorkspace(errorConsoleURI, errorMessagesDuringInitialisation) |
57 | this.errorFileName = prepareFileName(errorConsoleURI) | 36 | this.errorFileName = prepareFileName(errorConsoleURI) |
58 | this.statisticsWorkspace = prepareWorkspace(statisticsConsoleURI,errorMessagesDuringInitialisation) | 37 | this.statisticsWorkspace = prepareWorkspace(statisticsConsoleURI, errorMessagesDuringInitialisation) |
59 | this.statisticsFileName = prepareFileName(statisticsConsoleURI) | 38 | this.statisticsFileName = prepareFileName(statisticsConsoleURI) |
60 | 39 | ||
61 | this.printToConsole = (ConsolePlugin.getDefault() === null) | 40 | this.printToConsole = printToConsole |
62 | this.runtimeConsole = if(printToRuntimeConsole) { prepareRuntimeConsole } else { null } | 41 | } |
63 | 42 | ||
64 | errorMessagesDuringInitialisation.forEach[ | 43 | /** |
44 | * Writes any error messages that occurred during console initialization. | ||
45 | * | ||
46 | * Should be called by implementations at the end of their constructors. | ||
47 | */ | ||
48 | protected final def writeErrorMessagesDuringInitialisation() { | ||
49 | errorMessagesDuringInitialisation.forEach [ | ||
65 | this.writeError('''Error during console initialisation: "«it»"''') | 50 | this.writeError('''Error during console initialisation: "«it»"''') |
66 | ] | 51 | ] |
52 | errorMessagesDuringInitialisation.clear | ||
67 | } | 53 | } |
68 | 54 | ||
69 | public def writeMessage(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { | 55 | def void writeMessage(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { |
70 | val resolvedText = this.resolveToText(message, separator, decorators) | 56 | val resolvedText = this.resolveToText(message, separator, decorators) |
71 | if(messageWorkspace!==null) { | 57 | if (messageWorkspace !== null) { |
72 | messageWorkspace.writeText(messageFileName,resolvedText); | 58 | messageWorkspace.writeText(messageFileName, resolvedText); |
73 | } | 59 | } |
74 | if(printToConsole) { | 60 | if (printToConsole) { |
75 | println(resolvedText) | 61 | println(resolvedText) |
76 | } | 62 | } |
77 | if(runtimeConsole!==null) { | ||
78 | writeToRuntimeConsole(message, separator, decorators) | ||
79 | } | ||
80 | } | 63 | } |
81 | public def writeMessage(String message) { | 64 | |
82 | if(messageWorkspace!==null) { | 65 | def void writeMessage(String message) { |
83 | messageWorkspace.writeText(messageFileName,message); | 66 | if (messageWorkspace !== null) { |
67 | messageWorkspace.writeText(messageFileName, message); | ||
84 | } | 68 | } |
85 | if(printToConsole) { | 69 | if (printToConsole) { |
86 | println(message) | 70 | println(message) |
87 | } | 71 | } |
88 | if(runtimeConsole!==null) { | ||
89 | writeToRuntimeConsole(message) | ||
90 | } | ||
91 | } | 72 | } |
92 | public def writeError(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { | 73 | |
74 | def void writeError(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { | ||
93 | val resolvedText = this.resolveToText(message, separator, decorators) | 75 | val resolvedText = this.resolveToText(message, separator, decorators) |
94 | if(errorWorkspace!==null) { | 76 | if (errorWorkspace !== null) { |
95 | errorWorkspace.writeText(errorFileName,resolvedText); | 77 | errorWorkspace.writeText(errorFileName, resolvedText); |
96 | } | 78 | } |
97 | println(message) | 79 | println(message) |
98 | if(runtimeConsole!==null) { | ||
99 | writeToRuntimeConsole(message, separator, decorators) | ||
100 | } | ||
101 | } | 80 | } |
102 | public def writeError(String message) { | 81 | |
103 | if(errorWorkspace!==null) { | 82 | def void writeError(String message) { |
104 | errorWorkspace.writeText(errorFileName,message); | 83 | if (errorWorkspace !== null) { |
84 | errorWorkspace.writeText(errorFileName, message); | ||
105 | } | 85 | } |
106 | println(message) | 86 | println(message) |
107 | if(runtimeConsole!==null) { | ||
108 | writeToRuntimeConsole(message) | ||
109 | } | ||
110 | } | 87 | } |
111 | public def writeStatistics(LinkedHashMap<String,? extends Object> statistics) { | 88 | |
112 | if(statisticsWorkspace!==null) { | 89 | def writeStatistics(LinkedHashMap<String, ? extends Object> statistics) { |
113 | val message = ''' | 90 | if (statisticsWorkspace !== null) { |
91 | val message = ''' | ||
114 | «FOR key : statistics.keySet SEPARATOR delimier»«key»«ENDFOR» | 92 | «FOR key : statistics.keySet SEPARATOR delimier»«key»«ENDFOR» |
115 | «FOR value : statistics.values SEPARATOR delimier»«value»«ENDFOR»''' | 93 | «FOR value : statistics.values SEPARATOR delimier»«value»«ENDFOR»''' |
116 | statisticsWorkspace.writeText(statisticsFileName,message); | 94 | statisticsWorkspace.writeText(statisticsFileName, message); |
117 | } | 95 | } |
118 | } | 96 | } |
119 | public def addStatistics(LinkedHashMap<String,? extends Object> statistics) { | 97 | |
120 | for(key : statistics.keySet) { | 98 | def addStatistics(LinkedHashMap<String, ? extends Object> statistics) { |
99 | for (key : statistics.keySet) { | ||
121 | this.statisticsHeaderBuffer.add(key); | 100 | this.statisticsHeaderBuffer.add(key); |
122 | } | 101 | } |
123 | this.statisticsDataBuffer.add(statistics) | 102 | this.statisticsDataBuffer.add(statistics) |
124 | } | 103 | } |
125 | public def flushStatistics() { | 104 | |
126 | if(statisticsWorkspace!==null) { | 105 | def flushStatistics() { |
127 | val message = ''' | 106 | if (statisticsWorkspace !== null) { |
128 | «FOR key : statisticsHeaderBuffer SEPARATOR delimier»«key»«ENDFOR» | 107 | val message = ''' |
129 | «FOR line : statisticsDataBuffer» | 108 | «FOR key : statisticsHeaderBuffer SEPARATOR delimier»«key»«ENDFOR» |
130 | «FOR key : statisticsHeaderBuffer SEPARATOR delimier»«IF line.containsKey(key)»«line.get(key)»«ELSE»«empty»«ENDIF»«ENDFOR» | 109 | «FOR line : statisticsDataBuffer» |
131 | «ENDFOR» | 110 | «FOR key : statisticsHeaderBuffer SEPARATOR delimier»«IF line.containsKey(key)»«line.get(key)»«ELSE»«empty»«ENDIF»«ENDFOR» |
111 | «ENDFOR» | ||
132 | ''' | 112 | ''' |
133 | statisticsWorkspace.writeText(statisticsFileName,message); | 113 | statisticsWorkspace.writeText(statisticsFileName, message); |
134 | statisticsHeaderBuffer.clear | 114 | statisticsHeaderBuffer.clear |
135 | statisticsDataBuffer.clear | 115 | statisticsDataBuffer.clear |
136 | } | 116 | } |
@@ -140,143 +120,66 @@ class ScriptConsole { | |||
140 | if (uri === null) { | 120 | if (uri === null) { |
141 | return null | 121 | return null |
142 | } else { | 122 | } else { |
143 | try{ | 123 | try { |
144 | val folderURI = uri.trimSegments(1) | 124 | val folderURI = uri.trimSegments(1) |
145 | if(folderURI.isFile) { | 125 | if (folderURI.isFile) { |
146 | return new FileSystemWorkspace(folderURI.toString,"")=>[init] | 126 | return new FileSystemWorkspace(folderURI.toString, "") => [init] |
147 | } else if(folderURI.isPlatformResource) { | 127 | } else if (folderURI.isPlatformResource) { |
148 | return new ProjectWorkspace(folderURI.toString,"")=>[init] | 128 | return new ProjectWorkspace(folderURI.toString, "") => [init] |
149 | } else { | 129 | } else { |
150 | throw new UnsupportedOperationException('''Unsupported file usi: "«uri»"!''') | 130 | throw new UnsupportedOperationException('''Unsupported file usi: "«uri»"!''') |
151 | } | 131 | } |
152 | } catch(Exception e) { | 132 | } catch (Exception e) { |
153 | errors += e.message | 133 | errors += e.message |
154 | return null | 134 | return null |
155 | } | 135 | } |
156 | } | 136 | } |
157 | } | 137 | } |
138 | |||
158 | private def prepareFileName(URI uri) { | 139 | private def prepareFileName(URI uri) { |
159 | if(uri!==null) { | 140 | if (uri !== null) { |
160 | return uri.lastSegment | 141 | return uri.lastSegment |
161 | } else { | 142 | } else { |
162 | null | 143 | null |
163 | } | 144 | } |
164 | } | 145 | } |
165 | 146 | ||
166 | private def MessageConsole prepareRuntimeConsole() { | ||
167 | val plugin = ConsolePlugin.getDefault(); | ||
168 | if(plugin === null) { | ||
169 | return null | ||
170 | } else { | ||
171 | val conMan = plugin.getConsoleManager(); | ||
172 | val existingConsoles = conMan.getConsoles(); | ||
173 | val existingConsolesWithID = existingConsoles.filter[it.name.equals(consoleID)] | ||
174 | if(existingConsolesWithID.empty) { | ||
175 | val MessageConsole res = new MessageConsole(consoleID,null) | ||
176 | conMan.addConsoles(#[res]); | ||
177 | |||
178 | return res | ||
179 | } else { | ||
180 | return existingConsolesWithID.head as MessageConsole | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | private def resolveToText(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { | 147 | private def resolveToText(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { |
185 | val messageString = message.toString | 148 | val messageString = message.toString |
186 | // 0. split the message | 149 | // 0. split the message |
187 | val separatedMessage = if(messageString.startsWith(separator,-1)) { | 150 | val separatedMessage = if (messageString.startsWith(separator, -1)) { |
188 | #[""]+messageString.split(separator,-1) | 151 | #[""] + messageString.split(separator, -1) |
189 | } else { | 152 | } else { |
190 | messageString.split(separator,-1).toList | 153 | messageString.split(separator, -1).toList |
191 | } | 154 | } |
192 | if(separatedMessage.size-1 !== decorators.size) { | 155 | if (separatedMessage.size - 1 !== decorators.size) { |
193 | throw new IllegalArgumentException | 156 | throw new IllegalArgumentException |
194 | } | 157 | } |
195 | 158 | ||
196 | return '''«FOR i : 0..<decorators.size»«separatedMessage.get(i)»[«decorators.get(i).text»]«ENDFOR»«separatedMessage.last»''' | 159 | return '''«FOR i : 0..<decorators.size»«separatedMessage.get(i)»[«decorators.get(i).text»]«ENDFOR»«separatedMessage.last»''' |
197 | } | 160 | } |
198 | private def writeToRuntimeConsole(CharSequence message) { | 161 | |
199 | // 1. reveal the console view | 162 | @FunctionalInterface |
200 | ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this.runtimeConsole); | 163 | interface Factory { |
201 | val stream = this.runtimeConsole.newMessageStream | 164 | def ScriptConsole createScriptConsole(boolean cleanFiles, URI messageConsoleURI, URI errorConsoleURI, |
202 | stream.println(message.toString) | 165 | URI statisticsConsoleURI) |
203 | stream.close | ||
204 | } | 166 | } |
205 | private def writeToRuntimeConsole(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { | 167 | } |
206 | val messageString = message.toString | 168 | |
207 | // 0. split the message | 169 | class StandardOutputBasedScriptConsole extends ScriptConsole { |
208 | val separatedMessage = if(messageString.startsWith(separator)) { | 170 | new(boolean cleanFiles, URI messageConsoleURI, URI errorConsoleURI, URI statisticsConsoleURI) { |
209 | #[""]+messageString.split(separator,-1) | 171 | super(true, cleanFiles, messageConsoleURI, errorConsoleURI, statisticsConsoleURI) |
210 | } else { | 172 | writeErrorMessagesDuringInitialisation() |
211 | messageString.split(separator,-1).toList | ||
212 | } | ||
213 | if(separatedMessage.size-1 !== decorators.size) { | ||
214 | throw new IllegalArgumentException | ||
215 | } | ||
216 | |||
217 | // 1. reveal the console view | ||
218 | ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this.runtimeConsole); | ||
219 | val stream = this.runtimeConsole.newMessageStream | ||
220 | |||
221 | // 2. print the segments of the view | ||
222 | for(i : 0..<decorators.size) { | ||
223 | stream.print(separatedMessage.get(i)) | ||
224 | writeDecoratedTextToRuntimeConsole(decorators.get(i),stream) | ||
225 | |||
226 | } | ||
227 | // 2.1 write the last segment of | ||
228 | stream.println(separatedMessage.last) | ||
229 | |||
230 | //stream.println(message.toString) | ||
231 | stream.close | ||
232 | } | 173 | } |
233 | private def writeDecoratedTextToRuntimeConsole(ScriptConsoleDecorator message, MessageConsoleStream stream) { | 174 | |
234 | val originalBackgroundColor = this.runtimeConsole.background | 175 | public static val FACTORY = new ScriptConsole.Factory { |
235 | var Color newColor = null; | 176 | override createScriptConsole(boolean cleanFiles, URI messageConsoleURI, URI errorConsoleURI, |
236 | 177 | URI statisticsConsoleURI) { | |
237 | val text = '''[«message.text»]''' | 178 | new StandardOutputBasedScriptConsole(cleanFiles, messageConsoleURI, errorConsoleURI, statisticsConsoleURI) |
238 | if(message.red >= 0 && message.green >= 0 && message.blue >= 0) { | ||
239 | newColor = new Color(originalBackgroundColor.device,message.red,message.green,message.blue) | ||
240 | this.runtimeConsole.setBackground(newColor) | ||
241 | } | ||
242 | stream.flush | ||
243 | val CompletableFuture<Boolean> finished = new CompletableFuture<Boolean> | ||
244 | val listener = new IDocumentListener() { | ||
245 | override documentAboutToBeChanged(DocumentEvent event) { } | ||
246 | override documentChanged(DocumentEvent event) { | ||
247 | //println('''ftext="«event.fText»", message="«message.text»" endswith=«event.fText.endsWith(message.text)»''') | ||
248 | if(event.fText.endsWith(text)) { | ||
249 | val from = event.fDocument.length-text.length+1 | ||
250 | val length = message.text.length | ||
251 | //println('''from: «from» length «length»''') | ||
252 | try{ | ||
253 | runtimeConsole.addHyperlink( | ||
254 | new ScriptConsoleFileHiperlink(message.hyperlink), | ||
255 | from, | ||
256 | length | ||
257 | ) | ||
258 | //println("link added") | ||
259 | } catch(BadLocationException e) { | ||
260 | |||
261 | } finally { | ||
262 | runtimeConsole.document.removeDocumentListener(this) | ||
263 | finished.complete(true) | ||
264 | } | ||
265 | } | ||
266 | |||
267 | } | ||
268 | } | ||
269 | runtimeConsole.document.addDocumentListener(listener) | ||
270 | stream.print(text) | ||
271 | stream.flush | ||
272 | finished.get | ||
273 | //stream.console.new | ||
274 | if(message.red >= 0 && message.green >= 0 && message.blue >= 0) { | ||
275 | newColor.dispose | ||
276 | this.runtimeConsole.setBackground(originalBackgroundColor) | ||
277 | } | 179 | } |
278 | } | 180 | } |
279 | } | 181 | } |
182 | |||
280 | @Data | 183 | @Data |
281 | class ScriptConsoleDecorator { | 184 | class ScriptConsoleDecorator { |
282 | String text | 185 | String text |
@@ -284,33 +187,36 @@ class ScriptConsoleDecorator { | |||
284 | int Red | 187 | int Red |
285 | int Green | 188 | int Green |
286 | int Blue | 189 | int Blue |
287 | 190 | ||
288 | public new(String text) { | 191 | new(String text) { |
289 | this.text = text | 192 | this.text = text |
290 | this.hyperlink = null | 193 | this.hyperlink = null |
291 | this.Red = -1 | 194 | this.Red = -1 |
292 | this.Green = -1 | 195 | this.Green = -1 |
293 | this.Blue = -1 | 196 | this.Blue = -1 |
294 | } | 197 | } |
295 | public new(String text, File hyperlink) { | 198 | |
199 | new(String text, File hyperlink) { | ||
296 | this.text = text | 200 | this.text = text |
297 | this.hyperlink = hyperlink | 201 | this.hyperlink = hyperlink |
298 | this.Red = -1 | 202 | this.Red = -1 |
299 | this.Green = -1 | 203 | this.Green = -1 |
300 | this.Blue = -1 | 204 | this.Blue = -1 |
301 | } | 205 | } |
302 | public new(String text, int red, int green, int blue) { | 206 | |
207 | new(String text, int red, int green, int blue) { | ||
303 | this.text = text | 208 | this.text = text |
304 | this.hyperlink = null | 209 | this.hyperlink = null |
305 | this.Red = red | 210 | this.Red = red |
306 | this.Green = green | 211 | this.Green = green |
307 | this.Blue = blue | 212 | this.Blue = blue |
308 | } | 213 | } |
309 | public new(String text, File hyperlink, int red, int green, int blue) { | 214 | |
215 | new(String text, File hyperlink, int red, int green, int blue) { | ||
310 | this.text = text | 216 | this.text = text |
311 | this.hyperlink = hyperlink | 217 | this.hyperlink = hyperlink |
312 | this.Red = red | 218 | this.Red = red |
313 | this.Green = green | 219 | this.Green = green |
314 | this.Blue = blue | 220 | this.Blue = blue |
315 | } | 221 | } |
316 | } \ No newline at end of file | 222 | } |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsoleFileHiperlink.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsoleFileHiperlink.xtend deleted file mode 100644 index 25e49c80..00000000 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsoleFileHiperlink.xtend +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import org.eclipse.ui.console.IHyperlink | ||
4 | import org.eclipse.ui.ide.IDE | ||
5 | import org.eclipse.ui.PlatformUI | ||
6 | import org.eclipse.core.filesystem.EFS | ||
7 | import java.io.File | ||
8 | import java.net.URI | ||
9 | |||
10 | class ScriptConsoleFileHiperlink implements IHyperlink { | ||
11 | |||
12 | private val URI path; | ||
13 | |||
14 | new(File file) { | ||
15 | this.path = file.toURI() | ||
16 | } | ||
17 | |||
18 | override linkActivated() { | ||
19 | //println("open path: "+path.toString) | ||
20 | val page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
21 | val fileStore = EFS.getStore(path) | ||
22 | IDE.openEditorOnFileStore(page,fileStore) | ||
23 | } | ||
24 | |||
25 | override linkEntered() { } | ||
26 | |||
27 | override linkExited() { } | ||
28 | } \ No newline at end of file | ||
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 04449a74..3dea677f 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 | |||
@@ -14,6 +14,8 @@ import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GraphPatt | |||
14 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MemoryEntry | 14 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MemoryEntry |
15 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelReference | 15 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelReference |
16 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification | 16 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification |
17 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ObjectiveReference | ||
18 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ObjectiveSpecification | ||
17 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelReference | 19 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelReference |
18 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelSpecification | 20 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelSpecification |
19 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternSpecification | 21 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternSpecification |
@@ -29,14 +31,18 @@ import org.eclipse.core.runtime.IProgressMonitor | |||
29 | import org.eclipse.core.runtime.Status | 31 | import org.eclipse.core.runtime.Status |
30 | import org.eclipse.core.runtime.jobs.Job | 32 | import org.eclipse.core.runtime.jobs.Job |
31 | import org.eclipse.emf.common.util.URI | 33 | import org.eclipse.emf.common.util.URI |
34 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | ||
32 | 35 | ||
36 | @FinalFieldsConstructor | ||
33 | class ScriptExecutor { | 37 | class ScriptExecutor { |
34 | val parser = new ApplicationConfigurationParser | 38 | val parser = new ApplicationConfigurationParser |
35 | 39 | ||
40 | val ScriptConsole.Factory scriptConsoleFactory | ||
41 | |||
36 | /** | 42 | /** |
37 | * Executes a script | 43 | * Executes a script |
38 | */ | 44 | */ |
39 | public def executeScript(URI uri) { | 45 | def executeScript(URI uri) { |
40 | val job = new Job('''Model Generation: «uri.lastSegment»''') { | 46 | val job = new Job('''Model Generation: «uri.lastSegment»''') { |
41 | override protected run(IProgressMonitor monitor) { | 47 | override protected run(IProgressMonitor monitor) { |
42 | try{ | 48 | try{ |
@@ -53,10 +59,10 @@ class ScriptExecutor { | |||
53 | job.schedule(); | 59 | job.schedule(); |
54 | } | 60 | } |
55 | 61 | ||
56 | public def executeScript(ConfigurationScript script, IProgressMonitor monitor) { | 62 | def executeScript(ConfigurationScript script, IProgressMonitor monitor) { |
57 | script.activateAllEPackageReferences | 63 | script.activateAllEPackageReferences |
58 | val tasks = script.commands.filter(Task) | 64 | val tasks = script.commands.filter(Task) |
59 | val intermediateScriptConsole = new ScriptConsole(true,false,null,null,null) | 65 | val intermediateScriptConsole = scriptConsoleFactory.createScriptConsole(false, null, null, null) |
60 | 66 | ||
61 | for(taskIndex : 0..<tasks.size) { | 67 | for(taskIndex : 0..<tasks.size) { |
62 | if(taskIndex>0) { | 68 | if(taskIndex>0) { |
@@ -94,12 +100,12 @@ class ScriptExecutor { | |||
94 | // } | 100 | // } |
95 | } | 101 | } |
96 | 102 | ||
97 | def public dispatch execute(GenerationTask task, IProgressMonitor monitor) { | 103 | def dispatch void execute(GenerationTask task, IProgressMonitor monitor) { |
98 | val generationTaskExecutor = new GenerationTaskExecutor | 104 | val generationTaskExecutor = new GenerationTaskExecutor |
99 | generationTaskExecutor.executeGenerationTask(task,this,monitor) | 105 | generationTaskExecutor.executeGenerationTask(task,this,scriptConsoleFactory,monitor) |
100 | } | 106 | } |
101 | 107 | ||
102 | def public dispatch execute(Task task, IProgressMonitor monitor) { | 108 | def dispatch void execute(Task task, IProgressMonitor monitor) { |
103 | throw new IllegalArgumentException('''Unsupported task type: «task.class.simpleName»!''') | 109 | throw new IllegalArgumentException('''Unsupported task type: «task.class.simpleName»!''') |
104 | } | 110 | } |
105 | 111 | ||
@@ -174,6 +180,16 @@ class ScriptExecutor { | |||
174 | null | 180 | null |
175 | } | 181 | } |
176 | 182 | ||
183 | def dispatch getObjectiveSpecification(ObjectiveSpecification config) { | ||
184 | config | ||
185 | } | ||
186 | def dispatch getObjectiveSpecification(ObjectiveReference config) { | ||
187 | config.referred.specification | ||
188 | } | ||
189 | def dispatch getObjectiveSpecification(Void config) { | ||
190 | null | ||
191 | } | ||
192 | |||
177 | def dispatch getConfiguration(ConfigSpecification config) { | 193 | def dispatch getConfiguration(ConfigSpecification config) { |
178 | config | 194 | config |
179 | } | 195 | } |
@@ -238,6 +254,7 @@ class ScriptExecutor { | |||
238 | } | 254 | } |
239 | } | 255 | } |
240 | } | 256 | } |
257 | |||
241 | static val boolean measuring = true | 258 | static val boolean measuring = true |
242 | static def restForMeasurements(ScriptConsole console) { | 259 | static def restForMeasurements(ScriptConsole console) { |
243 | if(measuring) { | 260 | if(measuring) { |
@@ -248,4 +265,5 @@ class ScriptExecutor { | |||
248 | Thread.sleep(2500) | 265 | Thread.sleep(2500) |
249 | } | 266 | } |
250 | } | 267 | } |
251 | } \ No newline at end of file | 268 | } |
269 | |||
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 2fe69a47..b1be56cb 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,45 +1,47 @@ | |||
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.dlsreasoner.alloy.reasoner.AlloyBackendSolver | ||
4 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolver | 3 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolver |
5 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolverConfiguration | 4 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolverConfiguration |
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.CostObjectiveFunction | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ObjectiveEntry | ||
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.OptimizationEntry | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Solver | 8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Solver |
9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ThresholdEntry | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration | 10 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration |
8 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SMTSolver | 11 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SMTSolver |
9 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SmtSolverConfiguration | 12 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SmtSolverConfiguration |
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveConfiguration | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveElementConfiguration | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DiversityDescriptor | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | 16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner |
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | 17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration |
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind | ||
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold | ||
20 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser | ||
21 | import java.util.List | ||
12 | import java.util.Map | 22 | import java.util.Map |
13 | import java.util.Optional | 23 | import java.util.Optional |
24 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel | ||
25 | import org.eclipse.xtext.EcoreUtil2 | ||
14 | import org.eclipse.xtext.xbase.lib.Functions.Function1 | 26 | import org.eclipse.xtext.xbase.lib.Functions.Function1 |
15 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DiversityDescriptor | ||
17 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.builder.SolverConfiguration | ||
18 | 27 | ||
19 | class SolverLoader { | 28 | class SolverLoader { |
20 | def loadSolver(Solver solver, Map<String, String> config) { | 29 | def loadSolver(Solver solver, Map<String, String> config) { |
21 | switch(solver) { | 30 | switch (solver) { |
22 | case ALLOY_SOLVER: return new AlloySolver | 31 | case ALLOY_SOLVER: return new AlloySolver |
23 | case SMT_SOLVER: return new SMTSolver | 32 | case SMT_SOLVER: return new SMTSolver |
24 | case VIATRA_SOLVER: return new ViatraReasoner | 33 | case VIATRA_SOLVER: return new ViatraReasoner |
25 | } | 34 | } |
26 | } | 35 | } |
27 | 36 | ||
28 | 37 | private def <Type> Optional<Type> getAsType(Map<String, String> config, String key, ScriptConsole console, | |
29 | 38 | Function1<String, Type> parser, Class<Type> requestedType) { | |
30 | private def <Type> Optional<Type> getAsType( | 39 | if (config.containsKey(key)) { |
31 | Map<String, String> config, | ||
32 | String key, | ||
33 | ScriptConsole console, | ||
34 | Function1<String,Type> parser, | ||
35 | Class<Type> requestedType) | ||
36 | { | ||
37 | if(config.containsKey(key)) { | ||
38 | val stringValue = config.get(key) | 40 | val stringValue = config.get(key) |
39 | try{ | 41 | try { |
40 | val parsedValue = parser.apply(stringValue) | 42 | val parsedValue = parser.apply(stringValue) |
41 | return Optional.of(parsedValue) | 43 | return Optional.of(parsedValue) |
42 | } catch(Exception e) { | 44 | } catch (Exception e) { |
43 | console.writeError('''Unable to parse configuration value for "«key»" to «requestedType.simpleName»!''') | 45 | console.writeError('''Unable to parse configuration value for "«key»" to «requestedType.simpleName»!''') |
44 | return Optional::empty | 46 | return Optional::empty |
45 | } | 47 | } |
@@ -47,45 +49,54 @@ class SolverLoader { | |||
47 | return Optional::empty | 49 | return Optional::empty |
48 | } | 50 | } |
49 | } | 51 | } |
52 | |||
50 | private def getAsInteger(Map<String, String> config, String key, ScriptConsole console) { | 53 | private def getAsInteger(Map<String, String> config, String key, ScriptConsole console) { |
51 | return getAsType(config,key,console,[x|Integer.parseInt(x)],Integer) | 54 | return getAsType(config, key, console, [x|Integer.parseInt(x)], Integer) |
52 | } | 55 | } |
56 | |||
53 | private def getAsBoolean(Map<String, String> config, String key, ScriptConsole console) { | 57 | private def getAsBoolean(Map<String, String> config, String key, ScriptConsole console) { |
54 | return getAsType(config,key,console,[x|Boolean.parseBoolean(x)],Boolean) | 58 | return getAsType(config, key, console, [x|Boolean.parseBoolean(x)], Boolean) |
55 | } | 59 | } |
60 | |||
56 | private def getAsDouble(Map<String, String> config, String key, ScriptConsole console) { | 61 | private def getAsDouble(Map<String, String> config, String key, ScriptConsole console) { |
57 | return getAsType(config,key,console,[x|Double.parseDouble(x)],Double) | 62 | return getAsType(config, key, console, [x|Double.parseDouble(x)], Double) |
58 | } | 63 | } |
59 | 64 | ||
60 | def loadSolverConfig( | 65 | def loadSolverConfig(Solver solver, Map<String, String> config, List<ObjectiveEntry> objectiveEntries, |
61 | Solver solver, | 66 | ScriptConsole console) { |
62 | Map<String, String> config, | 67 | switch (solver) { |
63 | ScriptConsole console) | 68 | case ALLOY_SOLVER: { |
64 | { | 69 | if (!objectiveEntries.empty) { |
65 | if(solver === Solver::ALLOY_SOLVER) { | 70 | throw new IllegalArgumentException("Objectives are not supported by Alloy.") |
66 | return new AlloySolverConfiguration => [c| | 71 | } |
67 | config.getAsInteger("symmetry",console) | 72 | val c = new SmtSolverConfiguration |
68 | .ifPresent[c.symmetry = it] | 73 | config.getAsBoolean("fixRandomSeed", console).ifPresent[c.fixRandomSeed = it] |
69 | config.getAsType("solver",console,[x|AlloyBackendSolver::valueOf(x)],AlloyBackendSolver) | 74 | config.getAsType("path", console, [it], String).ifPresent[c.solverPath = it] |
70 | .ifPresent[c.solver = it] | 75 | c |
71 | ] | 76 | } |
72 | } else if(solver === Solver::SMT_SOLVER) { | 77 | case SMT_SOLVER: { |
73 | return new SmtSolverConfiguration => [c| | 78 | if (!objectiveEntries.empty) { |
74 | config.getAsBoolean("fixRandomSeed",console).ifPresent[c.fixRandomSeed = it] | 79 | throw new IllegalArgumentException("Objectives are not supported by Z3.") |
75 | config.getAsType("path",console,[it],String).ifPresent[c.solverPath = it] | 80 | } |
76 | ] | 81 | val c = new SmtSolverConfiguration |
77 | } else if(solver === Solver::VIATRA_SOLVER) { | 82 | config.getAsBoolean("fixRandomSeed", console).ifPresent[c.fixRandomSeed = it] |
78 | return new ViatraReasonerConfiguration => [c| | 83 | config.getAsType("path", console, [it], String).ifPresent[c.solverPath = it] |
79 | c.debugCongiguration.partialInterpretatioVisualiser = new GraphvizVisualiser | 84 | c |
80 | if(config.containsKey("diversity-range")) { | 85 | } |
86 | case VIATRA_SOLVER: { | ||
87 | val c = new ViatraReasonerConfiguration | ||
88 | c.debugConfiguration.partialInterpretatioVisualiser = new GraphvizVisualiser | ||
89 | if (config.containsKey("diversity-range")) { | ||
81 | val stringValue = config.get("diversity-range") | 90 | val stringValue = config.get("diversity-range") |
82 | try{ | 91 | try { |
83 | val range = Integer.parseInt(stringValue) | 92 | val range = Integer.parseInt(stringValue) |
84 | c.diversityRequirement = new DiversityDescriptor => [ | 93 | c.diversityRequirement = new DiversityDescriptor => [ |
85 | it.ensureDiversity = true | 94 | it.ensureDiversity = true |
86 | it.range = range | 95 | it.range = range |
87 | ] | 96 | ] |
88 | } catch (NumberFormatException e) {console.writeError('''Malformed number format: «e.message»''')} | 97 | } catch (NumberFormatException e) { |
98 | console.writeError('''Malformed number format: «e.message»''') | ||
99 | } | ||
89 | } | 100 | } |
90 | if(config.containsKey("numeric-solver-at-end")) { | 101 | if(config.containsKey("numeric-solver-at-end")) { |
91 | val stringValue = config.get("numeric-solver-at-end") | 102 | val stringValue = config.get("numeric-solver-at-end") |
@@ -124,26 +135,83 @@ class SolverLoader { | |||
124 | c.unfinishedWFWeight = Integer.parseInt(stringValue) | 135 | c.unfinishedWFWeight = Integer.parseInt(stringValue) |
125 | } catch(Exception e) {} | 136 | } catch(Exception e) {} |
126 | } | 137 | } |
127 | if(config.containsKey("fitness-objectCreationCosts")) { | 138 | for (objectiveEntry : objectiveEntries) { |
128 | val stringValue = config.get("fitness-objectCreationCosts") | 139 | val costObjectiveConfig = new CostObjectiveConfiguration |
129 | try { | 140 | switch (objectiveEntry) { |
130 | c.calculateObjectCreationCosts = Boolean.parseBoolean(stringValue) | 141 | OptimizationEntry: { |
131 | } catch(Exception e) {} | 142 | costObjectiveConfig.findExtremum = true |
143 | costObjectiveConfig.kind = switch (direction : objectiveEntry.direction) { | ||
144 | case MAXIMIZE: | ||
145 | ObjectiveKind.HIGHER_IS_BETTER | ||
146 | case MINIMIZE: | ||
147 | ObjectiveKind.LOWER_IS_BETTER | ||
148 | default: | ||
149 | throw new IllegalArgumentException("Unknown direction: " + direction) | ||
150 | } | ||
151 | costObjectiveConfig.threshold = ObjectiveThreshold.NO_THRESHOLD | ||
152 | } | ||
153 | ThresholdEntry: { | ||
154 | costObjectiveConfig.findExtremum = false | ||
155 | val threshold = objectiveEntry.threshold.doubleValue | ||
156 | switch (operator : objectiveEntry.operator) { | ||
157 | case LESS: { | ||
158 | costObjectiveConfig.kind = ObjectiveKind.LOWER_IS_BETTER | ||
159 | costObjectiveConfig.threshold = new ObjectiveThreshold.Exclusive(threshold) | ||
160 | } | ||
161 | case GREATER: { | ||
162 | costObjectiveConfig.kind = ObjectiveKind.HIGHER_IS_BETTER | ||
163 | costObjectiveConfig.threshold = new ObjectiveThreshold.Exclusive(threshold) | ||
164 | } | ||
165 | case LESS_EQUALS: { | ||
166 | costObjectiveConfig.kind = ObjectiveKind.LOWER_IS_BETTER | ||
167 | costObjectiveConfig.threshold = new ObjectiveThreshold.Exclusive(threshold) | ||
168 | } | ||
169 | case GREATER_EQUALS: { | ||
170 | costObjectiveConfig.kind = ObjectiveKind.HIGHER_IS_BETTER | ||
171 | costObjectiveConfig.threshold = new ObjectiveThreshold.Exclusive(threshold) | ||
172 | } | ||
173 | default: | ||
174 | throw new IllegalArgumentException("Unknown operator: " + operator) | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | val function = objectiveEntry.function | ||
179 | if (function instanceof CostObjectiveFunction) { | ||
180 | for (costEntry : function.entries) { | ||
181 | val element = new CostObjectiveElementConfiguration | ||
182 | val pattern = costEntry.patternElement.pattern | ||
183 | val packageName = costEntry.patternElement.package?.packageName ?: | ||
184 | EcoreUtil2.getContainerOfType(pattern, PatternModel)?.packageName | ||
185 | element.patternQualifiedName = if (packageName.nullOrEmpty) { | ||
186 | pattern.name | ||
187 | } else { | ||
188 | packageName + "." + pattern.name | ||
189 | } | ||
190 | element.weight = costEntry.weight | ||
191 | costObjectiveConfig.elements += element | ||
192 | } | ||
193 | } else { | ||
194 | throw new IllegalArgumentException("Only cost objectives are supported by VIATRA.") | ||
195 | } | ||
196 | c.costObjectives += costObjectiveConfig | ||
132 | } | 197 | } |
133 | ] | 198 | c |
134 | } else { | 199 | } |
135 | throw new UnsupportedOperationException('''Unknown solver: «solver»''') | 200 | default: |
201 | throw new UnsupportedOperationException('''Unknown solver: «solver»''') | ||
136 | } | 202 | } |
137 | } | 203 | } |
138 | 204 | ||
139 | def dispatch void setRunIndex(AlloySolverConfiguration config, Map<String, String> parameters, int runIndex, ScriptConsole console) { | 205 | def dispatch void setRunIndex(AlloySolverConfiguration config, Map<String, String> parameters, int runIndex, |
140 | parameters.getAsBoolean("randomize",console).ifPresent[ | 206 | ScriptConsole console) { |
141 | if(it) { | 207 | parameters.getAsBoolean("randomize", console).ifPresent [ |
142 | config.randomise = runIndex-1 | 208 | if (it) { |
209 | config.randomise = runIndex - 1 | ||
143 | } | 210 | } |
144 | ] | 211 | ] |
145 | } | 212 | } |
146 | def dispatch void setRunIndex(LogicSolverConfiguration config, Map<String, String> parameters, int runIndex, ScriptConsole console) { | 213 | |
147 | 214 | def dispatch void setRunIndex(LogicSolverConfiguration config, Map<String, String> parameters, int runIndex, | |
215 | ScriptConsole console) { | ||
148 | } | 216 | } |
149 | } \ No newline at end of file | 217 | } |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend index c612f0ea..42be3ed7 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend | |||
@@ -1,27 +1,17 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | 1 | package hu.bme.mit.inf.dslreasoner.application.execution |
2 | 2 | ||
3 | import com.google.inject.Guice | ||
4 | import com.google.inject.Injector | ||
3 | import hu.bme.mit.inf.dslreasoner.application.ApplicationConfigurationStandaloneSetup | 5 | import hu.bme.mit.inf.dslreasoner.application.ApplicationConfigurationStandaloneSetup |
4 | import org.eclipse.emf.common.util.URI | ||
5 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | 6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript |
7 | import org.eclipse.core.runtime.NullProgressMonitor | 7 | import org.eclipse.core.runtime.NullProgressMonitor |
8 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | 8 | import org.eclipse.emf.common.util.URI |
9 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
10 | import java.io.FileNotFoundException | ||
11 | import org.eclipse.emf.ecore.resource.Resource | 9 | import org.eclipse.emf.ecore.resource.Resource |
12 | import java.io.IOException | 10 | import org.eclipse.emf.ecore.util.EcoreUtil |
13 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | 11 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl |
14 | import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactoryProvider | 12 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup |
15 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactoryProvider | ||
16 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions | ||
17 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint | ||
18 | import org.eclipse.viatra.query.runtime.rete.util.ReteHintOptions | ||
19 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine | 13 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine |
20 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneCompilerSetup | ||
21 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetupGenerated | ||
22 | import org.eclipse.xtext.resource.XtextResourceSet | 14 | import org.eclipse.xtext.resource.XtextResourceSet |
23 | import com.google.inject.Injector | ||
24 | import com.google.inject.Guice | ||
25 | 15 | ||
26 | class StandaloneScriptExecutor { | 16 | class StandaloneScriptExecutor { |
27 | def static void main(String[] args) { | 17 | def static void main(String[] args) { |
@@ -81,11 +71,11 @@ class StandaloneScriptExecutor { | |||
81 | throw new IllegalArgumentException(message) | 71 | throw new IllegalArgumentException(message) |
82 | } | 72 | } |
83 | } else { | 73 | } else { |
84 | val message = ''' | 74 | val message = ''' |
85 | The Configuration Script contains «errors.size» error«IF errors.size>1»s«ENDIF»: | 75 | The Configuration Script contains «errors.size» error«IF errors.size>1»s«ENDIF»: |
86 | «FOR error : errors» | 76 | «FOR error : errors» |
87 | «"\t"»«error.message» | 77 | «"\t"»«error.message» |
88 | «ENDFOR» | 78 | «ENDFOR» |
89 | ''' | 79 | ''' |
90 | throw new IllegalArgumentException(message) | 80 | throw new IllegalArgumentException(message) |
91 | } | 81 | } |
@@ -94,8 +84,12 @@ class StandaloneScriptExecutor { | |||
94 | } | 84 | } |
95 | } | 85 | } |
96 | 86 | ||
97 | def static executeScript(String path){ | 87 | def static executeScript(String path) { |
98 | val executor = new ScriptExecutor | 88 | executeScript(path, StandardOutputBasedScriptConsole.FACTORY) |
89 | } | ||
90 | |||
91 | def static executeScript(String path, ScriptConsole.Factory scriptConsoleFactory){ | ||
92 | val executor = new ScriptExecutor(scriptConsoleFactory) | ||
99 | try{ | 93 | try{ |
100 | val content = loadScript(path) | 94 | val content = loadScript(path) |
101 | executor.executeScript(content,new NullProgressMonitor) | 95 | executor.executeScript(content,new NullProgressMonitor) |
@@ -104,4 +98,4 @@ class StandaloneScriptExecutor { | |||
104 | return e.message | 98 | return e.message |
105 | } | 99 | } |
106 | } | 100 | } |
107 | } \ No newline at end of file | 101 | } |
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 index ea738c5a..0d11bd31 100644 --- 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 | |||
@@ -15,4 +15,4 @@ class ApplicationConfigurationParser { | |||
15 | throw new IllegalArgumentException('''Content is not an ConfigurationScript! (got: «content.class.simpleName»)''') | 15 | throw new IllegalArgumentException('''Content is not an ConfigurationScript! (got: «content.class.simpleName»)''') |
16 | } | 16 | } |
17 | } | 17 | } |
18 | } \ No newline at end of file | 18 | } |