Search in sources :

Example 6 with DefaultExtensionalUniSet

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

the class VariableComponent method chooseDepthImportantFirst.

public int chooseDepthImportantFirst() {
    Expression min = parse("{ 1 }");
    Integer jToReturn = 0;
    for (int j = 0; j < this.children.size(); j++) {
        if (!this.children.get(j).entirelyDiscover) {
            Set<Expression> toMultiply = this.model.getNeighbors(this.children.get(j).phi);
            toMultiply.removeAll(this.children.get(j).parent);
            DefaultExtensionalUniSet varToMultiply = new DefaultExtensionalUniSet(new ArrayList<>(toMultiply));
            IndexExpressionsSet indices = getIndexExpressionsOfFreeVariablesIn(varToMultiply, this.model.context);
            // TODO Find a way to do : intersection (variablesToBeSummedOut, FreeVariables(phi))
            Expression setOfFactorInstantiations = IntensionalSet.makeMultiSet(indices, // head
            Bounds.normalizeSingleExpression(this.children.get(j).phi, this.model.theory, this.model.context), // No Condition
            makeSymbol(true));
            Expression firstProduct = apply(TIMES, setOfFactorInstantiations);
            Expression evaluation = this.model.theory.evaluate(firstProduct, this.model.context);
            DefaultExtensionalUniSet varToSum = new DefaultExtensionalUniSet(new ArrayList<>(this.children.get(j).parent));
            indices = getIndexExpressionsOfFreeVariablesIn(varToSum, this.model.context);
            setOfFactorInstantiations = IntensionalSet.makeMultiSet(indices, // head
            evaluation, // No Condition
            makeSymbol(true));
            Expression sumOnPhi = apply(SUM, setOfFactorInstantiations);
            evaluation = this.model.theory.evaluate(sumOnPhi, this.model.context);
            if (evaluation.compareTo(min) < 0) {
                min = evaluation;
                jToReturn = j;
            }
        }
    }
    return jToReturn;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Example 7 with DefaultExtensionalUniSet

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

the class VariableComponent method calculateBound.

public void calculateBound() {
    Theory theory = this.model.theory;
    Context context = this.model.context;
    // Expression childrenBound = parse("{ 1 }");
    // for (FactorComponent children : this.children) {
    // childrenBound = Bounds.boundProduct(theory, context, childrenBound, children.bound);
    // }
    Bound[] childrenArray = new Bound[children.size()];
    int i = 0;
    for (FactorComponent children : this.children) {
        childrenArray[i] = children.bound;
        i++;
    }
    Bound childrenBound;
    if (childrenArray.length != 0) {
        childrenBound = Bounds.boundProduct(this.model.theory, this.model.context, isExtensionalBound, childrenArray);
    } else {
        childrenBound = Bounds.makeSingleElementBound(makeSymbol(1), isExtensionalBound);
    }
    Iterator<Expression> iteratorToVariables = this.cutsetInsideSubModel.iterator();
    ArrayList<Expression> variablesToBeSummedOut = new ArrayList<>(this.cutsetInsideSubModel.size());
    for (Expression var : Util.in(iteratorToVariables)) {
        variablesToBeSummedOut.add(var);
    }
    // We want sum other toSum of Phi*childrenBound
    DefaultExtensionalUniSet varToSum = new DefaultExtensionalUniSet(variablesToBeSummedOut);
    bound = childrenBound.summingBound(varToSum, context, theory);
}
Also used : Context(com.sri.ai.grinder.api.Context) Theory(com.sri.ai.grinder.api.Theory) Expression(com.sri.ai.expresso.api.Expression) Bound(com.sri.ai.grinder.library.bounds.Bound) ArrayList(java.util.ArrayList) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Example 8 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)

Example 9 with DefaultExtensionalUniSet

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

the class Bounds method updateExtremes.

/**
	 * Eliminate factors not in Ext(C.Hull(B)) 
	 * @param B
	 * @return 
	 */
private static Expression updateExtremes(Expression B, Theory theory, Context context) {
    List<Expression> listOfB = getElements(B);
    ArrayList<Expression> elements = new ArrayList<>(listOfB.size());
    int indexPhi = 0;
    for (Expression phi : listOfB) {
        if (isExtremePoint(phi, indexPhi, B, theory, context)) {
            elements.add(phi);
        }
        indexPhi++;
    }
    DefaultExtensionalUniSet result = new DefaultExtensionalUniSet(elements);
    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 10 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)

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