use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class SingleVariableConstraint method satisfiability.
/**
* Returns the satisfiability of this single-variable constraint under a context and context,
* or null if there is no appropriate solver.
* @param context
* @return
*/
default default Expression satisfiability(Context context) {
ExpressionLiteralSplitterStepSolver satisfiabilityStepSolver = getTheory().getSingleVariableConstraintSatisfiabilityStepSolver(this, context);
Expression satisfiability;
if (satisfiabilityStepSolver != null) {
satisfiability = satisfiabilityStepSolver.solve(context);
} else {
satisfiability = null;
}
return satisfiability;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class Examples method RealCancerModel.
public static VariableComponent RealCancerModel(Set<Expression> condition) {
// https://qph.ec.quoracdn.net/main-qimg-17c53810d49f6e917af93e576a9ec8da
Expression visitToAsia = DefaultSymbol.createSymbol("VisitToAsia");
Expression tuberculosis = DefaultSymbol.createSymbol("Tuberculosis");
Expression lungCancer = DefaultSymbol.createSymbol("LungCancer");
Expression lungCancerOrTuberculosis = DefaultSymbol.createSymbol("LungCancerOrTuberculosis");
Expression positiveXRay = DefaultSymbol.createSymbol("PositiveXRay");
Expression dispnea = DefaultSymbol.createSymbol("Dispnea");
Expression bronchitis = DefaultSymbol.createSymbol("Bronchitis");
Expression smoker = DefaultSymbol.createSymbol("Smoker");
Expression probabilityVisitToAsia = IfThenElse.make(visitToAsia, parse("0.01"), parse("0.99"));
Expression probabilitySmoker = IfThenElse.make(smoker, parse("0.5"), parse("0.5"));
Expression f1 = IfThenElse.make(visitToAsia, IfThenElse.make(tuberculosis, parse("0.05"), parse("0.95")), IfThenElse.make(tuberculosis, parse("0.01"), parse("0.99")));
Expression f2 = IfThenElse.make(smoker, IfThenElse.make(lungCancer, parse("0.1"), parse("0.9")), IfThenElse.make(lungCancer, parse("0.01"), parse("0.99")));
Expression f3 = IfThenElse.make(smoker, IfThenElse.make(bronchitis, parse("0.6"), parse("0.4")), IfThenElse.make(bronchitis, parse("0.3"), parse("0.7")));
Expression f4 = IfThenElse.make(lungCancerOrTuberculosis, IfThenElse.make(positiveXRay, parse("0.98"), parse("0.02")), IfThenElse.make(positiveXRay, parse("0.05"), parse("0.95")));
Expression f5 = IfThenElse.make(lungCancerOrTuberculosis, IfThenElse.make(lungCancer, parse("1"), IfThenElse.make(tuberculosis, parse("1"), parse("0"))), IfThenElse.make(lungCancer, parse("0"), IfThenElse.make(tuberculosis, parse("0"), parse("1"))));
Expression f6 = IfThenElse.make(lungCancerOrTuberculosis, IfThenElse.make(bronchitis, IfThenElse.make(dispnea, parse("0.9"), parse("0.1")), IfThenElse.make(dispnea, parse("0.7"), parse("0.3"))), IfThenElse.make(bronchitis, IfThenElse.make(dispnea, parse("0.8"), parse("0.2")), IfThenElse.make(dispnea, parse("0.1"), parse("0.9"))));
Set<Expression> Factor = new HashSet<Expression>();
Factor.add(f1);
Factor.add(f2);
Factor.add(f3);
Factor.add(f4);
Factor.add(f5);
Factor.add(f6);
Factor.add(probabilityVisitToAsia);
Factor.add(probabilitySmoker);
Model m = new Model(Factor);
m.addConditions(condition);
VariableComponent ComponentResultat = new VariableComponent(lungCancer, DefaultSymbol.createSymbol(""), m, new HashSet<Expression>());
return ComponentResultat;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class Examples method TriangleModel.
public static VariableComponent TriangleModel() {
Expression func = DefaultSymbol.createSymbol("f");
Expression a = DefaultSymbol.createSymbol("A");
Expression b = DefaultSymbol.createSymbol("B");
Expression q = DefaultSymbol.createSymbol("Q");
Expression f1 = apply(IF_THEN_ELSE, a, q, 5);
Expression f2 = apply(IF_THEN_ELSE, b, q, 5);
Expression f3 = apply(IF_THEN_ELSE, a, b, 5);
Expression res = apply(func, q);
Set<Expression> Factor = new HashSet<Expression>();
Factor.add(f1);
Factor.add(f2);
Factor.add(f3);
Factor.add(res);
Model m = new Model(Factor);
VariableComponent ComponentResultat = new VariableComponent(q, res, m, new HashSet<Expression>());
return ComponentResultat;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class TrueContext method add.
@Override
public TrueContext add(Type type) {
TrueContext result = clone();
String name = type.getName();
Expression typeExpression = parse(name);
LinkedHashMap<Expression, Type> additionalTypeMap = map(typeExpression, type);
result.fromTypeExpressionToType = new StackedHashMap<>(additionalTypeMap, fromTypeExpressionToType);
return result;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableConstraint method computeInnerExpressionIfNotContradiction.
@Override
protected Expression computeInnerExpressionIfNotContradiction() {
List<Expression> conjuncts = list();
conjuncts.addAll(positiveNormalizedAtoms);
Util.mapIntoList(negativeNormalizedAtoms, n -> fromNormalizedAtomToItsNegationAsLiteral(n), conjuncts);
conjuncts.addAll(externalLiterals);
Expression result = And.make(conjuncts);
return result;
}
Aggregations