Code Duplication    Length = 85-88 lines in 2 locations

src/main/java/it/cnr/istc/pst/platinum/ai/framework/microkernel/resolver/plan/TimelineAwarePlanRefinementResolver.java 1 location

@@ 791-878 (lines=88) @@
788
	 * @param decision
789
	 * @return
790
	 */
791
	private boolean isTemporalUnificationFeasible(Decision goal,  Decision decision) {
792
		
793
		// feasibility flag
794
		boolean feasible = true;
795
		// list of translated relations
796
		Set<Relation> translated = new HashSet<>();
797
		// list of committed relations
798
		Set<Relation> committed = new HashSet<>();
799
		
800
		// get goal component 
801
		DomainComponent gComp = goal.getComponent();
802
		// get all (pending) relations associated to the goal 
803
		Set<Relation> pRels = gComp.getRelations(goal);
804
		// translate relations
805
		for (Relation pRel : pRels)
806
		{
807
			// focus on temporal relations only 
808
			if (pRel.getCategory().equals(ConstraintCategory.TEMPORAL_CONSTRAINT))
809
			{
810
				// check relation reference
811
				if (pRel.getReference().equals(goal)) {
812
					// replace reference
813
					pRel.setReference(decision);
814
					// add translated relation
815
					translated.add(pRel);
816
				}
817
				
818
				// check relation target
819
				if (pRel.getTarget().equals(goal)) {
820
					// replace target
821
					pRel.setTarget(decision);
822
					// add translated relation
823
					translated.add(pRel);
824
				}
825
			}
826
		}
827
	
828
		try {
829
			
830
			// check translated relation and activate them if possible
831
			for (Relation tRel : translated) {
832
				// activate relation
833
				if (tRel.getReference().getComponent().activate(tRel)) {
834
835
					// add relation to committed list
836
					committed.add(tRel);
837
				}
838
			}
839
			
840
			// check temporal consistency after activated relations
841
			this.tdb.verify();
842
			
843
		} catch (ConsistencyCheckException | RelationPropagationException ex) {
844
			
845
			// not feasible unification 
846
			feasible = false;
847
			// not feasible unification
848
			debug("Not feasible temporal unification:\n"
849
					+ "- planning goal: " + goal + "\n"
850
					+ "- unification decision: " + decision + "\n");
851
			
852
		} finally {
853
			
854
			// deactivate relations
855
			for (Relation rel : committed) {
856
				// deactivate relation
857
				rel.getReference().getComponent().deactivate(rel);
858
			}
859
			
860
			// translate back relations
861
			for (Relation rel : translated) {
862
				
863
				// check reference 
864
				if (rel.getReference().equals(decision)) {
865
					// replace reference
866
					rel.setReference(goal);
867
				}
868
				
869
				// check target
870
				if (rel.getTarget().equals(decision)) {
871
					// replace target
872
					rel.setTarget(goal);
873
				}
874
			}
875
		}
876
		
877
		// get feasibility flag
878
		return feasible;
879
	}
880
	
881
	/**

src/main/java/it/cnr/istc/pst/platinum/ai/framework/microkernel/resolver/plan/PlanRefinementResolver.java 1 location

@@ 788-872 (lines=85) @@
785
	 * @param decision
786
	 * @return
787
	 */
788
	private boolean isTemporalUnificationFeasible(Decision goal,  Decision decision) 
789
	{
790
		// feasibility flag
791
		boolean feasible = true;
792
		// list of translated relations
793
		Set<Relation> translated = new HashSet<>();
794
		// list of committed relations
795
		Set<Relation> committed = new HashSet<>();
796
		
797
		// get goal component 
798
		DomainComponent gComp = goal.getComponent();
799
		// get all (pending) relations associated to the goal 
800
		Set<Relation> pRels = gComp.getRelations(goal);
801
		// translate relations
802
		for (Relation pRel : pRels)
803
		{
804
			// focus on temporal relations only 
805
			if (pRel.getCategory().equals(ConstraintCategory.TEMPORAL_CONSTRAINT))
806
			{
807
				// check relation reference
808
				if (pRel.getReference().equals(goal)) {
809
					// replace reference
810
					pRel.setReference(decision);
811
					// add translated relation
812
					translated.add(pRel);
813
				}
814
				
815
				// check relation target
816
				if (pRel.getTarget().equals(goal)) {
817
					// replace target
818
					pRel.setTarget(decision);
819
					// add translated relation
820
					translated.add(pRel);
821
				}
822
			}
823
		}
824
	
825
		try
826
		{
827
			// check translated relation and activate them if possible
828
			for (Relation tRel : translated) {
829
				// activate relation
830
				if (tRel.getReference().getComponent().activate(tRel)) {
831
					// add relation to committed list
832
					committed.add(tRel);
833
				}
834
			}
835
			
836
			// check temporal consistency after activated relations
837
//			this.tdb.verify();
838
		}
839
		catch (RelationPropagationException ex) {
840
			// not feasible unification 
841
			feasible = false;
842
			// not feasible unification
843
			debug("Not feasible temporal unification:\n"
844
					+ "- planning goal: " + goal + "\n"
845
					+ "- unification decision: " + decision + "\n");
846
		}
847
		finally 
848
		{
849
			// deactivate relations
850
			for (Relation rel : committed) {
851
				// deactivate relation
852
				rel.getReference().getComponent().deactivate(rel);
853
			}
854
			
855
			// translate back relations
856
			for (Relation rel : translated) {
857
				// check reference 
858
				if (rel.getReference().equals(decision)) {
859
					// replace reference
860
					rel.setReference(goal);
861
				}
862
				
863
				// check target
864
				if (rel.getTarget().equals(decision)) {
865
					// replace target
866
					rel.setTarget(goal);
867
				}
868
			}
869
		}
870
		
871
		// get feasibility flag
872
		return feasible;
873
	}
874
	
875
	/**