diff options
author | 2020-04-28 12:29:49 -0400 | |
---|---|---|
committer | 2020-04-28 12:29:49 -0400 | |
commit | 269d5cc271f4fa203db64ba46345e4616d771b51 (patch) | |
tree | c2ecb0c804b342bfa40decfecd04ee3230e4dddc /Tests/MODELS2020-CaseStudies/case.study.pledge.run | |
parent | Able to run Pledge Case Study (diff) | |
download | VIATRA-Generator-269d5cc271f4fa203db64ba46345e4616d771b51.tar.gz VIATRA-Generator-269d5cc271f4fa203db64ba46345e4616d771b51.tar.zst VIATRA-Generator-269d5cc271f4fa203db64ba46345e4616d771b51.zip |
Rename pledge case study file
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.run')
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.run/plugin.xml | 43 | ||||
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend (renamed from Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateScenarios.xtend) | 2 | ||||
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.GeneratePledgeModels.xtendbin | bin | 0 -> 12504 bytes | |||
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.gitignore | 1 | ||||
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/GeneratePledgeModels.java | 296 |
5 files changed, 340 insertions, 2 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/plugin.xml b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/plugin.xml index 2f4febdb..63aa0b02 100644 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/plugin.xml +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/plugin.xml | |||
@@ -1 +1,42 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?><plugin/> | 1 | <?xml version="1.0" encoding="UTF-8"?><plugin> |
2 | <extension id="queries.Case_study_A" point="org.eclipse.viatra.query.runtime.queryspecification"> | ||
3 | <group group="org.eclipse.viatra.query.runtime.extensibility.SingletonExtensionFactory:queries.Case_study_A" id="queries.Case_study_A"> | ||
4 | <query-specification fqn="queries.inv03"/> | ||
5 | <query-specification fqn="queries.x_inv03_eligAll"/> | ||
6 | <query-specification fqn="queries.x_inv03_hasAll"/> | ||
7 | <query-specification fqn="queries.inv05"/> | ||
8 | <query-specification fqn="queries.x_inv05_inRange"/> | ||
9 | <query-specification fqn="queries.inv06"/> | ||
10 | <query-specification fqn="queries.inv07"/> | ||
11 | <query-specification fqn="queries.inv08"/> | ||
12 | <query-specification fqn="queries.x_inv08_notEI"/> | ||
13 | <query-specification fqn="queries.x_inv08_noType"/> | ||
14 | <query-specification fqn="queries.x_inv08_inRange"/> | ||
15 | <query-specification fqn="queries.inv10"/> | ||
16 | <query-specification fqn="queries.inv11"/> | ||
17 | <query-specification fqn="queries.x_inv11_incOver100"/> | ||
18 | <query-specification fqn="queries.x_inv11_incNotOver100"/> | ||
19 | <query-specification fqn="queries.inv12"/> | ||
20 | <query-specification fqn="queries.x_inv12_notNonRes"/> | ||
21 | <query-specification fqn="queries.x_inv12_notZZ"/> | ||
22 | <query-specification fqn="queries.inv13"/> | ||
23 | <query-specification fqn="queries.x_inv13"/> | ||
24 | <query-specification fqn="queries.inv15"/> | ||
25 | <query-specification fqn="queries.x_inv15"/> | ||
26 | <query-specification fqn="queries.inv17"/> | ||
27 | <query-specification fqn="queries.inv20"/> | ||
28 | <query-specification fqn="queries.inv33"/> | ||
29 | <query-specification fqn="queries.inv34"/> | ||
30 | <query-specification fqn="queries.inv35"/> | ||
31 | <query-specification fqn="queries.inv47"/> | ||
32 | <query-specification fqn="queries.x_inv47"/> | ||
33 | <query-specification fqn="queries.inv48"/> | ||
34 | <query-specification fqn="queries.x_inv48_notDis"/> | ||
35 | <query-specification fqn="queries.x_inv48_Dis"/> | ||
36 | <query-specification fqn="queries.x_inv48_3"/> | ||
37 | <query-specification fqn="queries.inv49"/> | ||
38 | <query-specification fqn="queries.x_inv49_1"/> | ||
39 | <query-specification fqn="queries.x_inv49_2"/> | ||
40 | </group> | ||
41 | </extension> | ||
42 | </plugin> | ||
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateScenarios.xtend b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend index 8445130a..be641c87 100644 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateScenarios.xtend +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend | |||
@@ -43,7 +43,7 @@ import org.eclipse.viatra.query.runtime.api.IQueryGroup | |||
43 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine | 43 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine |
44 | import queries.Case_study_A | 44 | import queries.Case_study_A |
45 | 45 | ||
46 | class GenerateScenarios { | 46 | class GeneratePledgeModels { |
47 | def static void main(String[] args) { | 47 | def static void main(String[] args) { |
48 | val x = (new EMFPatternLanguageStandaloneSetup).createInjectorAndDoEMFRegistration | 48 | val x = (new EMFPatternLanguageStandaloneSetup).createInjectorAndDoEMFRegistration |
49 | // //PatternLanguageWithRSSetup.createInjectorAndDoEMFRegistration | 49 | // //PatternLanguageWithRSSetup.createInjectorAndDoEMFRegistration |
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.GeneratePledgeModels.xtendbin b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.GeneratePledgeModels.xtendbin new file mode 100644 index 00000000..7c005ae3 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.GeneratePledgeModels.xtendbin | |||
Binary files differ | |||
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.gitignore index 01244e82..01940246 100644 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.gitignore +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/.gitignore | |||
@@ -3,3 +3,4 @@ | |||
3 | /.RunGenerator.xtendbin | 3 | /.RunGenerator.xtendbin |
4 | /GenerateScenarios.java | 4 | /GenerateScenarios.java |
5 | /.GenerateScenarios.xtendbin | 5 | /.GenerateScenarios.xtendbin |
6 | /.GeneratePledgeModels.java._trace | ||
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/GeneratePledgeModels.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/GeneratePledgeModels.java new file mode 100644 index 00000000..24f2b9b4 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/xtend-gen/run/GeneratePledgeModels.java | |||
@@ -0,0 +1,296 @@ | |||
1 | package run; | ||
2 | |||
3 | import Taxation.TaxationPackage; | ||
4 | import com.google.common.base.Objects; | ||
5 | import com.google.common.collect.Iterables; | ||
6 | import com.google.inject.Injector; | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration; | ||
9 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
10 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor; | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation; | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; | ||
13 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
14 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | ||
15 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; | ||
16 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; | ||
17 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.Statistics; | ||
18 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore; | ||
19 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic; | ||
20 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration; | ||
21 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicTrace; | ||
22 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor; | ||
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic; | ||
24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml; | ||
26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualisation; | ||
27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner; | ||
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; | ||
29 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser; | ||
30 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; | ||
31 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace; | ||
32 | import java.math.BigDecimal; | ||
33 | import java.text.SimpleDateFormat; | ||
34 | import java.util.Collections; | ||
35 | import java.util.Date; | ||
36 | import java.util.HashMap; | ||
37 | import java.util.List; | ||
38 | import java.util.Map; | ||
39 | import java.util.Set; | ||
40 | import java.util.TreeSet; | ||
41 | import org.eclipse.emf.common.util.EList; | ||
42 | import org.eclipse.emf.ecore.EAttribute; | ||
43 | import org.eclipse.emf.ecore.EClass; | ||
44 | import org.eclipse.emf.ecore.EEnum; | ||
45 | import org.eclipse.emf.ecore.EEnumLiteral; | ||
46 | import org.eclipse.emf.ecore.EObject; | ||
47 | import org.eclipse.emf.ecore.EPackage; | ||
48 | import org.eclipse.emf.ecore.EReference; | ||
49 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
50 | import org.eclipse.emf.ecore.resource.Resource; | ||
51 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
52 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup; | ||
53 | import org.eclipse.viatra.query.runtime.api.IQueryGroup; | ||
54 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
55 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
56 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine; | ||
57 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
58 | import org.eclipse.xtext.xbase.lib.CollectionExtensions; | ||
59 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
60 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
61 | import org.eclipse.xtext.xbase.lib.ExclusiveRange; | ||
62 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
63 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
64 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
65 | import org.eclipse.xtext.xbase.lib.ListExtensions; | ||
66 | import org.eclipse.xtext.xbase.lib.ObjectExtensions; | ||
67 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
68 | import queries.Case_study_A; | ||
69 | |||
70 | @SuppressWarnings("all") | ||
71 | public class GeneratePledgeModels { | ||
72 | public static void main(final String[] args) { | ||
73 | try { | ||
74 | final Injector x = new EMFPatternLanguageStandaloneSetup().createInjectorAndDoEMFRegistration(); | ||
75 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
76 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
77 | _extensionToFactoryMap.put("xmi", _xMIResourceFactoryImpl); | ||
78 | Map<String, Object> _extensionToFactoryMap_1 = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
79 | XMIResourceFactoryImpl _xMIResourceFactoryImpl_1 = new XMIResourceFactoryImpl(); | ||
80 | _extensionToFactoryMap_1.put("logicproblem", _xMIResourceFactoryImpl_1); | ||
81 | Map<String, Object> _extensionToFactoryMap_2 = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
82 | XMIResourceFactoryImpl _xMIResourceFactoryImpl_2 = new XMIResourceFactoryImpl(); | ||
83 | _extensionToFactoryMap_2.put("partialmodel", _xMIResourceFactoryImpl_2); | ||
84 | ReteEngine.class.getClass(); | ||
85 | final Ecore2Logic ecore2Logic = new Ecore2Logic(); | ||
86 | final Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic); | ||
87 | final Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic); | ||
88 | final InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic(); | ||
89 | long _currentTimeMillis = System.currentTimeMillis(); | ||
90 | final Date date = new Date(_currentTimeMillis); | ||
91 | final SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | ||
92 | final String formattedDate = format.format(date); | ||
93 | StringConcatenation _builder = new StringConcatenation(); | ||
94 | _builder.append("inputs/"); | ||
95 | final FileSystemWorkspace inputs = new FileSystemWorkspace(_builder.toString(), ""); | ||
96 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
97 | _builder_1.append("output/"); | ||
98 | String _plus = (_builder_1.toString() + formattedDate); | ||
99 | StringConcatenation _builder_2 = new StringConcatenation(); | ||
100 | _builder_2.append("/"); | ||
101 | String _plus_1 = (_plus + _builder_2); | ||
102 | final FileSystemWorkspace workspace = new FileSystemWorkspace(_plus_1, ""); | ||
103 | workspace.initAndClear(); | ||
104 | InputOutput.<String>println("Input and output workspaces are created"); | ||
105 | final EcoreMetamodelDescriptor metamodel = GeneratePledgeModels.loadMetamodel(TaxationPackage.eINSTANCE); | ||
106 | final EList<EObject> partialModel = GeneratePledgeModels.loadPartialModel(inputs, "Household.xmi"); | ||
107 | final ViatraQuerySetDescriptor queries = GeneratePledgeModels.loadQueries(metamodel, Case_study_A.instance()); | ||
108 | InputOutput.<String>println("DSL loaded"); | ||
109 | final int SIZE = 10; | ||
110 | int REPS = 1; | ||
111 | final int RUNTIME = 600; | ||
112 | Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration(); | ||
113 | final TracedOutput<LogicProblem, Ecore2Logic_Trace> modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration); | ||
114 | LogicProblem problem = modelGenerationProblem.getOutput(); | ||
115 | Viatra2LogicConfiguration _viatra2LogicConfiguration = new Viatra2LogicConfiguration(); | ||
116 | final TracedOutput<LogicProblem, Viatra2LogicTrace> validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelGenerationProblem, _viatra2LogicConfiguration); | ||
117 | problem = validModelExtensionProblem.getOutput(); | ||
118 | workspace.writeModel(problem, "problem.logicproblem"); | ||
119 | InputOutput.<String>println("Problem created"); | ||
120 | for (int i = 0; (i < REPS); i++) { | ||
121 | { | ||
122 | InputOutput.<String>println((("Run #" + Integer.valueOf(i)) + ":")); | ||
123 | ViatraReasoner reasoner = new ViatraReasoner(); | ||
124 | final TreeSet<Integer> knownIntegers = new TreeSet<Integer>(); | ||
125 | CollectionExtensions.<Integer>addAll(knownIntegers, Integer.valueOf(0)); | ||
126 | final TreeSet<BigDecimal> knownReals = new TreeSet<BigDecimal>(); | ||
127 | BigDecimal _bigDecimal = new BigDecimal("0.0"); | ||
128 | CollectionExtensions.<BigDecimal>addAll(knownReals, _bigDecimal); | ||
129 | final TreeSet<String> knownStrings = new TreeSet<String>(); | ||
130 | CollectionExtensions.<String>addAll(knownStrings, "r0", "r1", "r2"); | ||
131 | ViatraReasonerConfiguration _viatraReasonerConfiguration = new ViatraReasonerConfiguration(); | ||
132 | final Procedure1<ViatraReasonerConfiguration> _function = (ViatraReasonerConfiguration it) -> { | ||
133 | it.runtimeLimit = RUNTIME; | ||
134 | it.typeScopes.maxNewElements = SIZE; | ||
135 | boolean _isEmpty = knownIntegers.isEmpty(); | ||
136 | boolean _not = (!_isEmpty); | ||
137 | if (_not) { | ||
138 | it.typeScopes.knownIntegers = knownIntegers; | ||
139 | } | ||
140 | boolean _isEmpty_1 = knownReals.isEmpty(); | ||
141 | boolean _not_1 = (!_isEmpty_1); | ||
142 | if (_not_1) { | ||
143 | it.typeScopes.knownReals = knownReals; | ||
144 | } | ||
145 | }; | ||
146 | final ViatraReasonerConfiguration solverConfig = ObjectExtensions.<ViatraReasonerConfiguration>operator_doubleArrow(_viatraReasonerConfiguration, _function); | ||
147 | final long startTime = System.currentTimeMillis(); | ||
148 | LogicResult solution = reasoner.solve(problem, solverConfig, workspace); | ||
149 | long _currentTimeMillis_1 = System.currentTimeMillis(); | ||
150 | final long totalTime = (_currentTimeMillis_1 - startTime); | ||
151 | InputOutput.<String>println(" Problem Solved"); | ||
152 | GeneratePledgeModels.writeStats(solution, totalTime); | ||
153 | if ((solution instanceof ModelResult)) { | ||
154 | GeneratePledgeModels.writeRepresentation(solution, workspace, i); | ||
155 | InputOutput.<String>println(" Solution saved and visualised"); | ||
156 | } else { | ||
157 | String _string = solution.getClass().getSimpleName().toString(); | ||
158 | String _plus_2 = (" Returned: " + _string); | ||
159 | InputOutput.<String>println(_plus_2); | ||
160 | } | ||
161 | final Runtime r = Runtime.getRuntime(); | ||
162 | r.gc(); | ||
163 | r.gc(); | ||
164 | r.gc(); | ||
165 | Thread.sleep(3000); | ||
166 | } | ||
167 | } | ||
168 | InputOutput.<String>println("---End---"); | ||
169 | } catch (Throwable _e) { | ||
170 | throw Exceptions.sneakyThrow(_e); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | public static Map<Type, Integer> getTypeMap(final Map<Class, Integer> classMap, final EcoreMetamodelDescriptor metamodel, final Ecore2Logic e2l, final Ecore2Logic_Trace trace) { | ||
175 | final HashMap<Type, Integer> typeMap = new HashMap<Type, Integer>(); | ||
176 | final Function1<EClass, String> _function = (EClass s) -> { | ||
177 | return s.getName(); | ||
178 | }; | ||
179 | final Map<String, EClass> listMap = IterableExtensions.<String, EClass>toMap(metamodel.getClasses(), _function); | ||
180 | Set<Class> _keySet = classMap.keySet(); | ||
181 | for (final Class elem : _keySet) { | ||
182 | typeMap.put( | ||
183 | e2l.TypeofEClass(trace, | ||
184 | listMap.get(elem.getSimpleName())), classMap.get(elem)); | ||
185 | } | ||
186 | return typeMap; | ||
187 | } | ||
188 | |||
189 | public static EcoreMetamodelDescriptor loadMetamodel(final EPackage pckg) { | ||
190 | final List<EClass> classes = IterableExtensions.<EClass>toList(Iterables.<EClass>filter(pckg.getEClassifiers(), EClass.class)); | ||
191 | final List<EEnum> enums = IterableExtensions.<EEnum>toList(Iterables.<EEnum>filter(pckg.getEClassifiers(), EEnum.class)); | ||
192 | final Function1<EEnum, EList<EEnumLiteral>> _function = (EEnum it) -> { | ||
193 | return it.getELiterals(); | ||
194 | }; | ||
195 | final List<EEnumLiteral> literals = IterableExtensions.<EEnumLiteral>toList(Iterables.<EEnumLiteral>concat(ListExtensions.<EEnum, EList<EEnumLiteral>>map(enums, _function))); | ||
196 | final Function1<EClass, EList<EReference>> _function_1 = (EClass it) -> { | ||
197 | return it.getEReferences(); | ||
198 | }; | ||
199 | final List<EReference> references = IterableExtensions.<EReference>toList(Iterables.<EReference>concat(ListExtensions.<EClass, EList<EReference>>map(classes, _function_1))); | ||
200 | final Function1<EClass, EList<EAttribute>> _function_2 = (EClass it) -> { | ||
201 | return it.getEAttributes(); | ||
202 | }; | ||
203 | final List<EAttribute> attributes = IterableExtensions.<EAttribute>toList(Iterables.<EAttribute>concat(ListExtensions.<EClass, EList<EAttribute>>map(classes, _function_2))); | ||
204 | return new EcoreMetamodelDescriptor(classes, Collections.<EClass>unmodifiableSet(CollectionLiterals.<EClass>newHashSet()), false, enums, literals, references, attributes); | ||
205 | } | ||
206 | |||
207 | public static EList<EObject> loadPartialModel(final ReasonerWorkspace inputs, final String path) { | ||
208 | EList<EObject> _xblockexpression = null; | ||
209 | { | ||
210 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
211 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
212 | _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl); | ||
213 | _xblockexpression = inputs.<EObject>readModel(EObject.class, path).eResource().getContents(); | ||
214 | } | ||
215 | return _xblockexpression; | ||
216 | } | ||
217 | |||
218 | public static ViatraQuerySetDescriptor loadQueries(final EcoreMetamodelDescriptor metamodel, final IQueryGroup i) { | ||
219 | final List<IQuerySpecification<?>> patterns = IterableExtensions.<IQuerySpecification<?>>toList(i.getSpecifications()); | ||
220 | final Function1<IQuerySpecification<?>, Boolean> _function = (IQuerySpecification<?> it) -> { | ||
221 | final Function1<PAnnotation, Boolean> _function_1 = (PAnnotation it_1) -> { | ||
222 | String _name = it_1.getName(); | ||
223 | return Boolean.valueOf(Objects.equal(_name, "Constraint")); | ||
224 | }; | ||
225 | return Boolean.valueOf(IterableExtensions.<PAnnotation>exists(it.getAllAnnotations(), _function_1)); | ||
226 | }; | ||
227 | final Set<IQuerySpecification<?>> wfPatterns = IterableExtensions.<IQuerySpecification<?>>toSet(IterableExtensions.<IQuerySpecification<?>>filter(patterns, _function)); | ||
228 | final Map<IQuerySpecification<?>, EStructuralFeature> derivedFeatures = CollectionLiterals.<IQuerySpecification<?>, EStructuralFeature>emptyMap(); | ||
229 | final ViatraQuerySetDescriptor res = new ViatraQuerySetDescriptor(patterns, wfPatterns, derivedFeatures); | ||
230 | return res; | ||
231 | } | ||
232 | |||
233 | public static void writeInterpretation(final LogicResult solution, final Logic2Ecore logic2Ecore, final ReasonerWorkspace workspace, final int i, final ViatraReasoner reasoner, final TracedOutput<LogicProblem, Ecore2Logic_Trace> mgProb) { | ||
234 | final List<? extends LogicModelInterpretation> interpretations = reasoner.getInterpretations(((ModelResult) solution)); | ||
235 | int _size = interpretations.size(); | ||
236 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true); | ||
237 | for (final Integer interpIndex : _doubleDotLessThan) { | ||
238 | { | ||
239 | final LogicModelInterpretation interpretation = interpretations.get((interpIndex).intValue()); | ||
240 | final EObject model = logic2Ecore.transformInterpretation(interpretation, mgProb.getTrace()); | ||
241 | StringConcatenation _builder = new StringConcatenation(); | ||
242 | _builder.append("solution"); | ||
243 | _builder.append(i); | ||
244 | _builder.append("_"); | ||
245 | _builder.append(interpIndex); | ||
246 | _builder.append(".xmi"); | ||
247 | workspace.writeModel(model, _builder.toString()); | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | public static void writeRepresentation(final LogicResult solution, final ReasonerWorkspace workspace, final int i) { | ||
253 | final EList<Object> representations = solution.getRepresentation(); | ||
254 | int _size = representations.size(); | ||
255 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true); | ||
256 | for (final Integer representationIndex : _doubleDotLessThan) { | ||
257 | { | ||
258 | final Object representation = representations.get((representationIndex).intValue()); | ||
259 | if ((representation instanceof PartialInterpretation)) { | ||
260 | final String gml = new PartialInterpretation2Gml().transform(((PartialInterpretation)representation)); | ||
261 | StringConcatenation _builder = new StringConcatenation(); | ||
262 | _builder.append("solution"); | ||
263 | _builder.append(i); | ||
264 | _builder.append("_"); | ||
265 | _builder.append(representationIndex); | ||
266 | _builder.append(".gml"); | ||
267 | workspace.writeText(_builder.toString(), gml); | ||
268 | final PartialInterpretationVisualisation png = new GraphvizVisualiser().visualiseConcretization(((PartialInterpretation)representation)); | ||
269 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
270 | _builder_1.append("solution"); | ||
271 | _builder_1.append(i); | ||
272 | _builder_1.append("_"); | ||
273 | _builder_1.append(representationIndex); | ||
274 | _builder_1.append(".png"); | ||
275 | png.writeToFile(workspace, _builder_1.toString()); | ||
276 | } else { | ||
277 | StringConcatenation _builder_2 = new StringConcatenation(); | ||
278 | _builder_2.append("solution"); | ||
279 | _builder_2.append(representationIndex); | ||
280 | _builder_2.append(".txt"); | ||
281 | workspace.writeText(_builder_2.toString(), representation.toString()); | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | |||
287 | public static String writeStats(final LogicResult solution, final long time) { | ||
288 | String _xblockexpression = null; | ||
289 | { | ||
290 | final Statistics stats = solution.getStatistics(); | ||
291 | InputOutput.<String>println(" Statistics:"); | ||
292 | _xblockexpression = InputOutput.<String>println(((" \"solve\" time: " + Double.valueOf((((double) time) / 1000))) + " s")); | ||
293 | } | ||
294 | return _xblockexpression; | ||
295 | } | ||
296 | } | ||