diff options
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3')
15 files changed, 2702 insertions, 0 deletions
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.CloseTrainsObjectiveHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.CloseTrainsObjectiveHint.xtendbin new file mode 100644 index 00000000..87975792 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.CloseTrainsObjectiveHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.EndOfSidingObjectiveHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.EndOfSidingObjectiveHint.xtendbin new file mode 100644 index 00000000..f243e180 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.EndOfSidingObjectiveHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.MisalignedTurnoutObjectiveHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.MisalignedTurnoutObjectiveHint.xtendbin new file mode 100644 index 00000000..cdef4dc7 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.MisalignedTurnoutObjectiveHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3ModelGenerator.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3ModelGenerator.xtendbin new file mode 100644 index 00000000..759ac9e4 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3ModelGenerator.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3TypeScopeHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3TypeScopeHint.xtendbin new file mode 100644 index 00000000..386baeda --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3TypeScopeHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3UnitPropagationGenerator.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3UnitPropagationGenerator.xtendbin new file mode 100644 index 00000000..79059b7f --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3UnitPropagationGenerator.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.TrainLocationsObjectiveHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.TrainLocationsObjectiveHint.xtendbin new file mode 100644 index 00000000..3c3a380e --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.TrainLocationsObjectiveHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore new file mode 100644 index 00000000..1a7df1d9 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore | |||
@@ -0,0 +1,13 @@ | |||
1 | /.Modes3ModelGenerator.java._trace | ||
2 | /.Modes3UnitPropagationGenerator.java._trace | ||
3 | /.Modes3TypeScopeHint.java._trace | ||
4 | /.Modes3TypeScopeHint.xtendbin | ||
5 | /.Modes3UnitPropagationGenerator.xtendbin | ||
6 | /Modes3TypeScopeHint.java | ||
7 | /.Modes3ModelGenerator.xtendbin | ||
8 | /Modes3ModelGenerator.java | ||
9 | /Modes3UnitPropagationGenerator.java | ||
10 | /.CloseTrainsObjectiveHint.java._trace | ||
11 | /.TrainLocationsObjectiveHint.java._trace | ||
12 | /.MisalignedTurnoutObjectiveHint.java._trace | ||
13 | /.EndOfSidingObjectiveHint.java._trace | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/CloseTrainsObjectiveHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/CloseTrainsObjectiveHint.java new file mode 100644 index 00000000..babfa7e1 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/CloseTrainsObjectiveHint.java | |||
@@ -0,0 +1,279 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import com.google.common.collect.ImmutableList; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers; | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint; | ||
15 | import java.util.Collection; | ||
16 | import java.util.List; | ||
17 | import java.util.Map; | ||
18 | import java.util.Set; | ||
19 | import modes3.Modes3Package; | ||
20 | import modes3.queries.CloseTrains_step_2; | ||
21 | import modes3.queries.CloseTrains_step_3; | ||
22 | import modes3.queries.CloseTrains_step_4; | ||
23 | import modes3.queries.CloseTrains_step_5; | ||
24 | import modes3.queries.CloseTrains_step_6; | ||
25 | import modes3.queries.CloseTrains_step_7; | ||
26 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
27 | import org.eclipse.xtext.xbase.lib.Extension; | ||
28 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
29 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
30 | |||
31 | @SuppressWarnings("all") | ||
32 | public class CloseTrainsObjectiveHint extends CostObjectiveHint { | ||
33 | private final Type segmentType; | ||
34 | |||
35 | private final Type trainType; | ||
36 | |||
37 | public CloseTrainsObjectiveHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
38 | @Extension | ||
39 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
40 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
41 | this.trainType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTrain()); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public boolean isExact() { | ||
46 | return true; | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public PolyhedronExtensionOperator createPolyhedronExtensionOperator(final Map<String, CostElementMatchers> costElementMatchers) { | ||
51 | PolyhedronExtensionOperator _xblockexpression = null; | ||
52 | { | ||
53 | final CostElementMatchers step2 = costElementMatchers.get(CloseTrains_step_2.instance().getFullyQualifiedName()); | ||
54 | final CostElementMatchers step3 = costElementMatchers.get(CloseTrains_step_3.instance().getFullyQualifiedName()); | ||
55 | final CostElementMatchers step4 = costElementMatchers.get(CloseTrains_step_4.instance().getFullyQualifiedName()); | ||
56 | final CostElementMatchers step5 = costElementMatchers.get(CloseTrains_step_5.instance().getFullyQualifiedName()); | ||
57 | final CostElementMatchers step6 = costElementMatchers.get(CloseTrains_step_6.instance().getFullyQualifiedName()); | ||
58 | final CostElementMatchers step7 = costElementMatchers.get(CloseTrains_step_7.instance().getFullyQualifiedName()); | ||
59 | final PolyhedronExtensionOperator _function = (ExtendedLinearExpressionBuilderFactory it) -> { | ||
60 | final ExtendedLinearExpressionBuilder objectiveBuilder = it.createBuilder(); | ||
61 | ImmutableList<CostElementMatch> _matches = step2.getMatches(); | ||
62 | for (final CostElementMatch m : _matches) { | ||
63 | { | ||
64 | final Dimension dimension = it.getDimension(m.getMatch()); | ||
65 | objectiveBuilder.add(step2.getWeight(), dimension); | ||
66 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
67 | boolean _isMulti = m.isMulti(); | ||
68 | if (_isMulti) { | ||
69 | it.createBuilder().add(1, dimension).add((-1), this.trainType).build().assertEqualsTo(0); | ||
70 | } else { | ||
71 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
72 | boolean _isMust = m.isMust(); | ||
73 | if (_isMust) { | ||
74 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | final ImmutableList<CostElementMatch> step3Matches = step3.getMatches(); | ||
80 | for (final CostElementMatch m_1 : step3Matches) { | ||
81 | { | ||
82 | final Dimension dimension = it.getDimension(m_1.getMatch()); | ||
83 | objectiveBuilder.add(step3.getWeight(), dimension); | ||
84 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
85 | boolean _isMulti = m_1.isMulti(); | ||
86 | boolean _not = (!_isMulti); | ||
87 | if (_not) { | ||
88 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
89 | boolean _isMust = m_1.isMust(); | ||
90 | if (_isMust) { | ||
91 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | final Function1<CostElementMatch, IPatternMatch> _function_1 = (CostElementMatch it_1) -> { | ||
97 | return step2.projectMayMatch(it_1.getMatch(), 2); | ||
98 | }; | ||
99 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step3Matches, _function_1).entrySet(); | ||
100 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair : _entrySet) { | ||
101 | { | ||
102 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
103 | List<CostElementMatch> _value = pair.getValue(); | ||
104 | for (final CostElementMatch m_2 : _value) { | ||
105 | multiplicityBuilder.add(1, m_2.getMatch()); | ||
106 | } | ||
107 | multiplicityBuilder.add((-1), pair.getKey()); | ||
108 | multiplicityBuilder.build().assertEqualsTo(0); | ||
109 | } | ||
110 | } | ||
111 | CloseTrainsObjectiveHint.boundLimit(it, step3Matches, 2, this.trainType, 1); | ||
112 | CloseTrainsObjectiveHint.boundLimit(it, step3Matches, 3, this.segmentType, 1); | ||
113 | final ImmutableList<CostElementMatch> step4Matches = step4.getMatches(); | ||
114 | for (final CostElementMatch m_2 : step4Matches) { | ||
115 | { | ||
116 | final Dimension dimension = it.getDimension(m_2.getMatch()); | ||
117 | objectiveBuilder.add(step4.getWeight(), dimension); | ||
118 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
119 | boolean _isMulti = m_2.isMulti(); | ||
120 | boolean _not = (!_isMulti); | ||
121 | if (_not) { | ||
122 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
123 | boolean _isMust = m_2.isMust(); | ||
124 | if (_isMust) { | ||
125 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | final Function1<CostElementMatch, IPatternMatch> _function_2 = (CostElementMatch it_1) -> { | ||
131 | return step3.projectMayMatch(it_1.getMatch(), 2, 3); | ||
132 | }; | ||
133 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_1 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step4Matches, _function_2).entrySet(); | ||
134 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_1 : _entrySet_1) { | ||
135 | { | ||
136 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
137 | List<CostElementMatch> _value = pair_1.getValue(); | ||
138 | for (final CostElementMatch m_3 : _value) { | ||
139 | multiplicityBuilder.add(1, m_3.getMatch()); | ||
140 | } | ||
141 | multiplicityBuilder.add((-2), pair_1.getKey()); | ||
142 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
143 | } | ||
144 | } | ||
145 | CloseTrainsObjectiveHint.boundLimit(it, step4Matches, 2, this.trainType, 2); | ||
146 | CloseTrainsObjectiveHint.boundLimit(it, step4Matches, 3, this.segmentType, 2); | ||
147 | CloseTrainsObjectiveHint.boundLimit(it, step4Matches, 4, this.segmentType, 2); | ||
148 | final ImmutableList<CostElementMatch> step5Matches = step5.getMatches(); | ||
149 | for (final CostElementMatch m_3 : step5Matches) { | ||
150 | { | ||
151 | final Dimension dimension = it.getDimension(m_3.getMatch()); | ||
152 | objectiveBuilder.add(step5.getWeight(), dimension); | ||
153 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
154 | boolean _isMulti = m_3.isMulti(); | ||
155 | boolean _not = (!_isMulti); | ||
156 | if (_not) { | ||
157 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
158 | boolean _isMust = m_3.isMust(); | ||
159 | if (_isMust) { | ||
160 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | final Function1<CostElementMatch, IPatternMatch> _function_3 = (CostElementMatch it_1) -> { | ||
166 | return step4.projectMayMatch(it_1.getMatch(), 2, 3, 4); | ||
167 | }; | ||
168 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_2 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step5Matches, _function_3).entrySet(); | ||
169 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_2 : _entrySet_2) { | ||
170 | { | ||
171 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
172 | List<CostElementMatch> _value = pair_2.getValue(); | ||
173 | for (final CostElementMatch m_4 : _value) { | ||
174 | multiplicityBuilder.add(1, m_4.getMatch()); | ||
175 | } | ||
176 | multiplicityBuilder.add((-2), pair_2.getKey()); | ||
177 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
178 | } | ||
179 | } | ||
180 | CloseTrainsObjectiveHint.boundLimit(it, step5Matches, 2, this.trainType, 4); | ||
181 | CloseTrainsObjectiveHint.boundLimit(it, step5Matches, 3, this.segmentType, 4); | ||
182 | CloseTrainsObjectiveHint.boundLimit(it, step5Matches, 4, this.segmentType, 4); | ||
183 | CloseTrainsObjectiveHint.boundLimit(it, step5Matches, 5, this.segmentType, 4); | ||
184 | final ImmutableList<CostElementMatch> step6Matches = step6.getMatches(); | ||
185 | for (final CostElementMatch m_4 : step6Matches) { | ||
186 | { | ||
187 | final Dimension dimension = it.getDimension(m_4.getMatch()); | ||
188 | objectiveBuilder.add(step6.getWeight(), dimension); | ||
189 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
190 | boolean _isMulti = m_4.isMulti(); | ||
191 | if (_isMulti) { | ||
192 | Object _get = m_4.getMatch().get(3); | ||
193 | Object _get_1 = m_4.getMatch().get(5); | ||
194 | boolean _equals = Objects.equal(_get, _get_1); | ||
195 | if (_equals) { | ||
196 | it.createBuilder().add(2, m_4.getMatch()).add((-1), step5.projectMayMatch(m_4.getMatch(), 2, 3, 4, 5)).build().assertEqualsTo(0); | ||
197 | } else { | ||
198 | it.createBuilder().add(1, m_4.getMatch()).add((-1), step5.projectMayMatch(m_4.getMatch(), 2, 3, 4, 5)).build().assertEqualsTo(0); | ||
199 | } | ||
200 | } else { | ||
201 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
202 | boolean _isMust = m_4.isMust(); | ||
203 | if (_isMust) { | ||
204 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | CloseTrainsObjectiveHint.boundLimit(it, step6Matches, 2, this.trainType, 2); | ||
210 | CloseTrainsObjectiveHint.boundLimit(it, step6Matches, 3, this.segmentType, 2); | ||
211 | CloseTrainsObjectiveHint.boundLimit(it, step6Matches, 4, this.segmentType, 2); | ||
212 | CloseTrainsObjectiveHint.boundLimit(it, step6Matches, 5, this.segmentType, 2); | ||
213 | final ImmutableList<CostElementMatch> step7Matches = step7.getMatches(); | ||
214 | for (final CostElementMatch m_5 : step7Matches) { | ||
215 | { | ||
216 | final Dimension dimension = it.getDimension(m_5.getMatch()); | ||
217 | objectiveBuilder.add(step7.getWeight(), dimension); | ||
218 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
219 | boolean _isMulti = m_5.isMulti(); | ||
220 | boolean _not = (!_isMulti); | ||
221 | if (_not) { | ||
222 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
223 | boolean _isMust = m_5.isMust(); | ||
224 | if (_isMust) { | ||
225 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | final Function1<CostElementMatch, IPatternMatch> _function_4 = (CostElementMatch it_1) -> { | ||
231 | return step6.projectMayMatch(it_1.getMatch(), 2, 3, 4, 5); | ||
232 | }; | ||
233 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_3 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step7Matches, _function_4).entrySet(); | ||
234 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_3 : _entrySet_3) { | ||
235 | { | ||
236 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
237 | List<CostElementMatch> _value = pair_3.getValue(); | ||
238 | for (final CostElementMatch m_6 : _value) { | ||
239 | multiplicityBuilder.add(1, m_6.getMatch()); | ||
240 | } | ||
241 | multiplicityBuilder.add((-1), pair_3.getKey()); | ||
242 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
243 | } | ||
244 | } | ||
245 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 2, this.trainType, 2); | ||
246 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 3, this.segmentType, 2); | ||
247 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 4, this.segmentType, 2); | ||
248 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 5, this.segmentType, 2); | ||
249 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 6, this.trainType, 2); | ||
250 | this.buildWithBounds(objectiveBuilder); | ||
251 | }; | ||
252 | _xblockexpression = _function; | ||
253 | } | ||
254 | return _xblockexpression; | ||
255 | } | ||
256 | |||
257 | private static void boundLimit(@Extension final ExtendedLinearExpressionBuilderFactory factory, final Collection<CostElementMatch> matches, final int index, final Type type, final int count) { | ||
258 | final Function1<CostElementMatch, Object> _function = (CostElementMatch it) -> { | ||
259 | return it.getMatch().get(index); | ||
260 | }; | ||
261 | Set<Map.Entry<Object, List<CostElementMatch>>> _entrySet = IterableExtensions.<Object, CostElementMatch>groupBy(matches, _function).entrySet(); | ||
262 | for (final Map.Entry<Object, List<CostElementMatch>> pair : _entrySet) { | ||
263 | { | ||
264 | final ExtendedLinearExpressionBuilder multiplicityBuilder = factory.createBuilder(); | ||
265 | List<CostElementMatch> _value = pair.getValue(); | ||
266 | for (final CostElementMatch m : _value) { | ||
267 | multiplicityBuilder.add(1, m.getMatch()); | ||
268 | } | ||
269 | boolean _isMulti = CostElementMatchers.isMulti(pair.getKey()); | ||
270 | if (_isMulti) { | ||
271 | multiplicityBuilder.add((-count), type); | ||
272 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
273 | } else { | ||
274 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(count)); | ||
275 | } | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java new file mode 100644 index 00000000..77c513e1 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java | |||
@@ -0,0 +1,193 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.collect.ImmutableList; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint; | ||
14 | import java.util.Collection; | ||
15 | import java.util.List; | ||
16 | import java.util.Map; | ||
17 | import java.util.Set; | ||
18 | import modes3.Modes3Package; | ||
19 | import modes3.queries.EndOfSiding_step_2; | ||
20 | import modes3.queries.EndOfSiding_step_3; | ||
21 | import modes3.queries.EndOfSiding_step_4; | ||
22 | import modes3.queries.EndOfSiding_step_5; | ||
23 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
24 | import org.eclipse.xtext.xbase.lib.Extension; | ||
25 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
26 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
27 | |||
28 | @SuppressWarnings("all") | ||
29 | public class EndOfSidingObjectiveHint extends CostObjectiveHint { | ||
30 | private final Type segmentType; | ||
31 | |||
32 | private final Type trainType; | ||
33 | |||
34 | public EndOfSidingObjectiveHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
35 | @Extension | ||
36 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
37 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
38 | this.trainType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTrain()); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public boolean isExact() { | ||
43 | return true; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public PolyhedronExtensionOperator createPolyhedronExtensionOperator(final Map<String, CostElementMatchers> costElementMatchers) { | ||
48 | PolyhedronExtensionOperator _xblockexpression = null; | ||
49 | { | ||
50 | final CostElementMatchers step2 = costElementMatchers.get(EndOfSiding_step_2.instance().getFullyQualifiedName()); | ||
51 | final CostElementMatchers step3 = costElementMatchers.get(EndOfSiding_step_3.instance().getFullyQualifiedName()); | ||
52 | final CostElementMatchers step4 = costElementMatchers.get(EndOfSiding_step_4.instance().getFullyQualifiedName()); | ||
53 | final CostElementMatchers step5 = costElementMatchers.get(EndOfSiding_step_5.instance().getFullyQualifiedName()); | ||
54 | final PolyhedronExtensionOperator _function = (ExtendedLinearExpressionBuilderFactory it) -> { | ||
55 | final ExtendedLinearExpressionBuilder objectiveBuilder = it.createBuilder(); | ||
56 | ImmutableList<CostElementMatch> _matches = step2.getMatches(); | ||
57 | for (final CostElementMatch m : _matches) { | ||
58 | { | ||
59 | final Dimension dimension = it.getDimension(m.getMatch()); | ||
60 | objectiveBuilder.add(step2.getWeight(), dimension); | ||
61 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
62 | boolean _isMulti = m.isMulti(); | ||
63 | if (_isMulti) { | ||
64 | it.createBuilder().add(1, dimension).add((-1), this.trainType).build().assertEqualsTo(0); | ||
65 | } else { | ||
66 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
67 | boolean _isMust = m.isMust(); | ||
68 | if (_isMust) { | ||
69 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | final ImmutableList<CostElementMatch> step3Matches = step3.getMatches(); | ||
75 | for (final CostElementMatch m_1 : step3Matches) { | ||
76 | { | ||
77 | final Dimension dimension = it.getDimension(m_1.getMatch()); | ||
78 | objectiveBuilder.add(step3.getWeight(), dimension); | ||
79 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
80 | boolean _isMulti = m_1.isMulti(); | ||
81 | boolean _not = (!_isMulti); | ||
82 | if (_not) { | ||
83 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
84 | boolean _isMust = m_1.isMust(); | ||
85 | if (_isMust) { | ||
86 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | final Function1<CostElementMatch, IPatternMatch> _function_1 = (CostElementMatch it_1) -> { | ||
92 | return step2.projectMayMatch(it_1.getMatch(), 2); | ||
93 | }; | ||
94 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step3Matches, _function_1).entrySet(); | ||
95 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair : _entrySet) { | ||
96 | { | ||
97 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
98 | List<CostElementMatch> _value = pair.getValue(); | ||
99 | for (final CostElementMatch m_2 : _value) { | ||
100 | multiplicityBuilder.add(1, m_2.getMatch()); | ||
101 | } | ||
102 | multiplicityBuilder.add((-1), pair.getKey()); | ||
103 | multiplicityBuilder.build().assertEqualsTo(0); | ||
104 | } | ||
105 | } | ||
106 | EndOfSidingObjectiveHint.boundLimit(it, step3Matches, 2, this.trainType, 1); | ||
107 | EndOfSidingObjectiveHint.boundLimit(it, step3Matches, 3, this.segmentType, 1); | ||
108 | final ImmutableList<CostElementMatch> step4Matches = step4.getMatches(); | ||
109 | for (final CostElementMatch m_2 : step4Matches) { | ||
110 | { | ||
111 | final Dimension dimension = it.getDimension(m_2.getMatch()); | ||
112 | objectiveBuilder.add(step4.getWeight(), dimension); | ||
113 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
114 | boolean _isMulti = m_2.isMulti(); | ||
115 | boolean _not = (!_isMulti); | ||
116 | if (_not) { | ||
117 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
118 | boolean _isMust = m_2.isMust(); | ||
119 | if (_isMust) { | ||
120 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | final Function1<CostElementMatch, IPatternMatch> _function_2 = (CostElementMatch it_1) -> { | ||
126 | return step3.projectMayMatch(it_1.getMatch(), 2, 3); | ||
127 | }; | ||
128 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_1 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step4Matches, _function_2).entrySet(); | ||
129 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_1 : _entrySet_1) { | ||
130 | { | ||
131 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
132 | List<CostElementMatch> _value = pair_1.getValue(); | ||
133 | for (final CostElementMatch m_3 : _value) { | ||
134 | multiplicityBuilder.add(1, m_3.getMatch()); | ||
135 | } | ||
136 | multiplicityBuilder.add((-2), pair_1.getKey()); | ||
137 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
138 | } | ||
139 | } | ||
140 | EndOfSidingObjectiveHint.boundLimit(it, step4Matches, 2, this.trainType, 2); | ||
141 | EndOfSidingObjectiveHint.boundLimit(it, step4Matches, 3, this.segmentType, 2); | ||
142 | EndOfSidingObjectiveHint.boundLimit(it, step4Matches, 4, this.segmentType, 2); | ||
143 | final ImmutableList<CostElementMatch> step5Matches = step5.getMatches(); | ||
144 | for (final CostElementMatch m_3 : step5Matches) { | ||
145 | { | ||
146 | final Dimension dimension = it.getDimension(m_3.getMatch()); | ||
147 | objectiveBuilder.add(step5.getWeight(), dimension); | ||
148 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
149 | boolean _isMulti = m_3.isMulti(); | ||
150 | boolean _not = (!_isMulti); | ||
151 | if (_not) { | ||
152 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
153 | boolean _isMust = m_3.isMust(); | ||
154 | if (_isMust) { | ||
155 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
156 | } | ||
157 | } | ||
158 | it.createBuilder().add(1, m_3.getMatch()).add((-1), step4.projectMayMatch(m_3.getMatch(), 2, 3, 4)).build().tightenUpperBound(Integer.valueOf(0)); | ||
159 | } | ||
160 | } | ||
161 | EndOfSidingObjectiveHint.boundLimit(it, step5Matches, 2, this.trainType, 1); | ||
162 | EndOfSidingObjectiveHint.boundLimit(it, step5Matches, 3, this.segmentType, 2); | ||
163 | EndOfSidingObjectiveHint.boundLimit(it, step5Matches, 4, this.segmentType, 1); | ||
164 | this.buildWithBounds(objectiveBuilder); | ||
165 | }; | ||
166 | _xblockexpression = _function; | ||
167 | } | ||
168 | return _xblockexpression; | ||
169 | } | ||
170 | |||
171 | private static void boundLimit(@Extension final ExtendedLinearExpressionBuilderFactory factory, final Collection<CostElementMatch> matches, final int index, final Type type, final int count) { | ||
172 | final Function1<CostElementMatch, Object> _function = (CostElementMatch it) -> { | ||
173 | return it.getMatch().get(index); | ||
174 | }; | ||
175 | Set<Map.Entry<Object, List<CostElementMatch>>> _entrySet = IterableExtensions.<Object, CostElementMatch>groupBy(matches, _function).entrySet(); | ||
176 | for (final Map.Entry<Object, List<CostElementMatch>> pair : _entrySet) { | ||
177 | { | ||
178 | final ExtendedLinearExpressionBuilder multiplicityBuilder = factory.createBuilder(); | ||
179 | List<CostElementMatch> _value = pair.getValue(); | ||
180 | for (final CostElementMatch m : _value) { | ||
181 | multiplicityBuilder.add(1, m.getMatch()); | ||
182 | } | ||
183 | boolean _isMulti = CostElementMatchers.isMulti(pair.getKey()); | ||
184 | if (_isMulti) { | ||
185 | multiplicityBuilder.add((-count), type); | ||
186 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
187 | } else { | ||
188 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(count)); | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/MisalignedTurnoutObjectiveHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/MisalignedTurnoutObjectiveHint.java new file mode 100644 index 00000000..835a6559 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/MisalignedTurnoutObjectiveHint.java | |||
@@ -0,0 +1,195 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.collect.ImmutableList; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint; | ||
14 | import java.util.Collection; | ||
15 | import java.util.List; | ||
16 | import java.util.Map; | ||
17 | import java.util.Set; | ||
18 | import modes3.Modes3Package; | ||
19 | import modes3.queries.MisalignedTurnout_step_2; | ||
20 | import modes3.queries.MisalignedTurnout_step_3; | ||
21 | import modes3.queries.MisalignedTurnout_step_4; | ||
22 | import modes3.queries.MisalignedTurnout_step_5; | ||
23 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
24 | import org.eclipse.xtext.xbase.lib.Extension; | ||
25 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
26 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
27 | |||
28 | @SuppressWarnings("all") | ||
29 | public class MisalignedTurnoutObjectiveHint extends CostObjectiveHint { | ||
30 | private final Type segmentType; | ||
31 | |||
32 | private final Type turnoutType; | ||
33 | |||
34 | private final Type trainType; | ||
35 | |||
36 | public MisalignedTurnoutObjectiveHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
37 | @Extension | ||
38 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
39 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
40 | this.turnoutType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTurnout()); | ||
41 | this.trainType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTrain()); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public boolean isExact() { | ||
46 | return true; | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public PolyhedronExtensionOperator createPolyhedronExtensionOperator(final Map<String, CostElementMatchers> costElementMatchers) { | ||
51 | PolyhedronExtensionOperator _xblockexpression = null; | ||
52 | { | ||
53 | final CostElementMatchers step2 = costElementMatchers.get(MisalignedTurnout_step_2.instance().getFullyQualifiedName()); | ||
54 | final CostElementMatchers step3 = costElementMatchers.get(MisalignedTurnout_step_3.instance().getFullyQualifiedName()); | ||
55 | final CostElementMatchers step4 = costElementMatchers.get(MisalignedTurnout_step_4.instance().getFullyQualifiedName()); | ||
56 | final CostElementMatchers step5 = costElementMatchers.get(MisalignedTurnout_step_5.instance().getFullyQualifiedName()); | ||
57 | final PolyhedronExtensionOperator _function = (ExtendedLinearExpressionBuilderFactory it) -> { | ||
58 | final ExtendedLinearExpressionBuilder objectiveBuilder = it.createBuilder(); | ||
59 | ImmutableList<CostElementMatch> _matches = step2.getMatches(); | ||
60 | for (final CostElementMatch m : _matches) { | ||
61 | { | ||
62 | final Dimension dimension = it.getDimension(m.getMatch()); | ||
63 | objectiveBuilder.add(step2.getWeight(), dimension); | ||
64 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
65 | boolean _isMulti = m.isMulti(); | ||
66 | if (_isMulti) { | ||
67 | it.createBuilder().add(1, dimension).add((-1), this.turnoutType).build().assertEqualsTo(0); | ||
68 | } else { | ||
69 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
70 | boolean _isMust = m.isMust(); | ||
71 | if (_isMust) { | ||
72 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | final ImmutableList<CostElementMatch> step3Matches = step3.getMatches(); | ||
78 | for (final CostElementMatch m_1 : step3Matches) { | ||
79 | { | ||
80 | final Dimension dimension = it.getDimension(m_1.getMatch()); | ||
81 | objectiveBuilder.add(step3.getWeight(), dimension); | ||
82 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
83 | boolean _isMulti = m_1.isMulti(); | ||
84 | boolean _not = (!_isMulti); | ||
85 | if (_not) { | ||
86 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
87 | boolean _isMust = m_1.isMust(); | ||
88 | if (_isMust) { | ||
89 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | final Function1<CostElementMatch, IPatternMatch> _function_1 = (CostElementMatch it_1) -> { | ||
95 | return step2.projectMayMatch(it_1.getMatch(), 2); | ||
96 | }; | ||
97 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step3Matches, _function_1).entrySet(); | ||
98 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair : _entrySet) { | ||
99 | { | ||
100 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
101 | List<CostElementMatch> _value = pair.getValue(); | ||
102 | for (final CostElementMatch m_2 : _value) { | ||
103 | multiplicityBuilder.add(1, m_2.getMatch()); | ||
104 | } | ||
105 | multiplicityBuilder.add((-1), pair.getKey()); | ||
106 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
107 | } | ||
108 | } | ||
109 | MisalignedTurnoutObjectiveHint.boundLimit(it, step3Matches, 2, this.turnoutType, 1); | ||
110 | MisalignedTurnoutObjectiveHint.boundLimit(it, step3Matches, 3, this.segmentType, 2); | ||
111 | final ImmutableList<CostElementMatch> step4Matches = step4.getMatches(); | ||
112 | for (final CostElementMatch m_2 : step4Matches) { | ||
113 | { | ||
114 | final Dimension dimension = it.getDimension(m_2.getMatch()); | ||
115 | objectiveBuilder.add(step4.getWeight(), dimension); | ||
116 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
117 | boolean _isMulti = m_2.isMulti(); | ||
118 | boolean _not = (!_isMulti); | ||
119 | if (_not) { | ||
120 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
121 | boolean _isMust = m_2.isMust(); | ||
122 | if (_isMust) { | ||
123 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
124 | } | ||
125 | } | ||
126 | it.createBuilder().add(1, m_2.getMatch()).add((-1), step3.projectMayMatch(m_2.getMatch(), 2, 3)).build().tightenUpperBound(Integer.valueOf(0)); | ||
127 | } | ||
128 | } | ||
129 | MisalignedTurnoutObjectiveHint.boundLimit(it, step4Matches, 2, this.turnoutType, 1); | ||
130 | MisalignedTurnoutObjectiveHint.boundLimit(it, step4Matches, 3, this.segmentType, 2); | ||
131 | final ImmutableList<CostElementMatch> step5Matches = step5.getMatches(); | ||
132 | for (final CostElementMatch m_3 : step5Matches) { | ||
133 | { | ||
134 | final Dimension dimension = it.getDimension(m_3.getMatch()); | ||
135 | objectiveBuilder.add(step5.getWeight(), dimension); | ||
136 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
137 | boolean _isMulti = m_3.isMulti(); | ||
138 | boolean _not = (!_isMulti); | ||
139 | if (_not) { | ||
140 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
141 | boolean _isMust = m_3.isMust(); | ||
142 | if (_isMust) { | ||
143 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | final Function1<CostElementMatch, IPatternMatch> _function_2 = (CostElementMatch it_1) -> { | ||
149 | return step4.projectMayMatch(it_1.getMatch(), 2, 3); | ||
150 | }; | ||
151 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_1 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step5Matches, _function_2).entrySet(); | ||
152 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_1 : _entrySet_1) { | ||
153 | { | ||
154 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
155 | List<CostElementMatch> _value = pair_1.getValue(); | ||
156 | for (final CostElementMatch m_4 : _value) { | ||
157 | multiplicityBuilder.add(1, m_4.getMatch()); | ||
158 | } | ||
159 | multiplicityBuilder.add((-1), pair_1.getKey()); | ||
160 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
161 | } | ||
162 | } | ||
163 | MisalignedTurnoutObjectiveHint.boundLimit(it, step5Matches, 2, this.turnoutType, 1); | ||
164 | MisalignedTurnoutObjectiveHint.boundLimit(it, step5Matches, 3, this.segmentType, 2); | ||
165 | MisalignedTurnoutObjectiveHint.boundLimit(it, step5Matches, 4, this.trainType, 2); | ||
166 | this.buildWithBounds(objectiveBuilder); | ||
167 | }; | ||
168 | _xblockexpression = _function; | ||
169 | } | ||
170 | return _xblockexpression; | ||
171 | } | ||
172 | |||
173 | private static void boundLimit(@Extension final ExtendedLinearExpressionBuilderFactory factory, final Collection<CostElementMatch> matches, final int index, final Type type, final int count) { | ||
174 | final Function1<CostElementMatch, Object> _function = (CostElementMatch it) -> { | ||
175 | return it.getMatch().get(index); | ||
176 | }; | ||
177 | Set<Map.Entry<Object, List<CostElementMatch>>> _entrySet = IterableExtensions.<Object, CostElementMatch>groupBy(matches, _function).entrySet(); | ||
178 | for (final Map.Entry<Object, List<CostElementMatch>> pair : _entrySet) { | ||
179 | { | ||
180 | final ExtendedLinearExpressionBuilder multiplicityBuilder = factory.createBuilder(); | ||
181 | List<CostElementMatch> _value = pair.getValue(); | ||
182 | for (final CostElementMatch m : _value) { | ||
183 | multiplicityBuilder.add(1, m.getMatch()); | ||
184 | } | ||
185 | boolean _isMulti = CostElementMatchers.isMulti(pair.getKey()); | ||
186 | if (_isMulti) { | ||
187 | multiplicityBuilder.add((-count), type); | ||
188 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
189 | } else { | ||
190 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(count)); | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | } | ||
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 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import com.google.common.collect.ImmutableList; | ||
5 | import com.google.common.collect.ImmutableSet; | ||
6 | import com.google.common.collect.Iterables; | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EReferenceMapper_RelationsOverTypes_Trace; | ||
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
9 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration; | ||
10 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
11 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor; | ||
12 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsFactory; | ||
13 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage; | ||
14 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion; | ||
15 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; | ||
16 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation; | ||
17 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder; | ||
18 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope; | ||
19 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; | ||
20 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes; | ||
21 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.VariableContext; | ||
22 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Assertion; | ||
23 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Iff; | ||
24 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage; | ||
25 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration; | ||
26 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue; | ||
27 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription; | ||
28 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
29 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition; | ||
30 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable; | ||
31 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.Annotation; | ||
32 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | ||
33 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage; | ||
34 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; | ||
35 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; | ||
36 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore; | ||
37 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic; | ||
38 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration; | ||
39 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicTrace; | ||
40 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor; | ||
41 | import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsPackage; | ||
42 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod; | ||
43 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorConstraints; | ||
44 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorSolver; | ||
45 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy; | ||
46 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic; | ||
47 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink; | ||
48 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation; | ||
49 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
50 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation; | ||
51 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage; | ||
52 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink; | ||
53 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml; | ||
54 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualisation; | ||
55 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveConfiguration; | ||
56 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveElementConfiguration; | ||
57 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DebugConfiguration; | ||
58 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.StateCoderStrategy; | ||
59 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner; | ||
60 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; | ||
61 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.PartialModelAsLogicInterpretation; | ||
62 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind; | ||
63 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold; | ||
64 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser; | ||
65 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; | ||
66 | import java.util.Collections; | ||
67 | import java.util.List; | ||
68 | import java.util.Map; | ||
69 | import java.util.Set; | ||
70 | import java.util.function.Predicate; | ||
71 | import modes3.Modes3Factory; | ||
72 | import modes3.Modes3ModelRoot; | ||
73 | import modes3.Modes3Package; | ||
74 | import modes3.queries.CloseTrains_step_2; | ||
75 | import modes3.queries.CloseTrains_step_3; | ||
76 | import modes3.queries.CloseTrains_step_4; | ||
77 | import modes3.queries.CloseTrains_step_5; | ||
78 | import modes3.queries.CloseTrains_step_6; | ||
79 | import modes3.queries.CloseTrains_step_7; | ||
80 | import modes3.queries.EndOfSiding_step_2; | ||
81 | import modes3.queries.EndOfSiding_step_3; | ||
82 | import modes3.queries.EndOfSiding_step_4; | ||
83 | import modes3.queries.EndOfSiding_step_5; | ||
84 | import modes3.queries.MisalignedTurnout_step_2; | ||
85 | import modes3.queries.MisalignedTurnout_step_3; | ||
86 | import modes3.queries.MisalignedTurnout_step_4; | ||
87 | import modes3.queries.MisalignedTurnout_step_5; | ||
88 | import modes3.queries.Modes3Queries; | ||
89 | import modes3.queries.TrainLocations_step_2; | ||
90 | import modes3.queries.TrainLocations_step_3; | ||
91 | import modes3.run.CloseTrainsObjectiveHint; | ||
92 | import modes3.run.EndOfSidingObjectiveHint; | ||
93 | import modes3.run.MisalignedTurnoutObjectiveHint; | ||
94 | import modes3.run.Modes3TypeScopeHint; | ||
95 | import modes3.run.Modes3UnitPropagationGenerator; | ||
96 | import modes3.run.TrainLocationsObjectiveHint; | ||
97 | import org.eclipse.emf.common.util.EList; | ||
98 | import org.eclipse.emf.common.util.TreeIterator; | ||
99 | import org.eclipse.emf.common.util.URI; | ||
100 | import org.eclipse.emf.ecore.EAttribute; | ||
101 | import org.eclipse.emf.ecore.EClass; | ||
102 | import org.eclipse.emf.ecore.EEnum; | ||
103 | import org.eclipse.emf.ecore.EEnumLiteral; | ||
104 | import org.eclipse.emf.ecore.EObject; | ||
105 | import org.eclipse.emf.ecore.EReference; | ||
106 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
107 | import org.eclipse.emf.ecore.resource.Resource; | ||
108 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
109 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup; | ||
110 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
111 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions; | ||
112 | import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchEMFBackendFactory; | ||
113 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
114 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory; | ||
115 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor; | ||
116 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
117 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
118 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
119 | import org.eclipse.xtext.xbase.lib.ExclusiveRange; | ||
120 | import org.eclipse.xtext.xbase.lib.Extension; | ||
121 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
122 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
123 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
124 | import org.eclipse.xtext.xbase.lib.ObjectExtensions; | ||
125 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
126 | |||
127 | @FinalFieldsConstructor | ||
128 | @SuppressWarnings("all") | ||
129 | public 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 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3TypeScopeHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3TypeScopeHint.java new file mode 100644 index 00000000..adb69760 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3TypeScopeHint.java | |||
@@ -0,0 +1,133 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearBoundedExpression; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearTypeConstraintHint; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearTypeExpressionBuilderFactory; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationConstraintUpdater; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PatternGenerator; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
13 | import java.util.Iterator; | ||
14 | import java.util.Map; | ||
15 | import modes3.Modes3Package; | ||
16 | import modes3.queries.Adjacent; | ||
17 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
18 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; | ||
20 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
21 | import org.eclipse.xtext.xbase.lib.Extension; | ||
22 | |||
23 | @SuppressWarnings("all") | ||
24 | public class Modes3TypeScopeHint implements LinearTypeConstraintHint { | ||
25 | private static final String TURNOUT_NEIGHBOR_COUNT = "turnoutNeighborCount"; | ||
26 | |||
27 | private final Type segmentType; | ||
28 | |||
29 | private final Type turnoutType; | ||
30 | |||
31 | public Modes3TypeScopeHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
32 | @Extension | ||
33 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
34 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
35 | this.turnoutType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTurnout()); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public CharSequence getAdditionalPatterns(@Extension final PatternGenerator patternGenerator, final Map<String, PQuery> fqnToPQuery) { | ||
40 | StringConcatenation _builder = new StringConcatenation(); | ||
41 | _builder.append("\t"); | ||
42 | _builder.append("pattern "); | ||
43 | _builder.append(Modes3TypeScopeHint.TURNOUT_NEIGHBOR_COUNT, "\t"); | ||
44 | _builder.append("_helper(problem: LogicProblem, interpretation: PartialInterpretation, source: DefinedElement, target: DefinedElement) {"); | ||
45 | _builder.newLineIfNotEmpty(); | ||
46 | _builder.append("\t\t"); | ||
47 | _builder.append("find interpretation(problem, interpretation);"); | ||
48 | _builder.newLine(); | ||
49 | _builder.append("\t\t"); | ||
50 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
51 | _builder.newLine(); | ||
52 | _builder.append("\t\t"); | ||
53 | _builder.append("find mustExist(problem, interpretation, target);"); | ||
54 | _builder.newLine(); | ||
55 | _builder.append("\t\t"); | ||
56 | CharSequence _referInstanceOf = patternGenerator.getTypeIndexer().referInstanceOf(this.turnoutType, Modality.MUST, "source"); | ||
57 | _builder.append(_referInstanceOf, "\t\t"); | ||
58 | _builder.newLineIfNotEmpty(); | ||
59 | _builder.append("\t\t"); | ||
60 | CharSequence _referInstanceOf_1 = patternGenerator.getTypeIndexer().referInstanceOf(this.segmentType, Modality.MUST, "target"); | ||
61 | _builder.append(_referInstanceOf_1, "\t\t"); | ||
62 | _builder.newLineIfNotEmpty(); | ||
63 | _builder.append("\t\t"); | ||
64 | CharSequence _referPattern = patternGenerator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "source", "target" }, Modality.MUST, true, false); | ||
65 | _builder.append(_referPattern, "\t\t"); | ||
66 | _builder.newLineIfNotEmpty(); | ||
67 | _builder.append("\t"); | ||
68 | _builder.append("}"); | ||
69 | _builder.newLine(); | ||
70 | _builder.newLine(); | ||
71 | _builder.append("\t"); | ||
72 | _builder.append("pattern "); | ||
73 | _builder.append(Modes3TypeScopeHint.TURNOUT_NEIGHBOR_COUNT, "\t"); | ||
74 | _builder.append("(problem: LogicProblem, interpretation: PartialInterpretation, element: DefinedElement, N) {"); | ||
75 | _builder.newLineIfNotEmpty(); | ||
76 | _builder.append("\t\t"); | ||
77 | _builder.append("find interpretation(problem, interpretation);"); | ||
78 | _builder.newLine(); | ||
79 | _builder.append("\t\t"); | ||
80 | _builder.append("find mustExist(problem, interpretation, element);"); | ||
81 | _builder.newLine(); | ||
82 | _builder.append("\t\t"); | ||
83 | CharSequence _referInstanceOf_2 = patternGenerator.getTypeIndexer().referInstanceOf(this.turnoutType, Modality.MUST, "element"); | ||
84 | _builder.append(_referInstanceOf_2, "\t\t"); | ||
85 | _builder.newLineIfNotEmpty(); | ||
86 | _builder.append("\t\t"); | ||
87 | _builder.append("N == count find "); | ||
88 | _builder.append(Modes3TypeScopeHint.TURNOUT_NEIGHBOR_COUNT, "\t\t"); | ||
89 | _builder.append("_helper(problem, interpretation, element, _);"); | ||
90 | _builder.newLineIfNotEmpty(); | ||
91 | _builder.append("\t"); | ||
92 | _builder.append("}"); | ||
93 | _builder.newLine(); | ||
94 | return _builder; | ||
95 | } | ||
96 | |||
97 | @Override | ||
98 | public RelationConstraintUpdater createConstraintUpdater(final LinearTypeExpressionBuilderFactory builderFactory) { | ||
99 | final ViatraQueryMatcher<? extends IPatternMatch> turnoutNeighborCountMatcher = builderFactory.createMatcher(Modes3TypeScopeHint.TURNOUT_NEIGHBOR_COUNT); | ||
100 | final LinearBoundedExpression newNeighbors = builderFactory.createBuilder().add(1, this.segmentType).build(); | ||
101 | final RelationConstraintUpdater _function = (PartialInterpretation partialInterpretation) -> { | ||
102 | final int requiredNeighbbors = Modes3TypeScopeHint.getRemainingCount(turnoutNeighborCountMatcher, partialInterpretation, 3); | ||
103 | newNeighbors.tightenLowerBound(Integer.valueOf(requiredNeighbbors)); | ||
104 | }; | ||
105 | return _function; | ||
106 | } | ||
107 | |||
108 | private static <T extends IPatternMatch> int getRemainingCount(final ViatraQueryMatcher<T> matcher, final PartialInterpretation partialInterpretation, final int capacity) { | ||
109 | int _xblockexpression = (int) 0; | ||
110 | { | ||
111 | final T partialMatch = matcher.newEmptyMatch(); | ||
112 | partialMatch.set(0, partialInterpretation.getProblem()); | ||
113 | partialMatch.set(1, partialInterpretation); | ||
114 | final Iterator<T> iterator = matcher.streamAllMatches(partialMatch).iterator(); | ||
115 | int max = 0; | ||
116 | while (iterator.hasNext()) { | ||
117 | { | ||
118 | final T match = iterator.next(); | ||
119 | Object _get = match.get(3); | ||
120 | final int n = ((Integer) _get).intValue(); | ||
121 | if ((n < capacity)) { | ||
122 | final int required = (capacity - n); | ||
123 | if ((max < required)) { | ||
124 | max = required; | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | _xblockexpression = max; | ||
130 | } | ||
131 | return _xblockexpression; | ||
132 | } | ||
133 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3UnitPropagationGenerator.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3UnitPropagationGenerator.java new file mode 100644 index 00000000..5c5f82c5 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3UnitPropagationGenerator.java | |||
@@ -0,0 +1,1174 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PatternGenerator; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.UnitPropagationPatternGenerator; | ||
10 | import java.util.Collections; | ||
11 | import java.util.Map; | ||
12 | import modes3.Modes3Package; | ||
13 | import modes3.queries.Adjacent; | ||
14 | import modes3.queries.Output; | ||
15 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; | ||
16 | import org.eclipse.xtend2.lib.StringConcatenationClient; | ||
17 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
18 | import org.eclipse.xtext.xbase.lib.Extension; | ||
19 | import org.eclipse.xtext.xbase.lib.Pair; | ||
20 | |||
21 | @SuppressWarnings("all") | ||
22 | public class Modes3UnitPropagationGenerator implements UnitPropagationPatternGenerator { | ||
23 | private static final String MUST_NOT_CONNECTED_TO = "mustNotConnectedTo"; | ||
24 | |||
25 | private static final String MUST_NOT_STRAIGHT = "mustNotStraight"; | ||
26 | |||
27 | private static final String MUST_NOT_DIVERGENT = "mustNotDivergent"; | ||
28 | |||
29 | private static final String MUST_CONNECTED_TO = "mustConnectedTo"; | ||
30 | |||
31 | private static final String MUST_STRAIGHT = "mustStraight"; | ||
32 | |||
33 | private static final String MUST_DIVERGENT = "mustDivergent"; | ||
34 | |||
35 | private final Type segmentType; | ||
36 | |||
37 | private final Type simpleSegmentType; | ||
38 | |||
39 | private final Type turnoutType; | ||
40 | |||
41 | private final Relation connectedToRelation; | ||
42 | |||
43 | private final Relation straightRelation; | ||
44 | |||
45 | private final Relation divergentRelation; | ||
46 | |||
47 | public Modes3UnitPropagationGenerator(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
48 | @Extension | ||
49 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
50 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
51 | this.simpleSegmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSimpleSegment()); | ||
52 | this.turnoutType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTurnout()); | ||
53 | this.connectedToRelation = ecore2Logic.relationOfReference(ecore2LogicTrace, Modes3Package.getSegment_ConnectedTo()); | ||
54 | this.straightRelation = ecore2Logic.relationOfReference(ecore2LogicTrace, Modes3Package.getTurnout_Straight()); | ||
55 | this.divergentRelation = ecore2Logic.relationOfReference(ecore2LogicTrace, Modes3Package.getTurnout_Divergent()); | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | public Map<Relation, String> getMustPatterns() { | ||
60 | Pair<Relation, String> _mappedTo = Pair.<Relation, String>of(this.connectedToRelation, Modes3UnitPropagationGenerator.MUST_CONNECTED_TO); | ||
61 | Pair<Relation, String> _mappedTo_1 = Pair.<Relation, String>of(this.straightRelation, Modes3UnitPropagationGenerator.MUST_STRAIGHT); | ||
62 | Pair<Relation, String> _mappedTo_2 = Pair.<Relation, String>of(this.divergentRelation, Modes3UnitPropagationGenerator.MUST_DIVERGENT); | ||
63 | return Collections.<Relation, String>unmodifiableMap(CollectionLiterals.<Relation, String>newHashMap(_mappedTo, _mappedTo_1, _mappedTo_2)); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public Map<Relation, String> getMustNotPatterns() { | ||
68 | Pair<Relation, String> _mappedTo = Pair.<Relation, String>of(this.connectedToRelation, Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO); | ||
69 | Pair<Relation, String> _mappedTo_1 = Pair.<Relation, String>of(this.straightRelation, Modes3UnitPropagationGenerator.MUST_NOT_STRAIGHT); | ||
70 | Pair<Relation, String> _mappedTo_2 = Pair.<Relation, String>of(this.divergentRelation, Modes3UnitPropagationGenerator.MUST_NOT_DIVERGENT); | ||
71 | return Collections.<Relation, String>unmodifiableMap(CollectionLiterals.<Relation, String>newHashMap(_mappedTo, _mappedTo_1, _mappedTo_2)); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public StringConcatenationClient getAdditionalPatterns(@Extension final PatternGenerator generator, final Map<String, PQuery> fqnToPQuery) { | ||
76 | StringConcatenationClient _xblockexpression = null; | ||
77 | { | ||
78 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
79 | @Override | ||
80 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
81 | _builder.append("problem: LogicProblem, interpretation: PartialInterpretation,"); | ||
82 | _builder.newLine(); | ||
83 | _builder.append("source: DefinedElement, target: DefinedElement"); | ||
84 | _builder.newLine(); | ||
85 | } | ||
86 | }; | ||
87 | final StringConcatenationClient parameters = _client; | ||
88 | StringConcatenationClient _client_1 = new StringConcatenationClient() { | ||
89 | @Override | ||
90 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
91 | _builder.append("find interpretation(problem, interpretation);"); | ||
92 | _builder.newLine(); | ||
93 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
94 | _builder.newLine(); | ||
95 | _builder.append("find mustExist(problem, interpretation, target);"); | ||
96 | _builder.newLine(); | ||
97 | } | ||
98 | }; | ||
99 | final StringConcatenationClient commonMustParameterConstraints = _client_1; | ||
100 | StringConcatenationClient _client_2 = new StringConcatenationClient() { | ||
101 | @Override | ||
102 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
103 | _builder.append("find interpretation(problem, interpretation);"); | ||
104 | _builder.newLine(); | ||
105 | _builder.append("find mayExist(problem, interpretation, source);"); | ||
106 | _builder.newLine(); | ||
107 | _builder.append("find mayExist(problem, interpretation, target);"); | ||
108 | _builder.newLine(); | ||
109 | } | ||
110 | }; | ||
111 | final StringConcatenationClient commonMayParameterConstraints = _client_2; | ||
112 | StringConcatenationClient _client_3 = new StringConcatenationClient() { | ||
113 | @Override | ||
114 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
115 | _builder.append("pattern mayInput("); | ||
116 | _builder.append(parameters); | ||
117 | _builder.append(") {"); | ||
118 | _builder.newLineIfNotEmpty(); | ||
119 | _builder.append("\t"); | ||
120 | _builder.append(commonMayParameterConstraints, "\t"); | ||
121 | _builder.newLineIfNotEmpty(); | ||
122 | _builder.append("\t"); | ||
123 | CharSequence _referInstanceOf = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
124 | _builder.append(_referInstanceOf, "\t"); | ||
125 | _builder.newLineIfNotEmpty(); | ||
126 | _builder.append("\t"); | ||
127 | CharSequence _referPattern = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "target", "source" }, Modality.MAY, true, false); | ||
128 | _builder.append(_referPattern, "\t"); | ||
129 | _builder.newLineIfNotEmpty(); | ||
130 | _builder.append("\t"); | ||
131 | _builder.append("neg "); | ||
132 | CharSequence _referRelation = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "target", "source", Modality.MUST, fqnToPQuery); | ||
133 | _builder.append(_referRelation, "\t"); | ||
134 | _builder.newLineIfNotEmpty(); | ||
135 | _builder.append("\t"); | ||
136 | _builder.append("neg "); | ||
137 | CharSequence _referRelation_1 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "target", "source", Modality.MUST, fqnToPQuery); | ||
138 | _builder.append(_referRelation_1, "\t"); | ||
139 | _builder.newLineIfNotEmpty(); | ||
140 | _builder.append("}"); | ||
141 | _builder.newLine(); | ||
142 | _builder.newLine(); | ||
143 | _builder.append("pattern multipleMayInput(problem: LogicProblem, interpretation: PartialInterpretation,"); | ||
144 | _builder.newLine(); | ||
145 | _builder.append("\t\t\t"); | ||
146 | _builder.append("target: DefinedElement) {"); | ||
147 | _builder.newLine(); | ||
148 | _builder.append("\t"); | ||
149 | _builder.append("find interpretation(problem, interpretation);"); | ||
150 | _builder.newLine(); | ||
151 | _builder.append("\t"); | ||
152 | _builder.append("find mustExist(problem, interpretation, target);"); | ||
153 | _builder.newLine(); | ||
154 | _builder.append("\t"); | ||
155 | _builder.append("find mayInput(problem, interpretaton, source1, target);"); | ||
156 | _builder.newLine(); | ||
157 | _builder.append("\t"); | ||
158 | _builder.append("find mayInput(problem, interpretaton, source2, target);"); | ||
159 | _builder.newLine(); | ||
160 | _builder.append("\t"); | ||
161 | _builder.append("neg find mustEquivalent(problem, interpretation, source1, source2);"); | ||
162 | _builder.newLine(); | ||
163 | _builder.append("}"); | ||
164 | _builder.newLine(); | ||
165 | _builder.newLine(); | ||
166 | _builder.append("pattern multipleMayStraight(problem: LogicProblem, interpretation: PartialInterpretation,"); | ||
167 | _builder.newLine(); | ||
168 | _builder.append("\t\t\t"); | ||
169 | _builder.append("source: DefinedElement) {"); | ||
170 | _builder.newLine(); | ||
171 | _builder.append("\t"); | ||
172 | _builder.append("find interpretation(problem, interpretation);"); | ||
173 | _builder.newLine(); | ||
174 | _builder.append("\t"); | ||
175 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
176 | _builder.newLine(); | ||
177 | _builder.append("\t"); | ||
178 | CharSequence _referInstanceOf_1 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
179 | _builder.append(_referInstanceOf_1, "\t"); | ||
180 | _builder.newLineIfNotEmpty(); | ||
181 | _builder.append("\t"); | ||
182 | CharSequence _referRelation_2 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target1", Modality.MAY, fqnToPQuery); | ||
183 | _builder.append(_referRelation_2, "\t"); | ||
184 | _builder.newLineIfNotEmpty(); | ||
185 | _builder.append("\t"); | ||
186 | CharSequence _referRelation_3 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target2", Modality.MAY, fqnToPQuery); | ||
187 | _builder.append(_referRelation_3, "\t"); | ||
188 | _builder.newLineIfNotEmpty(); | ||
189 | _builder.append("\t"); | ||
190 | _builder.append("neg find mustEquivalent(problem, interpretation, target1, target2);"); | ||
191 | _builder.newLine(); | ||
192 | _builder.append("}"); | ||
193 | _builder.newLine(); | ||
194 | _builder.newLine(); | ||
195 | _builder.append("pattern multipleMayDivergent(problem: LogicProblem, interpretation: PartialInterpretation,"); | ||
196 | _builder.newLine(); | ||
197 | _builder.append("\t\t\t"); | ||
198 | _builder.append("source: DefinedElement) {"); | ||
199 | _builder.newLine(); | ||
200 | _builder.append("\t"); | ||
201 | _builder.append("find interpretation(problem, interpretation);"); | ||
202 | _builder.newLine(); | ||
203 | _builder.append("\t"); | ||
204 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
205 | _builder.newLine(); | ||
206 | _builder.append("\t"); | ||
207 | CharSequence _referInstanceOf_2 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
208 | _builder.append(_referInstanceOf_2, "\t"); | ||
209 | _builder.newLineIfNotEmpty(); | ||
210 | _builder.append("\t"); | ||
211 | CharSequence _referRelation_4 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target1", Modality.MAY, fqnToPQuery); | ||
212 | _builder.append(_referRelation_4, "\t"); | ||
213 | _builder.newLineIfNotEmpty(); | ||
214 | _builder.append("\t"); | ||
215 | CharSequence _referRelation_5 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target2", Modality.MAY, fqnToPQuery); | ||
216 | _builder.append(_referRelation_5, "\t"); | ||
217 | _builder.newLineIfNotEmpty(); | ||
218 | _builder.append("\t"); | ||
219 | _builder.append("neg find mustEquivalent(problem, interpretation, target1, target2);"); | ||
220 | _builder.newLine(); | ||
221 | _builder.append("}"); | ||
222 | _builder.newLine(); | ||
223 | _builder.newLine(); | ||
224 | _builder.append("pattern "); | ||
225 | _builder.append(Modes3UnitPropagationGenerator.MUST_CONNECTED_TO); | ||
226 | _builder.append("("); | ||
227 | _builder.append(parameters); | ||
228 | _builder.append(") {"); | ||
229 | _builder.newLineIfNotEmpty(); | ||
230 | _builder.append("\t"); | ||
231 | _builder.append(commonMustParameterConstraints, "\t"); | ||
232 | _builder.newLineIfNotEmpty(); | ||
233 | _builder.append("\t"); | ||
234 | CharSequence _referInstanceOf_3 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
235 | _builder.append(_referInstanceOf_3, "\t"); | ||
236 | _builder.newLineIfNotEmpty(); | ||
237 | _builder.append("\t"); | ||
238 | _builder.append("find mayInput(problem, interpretaton, source, target);"); | ||
239 | _builder.newLine(); | ||
240 | _builder.append("\t"); | ||
241 | _builder.append("neg find multipleMayInput(problem, interpretaton, target);"); | ||
242 | _builder.newLine(); | ||
243 | _builder.append("\t"); | ||
244 | CharSequence _referRelation_6 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
245 | _builder.append(_referRelation_6, "\t"); | ||
246 | _builder.newLineIfNotEmpty(); | ||
247 | _builder.append("\t"); | ||
248 | _builder.append("neg "); | ||
249 | CharSequence _referRelation_7 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
250 | _builder.append(_referRelation_7, "\t"); | ||
251 | _builder.newLineIfNotEmpty(); | ||
252 | _builder.append("\t"); | ||
253 | _builder.append("neg "); | ||
254 | CharSequence _referRelation_8 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
255 | _builder.append(_referRelation_8, "\t"); | ||
256 | _builder.newLineIfNotEmpty(); | ||
257 | _builder.append("\t"); | ||
258 | _builder.append("neg "); | ||
259 | CharSequence _referRelation_9 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
260 | _builder.append(_referRelation_9, "\t"); | ||
261 | _builder.newLineIfNotEmpty(); | ||
262 | _builder.append("}"); | ||
263 | _builder.newLine(); | ||
264 | _builder.newLine(); | ||
265 | _builder.append("pattern "); | ||
266 | _builder.append(Modes3UnitPropagationGenerator.MUST_STRAIGHT); | ||
267 | _builder.append("("); | ||
268 | _builder.append(parameters); | ||
269 | _builder.append(") {"); | ||
270 | _builder.newLineIfNotEmpty(); | ||
271 | _builder.append("\t"); | ||
272 | _builder.append(commonMustParameterConstraints, "\t"); | ||
273 | _builder.newLineIfNotEmpty(); | ||
274 | _builder.append("\t"); | ||
275 | _builder.append("neg "); | ||
276 | CharSequence _referRelation_10 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "_", Modality.MUST, fqnToPQuery); | ||
277 | _builder.append(_referRelation_10, "\t"); | ||
278 | _builder.newLineIfNotEmpty(); | ||
279 | _builder.append("\t"); | ||
280 | _builder.append("neg find multipleMayStraight(problem, interpretation, source);"); | ||
281 | _builder.newLine(); | ||
282 | _builder.append("\t"); | ||
283 | CharSequence _referRelation_11 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
284 | _builder.append(_referRelation_11, "\t"); | ||
285 | _builder.newLineIfNotEmpty(); | ||
286 | _builder.append("\t"); | ||
287 | _builder.append("neg "); | ||
288 | CharSequence _referRelation_12 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
289 | _builder.append(_referRelation_12, "\t"); | ||
290 | _builder.newLineIfNotEmpty(); | ||
291 | _builder.append("} or {"); | ||
292 | _builder.newLine(); | ||
293 | _builder.append("\t"); | ||
294 | _builder.append(commonMustParameterConstraints, "\t"); | ||
295 | _builder.newLineIfNotEmpty(); | ||
296 | _builder.append("\t"); | ||
297 | CharSequence _referInstanceOf_4 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
298 | _builder.append(_referInstanceOf_4, "\t"); | ||
299 | _builder.newLineIfNotEmpty(); | ||
300 | _builder.append("\t"); | ||
301 | _builder.append("find mayInput(problem, interpretaton, source, target);"); | ||
302 | _builder.newLine(); | ||
303 | _builder.append("\t"); | ||
304 | _builder.append("neg find multipleMayInput(problem, interpretaton, target);"); | ||
305 | _builder.newLine(); | ||
306 | _builder.append("\t"); | ||
307 | _builder.append("neg "); | ||
308 | CharSequence _referRelation_13 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
309 | _builder.append(_referRelation_13, "\t"); | ||
310 | _builder.newLineIfNotEmpty(); | ||
311 | _builder.append("\t"); | ||
312 | CharSequence _referRelation_14 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
313 | _builder.append(_referRelation_14, "\t"); | ||
314 | _builder.newLineIfNotEmpty(); | ||
315 | _builder.append("\t"); | ||
316 | _builder.append("neg "); | ||
317 | CharSequence _referRelation_15 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
318 | _builder.append(_referRelation_15, "\t"); | ||
319 | _builder.newLineIfNotEmpty(); | ||
320 | _builder.append("\t"); | ||
321 | _builder.append("neg "); | ||
322 | CharSequence _referRelation_16 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
323 | _builder.append(_referRelation_16, "\t"); | ||
324 | _builder.newLineIfNotEmpty(); | ||
325 | _builder.append("}"); | ||
326 | _builder.newLine(); | ||
327 | _builder.newLine(); | ||
328 | _builder.append("pattern "); | ||
329 | _builder.append(Modes3UnitPropagationGenerator.MUST_DIVERGENT); | ||
330 | _builder.append("("); | ||
331 | _builder.append(parameters); | ||
332 | _builder.append(") {"); | ||
333 | _builder.newLineIfNotEmpty(); | ||
334 | _builder.append("\t"); | ||
335 | _builder.append(commonMustParameterConstraints, "\t"); | ||
336 | _builder.newLineIfNotEmpty(); | ||
337 | _builder.append("\t"); | ||
338 | _builder.append("neg "); | ||
339 | CharSequence _referRelation_17 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "_", Modality.MUST, fqnToPQuery); | ||
340 | _builder.append(_referRelation_17, "\t"); | ||
341 | _builder.newLineIfNotEmpty(); | ||
342 | _builder.append("\t"); | ||
343 | _builder.append("neg find multipleMayDivergent(problem, interpretation, source);"); | ||
344 | _builder.newLine(); | ||
345 | _builder.append("\t"); | ||
346 | CharSequence _referRelation_18 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
347 | _builder.append(_referRelation_18, "\t"); | ||
348 | _builder.newLineIfNotEmpty(); | ||
349 | _builder.append("\t"); | ||
350 | _builder.append("neg "); | ||
351 | CharSequence _referRelation_19 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
352 | _builder.append(_referRelation_19, "\t"); | ||
353 | _builder.newLineIfNotEmpty(); | ||
354 | _builder.append("} or {"); | ||
355 | _builder.newLine(); | ||
356 | _builder.append("\t"); | ||
357 | _builder.append(commonMustParameterConstraints, "\t"); | ||
358 | _builder.newLineIfNotEmpty(); | ||
359 | _builder.append("\t"); | ||
360 | CharSequence _referInstanceOf_5 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
361 | _builder.append(_referInstanceOf_5, "\t"); | ||
362 | _builder.newLineIfNotEmpty(); | ||
363 | _builder.append("\t"); | ||
364 | _builder.append("find mayInput(problem, interpretaton, source, target);"); | ||
365 | _builder.newLine(); | ||
366 | _builder.append("\t"); | ||
367 | _builder.append("neg find multipleMayInput(problem, interpretaton, target);"); | ||
368 | _builder.newLine(); | ||
369 | _builder.append("\t"); | ||
370 | _builder.append("neg "); | ||
371 | CharSequence _referRelation_20 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
372 | _builder.append(_referRelation_20, "\t"); | ||
373 | _builder.newLineIfNotEmpty(); | ||
374 | _builder.append("\t"); | ||
375 | _builder.append("neg "); | ||
376 | CharSequence _referRelation_21 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
377 | _builder.append(_referRelation_21, "\t"); | ||
378 | _builder.newLineIfNotEmpty(); | ||
379 | _builder.append("\t"); | ||
380 | CharSequence _referRelation_22 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
381 | _builder.append(_referRelation_22, "\t"); | ||
382 | _builder.newLineIfNotEmpty(); | ||
383 | _builder.append("\t"); | ||
384 | _builder.append("neg "); | ||
385 | CharSequence _referRelation_23 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
386 | _builder.append(_referRelation_23, "\t"); | ||
387 | _builder.newLineIfNotEmpty(); | ||
388 | _builder.append("}"); | ||
389 | _builder.newLine(); | ||
390 | _builder.newLine(); | ||
391 | _builder.append("pattern turnoutOutput_must_to_true_by_straight("); | ||
392 | _builder.append(parameters); | ||
393 | _builder.append(", T : DefinedElement, S : DefinedElement) {"); | ||
394 | _builder.newLineIfNotEmpty(); | ||
395 | _builder.append("\t"); | ||
396 | _builder.append(commonMayParameterConstraints, "\t"); | ||
397 | _builder.newLineIfNotEmpty(); | ||
398 | _builder.append("\t"); | ||
399 | CharSequence _referInstanceOf_6 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
400 | _builder.append(_referInstanceOf_6, "\t"); | ||
401 | _builder.newLineIfNotEmpty(); | ||
402 | _builder.append("\t"); | ||
403 | CharSequence _referInstanceOf_7 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
404 | _builder.append(_referInstanceOf_7, "\t"); | ||
405 | _builder.newLineIfNotEmpty(); | ||
406 | _builder.append("\t"); | ||
407 | _builder.append("T == source;"); | ||
408 | _builder.newLine(); | ||
409 | _builder.append("\t"); | ||
410 | _builder.append("S == target;"); | ||
411 | _builder.newLine(); | ||
412 | _builder.append("}"); | ||
413 | _builder.newLine(); | ||
414 | _builder.newLine(); | ||
415 | _builder.append("pattern turnoutOutput_must_to_true_by_divergent("); | ||
416 | _builder.append(parameters); | ||
417 | _builder.append(", T : DefinedElement, S : DefinedElement) {"); | ||
418 | _builder.newLineIfNotEmpty(); | ||
419 | _builder.append("\t"); | ||
420 | _builder.append(commonMayParameterConstraints, "\t"); | ||
421 | _builder.newLineIfNotEmpty(); | ||
422 | _builder.append("\t"); | ||
423 | CharSequence _referInstanceOf_8 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
424 | _builder.append(_referInstanceOf_8, "\t"); | ||
425 | _builder.newLineIfNotEmpty(); | ||
426 | _builder.append("\t"); | ||
427 | CharSequence _referInstanceOf_9 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
428 | _builder.append(_referInstanceOf_9, "\t"); | ||
429 | _builder.newLineIfNotEmpty(); | ||
430 | _builder.append("\t"); | ||
431 | _builder.append("T == source;"); | ||
432 | _builder.newLine(); | ||
433 | _builder.append("\t"); | ||
434 | _builder.append("S == target;"); | ||
435 | _builder.newLine(); | ||
436 | _builder.append("}"); | ||
437 | _builder.newLine(); | ||
438 | _builder.newLine(); | ||
439 | _builder.append("pattern output_must_to_true_by_connectedTo("); | ||
440 | _builder.append(parameters); | ||
441 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
442 | _builder.newLineIfNotEmpty(); | ||
443 | _builder.append("\t"); | ||
444 | _builder.append(commonMayParameterConstraints, "\t"); | ||
445 | _builder.newLineIfNotEmpty(); | ||
446 | _builder.append("\t"); | ||
447 | CharSequence _referInstanceOf_10 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "source"); | ||
448 | _builder.append(_referInstanceOf_10, "\t"); | ||
449 | _builder.newLineIfNotEmpty(); | ||
450 | _builder.append("\t"); | ||
451 | CharSequence _referInstanceOf_11 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
452 | _builder.append(_referInstanceOf_11, "\t"); | ||
453 | _builder.newLineIfNotEmpty(); | ||
454 | _builder.append("\t"); | ||
455 | _builder.append("S1 == source;"); | ||
456 | _builder.newLine(); | ||
457 | _builder.append("\t"); | ||
458 | _builder.append("S2 == target;"); | ||
459 | _builder.newLine(); | ||
460 | _builder.append("}"); | ||
461 | _builder.newLine(); | ||
462 | _builder.newLine(); | ||
463 | _builder.append("pattern output_must_to_true_by_straight("); | ||
464 | _builder.append(parameters); | ||
465 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
466 | _builder.newLineIfNotEmpty(); | ||
467 | _builder.append("\t"); | ||
468 | _builder.append("find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, S1, S2);"); | ||
469 | _builder.newLine(); | ||
470 | _builder.append("}"); | ||
471 | _builder.newLine(); | ||
472 | _builder.newLine(); | ||
473 | _builder.append("pattern output_must_to_true_by_divergent("); | ||
474 | _builder.append(parameters); | ||
475 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
476 | _builder.newLineIfNotEmpty(); | ||
477 | _builder.append("\t"); | ||
478 | _builder.append("find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, S1, S2);"); | ||
479 | _builder.newLine(); | ||
480 | _builder.append("}"); | ||
481 | _builder.newLine(); | ||
482 | _builder.newLine(); | ||
483 | _builder.append("pattern adjacent_must_to_true_by_connectedTo("); | ||
484 | _builder.append(parameters); | ||
485 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
486 | _builder.newLineIfNotEmpty(); | ||
487 | _builder.append("\t"); | ||
488 | _builder.append("find output_must_to_true_by_connectedTo(problem, interpretation, source, target, S1, S2);"); | ||
489 | _builder.newLine(); | ||
490 | _builder.append("}"); | ||
491 | _builder.newLine(); | ||
492 | _builder.newLine(); | ||
493 | _builder.append("pattern adjacent_must_to_true_by_straight("); | ||
494 | _builder.append(parameters); | ||
495 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
496 | _builder.newLineIfNotEmpty(); | ||
497 | _builder.append("\t"); | ||
498 | _builder.append("find output_must_to_true_by_straight(problem, interpretation, source, target, S1, S2);"); | ||
499 | _builder.newLine(); | ||
500 | _builder.append("} or {"); | ||
501 | _builder.newLine(); | ||
502 | _builder.append("\t"); | ||
503 | _builder.append("find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, S2, S1);"); | ||
504 | _builder.newLine(); | ||
505 | _builder.append("}"); | ||
506 | _builder.newLine(); | ||
507 | _builder.newLine(); | ||
508 | _builder.append("pattern adjacent_must_to_true_by_divergent("); | ||
509 | _builder.append(parameters); | ||
510 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
511 | _builder.newLineIfNotEmpty(); | ||
512 | _builder.append("\t"); | ||
513 | _builder.append("find output_must_to_true_by_divergent(problem, interpretation, source, target, S1, S2);"); | ||
514 | _builder.newLine(); | ||
515 | _builder.append("} or {"); | ||
516 | _builder.newLine(); | ||
517 | _builder.append("\t"); | ||
518 | _builder.append("find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, S2, S1);"); | ||
519 | _builder.newLine(); | ||
520 | _builder.append("}"); | ||
521 | _builder.newLine(); | ||
522 | _builder.newLine(); | ||
523 | _builder.append("pattern connectedToReflexive_must_to_true_by_connectedTo("); | ||
524 | _builder.append(parameters); | ||
525 | _builder.append(", S : DefinedElement) {"); | ||
526 | _builder.newLineIfNotEmpty(); | ||
527 | _builder.append("\t"); | ||
528 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
529 | _builder.newLine(); | ||
530 | _builder.append("\t"); | ||
531 | CharSequence _referInstanceOf_12 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "source"); | ||
532 | _builder.append(_referInstanceOf_12, "\t"); | ||
533 | _builder.newLineIfNotEmpty(); | ||
534 | _builder.append("\t"); | ||
535 | _builder.append("S == source;"); | ||
536 | _builder.newLine(); | ||
537 | _builder.append("\t"); | ||
538 | _builder.append("S == target;"); | ||
539 | _builder.newLine(); | ||
540 | _builder.append("}"); | ||
541 | _builder.newLine(); | ||
542 | _builder.newLine(); | ||
543 | _builder.append("pattern outputReflexive_must_to_true_by_straight("); | ||
544 | _builder.append(parameters); | ||
545 | _builder.append(", T : DefinedElement) {"); | ||
546 | _builder.newLineIfNotEmpty(); | ||
547 | _builder.append("\t"); | ||
548 | _builder.append("find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, T, T);"); | ||
549 | _builder.newLine(); | ||
550 | _builder.append("}"); | ||
551 | _builder.newLine(); | ||
552 | _builder.newLine(); | ||
553 | _builder.append("pattern outputReflexive_must_to_true_by_divergent("); | ||
554 | _builder.append(parameters); | ||
555 | _builder.append(", T : DefinedElement) {"); | ||
556 | _builder.newLineIfNotEmpty(); | ||
557 | _builder.append("\t"); | ||
558 | _builder.append("find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, T, T);"); | ||
559 | _builder.newLine(); | ||
560 | _builder.append("}"); | ||
561 | _builder.newLine(); | ||
562 | _builder.newLine(); | ||
563 | _builder.append("pattern turnoutOutputsAreSame_must_to_true_by_straight("); | ||
564 | _builder.append(parameters); | ||
565 | _builder.append(", T : DefinedElement) {"); | ||
566 | _builder.newLineIfNotEmpty(); | ||
567 | _builder.append("\t"); | ||
568 | _builder.append(commonMayParameterConstraints, "\t"); | ||
569 | _builder.newLineIfNotEmpty(); | ||
570 | _builder.append("\t"); | ||
571 | CharSequence _referInstanceOf_13 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
572 | _builder.append(_referInstanceOf_13, "\t"); | ||
573 | _builder.newLineIfNotEmpty(); | ||
574 | _builder.append("\t"); | ||
575 | CharSequence _referInstanceOf_14 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
576 | _builder.append(_referInstanceOf_14, "\t"); | ||
577 | _builder.newLineIfNotEmpty(); | ||
578 | _builder.append("\t"); | ||
579 | _builder.append("T == source;"); | ||
580 | _builder.newLine(); | ||
581 | _builder.append("\t"); | ||
582 | _builder.append("S == target;"); | ||
583 | _builder.newLine(); | ||
584 | _builder.append("\t"); | ||
585 | CharSequence _referRelation_24 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "T", "S", Modality.MUST, fqnToPQuery); | ||
586 | _builder.append(_referRelation_24, "\t"); | ||
587 | _builder.newLineIfNotEmpty(); | ||
588 | _builder.append("}"); | ||
589 | _builder.newLine(); | ||
590 | _builder.newLine(); | ||
591 | _builder.append("pattern turnoutOutputsAreSame_must_to_true_by_divergent("); | ||
592 | _builder.append(parameters); | ||
593 | _builder.append(", T : DefinedElement) {"); | ||
594 | _builder.newLineIfNotEmpty(); | ||
595 | _builder.append("\t"); | ||
596 | _builder.append(commonMayParameterConstraints, "\t"); | ||
597 | _builder.newLineIfNotEmpty(); | ||
598 | _builder.append("\t"); | ||
599 | CharSequence _referInstanceOf_15 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
600 | _builder.append(_referInstanceOf_15, "\t"); | ||
601 | _builder.newLineIfNotEmpty(); | ||
602 | _builder.append("\t"); | ||
603 | CharSequence _referInstanceOf_16 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
604 | _builder.append(_referInstanceOf_16, "\t"); | ||
605 | _builder.newLineIfNotEmpty(); | ||
606 | _builder.append("\t"); | ||
607 | _builder.append("T == source;"); | ||
608 | _builder.newLine(); | ||
609 | _builder.append("\t"); | ||
610 | _builder.append("S == target;"); | ||
611 | _builder.newLine(); | ||
612 | _builder.append("\t"); | ||
613 | CharSequence _referRelation_25 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "T", "S", Modality.MUST, fqnToPQuery); | ||
614 | _builder.append(_referRelation_25, "\t"); | ||
615 | _builder.newLineIfNotEmpty(); | ||
616 | _builder.append("}"); | ||
617 | _builder.newLine(); | ||
618 | _builder.newLine(); | ||
619 | _builder.append("pattern tooManyInputsOfSegment_must_to_true_by_connectedTo("); | ||
620 | _builder.append(parameters); | ||
621 | _builder.append(", S : DefinedElement) {"); | ||
622 | _builder.newLineIfNotEmpty(); | ||
623 | _builder.append("\t"); | ||
624 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
625 | _builder.newLine(); | ||
626 | _builder.append("\t"); | ||
627 | CharSequence _referInstanceOf_17 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.simpleSegmentType, Modality.MUST, "S"); | ||
628 | _builder.append(_referInstanceOf_17, "\t"); | ||
629 | _builder.newLineIfNotEmpty(); | ||
630 | _builder.append("\t"); | ||
631 | _builder.append("find output_must_to_true_by_connectedTo(problem, interpretation, source, target, I1, S);"); | ||
632 | _builder.newLine(); | ||
633 | _builder.append("\t"); | ||
634 | CharSequence _referPattern_1 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
635 | _builder.append(_referPattern_1, "\t"); | ||
636 | _builder.newLineIfNotEmpty(); | ||
637 | _builder.append("\t"); | ||
638 | CharSequence _referPattern_2 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
639 | _builder.append(_referPattern_2, "\t"); | ||
640 | _builder.newLineIfNotEmpty(); | ||
641 | _builder.append("\t"); | ||
642 | _builder.append("I1 != I2;"); | ||
643 | _builder.newLine(); | ||
644 | _builder.append("\t"); | ||
645 | _builder.append("I1 != I3;"); | ||
646 | _builder.newLine(); | ||
647 | _builder.append("\t"); | ||
648 | _builder.append("I2 != I3;"); | ||
649 | _builder.newLine(); | ||
650 | _builder.append("}"); | ||
651 | _builder.newLine(); | ||
652 | _builder.newLine(); | ||
653 | _builder.append("pattern tooManyInputsOfSegment_must_to_true_by_straight("); | ||
654 | _builder.append(parameters); | ||
655 | _builder.append(", S : DefinedElement) {"); | ||
656 | _builder.newLineIfNotEmpty(); | ||
657 | _builder.append("\t"); | ||
658 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
659 | _builder.newLine(); | ||
660 | _builder.append("\t"); | ||
661 | CharSequence _referInstanceOf_18 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.simpleSegmentType, Modality.MUST, "S"); | ||
662 | _builder.append(_referInstanceOf_18, "\t"); | ||
663 | _builder.newLineIfNotEmpty(); | ||
664 | _builder.append("\t"); | ||
665 | _builder.append("find output_must_to_true_by_straight(problem, interpretation, source, target, I1, S);"); | ||
666 | _builder.newLine(); | ||
667 | _builder.append("\t"); | ||
668 | CharSequence _referPattern_3 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
669 | _builder.append(_referPattern_3, "\t"); | ||
670 | _builder.newLineIfNotEmpty(); | ||
671 | _builder.append("\t"); | ||
672 | CharSequence _referPattern_4 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
673 | _builder.append(_referPattern_4, "\t"); | ||
674 | _builder.newLineIfNotEmpty(); | ||
675 | _builder.append("\t"); | ||
676 | _builder.append("I1 != I2;"); | ||
677 | _builder.newLine(); | ||
678 | _builder.append("\t"); | ||
679 | _builder.append("I1 != I3;"); | ||
680 | _builder.newLine(); | ||
681 | _builder.append("\t"); | ||
682 | _builder.append("I2 != I3;"); | ||
683 | _builder.newLine(); | ||
684 | _builder.append("}"); | ||
685 | _builder.newLine(); | ||
686 | _builder.newLine(); | ||
687 | _builder.append("pattern tooManyInputsOfSegment_must_to_true_by_divergent("); | ||
688 | _builder.append(parameters); | ||
689 | _builder.append(", S : DefinedElement) {"); | ||
690 | _builder.newLineIfNotEmpty(); | ||
691 | _builder.append("\t"); | ||
692 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
693 | _builder.newLine(); | ||
694 | _builder.append("\t"); | ||
695 | CharSequence _referInstanceOf_19 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.simpleSegmentType, Modality.MUST, "S"); | ||
696 | _builder.append(_referInstanceOf_19, "\t"); | ||
697 | _builder.newLineIfNotEmpty(); | ||
698 | _builder.append("\t"); | ||
699 | _builder.append("find output_must_to_true_by_divergent(problem, interpretation, source, target, I1, S);"); | ||
700 | _builder.newLine(); | ||
701 | _builder.append("\t"); | ||
702 | CharSequence _referPattern_5 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
703 | _builder.append(_referPattern_5, "\t"); | ||
704 | _builder.newLineIfNotEmpty(); | ||
705 | _builder.append("\t"); | ||
706 | CharSequence _referPattern_6 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
707 | _builder.append(_referPattern_6, "\t"); | ||
708 | _builder.newLineIfNotEmpty(); | ||
709 | _builder.append("\t"); | ||
710 | _builder.append("I1 != I2;"); | ||
711 | _builder.newLine(); | ||
712 | _builder.append("\t"); | ||
713 | _builder.append("I1 != I3;"); | ||
714 | _builder.newLine(); | ||
715 | _builder.append("\t"); | ||
716 | _builder.append("I2 != I3;"); | ||
717 | _builder.newLine(); | ||
718 | _builder.append("}"); | ||
719 | _builder.newLine(); | ||
720 | _builder.newLine(); | ||
721 | _builder.append("pattern turnoutConnectedToBothOutputs_must_to_true_by_connectedTo("); | ||
722 | _builder.append(parameters); | ||
723 | _builder.append(", T : DefinedElement) {"); | ||
724 | _builder.newLineIfNotEmpty(); | ||
725 | _builder.append("\t"); | ||
726 | _builder.append(commonMayParameterConstraints, "\t"); | ||
727 | _builder.newLineIfNotEmpty(); | ||
728 | _builder.append("\t"); | ||
729 | _builder.append("find mustExist(problem, interpretation, Straight);"); | ||
730 | _builder.newLine(); | ||
731 | _builder.append("\t"); | ||
732 | _builder.append("find mustExist(problem, interpretation, Divergent);"); | ||
733 | _builder.newLine(); | ||
734 | _builder.append("\t"); | ||
735 | CharSequence _referInstanceOf_20 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
736 | _builder.append(_referInstanceOf_20, "\t"); | ||
737 | _builder.newLineIfNotEmpty(); | ||
738 | _builder.append("\t"); | ||
739 | CharSequence _referInstanceOf_21 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
740 | _builder.append(_referInstanceOf_21, "\t"); | ||
741 | _builder.newLineIfNotEmpty(); | ||
742 | _builder.append("\t"); | ||
743 | CharSequence _referInstanceOf_22 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Straight"); | ||
744 | _builder.append(_referInstanceOf_22, "\t"); | ||
745 | _builder.newLineIfNotEmpty(); | ||
746 | _builder.append("\t"); | ||
747 | CharSequence _referInstanceOf_23 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Divergent"); | ||
748 | _builder.append(_referInstanceOf_23, "\t"); | ||
749 | _builder.newLineIfNotEmpty(); | ||
750 | _builder.append("\t"); | ||
751 | CharSequence _referRelation_26 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
752 | _builder.append(_referRelation_26, "\t"); | ||
753 | _builder.newLineIfNotEmpty(); | ||
754 | _builder.append("\t"); | ||
755 | CharSequence _referRelation_27 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
756 | _builder.append(_referRelation_27, "\t"); | ||
757 | _builder.newLineIfNotEmpty(); | ||
758 | _builder.append("\t"); | ||
759 | _builder.append("T == source;"); | ||
760 | _builder.newLine(); | ||
761 | _builder.append("\t"); | ||
762 | _builder.append("Straight == target;"); | ||
763 | _builder.newLine(); | ||
764 | _builder.append("\t"); | ||
765 | CharSequence _referRelation_28 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
766 | _builder.append(_referRelation_28, "\t"); | ||
767 | _builder.newLineIfNotEmpty(); | ||
768 | _builder.append("} or {"); | ||
769 | _builder.newLine(); | ||
770 | _builder.append("\t"); | ||
771 | _builder.append(commonMayParameterConstraints, "\t"); | ||
772 | _builder.newLineIfNotEmpty(); | ||
773 | _builder.append("\t"); | ||
774 | _builder.append("find mustExist(problem, interpretation, Straight);"); | ||
775 | _builder.newLine(); | ||
776 | _builder.append("\t"); | ||
777 | _builder.append("find mustExist(problem, interpretation, Divergent);"); | ||
778 | _builder.newLine(); | ||
779 | _builder.append("\t"); | ||
780 | CharSequence _referInstanceOf_24 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
781 | _builder.append(_referInstanceOf_24, "\t"); | ||
782 | _builder.newLineIfNotEmpty(); | ||
783 | _builder.append("\t"); | ||
784 | CharSequence _referInstanceOf_25 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
785 | _builder.append(_referInstanceOf_25, "\t"); | ||
786 | _builder.newLineIfNotEmpty(); | ||
787 | _builder.append("\t"); | ||
788 | CharSequence _referInstanceOf_26 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Straight"); | ||
789 | _builder.append(_referInstanceOf_26, "\t"); | ||
790 | _builder.newLineIfNotEmpty(); | ||
791 | _builder.append("\t"); | ||
792 | CharSequence _referInstanceOf_27 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Divergent"); | ||
793 | _builder.append(_referInstanceOf_27, "\t"); | ||
794 | _builder.newLineIfNotEmpty(); | ||
795 | _builder.append("\t"); | ||
796 | CharSequence _referRelation_29 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
797 | _builder.append(_referRelation_29, "\t"); | ||
798 | _builder.newLineIfNotEmpty(); | ||
799 | _builder.append("\t"); | ||
800 | CharSequence _referRelation_30 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
801 | _builder.append(_referRelation_30, "\t"); | ||
802 | _builder.newLineIfNotEmpty(); | ||
803 | _builder.append("\t"); | ||
804 | CharSequence _referRelation_31 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
805 | _builder.append(_referRelation_31, "\t"); | ||
806 | _builder.newLineIfNotEmpty(); | ||
807 | _builder.append("\t"); | ||
808 | _builder.append("T == source;"); | ||
809 | _builder.newLine(); | ||
810 | _builder.append("\t"); | ||
811 | _builder.append("Straight == target;"); | ||
812 | _builder.newLine(); | ||
813 | _builder.append("}"); | ||
814 | _builder.newLine(); | ||
815 | _builder.newLine(); | ||
816 | _builder.append("pattern turnoutConnectedToBothOutputs_must_to_true_by_straight("); | ||
817 | _builder.append(parameters); | ||
818 | _builder.append(", T : DefinedElement) {"); | ||
819 | _builder.newLineIfNotEmpty(); | ||
820 | _builder.append("\t"); | ||
821 | _builder.append(commonMayParameterConstraints, "\t"); | ||
822 | _builder.newLineIfNotEmpty(); | ||
823 | _builder.append("\t"); | ||
824 | _builder.append("find mustExist(problem, interpretation, Straight);"); | ||
825 | _builder.newLine(); | ||
826 | _builder.append("\t"); | ||
827 | _builder.append("find mustExist(problem, interpretation, Divergent);"); | ||
828 | _builder.newLine(); | ||
829 | _builder.append("\t"); | ||
830 | CharSequence _referInstanceOf_28 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
831 | _builder.append(_referInstanceOf_28, "\t"); | ||
832 | _builder.newLineIfNotEmpty(); | ||
833 | _builder.append("\t"); | ||
834 | CharSequence _referInstanceOf_29 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
835 | _builder.append(_referInstanceOf_29, "\t"); | ||
836 | _builder.newLineIfNotEmpty(); | ||
837 | _builder.append("\t"); | ||
838 | CharSequence _referInstanceOf_30 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Straight"); | ||
839 | _builder.append(_referInstanceOf_30, "\t"); | ||
840 | _builder.newLineIfNotEmpty(); | ||
841 | _builder.append("\t"); | ||
842 | CharSequence _referInstanceOf_31 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Divergent"); | ||
843 | _builder.append(_referInstanceOf_31, "\t"); | ||
844 | _builder.newLineIfNotEmpty(); | ||
845 | _builder.append("\t"); | ||
846 | _builder.append("T == source;"); | ||
847 | _builder.newLine(); | ||
848 | _builder.append("\t"); | ||
849 | _builder.append("Straight == target;"); | ||
850 | _builder.newLine(); | ||
851 | _builder.append("\t"); | ||
852 | CharSequence _referRelation_32 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
853 | _builder.append(_referRelation_32, "\t"); | ||
854 | _builder.newLineIfNotEmpty(); | ||
855 | _builder.append("\t"); | ||
856 | CharSequence _referRelation_33 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
857 | _builder.append(_referRelation_33, "\t"); | ||
858 | _builder.newLineIfNotEmpty(); | ||
859 | _builder.append("\t"); | ||
860 | CharSequence _referRelation_34 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
861 | _builder.append(_referRelation_34, "\t"); | ||
862 | _builder.newLineIfNotEmpty(); | ||
863 | _builder.append("}"); | ||
864 | _builder.newLine(); | ||
865 | _builder.newLine(); | ||
866 | _builder.append("pattern turnoutConnectedToBothOutputs_must_to_true_by_divergent("); | ||
867 | _builder.append(parameters); | ||
868 | _builder.append(", T : DefinedElement) {"); | ||
869 | _builder.newLineIfNotEmpty(); | ||
870 | _builder.append("\t"); | ||
871 | _builder.append(commonMayParameterConstraints, "\t"); | ||
872 | _builder.newLineIfNotEmpty(); | ||
873 | _builder.append("\t"); | ||
874 | _builder.append("find mustExist(problem, interpretation, Straight);"); | ||
875 | _builder.newLine(); | ||
876 | _builder.append("\t"); | ||
877 | _builder.append("find mustExist(problem, interpretation, Divergent);"); | ||
878 | _builder.newLine(); | ||
879 | _builder.append("\t"); | ||
880 | CharSequence _referInstanceOf_32 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
881 | _builder.append(_referInstanceOf_32, "\t"); | ||
882 | _builder.newLineIfNotEmpty(); | ||
883 | _builder.append("\t"); | ||
884 | CharSequence _referInstanceOf_33 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
885 | _builder.append(_referInstanceOf_33, "\t"); | ||
886 | _builder.newLineIfNotEmpty(); | ||
887 | _builder.append("\t"); | ||
888 | CharSequence _referInstanceOf_34 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Straight"); | ||
889 | _builder.append(_referInstanceOf_34, "\t"); | ||
890 | _builder.newLineIfNotEmpty(); | ||
891 | _builder.append("\t"); | ||
892 | CharSequence _referInstanceOf_35 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Divergent"); | ||
893 | _builder.append(_referInstanceOf_35, "\t"); | ||
894 | _builder.newLineIfNotEmpty(); | ||
895 | _builder.append("\t"); | ||
896 | CharSequence _referRelation_35 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
897 | _builder.append(_referRelation_35, "\t"); | ||
898 | _builder.newLineIfNotEmpty(); | ||
899 | _builder.append("\t"); | ||
900 | _builder.append("T == source;"); | ||
901 | _builder.newLine(); | ||
902 | _builder.append("\t"); | ||
903 | _builder.append("Divergent == target;"); | ||
904 | _builder.newLine(); | ||
905 | _builder.append("\t"); | ||
906 | CharSequence _referRelation_36 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
907 | _builder.append(_referRelation_36, "\t"); | ||
908 | _builder.newLineIfNotEmpty(); | ||
909 | _builder.append("\t"); | ||
910 | CharSequence _referRelation_37 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
911 | _builder.append(_referRelation_37, "\t"); | ||
912 | _builder.newLineIfNotEmpty(); | ||
913 | _builder.append("}"); | ||
914 | _builder.newLine(); | ||
915 | _builder.newLine(); | ||
916 | _builder.append("pattern tooManyInputsOfTurnout_must_to_true_by_connectedTo("); | ||
917 | _builder.append(parameters); | ||
918 | _builder.append(", T : DefinedElement) {"); | ||
919 | _builder.newLineIfNotEmpty(); | ||
920 | _builder.append("\t"); | ||
921 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
922 | _builder.newLine(); | ||
923 | _builder.append("\t"); | ||
924 | CharSequence _referInstanceOf_36 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MUST, "S"); | ||
925 | _builder.append(_referInstanceOf_36, "\t"); | ||
926 | _builder.newLineIfNotEmpty(); | ||
927 | _builder.append("\t"); | ||
928 | _builder.append("find adjacent_must_to_true_by_connectedTo(problem, interpretation, source, target, I1, S);"); | ||
929 | _builder.newLine(); | ||
930 | _builder.append("\t"); | ||
931 | CharSequence _referPattern_7 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
932 | _builder.append(_referPattern_7, "\t"); | ||
933 | _builder.newLineIfNotEmpty(); | ||
934 | _builder.append("\t"); | ||
935 | CharSequence _referPattern_8 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
936 | _builder.append(_referPattern_8, "\t"); | ||
937 | _builder.newLineIfNotEmpty(); | ||
938 | _builder.append("\t"); | ||
939 | CharSequence _referPattern_9 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I4", "S" }, Modality.MUST, true, false); | ||
940 | _builder.append(_referPattern_9, "\t"); | ||
941 | _builder.newLineIfNotEmpty(); | ||
942 | _builder.append("\t"); | ||
943 | _builder.append("I1 != I2;"); | ||
944 | _builder.newLine(); | ||
945 | _builder.append("\t"); | ||
946 | _builder.append("I1 != I3;"); | ||
947 | _builder.newLine(); | ||
948 | _builder.append("\t"); | ||
949 | _builder.append("I1 != I4;"); | ||
950 | _builder.newLine(); | ||
951 | _builder.append("\t"); | ||
952 | _builder.append("I2 != I3;"); | ||
953 | _builder.newLine(); | ||
954 | _builder.append("\t"); | ||
955 | _builder.append("I2 != I4;"); | ||
956 | _builder.newLine(); | ||
957 | _builder.append("\t"); | ||
958 | _builder.append("I3 != I4;"); | ||
959 | _builder.newLine(); | ||
960 | _builder.append("}"); | ||
961 | _builder.newLine(); | ||
962 | _builder.newLine(); | ||
963 | _builder.append("pattern tooManyInputsOfTurnout_must_to_true_by_straight("); | ||
964 | _builder.append(parameters); | ||
965 | _builder.append(", T : DefinedElement) {"); | ||
966 | _builder.newLineIfNotEmpty(); | ||
967 | _builder.append("\t"); | ||
968 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
969 | _builder.newLine(); | ||
970 | _builder.append("\t"); | ||
971 | CharSequence _referInstanceOf_37 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MUST, "S"); | ||
972 | _builder.append(_referInstanceOf_37, "\t"); | ||
973 | _builder.newLineIfNotEmpty(); | ||
974 | _builder.append("\t"); | ||
975 | _builder.append("find adjacent_must_to_true_by_straight(problem, interpretation, source, target, I1, S);"); | ||
976 | _builder.newLine(); | ||
977 | _builder.append("\t"); | ||
978 | CharSequence _referPattern_10 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
979 | _builder.append(_referPattern_10, "\t"); | ||
980 | _builder.newLineIfNotEmpty(); | ||
981 | _builder.append("\t"); | ||
982 | CharSequence _referPattern_11 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
983 | _builder.append(_referPattern_11, "\t"); | ||
984 | _builder.newLineIfNotEmpty(); | ||
985 | _builder.append("\t"); | ||
986 | CharSequence _referPattern_12 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I4", "S" }, Modality.MUST, true, false); | ||
987 | _builder.append(_referPattern_12, "\t"); | ||
988 | _builder.newLineIfNotEmpty(); | ||
989 | _builder.append("\t"); | ||
990 | _builder.append("I1 != I2;"); | ||
991 | _builder.newLine(); | ||
992 | _builder.append("\t"); | ||
993 | _builder.append("I1 != I3;"); | ||
994 | _builder.newLine(); | ||
995 | _builder.append("\t"); | ||
996 | _builder.append("I1 != I4;"); | ||
997 | _builder.newLine(); | ||
998 | _builder.append("\t"); | ||
999 | _builder.append("I2 != I3;"); | ||
1000 | _builder.newLine(); | ||
1001 | _builder.append("\t"); | ||
1002 | _builder.append("I2 != I4;"); | ||
1003 | _builder.newLine(); | ||
1004 | _builder.append("\t"); | ||
1005 | _builder.append("I3 != I4;"); | ||
1006 | _builder.newLine(); | ||
1007 | _builder.append("}"); | ||
1008 | _builder.newLine(); | ||
1009 | _builder.newLine(); | ||
1010 | _builder.append("pattern tooManyInputsOfTurnout_must_to_true_by_divergent("); | ||
1011 | _builder.append(parameters); | ||
1012 | _builder.append(", T : DefinedElement) {"); | ||
1013 | _builder.newLineIfNotEmpty(); | ||
1014 | _builder.append("\t"); | ||
1015 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
1016 | _builder.newLine(); | ||
1017 | _builder.append("\t"); | ||
1018 | CharSequence _referInstanceOf_38 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MUST, "S"); | ||
1019 | _builder.append(_referInstanceOf_38, "\t"); | ||
1020 | _builder.newLineIfNotEmpty(); | ||
1021 | _builder.append("\t"); | ||
1022 | _builder.append("find adjacent_must_to_true_by_divergent(problem, interpretation, source, target, I1, S);"); | ||
1023 | _builder.newLine(); | ||
1024 | _builder.append("\t"); | ||
1025 | CharSequence _referPattern_13 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
1026 | _builder.append(_referPattern_13, "\t"); | ||
1027 | _builder.newLineIfNotEmpty(); | ||
1028 | _builder.append("\t"); | ||
1029 | CharSequence _referPattern_14 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
1030 | _builder.append(_referPattern_14, "\t"); | ||
1031 | _builder.newLineIfNotEmpty(); | ||
1032 | _builder.append("\t"); | ||
1033 | CharSequence _referPattern_15 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I4", "S" }, Modality.MUST, true, false); | ||
1034 | _builder.append(_referPattern_15, "\t"); | ||
1035 | _builder.newLineIfNotEmpty(); | ||
1036 | _builder.append("\t"); | ||
1037 | _builder.append("I1 != I2;"); | ||
1038 | _builder.newLine(); | ||
1039 | _builder.append("\t"); | ||
1040 | _builder.append("I1 != I3;"); | ||
1041 | _builder.newLine(); | ||
1042 | _builder.append("\t"); | ||
1043 | _builder.append("I1 != I4;"); | ||
1044 | _builder.newLine(); | ||
1045 | _builder.append("\t"); | ||
1046 | _builder.append("I2 != I3;"); | ||
1047 | _builder.newLine(); | ||
1048 | _builder.append("\t"); | ||
1049 | _builder.append("I2 != I4;"); | ||
1050 | _builder.newLine(); | ||
1051 | _builder.append("\t"); | ||
1052 | _builder.append("I3 != I4;"); | ||
1053 | _builder.newLine(); | ||
1054 | _builder.append("}"); | ||
1055 | _builder.newLine(); | ||
1056 | _builder.newLine(); | ||
1057 | _builder.append("pattern "); | ||
1058 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO); | ||
1059 | _builder.append("_helper("); | ||
1060 | _builder.append(parameters); | ||
1061 | _builder.append(") {"); | ||
1062 | _builder.newLineIfNotEmpty(); | ||
1063 | _builder.append("\t"); | ||
1064 | _builder.append("find connectedToReflexive_must_to_true_by_connectedTo(problem, interpretation, source, target, _);"); | ||
1065 | _builder.newLine(); | ||
1066 | _builder.append("} or {"); | ||
1067 | _builder.newLine(); | ||
1068 | _builder.append("\t"); | ||
1069 | _builder.append("find tooManyInputsOfSegment_must_to_true_by_connectedTo(problem, interpretation, source, target, _);"); | ||
1070 | _builder.newLine(); | ||
1071 | _builder.append("} or {"); | ||
1072 | _builder.newLine(); | ||
1073 | _builder.append("\t"); | ||
1074 | _builder.append("find turnoutConnectedToBothOutputs_must_to_true_by_connectedTo(problem, interpretation, source, target, _);"); | ||
1075 | _builder.newLine(); | ||
1076 | _builder.append("} or {"); | ||
1077 | _builder.newLine(); | ||
1078 | _builder.append("\t"); | ||
1079 | _builder.append("find tooManyInputsOfTurnout_must_to_true_by_connectedTo(problem, interpretation, source, target, _);"); | ||
1080 | _builder.newLine(); | ||
1081 | _builder.append("}"); | ||
1082 | _builder.newLine(); | ||
1083 | _builder.newLine(); | ||
1084 | _builder.append("pattern "); | ||
1085 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO); | ||
1086 | _builder.append("("); | ||
1087 | _builder.append(parameters); | ||
1088 | _builder.append(") {"); | ||
1089 | _builder.newLineIfNotEmpty(); | ||
1090 | _builder.append("\t"); | ||
1091 | _builder.append("find "); | ||
1092 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO, "\t"); | ||
1093 | _builder.append("_helper(problem, interpretation, source, target);"); | ||
1094 | _builder.newLineIfNotEmpty(); | ||
1095 | _builder.append("} or {"); | ||
1096 | _builder.newLine(); | ||
1097 | _builder.append("\t"); | ||
1098 | _builder.append("find "); | ||
1099 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO, "\t"); | ||
1100 | _builder.append("_helper(problem, interpretation, target, source);"); | ||
1101 | _builder.newLineIfNotEmpty(); | ||
1102 | _builder.append("}"); | ||
1103 | _builder.newLine(); | ||
1104 | _builder.newLine(); | ||
1105 | _builder.append("pattern "); | ||
1106 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_STRAIGHT); | ||
1107 | _builder.append("("); | ||
1108 | _builder.append(parameters); | ||
1109 | _builder.append(") {"); | ||
1110 | _builder.newLineIfNotEmpty(); | ||
1111 | _builder.append("\t"); | ||
1112 | _builder.append("find outputReflexive_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1113 | _builder.newLine(); | ||
1114 | _builder.append("} or {"); | ||
1115 | _builder.newLine(); | ||
1116 | _builder.append("\t"); | ||
1117 | _builder.append("find turnoutOutputsAreSame_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1118 | _builder.newLine(); | ||
1119 | _builder.append("} or {"); | ||
1120 | _builder.newLine(); | ||
1121 | _builder.append("\t"); | ||
1122 | _builder.append("find tooManyInputsOfSegment_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1123 | _builder.newLine(); | ||
1124 | _builder.append("} or {"); | ||
1125 | _builder.newLine(); | ||
1126 | _builder.append("\t"); | ||
1127 | _builder.append("find turnoutConnectedToBothOutputs_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1128 | _builder.newLine(); | ||
1129 | _builder.append("} or {"); | ||
1130 | _builder.newLine(); | ||
1131 | _builder.append("\t"); | ||
1132 | _builder.append("find tooManyInputsOfTurnout_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1133 | _builder.newLine(); | ||
1134 | _builder.append("}"); | ||
1135 | _builder.newLine(); | ||
1136 | _builder.newLine(); | ||
1137 | _builder.append("pattern "); | ||
1138 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_DIVERGENT); | ||
1139 | _builder.append("("); | ||
1140 | _builder.append(parameters); | ||
1141 | _builder.append(") {"); | ||
1142 | _builder.newLineIfNotEmpty(); | ||
1143 | _builder.append("\t"); | ||
1144 | _builder.append("find outputReflexive_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1145 | _builder.newLine(); | ||
1146 | _builder.append("} or {"); | ||
1147 | _builder.newLine(); | ||
1148 | _builder.append("\t"); | ||
1149 | _builder.append("find turnoutOutputsAreSame_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1150 | _builder.newLine(); | ||
1151 | _builder.append("} or {"); | ||
1152 | _builder.newLine(); | ||
1153 | _builder.append("\t"); | ||
1154 | _builder.append("find tooManyInputsOfSegment_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1155 | _builder.newLine(); | ||
1156 | _builder.append("} or {"); | ||
1157 | _builder.newLine(); | ||
1158 | _builder.append("\t"); | ||
1159 | _builder.append("find turnoutConnectedToBothOutputs_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1160 | _builder.newLine(); | ||
1161 | _builder.append("} or {"); | ||
1162 | _builder.newLine(); | ||
1163 | _builder.append("\t"); | ||
1164 | _builder.append("find tooManyInputsOfTurnout_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1165 | _builder.newLine(); | ||
1166 | _builder.append("}"); | ||
1167 | _builder.newLine(); | ||
1168 | } | ||
1169 | }; | ||
1170 | _xblockexpression = _client_3; | ||
1171 | } | ||
1172 | return _xblockexpression; | ||
1173 | } | ||
1174 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/TrainLocationsObjectiveHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/TrainLocationsObjectiveHint.java new file mode 100644 index 00000000..570f9deb --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/TrainLocationsObjectiveHint.java | |||
@@ -0,0 +1,117 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.collect.ImmutableList; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint; | ||
14 | import java.util.Collection; | ||
15 | import java.util.List; | ||
16 | import java.util.Map; | ||
17 | import java.util.Set; | ||
18 | import modes3.Modes3Package; | ||
19 | import modes3.queries.TrainLocations_step_2; | ||
20 | import modes3.queries.TrainLocations_step_3; | ||
21 | import org.eclipse.xtext.xbase.lib.Extension; | ||
22 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
23 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
24 | |||
25 | @SuppressWarnings("all") | ||
26 | public class TrainLocationsObjectiveHint extends CostObjectiveHint { | ||
27 | private final Type segmentType; | ||
28 | |||
29 | private final Type trainType; | ||
30 | |||
31 | public TrainLocationsObjectiveHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
32 | @Extension | ||
33 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
34 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
35 | this.trainType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTrain()); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public boolean isExact() { | ||
40 | return true; | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public PolyhedronExtensionOperator createPolyhedronExtensionOperator(final Map<String, CostElementMatchers> costElementMatchers) { | ||
45 | PolyhedronExtensionOperator _xblockexpression = null; | ||
46 | { | ||
47 | final CostElementMatchers step2 = costElementMatchers.get(TrainLocations_step_2.instance().getFullyQualifiedName()); | ||
48 | final CostElementMatchers step3 = costElementMatchers.get(TrainLocations_step_3.instance().getFullyQualifiedName()); | ||
49 | final PolyhedronExtensionOperator _function = (ExtendedLinearExpressionBuilderFactory it) -> { | ||
50 | final ExtendedLinearExpressionBuilder objectiveBuilder = it.createBuilder(); | ||
51 | ImmutableList<CostElementMatch> _matches = step2.getMatches(); | ||
52 | for (final CostElementMatch m : _matches) { | ||
53 | { | ||
54 | final Dimension dimension = it.getDimension(m.getMatch()); | ||
55 | objectiveBuilder.add(step2.getWeight(), dimension); | ||
56 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
57 | boolean _isMulti = m.isMulti(); | ||
58 | if (_isMulti) { | ||
59 | it.createBuilder().add(1, dimension).add((-1), this.trainType).build().assertEqualsTo(0); | ||
60 | } else { | ||
61 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
62 | boolean _isMust = m.isMust(); | ||
63 | if (_isMust) { | ||
64 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | final ImmutableList<CostElementMatch> step3Matches = step3.getMatches(); | ||
70 | for (final CostElementMatch m_1 : step3Matches) { | ||
71 | { | ||
72 | final Dimension dimension = it.getDimension(m_1.getMatch()); | ||
73 | objectiveBuilder.add(step3.getWeight(), dimension); | ||
74 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
75 | boolean _isMulti = m_1.isMulti(); | ||
76 | boolean _not = (!_isMulti); | ||
77 | if (_not) { | ||
78 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
79 | boolean _isMust = m_1.isMust(); | ||
80 | if (_isMust) { | ||
81 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | TrainLocationsObjectiveHint.boundLimit(it, step3Matches, 2, this.trainType, 1); | ||
87 | TrainLocationsObjectiveHint.boundLimit(it, step3Matches, 3, this.segmentType, 1); | ||
88 | this.buildWithBounds(objectiveBuilder); | ||
89 | }; | ||
90 | _xblockexpression = _function; | ||
91 | } | ||
92 | return _xblockexpression; | ||
93 | } | ||
94 | |||
95 | private static void boundLimit(@Extension final ExtendedLinearExpressionBuilderFactory factory, final Collection<CostElementMatch> matches, final int index, final Type type, final int count) { | ||
96 | final Function1<CostElementMatch, Object> _function = (CostElementMatch it) -> { | ||
97 | return it.getMatch().get(index); | ||
98 | }; | ||
99 | Set<Map.Entry<Object, List<CostElementMatch>>> _entrySet = IterableExtensions.<Object, CostElementMatch>groupBy(matches, _function).entrySet(); | ||
100 | for (final Map.Entry<Object, List<CostElementMatch>> pair : _entrySet) { | ||
101 | { | ||
102 | final ExtendedLinearExpressionBuilder multiplicityBuilder = factory.createBuilder(); | ||
103 | List<CostElementMatch> _value = pair.getValue(); | ||
104 | for (final CostElementMatch m : _value) { | ||
105 | multiplicityBuilder.add(1, m.getMatch()); | ||
106 | } | ||
107 | boolean _isMulti = CostElementMatchers.isMulti(pair.getKey()); | ||
108 | if (_isMulti) { | ||
109 | multiplicityBuilder.add((-count), type); | ||
110 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
111 | } else { | ||
112 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(count)); | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | } | ||