Code Duplication    Length = 133-147 lines in 2 locations

src/main/java/it/cnr/istc/pst/platinum/ai/lang/ddl/v3/DDLv3Compiler.java 2 locations

@@ 2405-2551 (lines=147) @@
2402
	 * @param ctarget
2403
	 * @param ddlRelType
2404
	 */
2405
	private void addConstraintToSynchronization(SynchronizationRule rule, TokenVariable reference, TokenVariable target, DDLTemporalRelationType ddlRelType) 
2406
	{
2407
		// check relation type
2408
		if (ddlRelType.getText().equalsIgnoreCase("meets")) {
2409
			// create meets constraint
2410
			rule.addTemporalConstraint(reference, target, RelationType.MEETS, new long[][] {});
2411
		}
2412
		else if (ddlRelType.getText().equalsIgnoreCase("met-by")) {
2413
			// create met-by constraint
2414
			rule.addTemporalConstraint(reference, target, RelationType.MET_BY, new long[][] {});
2415
		}
2416
		else if (ddlRelType.getText().equalsIgnoreCase("during")) { 
2417
			// create during constraint
2418
			rule.addTemporalConstraint(reference, target, 
2419
					RelationType.DURING, 
2420
					new long[][] {
2421
						new long[] {
2422
							ddlRelType.getFirstRange().getMin(), 
2423
							ddlRelType.getFirstRange().getMax() > this.horizon ? 
2424
									this.horizon : 
2425
									ddlRelType.getFirstRange().getMax()
2426
						},
2427
						new long[] {
2428
							ddlRelType.getSecondRange().getMin(),
2429
							ddlRelType.getSecondRange().getMax() > this.horizon ? 
2430
									this.horizon :
2431
									ddlRelType.getSecondRange().getMax()
2432
						}
2433
				});
2434
		}
2435
		else if (ddlRelType.getText().equalsIgnoreCase("equals")) {
2436
			// create equals constraint
2437
			rule.addTemporalConstraint(reference, target, RelationType.EQUALS, new long[][] {});
2438
		}
2439
		else if (ddlRelType.getText().equalsIgnoreCase("contains")) {
2440
			// create contains constraint
2441
			rule.addTemporalConstraint(reference, target, 
2442
					RelationType.CONTAINS, 
2443
					new long[][] {
2444
						new long[] {
2445
							ddlRelType.getFirstRange().getMin(),
2446
							ddlRelType.getFirstRange().getMax() > this.horizon ?
2447
									this.horizon :
2448
									ddlRelType.getFirstRange().getMax()
2449
						},
2450
						new long[] {
2451
							ddlRelType.getSecondRange().getMin(),
2452
							ddlRelType.getSecondRange().getMax() > this.horizon ?
2453
									this.horizon :
2454
									ddlRelType.getSecondRange().getMax()
2455
						}
2456
				});
2457
		}
2458
		else if (ddlRelType.getText().equalsIgnoreCase("before")) {
2459
			// create before constraint
2460
			rule.addTemporalConstraint(reference, target, 
2461
					RelationType.BEFORE, 
2462
					new long[][] {
2463
						new long[] {
2464
							ddlRelType.getFirstRange().getMin(),
2465
							ddlRelType.getFirstRange().getMax() > this.horizon ?
2466
									this.horizon : 
2467
									ddlRelType.getFirstRange().getMax()
2468
						}
2469
				});
2470
		}
2471
		else if (ddlRelType.getText().equalsIgnoreCase("after")) {
2472
			// create before constraint
2473
			rule.addTemporalConstraint(reference, target, 
2474
					RelationType.AFTER, 
2475
					new long[][] {
2476
						new long[] {
2477
							ddlRelType.getFirstRange().getMin(),
2478
							ddlRelType.getFirstRange().getMax() > this.horizon ?
2479
									this.horizon : 
2480
									ddlRelType.getFirstRange().getMax()
2481
						}
2482
				});
2483
		}
2484
		else if (ddlRelType.getText().equalsIgnoreCase("start-start")) {
2485
			// create start-start constraint
2486
			rule.addTemporalConstraint(reference, target, 
2487
					RelationType.START_START, 
2488
					new long[][] {
2489
						new long[] {
2490
								ddlRelType.getFirstRange().getMin(),
2491
								ddlRelType.getFirstRange().getMax() > this.horizon ? 
2492
										this.horizon : 
2493
										ddlRelType.getFirstRange().getMax()
2494
						}
2495
			});
2496
			
2497
		}
2498
		else if (ddlRelType.getText().equalsIgnoreCase("end-end")) {
2499
			// create end-end constraint
2500
			rule.addTemporalConstraint(reference, target, 
2501
					RelationType.END_END, 
2502
					new long[][] {
2503
						new long[] {
2504
								ddlRelType.getFirstRange().getMin(),
2505
								ddlRelType.getFirstRange().getMax() > this.horizon ? 
2506
										this.horizon : 
2507
										ddlRelType.getFirstRange().getMax()
2508
						}
2509
			});
2510
		}
2511
		else if (ddlRelType.getText().equalsIgnoreCase("starts-during")) {
2512
			rule.addTemporalConstraint(reference, target,
2513
					RelationType.STARTS_DURING, 
2514
					new long[][] {
2515
						new long[] {
2516
							ddlRelType.getFirstRange().getMin(),
2517
							ddlRelType.getFirstRange().getMax() > this.horizon ? 
2518
									this.horizon :
2519
									ddlRelType.getFirstRange().getMax()
2520
						},
2521
						new long[] {
2522
							ddlRelType.getSecondRange().getMin(),
2523
							ddlRelType.getSecondRange().getMax() > this.horizon ? 
2524
									this.horizon : 
2525
									ddlRelType.getSecondRange().getMax()
2526
						}
2527
					});
2528
		}
2529
		else if (ddlRelType.getText().equalsIgnoreCase("ends-during")) {
2530
			rule.addTemporalConstraint(reference, target,
2531
					RelationType.ENDS_DURING, 
2532
					new long[][] {
2533
						new long[] {
2534
							ddlRelType.getFirstRange().getMin(),
2535
							ddlRelType.getFirstRange().getMax() > this.horizon ? 
2536
									this.horizon :
2537
									ddlRelType.getFirstRange().getMax()
2538
						},
2539
						new long[] {
2540
								ddlRelType.getSecondRange().getMin(),
2541
								ddlRelType.getSecondRange().getMax() > this.horizon ? 
2542
										this.horizon : 
2543
										ddlRelType.getSecondRange().getMax()
2544
							}
2545
					});
2546
		}
2547
		else {
2548
			
2549
			throw new RuntimeException("Unknown temporal relation " + ddlRelType);
2550
		}
2551
	}
