@@ 318-374 (lines=57) @@ | ||
315 | * @param schedule |
|
316 | * @return |
|
317 | */ |
|
318 | private boolean checkTemporalFeasibility(List<Decision> schedule) { |
|
319 | ||
320 | // feasibility flag |
|
321 | boolean feasible = true; |
|
322 | // list of propagated constraints |
|
323 | List<BeforeIntervalConstraint> committed = new ArrayList<>(); |
|
324 | ||
325 | // check pairs of events |
|
326 | for (int index = 0; index < schedule.size() - 1 && feasible; index++) { |
|
327 | ||
328 | try { |
|
329 | ||
330 | // get activities |
|
331 | Decision a1 = schedule.get(index); |
|
332 | Decision a2 = schedule.get(index + 1); |
|
333 | ||
334 | // get associated tokens and temporal intervals to check schedule feasibility |
|
335 | TemporalInterval i1 = a1.getToken().getInterval(); |
|
336 | TemporalInterval i2 = a2.getToken().getInterval(); |
|
337 | ||
338 | // create precedence constraint "i1 < i2" |
|
339 | BeforeIntervalConstraint before = this.tdb.createTemporalConstraint( |
|
340 | TemporalConstraintType.BEFORE); |
|
341 | ||
342 | // set constraint data |
|
343 | before.setReference(i1); |
|
344 | before.setTarget(i2); |
|
345 | before.setLowerBound(0); |
|
346 | before.setUpperBound(this.tdb.getHorizon()); |
|
347 | ||
348 | // add constraints to committed |
|
349 | committed.add(before); |
|
350 | // propagate constraint |
|
351 | this.tdb.propagate(before); |
|
352 | // check temporal feasibility |
|
353 | this.tdb.verify(); |
|
354 | ||
355 | } catch (TemporalConstraintPropagationException | ConsistencyCheckException ex) { |
|
356 | ||
357 | // not feasible schedule |
|
358 | feasible = false; |
|
359 | // log data |
|
360 | debug("Component [" + this.label + "] temporally unfeasible schedule:\n" |
|
361 | + "- potential schedule critical set: " + schedule + "\n"); |
|
362 | ||
363 | } finally { |
|
364 | ||
365 | // retract all committed constraints |
|
366 | for (BeforeIntervalConstraint before : committed) { |
|
367 | // retract temporal constraint |
|
368 | this.tdb.retract(before); |
|
369 | } |
|
370 | } |
|
371 | } |
|
372 | ||
373 | // get feasibility flag |
|
374 | return feasible; |
|
375 | ||
376 | } |
|
377 |
@@ 178-232 (lines=55) @@ | ||
175 | * @param schedule |
|
176 | * @return |
|
177 | */ |
|
178 | private boolean checkTemporalFeasibility(List<ResourceEvent<?>> schedule) { |
|
179 | ||
180 | // feasibility flag |
|
181 | boolean feasible = true; |
|
182 | // list of propagated constraints |
|
183 | List<BeforeIntervalConstraint> committed = new ArrayList<>(); |
|
184 | // check pairs of events |
|
185 | for (int index = 0; index < schedule.size() - 1 && feasible; index++) { |
|
186 | ||
187 | try { |
|
188 | ||
189 | // get events |
|
190 | ResourceEvent<?> e1 = schedule.get(index); |
|
191 | ResourceEvent<?> e2 = schedule.get(index + 1); |
|
192 | ||
193 | // get associated tokens and temporal intervals to check schedule feasibility |
|
194 | TemporalInterval i1 = e1.getDecision().getToken().getInterval(); |
|
195 | TemporalInterval i2 = e2.getDecision().getToken().getInterval(); |
|
196 | ||
197 | // create precedence constraint "i1 < i2" |
|
198 | BeforeIntervalConstraint before = this.tdb.createTemporalConstraint( |
|
199 | TemporalConstraintType.BEFORE); |
|
200 | ||
201 | // set constraint data |
|
202 | before.setReference(i1); |
|
203 | before.setTarget(i2); |
|
204 | before.setLowerBound(0); |
|
205 | before.setUpperBound(this.tdb.getHorizon()); |
|
206 | ||
207 | // add constraints to committed |
|
208 | committed.add(before); |
|
209 | // propagate constraint |
|
210 | this.tdb.propagate(before); |
|
211 | // check temporal feasibility |
|
212 | this.tdb.verify(); |
|
213 | ||
214 | } catch (TemporalConstraintPropagationException | ConsistencyCheckException ex) { |
|
215 | // not feasible schedule |
|
216 | feasible = false; |
|
217 | // log data |
|
218 | debug("Component [" + this.label + "] temporally unfeasible schedule:\n" |
|
219 | + "- potential schedule critical set: " + schedule + "\n"); |
|
220 | ||
221 | } finally { |
|
222 | ||
223 | // retract all committed constraints |
|
224 | for (BeforeIntervalConstraint before : committed) { |
|
225 | // retract temporal constraint |
|
226 | this.tdb.retract(before); |
|
227 | } |
|
228 | } |
|
229 | } |
|
230 | ||
231 | // get feasibility flag |
|
232 | return feasible; |
|
233 | ||
234 | } |
|
235 |