use of com.sri.ai.expresso.core.DefaultExistentiallyQuantifiedFormula in project aic-expresso by aic-sri-international.
the class DefaultExtensionalBound method isExtremePoint.
/**
* Checks if \phi is a convex combination of the elements in bound
* @param phi
* factor
* @param bound
* @return
*/
public static boolean isExtremePoint(Expression phi, int indexPhi, Bound bound, Theory theory, Context context) {
// TODO
// caro pq recopia a lista toda
Expression boundWithoutPhi = removeNonDestructively(bound, indexPhi);
List<Expression> listOfB = getElements(boundWithoutPhi);
int n = listOfB.size();
Expression[] c = new Expression[n];
for (int i = 0; i < n; i++) {
c[i] = makeSymbol("C_" + i);
context = context.extendWithSymbolsAndTypes("C_" + i, "Real");
}
// 0<=ci<=1
ArrayList<Expression> listOfC = new ArrayList<>(listOfB.size());
for (int i = 0; i < n; i++) {
Expression cibetwen0And1 = apply(AND, apply(GREATER_THAN_OR_EQUAL_TO, 1, c[i]), apply(GREATER_THAN_OR_EQUAL_TO, c[i], 0));
listOfC.add(cibetwen0And1);
}
Expression allcibetwen0And1 = apply(AND, listOfC);
// sum over ci =1
listOfC = new ArrayList<>(Arrays.asList(c));
Expression sumOverCiEqualsOne = apply(EQUAL, 1, apply(PLUS, listOfC));
// sum of ci*phi1 = phi
ArrayList<Expression> prodciphii = new ArrayList<>(listOfB.size());
int i = 0;
for (Expression phii : listOfB) {
prodciphii.add(apply(TIMES, phii, c[i]));
i++;
}
Expression convexSum = apply(EQUAL, phi, apply(PLUS, prodciphii));
// (there exists) ci in Real
ArrayList<Expression> listOfCiInReal = new ArrayList<>(listOfB.size());
for (i = 0; i < n; i++) {
listOfCiInReal.add(apply(IN, c[i], "Real"));
context = context.extendWithSymbolsAndTypes(c[i], parse("Real"));
}
IndexExpressionsSet thereExistsCiInReal = new ExtensionalIndexExpressionsSet(listOfCiInReal);
// (for all) variables in their domains
IndexExpressionsSet forAllVariablesEvaluations = getIndexExpressionsOfFreeVariablesIn(bound, context);
Expression body = apply(AND, allcibetwen0And1, sumOverCiEqualsOne, convexSum);
Expression isExtreme = new DefaultExistentiallyQuantifiedFormula(thereExistsCiInReal, body);
isExtreme = new DefaultUniversallyQuantifiedFormula(forAllVariablesEvaluations, isExtreme);
// println(isExtreme);
Expression result = theory.evaluate(isExtreme, context);
return !result.booleanValue();
}
Aggregations