aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java
diff options
context:
space:
mode:
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java')
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java598
1 files changed, 598 insertions, 0 deletions
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java
new file mode 100644
index 00000000..16db7053
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java
@@ -0,0 +1,598 @@
1package modes3.run;
2
3import com.google.common.base.Objects;
4import com.google.common.collect.ImmutableList;
5import com.google.common.collect.ImmutableSet;
6import com.google.common.collect.Iterables;
7import hu.bme.mit.inf.dslreasoner.ecore2logic.EReferenceMapper_RelationsOverTypes_Trace;
8import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic;
9import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration;
10import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace;
11import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor;
12import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsFactory;
13import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage;
14import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion;
15import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel;
16import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation;
17import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder;
18import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope;
19import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput;
20import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes;
21import hu.bme.mit.inf.dslreasoner.logic.model.builder.VariableContext;
22import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Assertion;
23import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Iff;
24import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage;
25import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration;
26import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue;
27import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription;
28import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type;
29import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition;
30import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable;
31import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.Annotation;
32import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem;
33import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage;
34import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult;
35import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult;
36import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore;
37import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic;
38import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration;
39import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicTrace;
40import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor;
41import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsPackage;
42import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod;
43import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorConstraints;
44import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorSolver;
45import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy;
46import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic;
47import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink;
48import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation;
49import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation;
50import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation;
51import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage;
52import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink;
53import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml;
54import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualisation;
55import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveConfiguration;
56import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveElementConfiguration;
57import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DebugConfiguration;
58import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.StateCoderStrategy;
59import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner;
60import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration;
61import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.PartialModelAsLogicInterpretation;
62import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind;
63import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold;
64import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser;
65import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace;
66import java.util.Collections;
67import java.util.List;
68import java.util.Map;
69import java.util.Set;
70import java.util.function.Predicate;
71import modes3.Modes3Factory;
72import modes3.Modes3ModelRoot;
73import modes3.Modes3Package;
74import modes3.queries.CloseTrains_step_2;
75import modes3.queries.CloseTrains_step_3;
76import modes3.queries.CloseTrains_step_4;
77import modes3.queries.CloseTrains_step_5;
78import modes3.queries.CloseTrains_step_6;
79import modes3.queries.CloseTrains_step_7;
80import modes3.queries.EndOfSiding_step_2;
81import modes3.queries.EndOfSiding_step_3;
82import modes3.queries.EndOfSiding_step_4;
83import modes3.queries.EndOfSiding_step_5;
84import modes3.queries.MisalignedTurnout_step_2;
85import modes3.queries.MisalignedTurnout_step_3;
86import modes3.queries.MisalignedTurnout_step_4;
87import modes3.queries.MisalignedTurnout_step_5;
88import modes3.queries.Modes3Queries;
89import modes3.queries.TrainLocations_step_2;
90import modes3.queries.TrainLocations_step_3;
91import modes3.run.CloseTrainsObjectiveHint;
92import modes3.run.EndOfSidingObjectiveHint;
93import modes3.run.MisalignedTurnoutObjectiveHint;
94import modes3.run.Modes3TypeScopeHint;
95import modes3.run.Modes3UnitPropagationGenerator;
96import modes3.run.TrainLocationsObjectiveHint;
97import org.eclipse.emf.common.util.EList;
98import org.eclipse.emf.common.util.TreeIterator;
99import org.eclipse.emf.common.util.URI;
100import org.eclipse.emf.ecore.EAttribute;
101import org.eclipse.emf.ecore.EClass;
102import org.eclipse.emf.ecore.EEnum;
103import org.eclipse.emf.ecore.EEnumLiteral;
104import org.eclipse.emf.ecore.EObject;
105import org.eclipse.emf.ecore.EReference;
106import org.eclipse.emf.ecore.EStructuralFeature;
107import org.eclipse.emf.ecore.resource.Resource;
108import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
109import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup;
110import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
111import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions;
112import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchEMFBackendFactory;
113import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
114import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory;
115import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
116import org.eclipse.xtend2.lib.StringConcatenation;
117import org.eclipse.xtext.xbase.lib.CollectionLiterals;
118import org.eclipse.xtext.xbase.lib.Exceptions;
119import org.eclipse.xtext.xbase.lib.ExclusiveRange;
120import org.eclipse.xtext.xbase.lib.Extension;
121import org.eclipse.xtext.xbase.lib.Functions.Function1;
122import org.eclipse.xtext.xbase.lib.InputOutput;
123import org.eclipse.xtext.xbase.lib.IterableExtensions;
124import org.eclipse.xtext.xbase.lib.ObjectExtensions;
125import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
126
127@FinalFieldsConstructor
128@SuppressWarnings("all")
129public class Modes3ModelGenerator {
130 private enum MonitoringQuery {
131 closeTrains,
132
133 trainLocations,
134
135 endOfSiding,
136
137 misalignedTurnout;
138 }
139
140 private final Modes3ModelGenerator.MonitoringQuery monitoringQuery;
141
142 private final int modelSize;
143
144 private final Ecore2Logic ecore2Logic = new Ecore2Logic();
145
146 private final InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic();
147
148 private final Viatra2Logic viatra2Logic = new Viatra2Logic(this.ecore2Logic);
149
150 private final ViatraReasoner solver = new ViatraReasoner();
151
152 @Extension
153 private final LogicProblemBuilder _logicProblemBuilder = new LogicProblemBuilder();
154
155 public URI generate() {
156 try {
157 URI _xblockexpression = null;
158 {
159 final EcoreMetamodelDescriptor metamodel = Modes3ModelGenerator.createMetamodelDescriptor();
160 Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration();
161 final TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelLogic = this.ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration);
162 final Type segment = this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getSegment());
163 final RelationDeclaration connectedTo = this.ecore2Logic.relationOfReference(metamodelLogic.getTrace(),
164 Modes3Package.eINSTANCE.getSegment_ConnectedTo());
165 final RelationDeclaration connectedToIndicator = ((EReferenceMapper_RelationsOverTypes_Trace) metamodelLogic.getTrace().referenceMapperTrace).indicators.get(
166 Modes3Package.eINSTANCE.getSegment_ConnectedTo());
167 StringConcatenation _builder = new StringConcatenation();
168 _builder.append("oppositeReference ");
169 String _name = connectedTo.getName();
170 _builder.append(_name);
171 _builder.append(" ");
172 String _name_1 = connectedTo.getName();
173 _builder.append(_name_1);
174 final Function1<VariableContext, TermDescription> _function = (VariableContext it) -> {
175 Iff _xblockexpression_1 = null;
176 {
177 StringConcatenation _builder_1 = new StringConcatenation();
178 _builder_1.append("src");
179 final Variable src = it.addVar(_builder_1, segment);
180 StringConcatenation _builder_2 = new StringConcatenation();
181 _builder_2.append("trg");
182 final Variable trg = it.addVar(_builder_2, segment);
183 SymbolicValue _call = this._logicProblemBuilder.call(connectedToIndicator, src, trg);
184 SymbolicValue _call_1 = this._logicProblemBuilder.call(connectedToIndicator, trg, src);
185 _xblockexpression_1 = this._logicProblemBuilder.operator_spaceship(_call, _call_1);
186 }
187 return _xblockexpression_1;
188 };
189 final Assertion inverseAssertion = this._logicProblemBuilder.Assertion(_builder,
190 this._logicProblemBuilder.Forall(_function));
191 EList<Assertion> _assertions = metamodelLogic.getOutput().getAssertions();
192 _assertions.add(inverseAssertion);
193 InverseRelationAssertion _createInverseRelationAssertion = Ecore2logicannotationsFactory.eINSTANCE.createInverseRelationAssertion();
194 final Procedure1<InverseRelationAssertion> _function_1 = (InverseRelationAssertion it) -> {
195 it.setTarget(inverseAssertion);
196 it.setInverseA(connectedTo);
197 it.setInverseB(connectedTo);
198 };
199 final InverseRelationAssertion inverseAnnotation = ObjectExtensions.<InverseRelationAssertion>operator_doubleArrow(_createInverseRelationAssertion, _function_1);
200 EList<Annotation> _annotations = metamodelLogic.getOutput().getAnnotations();
201 _annotations.add(inverseAnnotation);
202 final List<EObject> initialModel = Modes3ModelGenerator.loadInitialModel();
203 final TracedOutput<LogicProblem, Ecore2Logic_Trace> initialModelLogic = this.instanceModel2Logic.transform(metamodelLogic, initialModel);
204 final ViatraQuerySetDescriptor queries = this.loadQueries();
205 Viatra2LogicConfiguration _viatra2LogicConfiguration = new Viatra2LogicConfiguration();
206 final TracedOutput<LogicProblem, Viatra2LogicTrace> logic = this.viatra2Logic.transformQueries(queries, initialModelLogic, _viatra2LogicConfiguration);
207 ViatraReasonerConfiguration _viatraReasonerConfiguration = new ViatraReasonerConfiguration();
208 final Procedure1<ViatraReasonerConfiguration> _function_2 = (ViatraReasonerConfiguration it) -> {
209 it.runtimeLimit = 3600;
210 final Procedure1<TypeScopes> _function_3 = (TypeScopes it_1) -> {
211 it_1.minNewElements = this.modelSize;
212 it_1.maxNewElements = this.modelSize;
213 final Procedure1<Map<Type, Integer>> _function_4 = (Map<Type, Integer> it_2) -> {
214 };
215 ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow(
216 it_1.minNewElementsByType, _function_4);
217 final Procedure1<Map<Type, Integer>> _function_5 = (Map<Type, Integer> it_2) -> {
218 it_2.put(this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getTrain()), Integer.valueOf((this.modelSize / 5)));
219 it_2.put(this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getTurnout()), Integer.valueOf((this.modelSize / 5)));
220 it_2.put(this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getSimpleSegment()), Integer.valueOf(((3 * this.modelSize) / 5)));
221 };
222 ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow(
223 it_1.maxNewElementsByType, _function_5);
224 };
225 ObjectExtensions.<TypeScopes>operator_doubleArrow(
226 it.typeScopes, _function_3);
227 final Procedure1<SolutionScope> _function_4 = (SolutionScope it_1) -> {
228 it_1.numberOfRequiredSolutions = 1;
229 };
230 ObjectExtensions.<SolutionScope>operator_doubleArrow(
231 it.solutionScope, _function_4);
232 CostObjectiveConfiguration _objective = this.getObjective(this.ecore2Logic, metamodelLogic.getTrace());
233 it.costObjectives.add(_objective);
234 it.scopeWeight = 6;
235 it.nameNewElements = false;
236 it.typeInferenceMethod = TypeInferenceMethod.PreliminaryAnalysis;
237 it.stateCoderStrategy = StateCoderStrategy.PairwiseNeighbourhood;
238 ScopePropagatorStrategy.Polyhedral _polyhedral = new ScopePropagatorStrategy.Polyhedral(
239 PolyhedralScopePropagatorConstraints.Relational, PolyhedralScopePropagatorSolver.Clp);
240 it.scopePropagatorStrategy = _polyhedral;
241 Ecore2Logic_Trace _trace = metamodelLogic.getTrace();
242 Modes3TypeScopeHint _modes3TypeScopeHint = new Modes3TypeScopeHint(this.ecore2Logic, _trace);
243 it.hints.add(_modes3TypeScopeHint);
244 Ecore2Logic_Trace _trace_1 = metamodelLogic.getTrace();
245 Modes3UnitPropagationGenerator _modes3UnitPropagationGenerator = new Modes3UnitPropagationGenerator(this.ecore2Logic, _trace_1);
246 it.unitPropagationPatternGenerators.add(_modes3UnitPropagationGenerator);
247 final Procedure1<DebugConfiguration> _function_5 = (DebugConfiguration it_1) -> {
248 GraphvizVisualiser _graphvizVisualiser = new GraphvizVisualiser();
249 it_1.partialInterpretatioVisualiser = _graphvizVisualiser;
250 };
251 ObjectExtensions.<DebugConfiguration>operator_doubleArrow(
252 it.debugConfiguration, _function_5);
253 it.documentationLevel = DocumentationLevel.NORMAL;
254 };
255 final ViatraReasonerConfiguration config = ObjectExtensions.<ViatraReasonerConfiguration>operator_doubleArrow(_viatraReasonerConfiguration, _function_2);
256 final FileSystemWorkspace workspace = new FileSystemWorkspace("output/", "");
257 workspace.writeModel(logic.getOutput(), "problem.logicproblem");
258 final LogicResult solution = this.solver.solve(logic.getOutput(), config, workspace);
259 URI _xifexpression = null;
260 if ((solution instanceof ModelResult)) {
261 InputOutput.<String>println("Saving generated solutions");
262 final Logic2Ecore logic2Ecore = new Logic2Ecore(this.ecore2Logic);
263 final List<? extends LogicModelInterpretation> interpretations = this.solver.getInterpretations(((ModelResult)solution));
264 int _size = interpretations.size();
265 ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
266 for (final Integer representationIndex : _doubleDotLessThan) {
267 {
268 final LogicModelInterpretation interpretation = interpretations.get((representationIndex).intValue());
269 final int representationNumber = ((representationIndex).intValue() + 1);
270 if ((interpretation instanceof PartialModelAsLogicInterpretation)) {
271 final PartialInterpretation representation = ((PartialModelAsLogicInterpretation)interpretation).getPartialInterpretation();
272 StringConcatenation _builder_1 = new StringConcatenation();
273 _builder_1.append("solution");
274 _builder_1.append(representationNumber);
275 _builder_1.append(".partialinterpretation");
276 workspace.writeModel(representation, _builder_1.toString());
277 final PartialInterpretation2Gml partialInterpretation2GML = new PartialInterpretation2Gml();
278 final String gml = partialInterpretation2GML.transform(representation);
279 StringConcatenation _builder_2 = new StringConcatenation();
280 _builder_2.append("solution");
281 _builder_2.append(representationNumber);
282 _builder_2.append(".gml");
283 workspace.writeText(_builder_2.toString(), gml);
284 final EObject model = logic2Ecore.transformInterpretation(interpretation, metamodelLogic.getTrace());
285 final TreeIterator<EObject> iterator = model.eAllContents();
286 int id = 0;
287 while (iterator.hasNext()) {
288 {
289 final EObject obj = iterator.next();
290 final Function1<EAttribute, Boolean> _function_3 = (EAttribute it) -> {
291 String _name_2 = it.getName();
292 return Boolean.valueOf(Objects.equal(_name_2, "id"));
293 };
294 final EAttribute idFeature = IterableExtensions.<EAttribute>findFirst(obj.eClass().getEAllAttributes(), _function_3);
295 if ((idFeature != null)) {
296 obj.eSet(idFeature, Integer.valueOf(id));
297 id++;
298 }
299 }
300 }
301 StringConcatenation _builder_3 = new StringConcatenation();
302 _builder_3.append("solution");
303 _builder_3.append(representationNumber);
304 _builder_3.append(".modes3");
305 workspace.writeModel(model, _builder_3.toString());
306 int _size_1 = representation.getNewElements().size();
307 boolean _lessThan = (_size_1 < 160);
308 if (_lessThan) {
309 final Function1<Type, Boolean> _function_3 = (Type it) -> {
310 String _name_2 = it.getName();
311 return Boolean.valueOf(Objects.equal(_name_2, "Modes3ModelRoot class DefinedPart"));
312 };
313 Type _findFirst = IterableExtensions.<Type>findFirst(representation.getProblem().getTypes(), _function_3);
314 final TypeDefinition rootType = ((TypeDefinition) _findFirst);
315 final Function1<PartialComplexTypeInterpretation, Boolean> _function_4 = (PartialComplexTypeInterpretation it) -> {
316 String _name_2 = it.getInterpretationOf().getName();
317 return Boolean.valueOf(Objects.equal(_name_2, "Modes3ModelRoot class"));
318 };
319 final PartialComplexTypeInterpretation rootIntepretation = IterableExtensions.<PartialComplexTypeInterpretation>findFirst(Iterables.<PartialComplexTypeInterpretation>filter(representation.getPartialtypeinterpratation(),
320 PartialComplexTypeInterpretation.class), _function_4);
321 rootIntepretation.getElements().removeAll(rootType.getElements());
322 representation.getProblem().getElements().removeAll(rootType.getElements());
323 EList<PartialRelationInterpretation> _partialrelationinterpretation = representation.getPartialrelationinterpretation();
324 for (final PartialRelationInterpretation relationInterpretation : _partialrelationinterpretation) {
325 final Predicate<RelationLink> _function_5 = (RelationLink link) -> {
326 boolean _xifexpression_1 = false;
327 if ((link instanceof BinaryElementRelationLink)) {
328 _xifexpression_1 = (rootType.getElements().contains(((BinaryElementRelationLink)link).getParam1()) ||
329 rootType.getElements().contains(((BinaryElementRelationLink)link).getParam2()));
330 } else {
331 _xifexpression_1 = false;
332 }
333 return _xifexpression_1;
334 };
335 relationInterpretation.getRelationlinks().removeIf(_function_5);
336 }
337 rootType.getElements().clear();
338 final GraphvizVisualiser visualiser = new GraphvizVisualiser();
339 final PartialInterpretationVisualisation visualisation = visualiser.visualiseConcretization(representation);
340 StringConcatenation _builder_4 = new StringConcatenation();
341 _builder_4.append("solution");
342 _builder_4.append(representationNumber);
343 _builder_4.append(".png");
344 visualisation.writeToFile(workspace, _builder_4.toString());
345 }
346 } else {
347 StringConcatenation _builder_5 = new StringConcatenation();
348 _builder_5.append("solution");
349 _builder_5.append(representationNumber);
350 _builder_5.append(".txt");
351 workspace.writeText(_builder_5.toString(), interpretation.toString());
352 }
353 }
354 }
355 } else {
356 URI _xblockexpression_1 = null;
357 {
358 InputOutput.<String>println("Failed to solve problem");
359 final LogicProblem partial = logic.getOutput();
360 _xblockexpression_1 = workspace.writeModel(partial, "solution.partialinterpretation");
361 }
362 _xifexpression = _xblockexpression_1;
363 }
364 _xblockexpression = _xifexpression;
365 }
366 return _xblockexpression;
367 } catch (Throwable _e) {
368 throw Exceptions.sneakyThrow(_e);
369 }
370 }
371
372 public static EcoreMetamodelDescriptor createMetamodelDescriptor() {
373 EcoreMetamodelDescriptor _xblockexpression = null;
374 {
375 final ImmutableList<EClass> eClasses = ImmutableList.<EClass>copyOf(Iterables.<EClass>filter(Modes3Package.eINSTANCE.getEClassifiers(), EClass.class));
376 Set<EClass> _emptySet = CollectionLiterals.<EClass>emptySet();
377 List<EEnum> _emptyList = CollectionLiterals.<EEnum>emptyList();
378 List<EEnumLiteral> _emptyList_1 = CollectionLiterals.<EEnumLiteral>emptyList();
379 final Function1<EClass, EList<EReference>> _function = (EClass it) -> {
380 return it.getEReferences();
381 };
382 ImmutableList<EReference> _copyOf = ImmutableList.<EReference>copyOf(IterableExtensions.<EClass, EReference>flatMap(eClasses, _function));
383 List<EAttribute> _emptyList_2 = CollectionLiterals.<EAttribute>emptyList();
384 _xblockexpression = new EcoreMetamodelDescriptor(eClasses, _emptySet,
385 false, _emptyList, _emptyList_1, _copyOf, _emptyList_2);
386 }
387 return _xblockexpression;
388 }
389
390 public static List<EObject> loadInitialModel() {
391 Modes3ModelRoot _createModes3ModelRoot = Modes3Factory.eINSTANCE.createModes3ModelRoot();
392 return Collections.<EObject>unmodifiableList(CollectionLiterals.<EObject>newArrayList(_createModes3ModelRoot));
393 }
394
395 public ViatraQuerySetDescriptor loadQueries() {
396 ViatraQuerySetDescriptor _xblockexpression = null;
397 {
398 final ImmutableList.Builder<IQuerySpecification<?>> patternsBuilder = ImmutableList.<IQuerySpecification<?>>builder();
399 patternsBuilder.addAll(Modes3Queries.instance().getSpecifications());
400 final ImmutableList<IQuerySpecification<?>> patterns = patternsBuilder.build();
401 final Function1<IQuerySpecification<?>, Boolean> _function = (IQuerySpecification<?> pattern) -> {
402 final Function1<PAnnotation, Boolean> _function_1 = (PAnnotation it) -> {
403 String _name = it.getName();
404 return Boolean.valueOf(Objects.equal(_name, "Constraint"));
405 };
406 return Boolean.valueOf(IterableExtensions.<PAnnotation>exists(pattern.getAllAnnotations(), _function_1));
407 };
408 final ImmutableSet<IQuerySpecification<?>> validationPatterns = ImmutableSet.<IQuerySpecification<?>>copyOf(IterableExtensions.<IQuerySpecification<?>>filter(patterns, _function));
409 Map<IQuerySpecification<?>, EStructuralFeature> _emptyMap = CollectionLiterals.<IQuerySpecification<?>, EStructuralFeature>emptyMap();
410 _xblockexpression = new ViatraQuerySetDescriptor(patterns, validationPatterns, _emptyMap);
411 }
412 return _xblockexpression;
413 }
414
415 public CostObjectiveConfiguration getObjective(final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) {
416 CostObjectiveConfiguration _costObjectiveConfiguration = new CostObjectiveConfiguration();
417 final Procedure1<CostObjectiveConfiguration> _function = (CostObjectiveConfiguration it) -> {
418 final Modes3ModelGenerator.MonitoringQuery monitoringQuery = this.monitoringQuery;
419 if (monitoringQuery != null) {
420 switch (monitoringQuery) {
421 case closeTrains:
422 CostObjectiveElementConfiguration _costObjectiveElementConfiguration = new CostObjectiveElementConfiguration();
423 final Procedure1<CostObjectiveElementConfiguration> _function_1 = (CostObjectiveElementConfiguration it_1) -> {
424 it_1.patternQualifiedName = CloseTrains_step_2.instance().getFullyQualifiedName();
425 it_1.weight = ((14 + 53) + 11);
426 };
427 CostObjectiveElementConfiguration _doubleArrow = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration, _function_1);
428 it.elements.add(_doubleArrow);
429 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_1 = new CostObjectiveElementConfiguration();
430 final Procedure1<CostObjectiveElementConfiguration> _function_2 = (CostObjectiveElementConfiguration it_1) -> {
431 it_1.patternQualifiedName = CloseTrains_step_3.instance().getFullyQualifiedName();
432 it_1.weight = (21 + 14);
433 };
434 CostObjectiveElementConfiguration _doubleArrow_1 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_1, _function_2);
435 it.elements.add(_doubleArrow_1);
436 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_2 = new CostObjectiveElementConfiguration();
437 final Procedure1<CostObjectiveElementConfiguration> _function_3 = (CostObjectiveElementConfiguration it_1) -> {
438 it_1.patternQualifiedName = CloseTrains_step_4.instance().getFullyQualifiedName();
439 it_1.weight = (((14 + 44) + 14) + 9);
440 };
441 CostObjectiveElementConfiguration _doubleArrow_2 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_2, _function_3);
442 it.elements.add(_doubleArrow_2);
443 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_3 = new CostObjectiveElementConfiguration();
444 final Procedure1<CostObjectiveElementConfiguration> _function_4 = (CostObjectiveElementConfiguration it_1) -> {
445 it_1.patternQualifiedName = CloseTrains_step_5.instance().getFullyQualifiedName();
446 it_1.weight = ((14 + 41) + 11);
447 };
448 CostObjectiveElementConfiguration _doubleArrow_3 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_3, _function_4);
449 it.elements.add(_doubleArrow_3);
450 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_4 = new CostObjectiveElementConfiguration();
451 final Procedure1<CostObjectiveElementConfiguration> _function_5 = (CostObjectiveElementConfiguration it_1) -> {
452 it_1.patternQualifiedName = CloseTrains_step_6.instance().getFullyQualifiedName();
453 it_1.weight = 27;
454 };
455 CostObjectiveElementConfiguration _doubleArrow_4 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_4, _function_5);
456 it.elements.add(_doubleArrow_4);
457 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_5 = new CostObjectiveElementConfiguration();
458 final Procedure1<CostObjectiveElementConfiguration> _function_6 = (CostObjectiveElementConfiguration it_1) -> {
459 it_1.patternQualifiedName = CloseTrains_step_7.instance().getFullyQualifiedName();
460 it_1.weight = 48;
461 };
462 CostObjectiveElementConfiguration _doubleArrow_5 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_5, _function_6);
463 it.elements.add(_doubleArrow_5);
464 CloseTrainsObjectiveHint _closeTrainsObjectiveHint = new CloseTrainsObjectiveHint(ecore2Logic, ecore2LogicTrace);
465 it.hint = _closeTrainsObjectiveHint;
466 break;
467 case trainLocations:
468 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_6 = new CostObjectiveElementConfiguration();
469 final Procedure1<CostObjectiveElementConfiguration> _function_7 = (CostObjectiveElementConfiguration it_1) -> {
470 it_1.patternQualifiedName = TrainLocations_step_2.instance().getFullyQualifiedName();
471 it_1.weight = ((14 + 53) + 11);
472 };
473 CostObjectiveElementConfiguration _doubleArrow_6 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_6, _function_7);
474 it.elements.add(_doubleArrow_6);
475 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_7 = new CostObjectiveElementConfiguration();
476 final Procedure1<CostObjectiveElementConfiguration> _function_8 = (CostObjectiveElementConfiguration it_1) -> {
477 it_1.patternQualifiedName = TrainLocations_step_3.instance().getFullyQualifiedName();
478 it_1.weight = 48;
479 };
480 CostObjectiveElementConfiguration _doubleArrow_7 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_7, _function_8);
481 it.elements.add(_doubleArrow_7);
482 TrainLocationsObjectiveHint _trainLocationsObjectiveHint = new TrainLocationsObjectiveHint(ecore2Logic, ecore2LogicTrace);
483 it.hint = _trainLocationsObjectiveHint;
484 break;
485 case misalignedTurnout:
486 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_8 = new CostObjectiveElementConfiguration();
487 final Procedure1<CostObjectiveElementConfiguration> _function_9 = (CostObjectiveElementConfiguration it_1) -> {
488 it_1.patternQualifiedName = MisalignedTurnout_step_2.instance().getFullyQualifiedName();
489 it_1.weight = ((14 + 53) + 11);
490 };
491 CostObjectiveElementConfiguration _doubleArrow_8 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_8, _function_9);
492 it.elements.add(_doubleArrow_8);
493 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_9 = new CostObjectiveElementConfiguration();
494 final Procedure1<CostObjectiveElementConfiguration> _function_10 = (CostObjectiveElementConfiguration it_1) -> {
495 it_1.patternQualifiedName = MisalignedTurnout_step_3.instance().getFullyQualifiedName();
496 it_1.weight = 108;
497 };
498 CostObjectiveElementConfiguration _doubleArrow_9 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_9, _function_10);
499 it.elements.add(_doubleArrow_9);
500 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_10 = new CostObjectiveElementConfiguration();
501 final Procedure1<CostObjectiveElementConfiguration> _function_11 = (CostObjectiveElementConfiguration it_1) -> {
502 it_1.patternQualifiedName = MisalignedTurnout_step_4.instance().getFullyQualifiedName();
503 it_1.weight = 27;
504 };
505 CostObjectiveElementConfiguration _doubleArrow_10 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_10, _function_11);
506 it.elements.add(_doubleArrow_10);
507 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_11 = new CostObjectiveElementConfiguration();
508 final Procedure1<CostObjectiveElementConfiguration> _function_12 = (CostObjectiveElementConfiguration it_1) -> {
509 it_1.patternQualifiedName = MisalignedTurnout_step_5.instance().getFullyQualifiedName();
510 it_1.weight = 48;
511 };
512 CostObjectiveElementConfiguration _doubleArrow_11 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_11, _function_12);
513 it.elements.add(_doubleArrow_11);
514 MisalignedTurnoutObjectiveHint _misalignedTurnoutObjectiveHint = new MisalignedTurnoutObjectiveHint(ecore2Logic, ecore2LogicTrace);
515 it.hint = _misalignedTurnoutObjectiveHint;
516 break;
517 case endOfSiding:
518 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_12 = new CostObjectiveElementConfiguration();
519 final Procedure1<CostObjectiveElementConfiguration> _function_13 = (CostObjectiveElementConfiguration it_1) -> {
520 it_1.patternQualifiedName = EndOfSiding_step_2.instance().getFullyQualifiedName();
521 it_1.weight = ((14 + 53) + 11);
522 };
523 CostObjectiveElementConfiguration _doubleArrow_12 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_12, _function_13);
524 it.elements.add(_doubleArrow_12);
525 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_13 = new CostObjectiveElementConfiguration();
526 final Procedure1<CostObjectiveElementConfiguration> _function_14 = (CostObjectiveElementConfiguration it_1) -> {
527 it_1.patternQualifiedName = EndOfSiding_step_3.instance().getFullyQualifiedName();
528 it_1.weight = (21 + 14);
529 };
530 CostObjectiveElementConfiguration _doubleArrow_13 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_13, _function_14);
531 it.elements.add(_doubleArrow_13);
532 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_14 = new CostObjectiveElementConfiguration();
533 final Procedure1<CostObjectiveElementConfiguration> _function_15 = (CostObjectiveElementConfiguration it_1) -> {
534 it_1.patternQualifiedName = EndOfSiding_step_4.instance().getFullyQualifiedName();
535 it_1.weight = (((((((14 + 35) + 21) + 15) + 14) + 21) + 15) + 11);
536 };
537 CostObjectiveElementConfiguration _doubleArrow_14 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_14, _function_15);
538 it.elements.add(_doubleArrow_14);
539 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_15 = new CostObjectiveElementConfiguration();
540 final Procedure1<CostObjectiveElementConfiguration> _function_16 = (CostObjectiveElementConfiguration it_1) -> {
541 it_1.patternQualifiedName = EndOfSiding_step_5.instance().getFullyQualifiedName();
542 it_1.weight = 48;
543 };
544 CostObjectiveElementConfiguration _doubleArrow_15 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_15, _function_16);
545 it.elements.add(_doubleArrow_15);
546 EndOfSidingObjectiveHint _endOfSidingObjectiveHint = new EndOfSidingObjectiveHint(ecore2Logic, ecore2LogicTrace);
547 it.hint = _endOfSidingObjectiveHint;
548 break;
549 default:
550 throw new IllegalArgumentException(("Unknown monitoring query: " + this.monitoringQuery));
551 }
552 } else {
553 throw new IllegalArgumentException(("Unknown monitoring query: " + this.monitoringQuery));
554 }
555 it.kind = ObjectiveKind.HIGHER_IS_BETTER;
556 it.threshold = ObjectiveThreshold.NO_THRESHOLD;
557 it.findExtremum = true;
558 };
559 return ObjectExtensions.<CostObjectiveConfiguration>operator_doubleArrow(_costObjectiveConfiguration, _function);
560 }
561
562 public static Object init() {
563 Object _xblockexpression = null;
564 {
565 EMFPatternLanguageStandaloneSetup.doSetup();
566 ViatraQueryEngineOptions.setSystemDefaultBackends(ReteBackendFactory.INSTANCE, ReteBackendFactory.INSTANCE,
567 LocalSearchEMFBackendFactory.INSTANCE);
568 LogiclanguagePackage.eINSTANCE.getClass();
569 LogicproblemPackage.eINSTANCE.getClass();
570 PartialinterpretationPackage.eINSTANCE.getClass();
571 Ecore2logicannotationsPackage.eINSTANCE.getClass();
572 Viatra2LogicAnnotationsPackage.eINSTANCE.getClass();
573 Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap();
574 XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl();
575 _xblockexpression = _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl);
576 }
577 return _xblockexpression;
578 }
579
580 public static void main(final String[] args) {
581 int _length = args.length;
582 boolean _notEquals = (_length != 2);
583 if (_notEquals) {
584 System.err.println("Usage: <query> <model size>");
585 }
586 final Modes3ModelGenerator.MonitoringQuery monitoringQuery = Modes3ModelGenerator.MonitoringQuery.valueOf(args[0]);
587 final int modelSize = Integer.parseInt(args[1]);
588 Modes3ModelGenerator.init();
589 final Modes3ModelGenerator generator = new Modes3ModelGenerator(monitoringQuery, modelSize);
590 generator.generate();
591 }
592
593 public Modes3ModelGenerator(final Modes3ModelGenerator.MonitoringQuery monitoringQuery, final int modelSize) {
594 super();
595 this.monitoringQuery = monitoringQuery;
596 this.modelSize = modelSize;
597 }
598}