Search in sources :

Example 1 with DefaultExtensionalUniSet

use of com.sri.ai.expresso.core.DefaultExtensionalUniSet in project aic-expresso by aic-sri-international.

the class IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver method getSolutionExpressionForBoundVariable.

@Override
public Expression getSolutionExpressionForBoundVariable() {
    Expression oneOfTheVariableValues = getFirst(getEquals());
    DefaultExtensionalUniSet result = new DefaultExtensionalUniSet(oneOfTheVariableValues);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Example 2 with DefaultExtensionalUniSet

use of com.sri.ai.expresso.core.DefaultExtensionalUniSet in project aic-expresso by aic-sri-international.

the class Bounds method simplex.

public static Expression simplex(List<Expression> Variables, Model model) {
    ArrayList<Expression> simplexList = new ArrayList<>();
    Expression one = makeSymbol("1");
    Expression zero = makeSymbol("0");
    for (Expression var : Variables) {
        //TODO getValues should return the right
        Expression values = parse(model.getValues(var));
        //Expression rather than a string to be parsed.
        //By the way, that expression should represent a UniSet 
        List<Expression> listOfValues = getElements(values);
        for (Expression value : listOfValues) {
            simplexList.add(apply(IF_THEN_ELSE, apply(EQUAL, var, value), one, zero));
        }
    //simplexList.add(apply(IF_THEN_ELSE, apply(EQUAL, var, true ), one, zero));
    //simplexList.add(apply(IF_THEN_ELSE, apply(EQUAL, var, false), one, zero));
    }
    Expression result = new DefaultExtensionalUniSet(simplexList);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Example 3 with DefaultExtensionalUniSet

use of com.sri.ai.expresso.core.DefaultExtensionalUniSet in project aic-expresso by aic-sri-international.

the class Bounds method applyFunctionToBound.

/*public static Expression boundProduct(Theory theory, Context context, Expression...listOfBounds){
		if(listOfBounds.length == 0){ 
			return null;
		}
		
		Expression result= boundProduct (0, theory, context, listOfBounds);
		return result;
	}

	private static Expression boundProduct(int i,  Theory theory, Context context, Expression...listOfBounds){
		if(listOfBounds.length - 1 == i){
			return listOfBounds[i];
		}
		
		Expression productOfOthers = boundProduct(i + 1, theory, context, listOfBounds);
		Expression b = listOfBounds[i];

		List<Expression> listOfb = ExtensionalSet.getElements(b);
		List<Expression> listOfProductOfOthers = ExtensionalSet.getElements(productOfOthers);
		
		ArrayList<Expression> elements = new ArrayList<>(listOfb.size()*listOfProductOfOthers.size());
		
		for (Expression phi1 : listOfb){
			for (Expression phi2 : listOfProductOfOthers){
				Expression product = apply("*",phi1,phi2);
				Expression evaluation = theory.evaluate(product,context);
				elements.add(evaluation);
			}
		}
		
		DefaultExtensionalUniSet productBound = new DefaultExtensionalUniSet(elements);
		//Updating extreme points
		Expression result = updateExtremes(productBound,theory,context);
		return result;
	}*/
/**
	 * apply a function (f) to each term of a bound (b) 
	 * @param f 
	 * 			function to be applied to the factors
	 * @param variableName
	 * 			The variable in f to be replaced by phi (for each phi in b). 
	 * 			If if is a function of the variable v, VariableName is v
	 * @param b
	 * 			Bound
	 * @param theory
	 * @param context
	 * @return {f(\phi) : \phi \in b}
	 */
public static Expression applyFunctionToBound(Expression f, Expression variableName, Expression b, Theory theory, Context context) {
    ExtensionalSet bAsExtensionalSet = (ExtensionalSet) b;
    int numberOfExtremes = bAsExtensionalSet.getArguments().size();
    ArrayList<Expression> elements = new ArrayList<>(numberOfExtremes);
    for (Expression phi : ExtensionalSets.getElements(bAsExtensionalSet)) {
        Expression substitution = f.replaceAllOccurrences(variableName, phi, context);
        //debuging
        if (debug)
            println("evaluating: " + substitution);
        // problem in evaluation method...
        Expression evaluation = theory.evaluate(substitution, context);
        //debuging
        if (debug)
            println("result: " + evaluation);
        elements.add(evaluation);
    }
    DefaultExtensionalUniSet fOfb = new DefaultExtensionalUniSet(elements);
    //Updating extreme points
    Expression result = updateExtremes(fOfb, theory, context);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) ExtensionalSet(com.sri.ai.expresso.api.ExtensionalSet) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Example 4 with DefaultExtensionalUniSet

use of com.sri.ai.expresso.core.DefaultExtensionalUniSet in project aic-expresso by aic-sri-international.

the class Bounds method boundProduct.

/**
	 * Computes the product of each term of a list of bounds
	 * @param theory
	 * @param context
	 * @param listOfBounds
	 * @return bound resulting from the product of bounds
	 */
public static Expression boundProduct(Theory theory, Context context, Expression... listOfBounds) {
    ArrayList<NullaryFunction<Iterator<Expression>>> iteratorForBoundList = mapIntoArrayList(listOfBounds, bound -> () -> getElements(bound).iterator());
    Iterator<ArrayList<Expression>> cartesianProduct = new CartesianProductIterator<Expression>(iteratorForBoundList);
    ArrayList<Expression> resultList = new ArrayList<>();
    for (ArrayList<Expression> element : in(cartesianProduct)) {
        Expression product = apply("*", element);
        Expression evaluation = theory.evaluate(product, context);
        resultList.add(evaluation);
    }
    Expression result = new DefaultExtensionalUniSet(resultList);
    // Updating extreme points
    result = updateExtremes(result, theory, context);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) NullaryFunction(com.sri.ai.util.base.NullaryFunction) CartesianProductIterator(com.sri.ai.util.collect.CartesianProductIterator) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Example 5 with DefaultExtensionalUniSet

use of com.sri.ai.expresso.core.DefaultExtensionalUniSet in project aic-expresso by aic-sri-international.

the class DistinctExpressionsStepSolver method makeSolution.

/**
 * @param distinctValuesList
 * @return
 */
private Solution makeSolution(List<Expression> distinctValuesList) {
    ArrayList<Expression> arrayList = new ArrayList<>(distinctValuesList);
    DefaultExtensionalUniSet set = new DefaultExtensionalUniSet(arrayList);
    Solution result = new Solution(set);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)13 DefaultExtensionalUniSet (com.sri.ai.expresso.core.DefaultExtensionalUniSet)13 ArrayList (java.util.ArrayList)8 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)4 Context (com.sri.ai.grinder.api.Context)2 Theory (com.sri.ai.grinder.api.Theory)2 Bound (com.sri.ai.grinder.library.bounds.Bound)2 ExtensionalSet (com.sri.ai.expresso.api.ExtensionalSet)1 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)1 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)1 DefaultLambdaExpression (com.sri.ai.expresso.core.DefaultLambdaExpression)1 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)1 IndexExpressions (com.sri.ai.grinder.library.indexexpression.IndexExpressions)1 NullaryFunction (com.sri.ai.util.base.NullaryFunction)1 CartesianProductIterator (com.sri.ai.util.collect.CartesianProductIterator)1 Collection (java.util.Collection)1