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.java597
1 files changed, 597 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..a0661c87
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java
@@ -0,0 +1,597 @@
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 };
221 ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow(
222 it_1.maxNewElementsByType, _function_5);
223 };
224 ObjectExtensions.<TypeScopes>operator_doubleArrow(
225 it.typeScopes, _function_3);
226 final Procedure1<SolutionScope> _function_4 = (SolutionScope it_1) -> {
227 it_1.numberOfRequiredSolutions = 1;
228 };
229 ObjectExtensions.<SolutionScope>operator_doubleArrow(
230 it.solutionScope, _function_4);
231 CostObjectiveConfiguration _objective = this.getObjective(this.ecore2Logic, metamodelLogic.getTrace());
232 it.costObjectives.add(_objective);
233 it.scopeWeight = 6;
234 it.nameNewElements = false;
235 it.typeInferenceMethod = TypeInferenceMethod.PreliminaryAnalysis;
236 it.stateCoderStrategy = StateCoderStrategy.PairwiseNeighbourhood;
237 ScopePropagatorStrategy.Polyhedral _polyhedral = new ScopePropagatorStrategy.Polyhedral(
238 PolyhedralScopePropagatorConstraints.Relational, PolyhedralScopePropagatorSolver.Clp);
239 it.scopePropagatorStrategy = _polyhedral;
240 Ecore2Logic_Trace _trace = metamodelLogic.getTrace();
241 Modes3TypeScopeHint _modes3TypeScopeHint = new Modes3TypeScopeHint(this.ecore2Logic, _trace);
242 it.hints.add(_modes3TypeScopeHint);
243 Ecore2Logic_Trace _trace_1 = metamodelLogic.getTrace();
244 Modes3UnitPropagationGenerator _modes3UnitPropagationGenerator = new Modes3UnitPropagationGenerator(this.ecore2Logic, _trace_1);
245 it.unitPropagationPatternGenerators.add(_modes3UnitPropagationGenerator);
246 final Procedure1<DebugConfiguration> _function_5 = (DebugConfiguration it_1) -> {
247 GraphvizVisualiser _graphvizVisualiser = new GraphvizVisualiser();
248 it_1.partialInterpretatioVisualiser = _graphvizVisualiser;
249 };
250 ObjectExtensions.<DebugConfiguration>operator_doubleArrow(
251 it.debugConfiguration, _function_5);
252 it.documentationLevel = DocumentationLevel.NORMAL;
253 };
254 final ViatraReasonerConfiguration config = ObjectExtensions.<ViatraReasonerConfiguration>operator_doubleArrow(_viatraReasonerConfiguration, _function_2);
255 final FileSystemWorkspace workspace = new FileSystemWorkspace("output/", "");
256 workspace.writeModel(logic.getOutput(), "problem.logicproblem");
257 final LogicResult solution = this.solver.solve(logic.getOutput(), config, workspace);
258 URI _xifexpression = null;
259 if ((solution instanceof ModelResult)) {
260 InputOutput.<String>println("Saving generated solutions");
261 final Logic2Ecore logic2Ecore = new Logic2Ecore(this.ecore2Logic);
262 final List<? extends LogicModelInterpretation> interpretations = this.solver.getInterpretations(((ModelResult)solution));
263 int _size = interpretations.size();
264 ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
265 for (final Integer representationIndex : _doubleDotLessThan) {
266 {
267 final LogicModelInterpretation interpretation = interpretations.get((representationIndex).intValue());
268 final int representationNumber = ((representationIndex).intValue() + 1);
269 if ((interpretation instanceof PartialModelAsLogicInterpretation)) {
270 final PartialInterpretation representation = ((PartialModelAsLogicInterpretation)interpretation).getPartialInterpretation();
271 StringConcatenation _builder_1 = new StringConcatenation();
272 _builder_1.append("solution");
273 _builder_1.append(representationNumber);
274 _builder_1.append(".partialinterpretation");
275 workspace.writeModel(representation, _builder_1.toString());
276 final PartialInterpretation2Gml partialInterpretation2GML = new PartialInterpretation2Gml();
277 final String gml = partialInterpretation2GML.transform(representation);
278 StringConcatenation _builder_2 = new StringConcatenation();
279 _builder_2.append("solution");
280 _builder_2.append(representationNumber);
281 _builder_2.append(".gml");
282 workspace.writeText(_builder_2.toString(), gml);
283 final EObject model = logic2Ecore.transformInterpretation(interpretation, metamodelLogic.getTrace());
284 final TreeIterator<EObject> iterator = model.eAllContents();
285 int id = 0;
286 while (iterator.hasNext()) {
287 {
288 final EObject obj = iterator.next();
289 final Function1<EAttribute, Boolean> _function_3 = (EAttribute it) -> {
290 String _name_2 = it.getName();
291 return Boolean.valueOf(Objects.equal(_name_2, "id"));
292 };
293 final EAttribute idFeature = IterableExtensions.<EAttribute>findFirst(obj.eClass().getEAllAttributes(), _function_3);
294 if ((idFeature != null)) {
295 obj.eSet(idFeature, Integer.valueOf(id));
296 id++;
297 }
298 }
299 }
300 StringConcatenation _builder_3 = new StringConcatenation();
301 _builder_3.append("solution");
302 _builder_3.append(representationNumber);
303 _builder_3.append(".modes3");
304 workspace.writeModel(model, _builder_3.toString());
305 int _size_1 = representation.getNewElements().size();
306 boolean _lessThan = (_size_1 < 160);
307 if (_lessThan) {
308 final Function1<Type, Boolean> _function_3 = (Type it) -> {
309 String _name_2 = it.getName();
310 return Boolean.valueOf(Objects.equal(_name_2, "Modes3ModelRoot class DefinedPart"));
311 };
312 Type _findFirst = IterableExtensions.<Type>findFirst(representation.getProblem().getTypes(), _function_3);
313 final TypeDefinition rootType = ((TypeDefinition) _findFirst);
314 final Function1<PartialComplexTypeInterpretation, Boolean> _function_4 = (PartialComplexTypeInterpretation it) -> {
315 String _name_2 = it.getInterpretationOf().getName();
316 return Boolean.valueOf(Objects.equal(_name_2, "Modes3ModelRoot class"));
317 };
318 final PartialComplexTypeInterpretation rootIntepretation = IterableExtensions.<PartialComplexTypeInterpretation>findFirst(Iterables.<PartialComplexTypeInterpretation>filter(representation.getPartialtypeinterpratation(),
319 PartialComplexTypeInterpretation.class), _function_4);
320 rootIntepretation.getElements().removeAll(rootType.getElements());
321 representation.getProblem().getElements().removeAll(rootType.getElements());
322 EList<PartialRelationInterpretation> _partialrelationinterpretation = representation.getPartialrelationinterpretation();
323 for (final PartialRelationInterpretation relationInterpretation : _partialrelationinterpretation) {
324 final Predicate<RelationLink> _function_5 = (RelationLink link) -> {
325 boolean _xifexpression_1 = false;
326 if ((link instanceof BinaryElementRelationLink)) {
327 _xifexpression_1 = (rootType.getElements().contains(((BinaryElementRelationLink)link).getParam1()) ||
328 rootType.getElements().contains(((BinaryElementRelationLink)link).getParam2()));
329 } else {
330 _xifexpression_1 = false;
331 }
332 return _xifexpression_1;
333 };
334 relationInterpretation.getRelationlinks().removeIf(_function_5);
335 }
336 rootType.getElements().clear();
337 final GraphvizVisualiser visualiser = new GraphvizVisualiser();
338 final PartialInterpretationVisualisation visualisation = visualiser.visualiseConcretization(representation);
339 StringConcatenation _builder_4 = new StringConcatenation();
340 _builder_4.append("solution");
341 _builder_4.append(representationNumber);
342 _builder_4.append(".png");
343 visualisation.writeToFile(workspace, _builder_4.toString());
344 }
345 } else {
346 StringConcatenation _builder_5 = new StringConcatenation();
347 _builder_5.append("solution");
348 _builder_5.append(representationNumber);
349 _builder_5.append(".txt");
350 workspace.writeText(_builder_5.toString(), interpretation.toString());
351 }
352 }
353 }
354 } else {
355 URI _xblockexpression_1 = null;
356 {
357 InputOutput.<String>println("Failed to solve problem");
358 final LogicProblem partial = logic.getOutput();
359 _xblockexpression_1 = workspace.writeModel(partial, "solution.partialinterpretation");
360 }
361 _xifexpression = _xblockexpression_1;
362 }
363 _xblockexpression = _xifexpression;
364 }
365 return _xblockexpression;
366 } catch (Throwable _e) {
367 throw Exceptions.sneakyThrow(_e);
368 }
369 }
370
371 public static EcoreMetamodelDescriptor createMetamodelDescriptor() {
372 EcoreMetamodelDescriptor _xblockexpression = null;
373 {
374 final ImmutableList<EClass> eClasses = ImmutableList.<EClass>copyOf(Iterables.<EClass>filter(Modes3Package.eINSTANCE.getEClassifiers(), EClass.class));
375 Set<EClass> _emptySet = CollectionLiterals.<EClass>emptySet();
376 List<EEnum> _emptyList = CollectionLiterals.<EEnum>emptyList();
377 List<EEnumLiteral> _emptyList_1 = CollectionLiterals.<EEnumLiteral>emptyList();
378 final Function1<EClass, EList<EReference>> _function = (EClass it) -> {
379 return it.getEReferences();
380 };
381 ImmutableList<EReference> _copyOf = ImmutableList.<EReference>copyOf(IterableExtensions.<EClass, EReference>flatMap(eClasses, _function));
382 List<EAttribute> _emptyList_2 = CollectionLiterals.<EAttribute>emptyList();
383 _xblockexpression = new EcoreMetamodelDescriptor(eClasses, _emptySet,
384 false, _emptyList, _emptyList_1, _copyOf, _emptyList_2);
385 }
386 return _xblockexpression;
387 }
388
389 public static List<EObject> loadInitialModel() {
390 Modes3ModelRoot _createModes3ModelRoot = Modes3Factory.eINSTANCE.createModes3ModelRoot();
391 return Collections.<EObject>unmodifiableList(CollectionLiterals.<EObject>newArrayList(_createModes3ModelRoot));
392 }
393
394 public ViatraQuerySetDescriptor loadQueries() {
395 ViatraQuerySetDescriptor _xblockexpression = null;
396 {
397 final ImmutableList.Builder<IQuerySpecification<?>> patternsBuilder = ImmutableList.<IQuerySpecification<?>>builder();
398 patternsBuilder.addAll(Modes3Queries.instance().getSpecifications());
399 final ImmutableList<IQuerySpecification<?>> patterns = patternsBuilder.build();
400 final Function1<IQuerySpecification<?>, Boolean> _function = (IQuerySpecification<?> pattern) -> {
401 final Function1<PAnnotation, Boolean> _function_1 = (PAnnotation it) -> {
402 String _name = it.getName();
403 return Boolean.valueOf(Objects.equal(_name, "Constraint"));
404 };
405 return Boolean.valueOf(IterableExtensions.<PAnnotation>exists(pattern.getAllAnnotations(), _function_1));
406 };
407 final ImmutableSet<IQuerySpecification<?>> validationPatterns = ImmutableSet.<IQuerySpecification<?>>copyOf(IterableExtensions.<IQuerySpecification<?>>filter(patterns, _function));
408 Map<IQuerySpecification<?>, EStructuralFeature> _emptyMap = CollectionLiterals.<IQuerySpecification<?>, EStructuralFeature>emptyMap();
409 _xblockexpression = new ViatraQuerySetDescriptor(patterns, validationPatterns, _emptyMap);
410 }
411 return _xblockexpression;
412 }
413
414 public CostObjectiveConfiguration getObjective(final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) {
415 CostObjectiveConfiguration _costObjectiveConfiguration = new CostObjectiveConfiguration();
416 final Procedure1<CostObjectiveConfiguration> _function = (CostObjectiveConfiguration it) -> {
417 final Modes3ModelGenerator.MonitoringQuery monitoringQuery = this.monitoringQuery;
418 if (monitoringQuery != null) {
419 switch (monitoringQuery) {
420 case closeTrains:
421 CostObjectiveElementConfiguration _costObjectiveElementConfiguration = new CostObjectiveElementConfiguration();
422 final Procedure1<CostObjectiveElementConfiguration> _function_1 = (CostObjectiveElementConfiguration it_1) -> {
423 it_1.patternQualifiedName = CloseTrains_step_2.instance().getFullyQualifiedName();
424 it_1.weight = ((14 + 53) + 11);
425 };
426 CostObjectiveElementConfiguration _doubleArrow = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration, _function_1);
427 it.elements.add(_doubleArrow);
428 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_1 = new CostObjectiveElementConfiguration();
429 final Procedure1<CostObjectiveElementConfiguration> _function_2 = (CostObjectiveElementConfiguration it_1) -> {
430 it_1.patternQualifiedName = CloseTrains_step_3.instance().getFullyQualifiedName();
431 it_1.weight = (21 + 14);
432 };
433 CostObjectiveElementConfiguration _doubleArrow_1 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_1, _function_2);
434 it.elements.add(_doubleArrow_1);
435 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_2 = new CostObjectiveElementConfiguration();
436 final Procedure1<CostObjectiveElementConfiguration> _function_3 = (CostObjectiveElementConfiguration it_1) -> {
437 it_1.patternQualifiedName = CloseTrains_step_4.instance().getFullyQualifiedName();
438 it_1.weight = (((14 + 44) + 14) + 9);
439 };
440 CostObjectiveElementConfiguration _doubleArrow_2 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_2, _function_3);
441 it.elements.add(_doubleArrow_2);
442 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_3 = new CostObjectiveElementConfiguration();
443 final Procedure1<CostObjectiveElementConfiguration> _function_4 = (CostObjectiveElementConfiguration it_1) -> {
444 it_1.patternQualifiedName = CloseTrains_step_5.instance().getFullyQualifiedName();
445 it_1.weight = ((14 + 41) + 11);
446 };
447 CostObjectiveElementConfiguration _doubleArrow_3 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_3, _function_4);
448 it.elements.add(_doubleArrow_3);
449 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_4 = new CostObjectiveElementConfiguration();
450 final Procedure1<CostObjectiveElementConfiguration> _function_5 = (CostObjectiveElementConfiguration it_1) -> {
451 it_1.patternQualifiedName = CloseTrains_step_6.instance().getFullyQualifiedName();
452 it_1.weight = 27;
453 };
454 CostObjectiveElementConfiguration _doubleArrow_4 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_4, _function_5);
455 it.elements.add(_doubleArrow_4);
456 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_5 = new CostObjectiveElementConfiguration();
457 final Procedure1<CostObjectiveElementConfiguration> _function_6 = (CostObjectiveElementConfiguration it_1) -> {
458 it_1.patternQualifiedName = CloseTrains_step_7.instance().getFullyQualifiedName();
459 it_1.weight = 48;
460 };
461 CostObjectiveElementConfiguration _doubleArrow_5 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_5, _function_6);
462 it.elements.add(_doubleArrow_5);
463 CloseTrainsObjectiveHint _closeTrainsObjectiveHint = new CloseTrainsObjectiveHint(ecore2Logic, ecore2LogicTrace);
464 it.hint = _closeTrainsObjectiveHint;
465 break;
466 case trainLocations:
467 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_6 = new CostObjectiveElementConfiguration();
468 final Procedure1<CostObjectiveElementConfiguration> _function_7 = (CostObjectiveElementConfiguration it_1) -> {
469 it_1.patternQualifiedName = TrainLocations_step_2.instance().getFullyQualifiedName();
470 it_1.weight = ((14 + 53) + 11);
471 };
472 CostObjectiveElementConfiguration _doubleArrow_6 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_6, _function_7);
473 it.elements.add(_doubleArrow_6);
474 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_7 = new CostObjectiveElementConfiguration();
475 final Procedure1<CostObjectiveElementConfiguration> _function_8 = (CostObjectiveElementConfiguration it_1) -> {
476 it_1.patternQualifiedName = TrainLocations_step_3.instance().getFullyQualifiedName();
477 it_1.weight = 48;
478 };
479 CostObjectiveElementConfiguration _doubleArrow_7 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_7, _function_8);
480 it.elements.add(_doubleArrow_7);
481 TrainLocationsObjectiveHint _trainLocationsObjectiveHint = new TrainLocationsObjectiveHint(ecore2Logic, ecore2LogicTrace);
482 it.hint = _trainLocationsObjectiveHint;
483 break;
484 case misalignedTurnout:
485 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_8 = new CostObjectiveElementConfiguration();
486 final Procedure1<CostObjectiveElementConfiguration> _function_9 = (CostObjectiveElementConfiguration it_1) -> {
487 it_1.patternQualifiedName = MisalignedTurnout_step_2.instance().getFullyQualifiedName();
488 it_1.weight = ((14 + 53) + 11);
489 };
490 CostObjectiveElementConfiguration _doubleArrow_8 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_8, _function_9);
491 it.elements.add(_doubleArrow_8);
492 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_9 = new CostObjectiveElementConfiguration();
493 final Procedure1<CostObjectiveElementConfiguration> _function_10 = (CostObjectiveElementConfiguration it_1) -> {
494 it_1.patternQualifiedName = MisalignedTurnout_step_3.instance().getFullyQualifiedName();
495 it_1.weight = 108;
496 };
497 CostObjectiveElementConfiguration _doubleArrow_9 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_9, _function_10);
498 it.elements.add(_doubleArrow_9);
499 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_10 = new CostObjectiveElementConfiguration();
500 final Procedure1<CostObjectiveElementConfiguration> _function_11 = (CostObjectiveElementConfiguration it_1) -> {
501 it_1.patternQualifiedName = MisalignedTurnout_step_4.instance().getFullyQualifiedName();
502 it_1.weight = 27;
503 };
504 CostObjectiveElementConfiguration _doubleArrow_10 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_10, _function_11);
505 it.elements.add(_doubleArrow_10);
506 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_11 = new CostObjectiveElementConfiguration();
507 final Procedure1<CostObjectiveElementConfiguration> _function_12 = (CostObjectiveElementConfiguration it_1) -> {
508 it_1.patternQualifiedName = MisalignedTurnout_step_5.instance().getFullyQualifiedName();
509 it_1.weight = 48;
510 };
511 CostObjectiveElementConfiguration _doubleArrow_11 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_11, _function_12);
512 it.elements.add(_doubleArrow_11);
513 MisalignedTurnoutObjectiveHint _misalignedTurnoutObjectiveHint = new MisalignedTurnoutObjectiveHint(ecore2Logic, ecore2LogicTrace);
514 it.hint = _misalignedTurnoutObjectiveHint;
515 break;
516 case endOfSiding:
517 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_12 = new CostObjectiveElementConfiguration();
518 final Procedure1<CostObjectiveElementConfiguration> _function_13 = (CostObjectiveElementConfiguration it_1) -> {
519 it_1.patternQualifiedName = EndOfSiding_step_2.instance().getFullyQualifiedName();
520 it_1.weight = ((14 + 53) + 11);
521 };
522 CostObjectiveElementConfiguration _doubleArrow_12 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_12, _function_13);
523 it.elements.add(_doubleArrow_12);
524 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_13 = new CostObjectiveElementConfiguration();
525 final Procedure1<CostObjectiveElementConfiguration> _function_14 = (CostObjectiveElementConfiguration it_1) -> {
526 it_1.patternQualifiedName = EndOfSiding_step_3.instance().getFullyQualifiedName();
527 it_1.weight = (21 + 14);
528 };
529 CostObjectiveElementConfiguration _doubleArrow_13 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_13, _function_14);
530 it.elements.add(_doubleArrow_13);
531 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_14 = new CostObjectiveElementConfiguration();
532 final Procedure1<CostObjectiveElementConfiguration> _function_15 = (CostObjectiveElementConfiguration it_1) -> {
533 it_1.patternQualifiedName = EndOfSiding_step_4.instance().getFullyQualifiedName();
534 it_1.weight = (((((((14 + 35) + 21) + 15) + 14) + 21) + 15) + 11);
535 };
536 CostObjectiveElementConfiguration _doubleArrow_14 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_14, _function_15);
537 it.elements.add(_doubleArrow_14);
538 CostObjectiveElementConfiguration _costObjectiveElementConfiguration_15 = new CostObjectiveElementConfiguration();
539 final Procedure1<CostObjectiveElementConfiguration> _function_16 = (CostObjectiveElementConfiguration it_1) -> {
540 it_1.patternQualifiedName = EndOfSiding_step_5.instance().getFullyQualifiedName();
541 it_1.weight = 48;
542 };
543 CostObjectiveElementConfiguration _doubleArrow_15 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_15, _function_16);
544 it.elements.add(_doubleArrow_15);
545 EndOfSidingObjectiveHint _endOfSidingObjectiveHint = new EndOfSidingObjectiveHint(ecore2Logic, ecore2LogicTrace);
546 it.hint = _endOfSidingObjectiveHint;
547 break;
548 default:
549 throw new IllegalArgumentException(("Unknown monitoring query: " + this.monitoringQuery));
550 }
551 } else {
552 throw new IllegalArgumentException(("Unknown monitoring query: " + this.monitoringQuery));
553 }
554 it.kind = ObjectiveKind.HIGHER_IS_BETTER;
555 it.threshold = ObjectiveThreshold.NO_THRESHOLD;
556 it.findExtremum = true;
557 };
558 return ObjectExtensions.<CostObjectiveConfiguration>operator_doubleArrow(_costObjectiveConfiguration, _function);
559 }
560
561 public static Object init() {
562 Object _xblockexpression = null;
563 {
564 EMFPatternLanguageStandaloneSetup.doSetup();
565 ViatraQueryEngineOptions.setSystemDefaultBackends(ReteBackendFactory.INSTANCE, ReteBackendFactory.INSTANCE,
566 LocalSearchEMFBackendFactory.INSTANCE);
567 LogiclanguagePackage.eINSTANCE.getClass();
568 LogicproblemPackage.eINSTANCE.getClass();
569 PartialinterpretationPackage.eINSTANCE.getClass();
570 Ecore2logicannotationsPackage.eINSTANCE.getClass();
571 Viatra2LogicAnnotationsPackage.eINSTANCE.getClass();
572 Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap();
573 XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl();
574 _xblockexpression = _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl);
575 }
576 return _xblockexpression;
577 }
578
579 public static void main(final String[] args) {
580 int _length = args.length;
581 boolean _notEquals = (_length != 2);
582 if (_notEquals) {
583 System.err.println("Usage: <query> <model size>");
584 }
585 final Modes3ModelGenerator.MonitoringQuery monitoringQuery = Modes3ModelGenerator.MonitoringQuery.valueOf(args[0]);
586 final int modelSize = Integer.parseInt(args[1]);
587 Modes3ModelGenerator.init();
588 final Modes3ModelGenerator generator = new Modes3ModelGenerator(monitoringQuery, modelSize);
589 generator.generate();
590 }
591
592 public Modes3ModelGenerator(final Modes3ModelGenerator.MonitoringQuery monitoringQuery, final int modelSize) {
593 super();
594 this.monitoringQuery = monitoringQuery;
595 this.modelSize = modelSize;
596 }
597}