leaf-analysis/src/simulation/CSPIntentions.java
/**
	 *  Creates the dynamic function constraints for the full path.
	 *  NotBoth constraints created at the end of the function.
	 */
Creates the dynamic function constraints for the full path.
NotBoth constraints created at the end of the function.
Creates the dynamic function constraints for the full path . NotBoth constraints created at the end of the function .
public static void initializeEvolvingFunctionsForIntentions(
			List<Constraint> constraints, ModelSpec spec,  
			BooleanVar[][][] values, HashMap<String, Integer> uniqueIDToValueIndex,
			IntVar[] timePoints, HashMap<IntVar, List<String>> timePointMap,
			IntVar infinity) {
    	for (Intention element : spec.getIntentions()){
    		if (Main.DEBUG) System.out.println("Evolving Intention for " + element.id);
    		Integer i = uniqueIDToValueIndex.get(element.getUniqueID());
    		FunctionSegment[] segList = element.getEvolvingFunctions();
    		if (i == null || segList == null) continue;
    		for (int f = 0; f < segList.length; f++) {
    			FunctionSegment seg = segList[f];
    			if (Main.DEBUG) System.out.println(seg.getType() + "\t" + seg.getStartTP() + "\t" + seg.getRefEvidencePair());
    			if (seg.getType().equals("R"))
    				continue;
    			IntVar segmentStart = CSPPath.getTimePoint(timePointMap, seg.getStartTP());
				IntVar segmentEnd = null;
				if (f == (segList.length - 1))
					segmentEnd = infinity;
				else
					segmentEnd = CSPPath.getTimePoint(timePointMap, segList[f+1].getStartTP());
				boolean[] refEvidence = convertEvalStringToEvidencePredicates(seg.getRefEvidencePair());	
				switch (seg.getType()) {
				case "C":	
					for (int t = 0; t < values[i].length; t++){
						PrimitiveConstraint[] tempConstant = createXeqC(values[i][t], refEvidence);
						constraints.add(new IfThen(
								new And(new XlteqY(segmentStart, timePoints[t]), new XgtY(segmentEnd, timePoints[t])),
								new And(tempConstant)));
					}
					break;
				case "I":	
	    			for (int t = 0; t < values[i].length; t++){
	    				for (int s = 0; s < values[i].length; s++){
	    					if (t==s)
	    						continue;
	                		PrimitiveConstraint timeCondition = new And(new XltY(timePoints[t], timePoints[s]),
                					new And(new And(new XlteqY(segmentStart, timePoints[t]), new XgtY(segmentEnd, timePoints[t])),
                							new And(new XlteqY(segmentStart, timePoints[s]), new XgtY(segmentEnd, timePoints[s]))));
	    					initializePathIncreaseHelper(constraints, values, i, t, s, timeCondition, false);
	    				}
                		PrimitiveConstraint timeCondition = new And(new XlteqY(segmentStart, timePoints[t]), new XgtY(segmentEnd, timePoints[t]));
	    				initializePathIncreaseMaxValueHelper(constraints, values, i, t, refEvidence, timeCondition);
	    			}
					break;
				case "D":	
					for (int t = 0; t < values[i].length; t++){
	        			for (int s = 0; s < values[i].length; s++){
	        				if (t==s)
	        					continue;
	                		PrimitiveConstraint timeCondition = new And(new XltY(timePoints[t], timePoints[s]),
                					new And(new And(new XlteqY(segmentStart, timePoints[t]), new XgtY(segmentEnd, timePoints[t])),
                							new And(new XlteqY(segmentStart, timePoints[s]), new XgtY(segmentEnd, timePoints[s]))));
	        				initializePathDecreaseHelper(constraints, values, i, t, s, timeCondition, false);
	        			}
                		PrimitiveConstraint timeCondition = new And(new XlteqY(segmentStart, timePoints[t]), new XgtY(segmentEnd, timePoints[t]));
        				initializePathDecreaseMaxValueHelper(constraints, values, i, t, refEvidence, timeCondition);
	        		}
					break;
				default:
					throw new RuntimeException("CSPIntentions: initializeEvolvingFunctionsForIntentions - unknown function segment.");
				}	
    		}    		
    	}
	}
