diff options
author | 2020-11-02 02:02:40 +0100 | |
---|---|---|
committer | 2020-11-02 02:02:40 +0100 | |
commit | f06427cd7375551582461f91b3458339a8227f9b (patch) | |
tree | 97bc6ec85f4c384e5080a6611b492caf460b6ce9 /Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen | |
parent | Must unit propagation (diff) | |
download | VIATRA-Generator-f06427cd7375551582461f91b3458339a8227f9b.tar.gz VIATRA-Generator-f06427cd7375551582461f91b3458339a8227f9b.tar.zst VIATRA-Generator-f06427cd7375551582461f91b3458339a8227f9b.zip |
Optimizing generator with linear objective functions
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen')
13 files changed, 1049 insertions, 50 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 index 77f1ea6e..759ac9e4 100644 --- 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 | |||
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 index 4fdbb71b..386baeda 100644 --- 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 | |||
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 index e5e1b63e..79059b7f 100644 --- 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 | |||
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 index fb94df96..1a7df1d9 100644 --- a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore | |||
@@ -1,3 +1,13 @@ | |||
1 | /.Modes3ModelGenerator.java._trace | 1 | /.Modes3ModelGenerator.java._trace |
2 | /.Modes3UnitPropagationGenerator.java._trace | 2 | /.Modes3UnitPropagationGenerator.java._trace |
3 | /.Modes3TypeScopeHint.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 index f32a7172..16db7053 100644 --- 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 | |||
@@ -13,6 +13,7 @@ import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logic | |||
13 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage; | 13 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage; |
14 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion; | 14 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion; |
15 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; | 15 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; |
16 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation; | ||
16 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder; | 17 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder; |
17 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope; | 18 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope; |
18 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; | 19 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; |
@@ -32,6 +33,7 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | |||
32 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage; | 33 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage; |
33 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; | 34 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; |
34 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; | 35 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; |
36 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore; | ||
35 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic; | 37 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic; |
36 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration; | 38 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration; |
37 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicTrace; | 39 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicTrace; |
@@ -50,10 +52,15 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par | |||
50 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink; | 52 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink; |
51 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml; | 53 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml; |
52 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualisation; | 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; | ||
53 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DebugConfiguration; | 57 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DebugConfiguration; |
54 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.StateCoderStrategy; | 58 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.StateCoderStrategy; |
55 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner; | 59 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner; |
56 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; | 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; | ||
57 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser; | 64 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser; |
58 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; | 65 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; |
59 | import java.util.Collections; | 66 | import java.util.Collections; |
@@ -64,10 +71,31 @@ import java.util.function.Predicate; | |||
64 | import modes3.Modes3Factory; | 71 | import modes3.Modes3Factory; |
65 | import modes3.Modes3ModelRoot; | 72 | import modes3.Modes3ModelRoot; |
66 | import modes3.Modes3Package; | 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; | ||
67 | import modes3.queries.Modes3Queries; | 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; | ||
68 | import modes3.run.Modes3TypeScopeHint; | 94 | import modes3.run.Modes3TypeScopeHint; |
69 | import modes3.run.Modes3UnitPropagationGenerator; | 95 | import modes3.run.Modes3UnitPropagationGenerator; |
96 | import modes3.run.TrainLocationsObjectiveHint; | ||
70 | import org.eclipse.emf.common.util.EList; | 97 | import org.eclipse.emf.common.util.EList; |
98 | import org.eclipse.emf.common.util.TreeIterator; | ||
71 | import org.eclipse.emf.common.util.URI; | 99 | import org.eclipse.emf.common.util.URI; |
72 | import org.eclipse.emf.ecore.EAttribute; | 100 | import org.eclipse.emf.ecore.EAttribute; |
73 | import org.eclipse.emf.ecore.EClass; | 101 | import org.eclipse.emf.ecore.EClass; |
@@ -102,6 +130,10 @@ public class Modes3ModelGenerator { | |||
102 | private enum MonitoringQuery { | 130 | private enum MonitoringQuery { |
103 | closeTrains, | 131 | closeTrains, |
104 | 132 | ||
133 | trainLocations, | ||
134 | |||
135 | endOfSiding, | ||
136 | |||
105 | misalignedTurnout; | 137 | misalignedTurnout; |
106 | } | 138 | } |
107 | 139 | ||
@@ -183,8 +215,9 @@ public class Modes3ModelGenerator { | |||
183 | ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow( | 215 | ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow( |
184 | it_1.minNewElementsByType, _function_4); | 216 | it_1.minNewElementsByType, _function_4); |
185 | final Procedure1<Map<Type, Integer>> _function_5 = (Map<Type, Integer> it_2) -> { | 217 | final Procedure1<Map<Type, Integer>> _function_5 = (Map<Type, Integer> it_2) -> { |
186 | it_2.put(this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getTrain()), Integer.valueOf(5)); | 218 | it_2.put(this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getTrain()), Integer.valueOf((this.modelSize / 5))); |
187 | it_2.put(this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getTurnout()), Integer.valueOf(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))); | ||
188 | }; | 221 | }; |
189 | ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow( | 222 | ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow( |
190 | it_1.maxNewElementsByType, _function_5); | 223 | it_1.maxNewElementsByType, _function_5); |
@@ -196,7 +229,9 @@ public class Modes3ModelGenerator { | |||
196 | }; | 229 | }; |
197 | ObjectExtensions.<SolutionScope>operator_doubleArrow( | 230 | ObjectExtensions.<SolutionScope>operator_doubleArrow( |
198 | it.solutionScope, _function_4); | 231 | it.solutionScope, _function_4); |
199 | it.scopeWeight = 5; | 232 | CostObjectiveConfiguration _objective = this.getObjective(this.ecore2Logic, metamodelLogic.getTrace()); |
233 | it.costObjectives.add(_objective); | ||
234 | it.scopeWeight = 6; | ||
200 | it.nameNewElements = false; | 235 | it.nameNewElements = false; |
201 | it.typeInferenceMethod = TypeInferenceMethod.PreliminaryAnalysis; | 236 | it.typeInferenceMethod = TypeInferenceMethod.PreliminaryAnalysis; |
202 | it.stateCoderStrategy = StateCoderStrategy.PairwiseNeighbourhood; | 237 | it.stateCoderStrategy = StateCoderStrategy.PairwiseNeighbourhood; |
@@ -224,80 +259,103 @@ public class Modes3ModelGenerator { | |||
224 | URI _xifexpression = null; | 259 | URI _xifexpression = null; |
225 | if ((solution instanceof ModelResult)) { | 260 | if ((solution instanceof ModelResult)) { |
226 | InputOutput.<String>println("Saving generated solutions"); | 261 | InputOutput.<String>println("Saving generated solutions"); |
227 | final EList<Object> representations = ((ModelResult)solution).getRepresentation(); | 262 | final Logic2Ecore logic2Ecore = new Logic2Ecore(this.ecore2Logic); |
228 | int _size = representations.size(); | 263 | final List<? extends LogicModelInterpretation> interpretations = this.solver.getInterpretations(((ModelResult)solution)); |
264 | int _size = interpretations.size(); | ||
229 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true); | 265 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true); |
230 | for (final Integer representationIndex : _doubleDotLessThan) { | 266 | for (final Integer representationIndex : _doubleDotLessThan) { |
231 | { | 267 | { |
232 | final Object representation = representations.get((representationIndex).intValue()); | 268 | final LogicModelInterpretation interpretation = interpretations.get((representationIndex).intValue()); |
233 | final int representationNumber = ((representationIndex).intValue() + 1); | 269 | final int representationNumber = ((representationIndex).intValue() + 1); |
234 | if ((representation instanceof PartialInterpretation)) { | 270 | if ((interpretation instanceof PartialModelAsLogicInterpretation)) { |
271 | final PartialInterpretation representation = ((PartialModelAsLogicInterpretation)interpretation).getPartialInterpretation(); | ||
235 | StringConcatenation _builder_1 = new StringConcatenation(); | 272 | StringConcatenation _builder_1 = new StringConcatenation(); |
236 | _builder_1.append("solution"); | 273 | _builder_1.append("solution"); |
237 | _builder_1.append(representationNumber); | 274 | _builder_1.append(representationNumber); |
238 | _builder_1.append(".partialinterpretation"); | 275 | _builder_1.append(".partialinterpretation"); |
239 | workspace.writeModel(((EObject)representation), _builder_1.toString()); | 276 | workspace.writeModel(representation, _builder_1.toString()); |
240 | final PartialInterpretation2Gml partialInterpretation2GML = new PartialInterpretation2Gml(); | 277 | final PartialInterpretation2Gml partialInterpretation2GML = new PartialInterpretation2Gml(); |
241 | final String gml = partialInterpretation2GML.transform(((PartialInterpretation)representation)); | 278 | final String gml = partialInterpretation2GML.transform(representation); |
242 | StringConcatenation _builder_2 = new StringConcatenation(); | 279 | StringConcatenation _builder_2 = new StringConcatenation(); |
243 | _builder_2.append("solution"); | 280 | _builder_2.append("solution"); |
244 | _builder_2.append(representationNumber); | 281 | _builder_2.append(representationNumber); |
245 | _builder_2.append(".gml"); | 282 | _builder_2.append(".gml"); |
246 | workspace.writeText(_builder_2.toString(), gml); | 283 | workspace.writeText(_builder_2.toString(), gml); |
247 | int _size_1 = ((PartialInterpretation)representation).getNewElements().size(); | 284 | final EObject model = logic2Ecore.transformInterpretation(interpretation, metamodelLogic.getTrace()); |
248 | boolean _lessThan = (_size_1 < 160); | 285 | final TreeIterator<EObject> iterator = model.eAllContents(); |
249 | if (_lessThan) { | 286 | int id = 0; |
250 | if ((representation instanceof PartialInterpretation)) { | 287 | while (iterator.hasNext()) { |
251 | final Function1<Type, Boolean> _function_3 = (Type it) -> { | 288 | { |
289 | final EObject obj = iterator.next(); | ||
290 | final Function1<EAttribute, Boolean> _function_3 = (EAttribute it) -> { | ||
252 | String _name_2 = it.getName(); | 291 | String _name_2 = it.getName(); |
253 | return Boolean.valueOf(Objects.equal(_name_2, "Modes3ModelRoot class DefinedPart")); | 292 | return Boolean.valueOf(Objects.equal(_name_2, "id")); |
254 | }; | 293 | }; |
255 | Type _findFirst = IterableExtensions.<Type>findFirst(((PartialInterpretation)representation).getProblem().getTypes(), _function_3); | 294 | final EAttribute idFeature = IterableExtensions.<EAttribute>findFirst(obj.eClass().getEAllAttributes(), _function_3); |
256 | final TypeDefinition rootType = ((TypeDefinition) _findFirst); | 295 | if ((idFeature != null)) { |
257 | final Function1<PartialComplexTypeInterpretation, Boolean> _function_4 = (PartialComplexTypeInterpretation it) -> { | 296 | obj.eSet(idFeature, Integer.valueOf(id)); |
258 | String _name_2 = it.getInterpretationOf().getName(); | 297 | id++; |
259 | return Boolean.valueOf(Objects.equal(_name_2, "Modes3ModelRoot class")); | ||
260 | }; | ||
261 | final PartialComplexTypeInterpretation rootIntepretation = IterableExtensions.<PartialComplexTypeInterpretation>findFirst(Iterables.<PartialComplexTypeInterpretation>filter(((PartialInterpretation)representation).getPartialtypeinterpratation(), | ||
262 | PartialComplexTypeInterpretation.class), _function_4); | ||
263 | rootIntepretation.getElements().removeAll(rootType.getElements()); | ||
264 | ((PartialInterpretation)representation).getProblem().getElements().removeAll(rootType.getElements()); | ||
265 | EList<PartialRelationInterpretation> _partialrelationinterpretation = ((PartialInterpretation)representation).getPartialrelationinterpretation(); | ||
266 | for (final PartialRelationInterpretation relationInterpretation : _partialrelationinterpretation) { | ||
267 | final Predicate<RelationLink> _function_5 = (RelationLink link) -> { | ||
268 | boolean _xifexpression_1 = false; | ||
269 | if ((link instanceof BinaryElementRelationLink)) { | ||
270 | _xifexpression_1 = (rootType.getElements().contains(((BinaryElementRelationLink)link).getParam1()) || rootType.getElements().contains(((BinaryElementRelationLink)link).getParam2())); | ||
271 | } else { | ||
272 | _xifexpression_1 = false; | ||
273 | } | ||
274 | return _xifexpression_1; | ||
275 | }; | ||
276 | relationInterpretation.getRelationlinks().removeIf(_function_5); | ||
277 | } | 298 | } |
278 | rootType.getElements().clear(); | ||
279 | } | 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(); | ||
280 | final GraphvizVisualiser visualiser = new GraphvizVisualiser(); | 338 | final GraphvizVisualiser visualiser = new GraphvizVisualiser(); |
281 | final PartialInterpretationVisualisation visualisation = visualiser.visualiseConcretization(((PartialInterpretation)representation)); | 339 | final PartialInterpretationVisualisation visualisation = visualiser.visualiseConcretization(representation); |
282 | StringConcatenation _builder_3 = new StringConcatenation(); | 340 | StringConcatenation _builder_4 = new StringConcatenation(); |
283 | _builder_3.append("solution"); | 341 | _builder_4.append("solution"); |
284 | _builder_3.append(representationNumber); | 342 | _builder_4.append(representationNumber); |
285 | _builder_3.append(".png"); | 343 | _builder_4.append(".png"); |
286 | visualisation.writeToFile(workspace, _builder_3.toString()); | 344 | visualisation.writeToFile(workspace, _builder_4.toString()); |
287 | } | 345 | } |
288 | } else { | 346 | } else { |
289 | StringConcatenation _builder_4 = new StringConcatenation(); | 347 | StringConcatenation _builder_5 = new StringConcatenation(); |
290 | _builder_4.append("solution"); | 348 | _builder_5.append("solution"); |
291 | _builder_4.append(representationNumber); | 349 | _builder_5.append(representationNumber); |
292 | _builder_4.append(".txt"); | 350 | _builder_5.append(".txt"); |
293 | workspace.writeText(_builder_4.toString(), representation.toString()); | 351 | workspace.writeText(_builder_5.toString(), interpretation.toString()); |
294 | } | 352 | } |
295 | } | 353 | } |
296 | } | 354 | } |
297 | } else { | 355 | } else { |
298 | URI _xblockexpression_1 = null; | 356 | URI _xblockexpression_1 = null; |
299 | { | 357 | { |
300 | InputOutput.<String>println("Failed to solver problem"); | 358 | InputOutput.<String>println("Failed to solve problem"); |
301 | final LogicProblem partial = logic.getOutput(); | 359 | final LogicProblem partial = logic.getOutput(); |
302 | _xblockexpression_1 = workspace.writeModel(partial, "solution.partialinterpretation"); | 360 | _xblockexpression_1 = workspace.writeModel(partial, "solution.partialinterpretation"); |
303 | } | 361 | } |
@@ -354,6 +412,153 @@ public class Modes3ModelGenerator { | |||
354 | return _xblockexpression; | 412 | return _xblockexpression; |
355 | } | 413 | } |
356 | 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 | |||
357 | public static Object init() { | 562 | public static Object init() { |
358 | Object _xblockexpression = null; | 563 | Object _xblockexpression = null; |
359 | { | 564 | { |
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 | } | ||