2552
	
2553
	/**
2554
	 * 
@@ 493-625 (lines=133) @@
490
	 * @param target
491
	 * @param ddlRelType
492
	 */
493
	private void addBinaryGoal(Problem problem, ProblemGoal reference, ProblemGoal target, DDLTemporalRelationType ddlRelType) {
494
		// check relation type
495
		if (ddlRelType.getText().equalsIgnoreCase("meets")) {
496
			// create meets constraint
497
			problem.addTemporalConstraint(RelationType.MEETS, reference, target, new long[][] {});
498
		}
499
		else if (ddlRelType.getText().equalsIgnoreCase("met-by")) {
500
			// create met-by constraint
501
			problem.addTemporalConstraint(RelationType.MET_BY, reference, target, new long[][] {});
502
		}
503
		else if (ddlRelType.getText().equalsIgnoreCase("during")) { 
504
			// create during constraint
505
			problem.addTemporalConstraint(RelationType.DURING, reference, target, 
506
				new long[][] {
507
					new long[] {
508
						ddlRelType.getFirstRange().getMin(),
509
						ddlRelType.getFirstRange().getMax() > this.horizon ? 
510
								this.horizon :
511
								ddlRelType.getFirstRange().getMax()
512
					},
513
					new long[] {
514
						ddlRelType.getSecondRange().getMin(),
515
						ddlRelType.getSecondRange().getMax() > this.horizon ? 
516
								this.horizon :
517
								ddlRelType.getSecondRange().getMax()
518
					}
519
				});
520
		}
521
		else if (ddlRelType.getText().equalsIgnoreCase("equals")) {
522
			// create equals constraint
523
			problem.addTemporalConstraint(RelationType.EQUALS, reference, target, new long[][] {});
524
		}
525
		else if (ddlRelType.getText().equalsIgnoreCase("contains")) {
526
			// create contains constraint
527
			problem.addTemporalConstraint(RelationType.CONTAINS, reference, target, 
528
				new long[][] {
529
					new long[] {
530
						ddlRelType.getFirstRange().getMin(),
531
						ddlRelType.getFirstRange().getMax() > this.horizon ? 
532
								this.horizon : 
533
								ddlRelType.getFirstRange().getMax()
534
					},
535
					new long[] {
536
						ddlRelType.getSecondRange().getMin(),
537
						ddlRelType.getSecondRange().getMax() > this.horizon ?
538
								this.horizon : 
539
								ddlRelType.getSecondRange().getMax()
540
					}
541
				});
542
		}
543
		else if (ddlRelType.getText().equalsIgnoreCase("before")) {
544
			problem.addTemporalConstraint(RelationType.BEFORE, reference, target, 
545
				new long[][] {
546
					new long[] {
547
						ddlRelType.getFirstRange().getMin(),
548
						ddlRelType.getFirstRange().getMax() > this.horizon ? 
549
								this.horizon :
550
								ddlRelType.getFirstRange().getMax()
551
					}
552
				});
553
		}
554
		else if (ddlRelType.getText().equalsIgnoreCase("after")) {
555
			problem.addTemporalConstraint(RelationType.AFTER, reference, target, 
556
					new long[][] {
557
						new long[] {
558
							ddlRelType.getFirstRange().getMin(),
559
							ddlRelType.getFirstRange().getMax() > this.horizon ? 
560
									this.horizon :
561
									ddlRelType.getFirstRange().getMax()
562
						}
563
					});
564
		}
565
		else if (ddlRelType.getText().equalsIgnoreCase("start-start")) {
566
			problem.addTemporalConstraint(RelationType.START_START, reference, target, 
567
					new long[][] {
568
						new long[] {
569
								ddlRelType.getFirstRange().getMin(),
570
								ddlRelType.getFirstRange().getMax() > this.horizon ? 
571
										this.horizon : 
572
										ddlRelType.getFirstRange().getMax()
573
						}
574
			});
575
		}
576
		else if (ddlRelType.getText().equalsIgnoreCase("end-end")) {
577
			problem.addTemporalConstraint(RelationType.END_END, reference, target, 
578
					new long[][] {
579
						new long[] {
580
								ddlRelType.getFirstRange().getMin(),
581
								ddlRelType.getFirstRange().getMax() > this.horizon ? 
582
										this.horizon : 
583
										ddlRelType.getFirstRange().getMax()
584
						}
585
			});
586
		}
587
		else if (ddlRelType.getText().equalsIgnoreCase("starts-during")) {
588
			problem.addTemporalConstraint(RelationType.STARTS_DURING, reference, target, 
589
					new long[][] {
590
						new long[] {
591
							ddlRelType.getFirstRange().getMin(),
592
							ddlRelType.getFirstRange().getMax() > this.horizon ? 
593
									this.horizon :
594
									ddlRelType.getFirstRange().getMax()
595
						},
596
						new long[] {
597
							ddlRelType.getSecondRange().getMin(),
598
							ddlRelType.getSecondRange().getMax() > this.horizon ? 
599
									this.horizon : 
600
									ddlRelType.getSecondRange().getMax()
601
						}
602
					});
603
		}
604
		else if (ddlRelType.getText().equalsIgnoreCase("ends-during")) {
605
			problem.addTemporalConstraint(RelationType.ENDS_DURING, reference, target, 
606
					new long[][] {
607
						new long[] {
608
							ddlRelType.getFirstRange().getMin(),
609
							ddlRelType.getFirstRange().getMax() > this.horizon ? 
610
									this.horizon :
611
									ddlRelType.getFirstRange().getMax()
612
						},
613
						new long[] {
614
								ddlRelType.getSecondRange().getMin(),
615
								ddlRelType.getSecondRange().getMax() > this.horizon ? 
616
										this.horizon : 
617
										ddlRelType.getSecondRange().getMax()
618
							}
619
					});
620
		}
621
		else {
622
			
623
			throw new RuntimeException("Unknown temporal relation " + ddlRelType);
624
		}
625
	}
626
	
627
	/**
628
	 *