public static void initializeEvolvingFunctionsForIntentions ( List < Constraint > constraints , ModelSpec spec , BooleanVar [ ] [ ] [ ] values , HashMap < String , Integer > uniqueIDToValueIndex , IntVar [ ] timePoints , HashMap < IntVar , List < String > > timePointMap , IntVar infinity ) { for ( Intention element : spec . getIntentions ( ) ) { if ( Main . DEBUG ) System . out . println ( "Evolving Intention for " + element . id ) ; Integer i = uniqueIDToValueIndex . get ( element . getUniqueID ( ) ) ; FunctionSegment [ ] segList = element . getEvolvingFunctions ( ) ; if ( i == null || segList == null ) continue ; for ( int f = 0 ; f < segList . length ; f ++ ) { FunctionSegment seg = segList [ f ] ; if ( Main . DEBUG ) System . out . println ( seg . getType ( ) + "\t" + seg . getStartTP ( ) + "\t" + seg . getRefEvidencePair ( ) ) ; if ( seg . getType ( ) . equals ( "R" ) ) continue ; IntVar segmentStart = CSPPath . getTimePoint ( timePointMap , seg . getStartTP ( ) ) ; IntVar segmentEnd = null ; if ( f == ( segList . length - 1 ) ) segmentEnd = infinity ; else segmentEnd = CSPPath . getTimePoint ( timePointMap , segList [ f + 1 ] . getStartTP ( ) ) ; boolean [ ] refEvidence = convertEvalStringToEvidencePredicates ( seg . getRefEvidencePair ( ) ) ; switch ( seg . getType ( ) ) { case "C" : for ( int t = 0 ; t < values [ i ] . length ; t ++ ) { PrimitiveConstraint [ ] tempConstant = createXeqC ( values [ i ] [ t ] , refEvidence ) ; constraints . add ( new IfThen ( new And ( new XlteqY ( segmentStart , timePoints [ t ] ) , new XgtY ( segmentEnd , timePoints [ t ] ) ) , new And ( tempConstant ) ) ) ; } break ; case "I" : for ( int t = 0 ; t < values [ i ] . length ; t ++ ) { for ( int s = 0 ; s < values [ i ] . length ; s ++ ) { if ( t == s ) continue ; PrimitiveConstraint timeCondition = new And ( new XltY ( timePoints [ t ] , timePoints [ s ] ) , new And ( new And ( new XlteqY ( segmentStart , timePoints [ t ] ) , new XgtY ( segmentEnd , timePoints [ t ] ) ) , new And ( new XlteqY ( segmentStart , timePoints [ s ] ) , new XgtY ( segmentEnd , timePoints [ s ] ) ) ) ) ; initializePathIncreaseHelper ( constraints , values , i , t , s , timeCondition , false ) ; } PrimitiveConstraint timeCondition = new And ( new XlteqY ( segmentStart , timePoints [ t ] ) , new XgtY ( segmentEnd , timePoints [ t ] ) ) ; initializePathIncreaseMaxValueHelper ( constraints , values , i , t , refEvidence , timeCondition ) ; } break ; case "D" : for ( int t = 0 ; t < values [ i ] . length ; t ++ ) { for ( int s = 0 ; s < values [ i ] . length ; s ++ ) { if ( t == s ) continue ; PrimitiveConstraint timeCondition = new And ( new XltY ( timePoints [ t ] , timePoints [ s ] ) , new And ( new And ( new XlteqY ( segmentStart , timePoints [ t ] ) , new XgtY ( segmentEnd , timePoints [ t ] ) ) , new And ( new XlteqY ( segmentStart , timePoints [ s ] ) , new XgtY ( segmentEnd , timePoints [ s ] ) ) ) ) ; initializePathDecreaseHelper ( constraints , values , i , t , s , timeCondition , false ) ; } PrimitiveConstraint timeCondition = new And ( new XlteqY ( segmentStart , timePoints [ t ] ) , new XgtY ( segmentEnd , timePoints [ t ] ) ) ; initializePathDecreaseMaxValueHelper ( constraints , values , i , t , refEvidence , timeCondition ) ; } break ; default : throw new RuntimeException ( "CSPIntentions: initializeEvolvingFunctionsForIntentions - unknown function segment." ) ; } } } }
Creates the dynamic function constraints for the full path.
Creates the dynamic function constraints for the full path .
// CONSTANT //INCREASING //DECREASING