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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations