aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java
diff options
context:
space:
mode:
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java')
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java193
1 files changed, 193 insertions, 0 deletions
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 @@
1package modes3.run;
2
3import com.google.common.collect.ImmutableList;
4import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic;
5import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace;
6import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type;
7import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension;
8import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder;
9import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory;
10import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator;
11import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch;
12import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers;
13import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint;
14import java.util.Collection;
15import java.util.List;
16import java.util.Map;
17import java.util.Set;
18import modes3.Modes3Package;
19import modes3.queries.EndOfSiding_step_2;
20import modes3.queries.EndOfSiding_step_3;
21import modes3.queries.EndOfSiding_step_4;
22import modes3.queries.EndOfSiding_step_5;
23import org.eclipse.viatra.query.runtime.api.IPatternMatch;
24import org.eclipse.xtext.xbase.lib.Extension;
25import org.eclipse.xtext.xbase.lib.Functions.Function1;
26import org.eclipse.xtext.xbase.lib.IterableExtensions;
27
28@SuppressWarnings("all")
29public 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}