Code Duplication    Length = 55-57 lines in 2 locations

src/main/java/it/cnr/istc/pst/platinum/ai/framework/microkernel/resolver/timeline/scheduling/TimelineSchedulingResolver.java 1 location

@@ 436-492 (lines=57) @@
433
	 * @param schedule
434
	 * @return
435
	 */
436
	private boolean checkTemporalFeasibility(List<Decision> schedule) {
437
		
438
		// feasibility flag
439
		boolean feasible = true;
440
		// list of propagated constraints
441
		List<BeforeIntervalConstraint> committed = new ArrayList<>();
442
		
443
		// check pairs of events 
444
		for (int index = 0; index < schedule.size() - 1 && feasible; index++) {
445
			
446
			try {
447
				
448
				// get activities
449
				Decision a1 = schedule.get(index);
450
				Decision a2 = schedule.get(index + 1);
451
				
452
				// get associated tokens and temporal intervals to check schedule feasibility
453
				TemporalInterval i1 = a1.getToken().getInterval();
454
				TemporalInterval i2 = a2.getToken().getInterval();
455
				
456
				// create precedence constraint "i1 < i2"
457
				BeforeIntervalConstraint before = this.tdb.createTemporalConstraint(
458
						TemporalConstraintType.BEFORE);
459
				
460
				// set constraint data
461
				before.setReference(i1);
462
				before.setTarget(i2);
463
				before.setLowerBound(0);
464
				before.setUpperBound(this.tdb.getHorizon());
465
				
466
				// add constraints to committed
467
				committed.add(before);
468
				// propagate constraint
469
				this.tdb.propagate(before);
470
				// check temporal feasibility
471
				this.tdb.verify();
472
				
473
			} catch (TemporalConstraintPropagationException | ConsistencyCheckException ex) {
474
				
475
				// not feasible schedule
476
				feasible = false;
477
				// log data
478
				debug("Component [" + this.label + "] temporally unfeasible schedule:\n"
479
						+ "- potential schedule critical set: " + schedule + "\n");
480
				
481
			} finally  {
482
				
483
				// retract all committed constraints
484
				for (BeforeIntervalConstraint before : committed) {
485
					// retract temporal constraint
486
					this.tdb.retract(before);
487
				}
488
			}
489
		}
490
		
491
		// get feasibility flag
492
		return feasible;
493
		
494
	}
495
	

src/main/java/it/cnr/istc/pst/platinum/ai/framework/microkernel/resolver/resource/reservoir/ReservoirResourceSchedulingResolver.java 1 location

@@ 183-237 (lines=55) @@
180
	 * @param schedule
181
	 * @return
182
	 */
183
	private boolean checkTemporalFeasibility(List<ResourceEvent<?>> schedule) {
184
		
185
		// feasibility flag
186
		boolean feasible = true;
187
		// list of propagated constraints
188
		List<BeforeIntervalConstraint> committed = new ArrayList<>();
189
		// check pairs of events 
190
		for (int index = 0; index < schedule.size() - 1 && feasible; index++) {
191
			
192
			try {
193
				
194
				// get events
195
				ResourceEvent<?> e1 = schedule.get(index);
196
				ResourceEvent<?> e2 = schedule.get(index + 1);
197
				
198
				// get associated tokens and temporal intervals to check schedule feasibility
199
				TemporalInterval i1 = e1.getDecision().getToken().getInterval();
200
				TemporalInterval i2 = e2.getDecision().getToken().getInterval();
201
				
202
				// create precedence constraint "i1 < i2"
203
				BeforeIntervalConstraint before = this.tdb.createTemporalConstraint(
204
						TemporalConstraintType.BEFORE);
205
				
206
				// set constraint data
207
				before.setReference(i1);
208
				before.setTarget(i2);
209
				before.setLowerBound(0);
210
				before.setUpperBound(this.tdb.getHorizon());
211
				
212
				// add constraints to committed
213
				committed.add(before);
214
				// propagate constraint
215
				this.tdb.propagate(before);
216
				// check temporal feasibility
217
				this.tdb.verify();
218
				
219
			} catch (TemporalConstraintPropagationException | ConsistencyCheckException ex) {
220
				// not feasible schedule
221
				feasible = false;
222
				// log data
223
				debug("Component [" + this.label + "] temporally unfeasible schedule:\n"
224
						+ "- potential schedule critical set: " + schedule + "\n");
225
				
226
			} finally {
227
				
228
				// retract all committed constraints
229
				for (BeforeIntervalConstraint before : committed) {
230
					// retract temporal constraint
231
					this.tdb.retract(before);
232
				}
233
			}
234
		}
235
		
236
		// get feasibility flag
237
		return feasible;
238
		
239
	}
240