Search in sources :

Example 6 with AssignmentMapsIterator

use of com.sri.ai.grinder.helper.AssignmentMapsIterator in project aic-expresso by aic-sri-international.

the class AssignmentsIteratorTest method test3.

@Test
public void test3() {
    Registry registry = new DefaultRegistry();
    Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
    Type petsType = new Categorical("Pets", 3, arrayList(makeSymbol("fido"), makeSymbol("purrs")));
    Symbol x = makeSymbol("X");
    Symbol y = makeSymbol("Y");
    String expected = "{X=oscar, Y=fido}\n" + "{X=mary, Y=fido}\n" + "{X=people3, Y=fido}\n" + "{X=people4, Y=fido}\n" + "{X=oscar, Y=purrs}\n" + "{X=mary, Y=purrs}\n" + "{X=people3, Y=purrs}\n" + "{X=people4, Y=purrs}\n" + "{X=oscar, Y=pets3}\n" + "{X=mary, Y=pets3}\n" + "{X=people3, Y=pets3}\n" + "{X=people4, Y=pets3}";
    Symbol myPeopleTypeExpression = makeSymbol(peopleType.getName());
    Symbol myPetsTypeExpression = makeSymbol(petsType.getName());
    registry = registry.makeNewContextWithAddedType(peopleType);
    registry = registry.makeNewContextWithAddedType(petsType);
    registry = registry.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(x, myPeopleTypeExpression, y, myPetsTypeExpression));
    AssignmentMapsIterator assignmentsIterator = new AssignmentMapsIterator(list(x, y), registry);
    String actual = join("\n", assignmentsIterator);
    // System.out.println(actual);
    assertEquals(expected, actual);
}
Also used : AssignmentMapsIterator(com.sri.ai.grinder.helper.AssignmentMapsIterator) Type(com.sri.ai.expresso.api.Type) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Symbol(com.sri.ai.expresso.api.Symbol) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Registry(com.sri.ai.grinder.api.Registry) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 7 with AssignmentMapsIterator

use of com.sri.ai.grinder.helper.AssignmentMapsIterator in project aic-expresso by aic-sri-international.

the class AssignmentsIteratorTest method test2.

@Test
public void test2() {
    Registry registry = new DefaultRegistry();
    Type myType = new Categorical("People", 2, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
    Symbol x = makeSymbol("X");
    Symbol y = makeSymbol("Y");
    String expected = "{X=oscar, Y=oscar}\n" + "{X=mary, Y=oscar}\n" + "{X=oscar, Y=mary}\n" + "{X=mary, Y=mary}";
    Symbol myTypeExpression = makeSymbol(myType.getName());
    registry = registry.makeNewContextWithAddedType(myType);
    registry = registry.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(x, myTypeExpression, y, myTypeExpression));
    AssignmentMapsIterator assignmentsIterator = new AssignmentMapsIterator(list(x, y), registry);
    String actual = join("\n", assignmentsIterator);
    // System.out.println(actual);
    assertEquals(expected, actual);
}
Also used : AssignmentMapsIterator(com.sri.ai.grinder.helper.AssignmentMapsIterator) Type(com.sri.ai.expresso.api.Type) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Symbol(com.sri.ai.expresso.api.Symbol) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Registry(com.sri.ai.grinder.api.Registry) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 8 with AssignmentMapsIterator

use of com.sri.ai.grinder.helper.AssignmentMapsIterator in project aic-expresso by aic-sri-international.

the class SGDPLLTTester method bruteForceModelCounterForVariableGivenInterpreterAndAssignmentToOtherVariables.

private static Expression bruteForceModelCounterForVariableGivenInterpreterAndAssignmentToOtherVariables(Expression variable, Expression conjunction, BruteForceCommonInterpreter interpreter, Theory theory, Context context) {
    output("Computing model count by brute force of: " + conjunction);
    int modelCount = 0;
    Expression testingVariable = variable;
    AssignmentMapsIterator testingVariableAssignmentsIterator = new AssignmentMapsIterator(list(testingVariable), context);
    for (Map<Expression, Expression> testingVariableAssignment : in(testingVariableAssignmentsIterator)) {
        Context extendedContext = Assignment.extendAssignments(testingVariableAssignment, context);
        Expression value = interpreter.apply(conjunction, extendedContext);
        if (value.equals(TRUE)) {
            modelCount++;
        }
    // output("For " + completeInterpreter.getAssignment() + ",");
    // output("value is " + value);
    // output("Model count is " + modelCount + "\n");
    }
    return makeSymbol(modelCount);
}
Also used : Context(com.sri.ai.grinder.api.Context) AssignmentMapsIterator(com.sri.ai.grinder.helper.AssignmentMapsIterator) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) IncompleteMultiVariableConstraint(com.sri.ai.grinder.core.constraint.IncompleteMultiVariableConstraint) SingleVariableConstraint(com.sri.ai.grinder.api.SingleVariableConstraint) Constraint(com.sri.ai.grinder.api.Constraint)

Example 9 with AssignmentMapsIterator

use of com.sri.ai.grinder.helper.AssignmentMapsIterator in project aic-expresso by aic-sri-international.

the class AssignmentsIteratorTest method test1.

@Test
public void test1() {
    Registry registry = new DefaultRegistry();
    Type myType = new Categorical("People", 4, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
    Symbol x = makeSymbol("X");
    Symbol y = makeSymbol("Y");
    String expected = "{X=oscar, Y=oscar}\n" + "{X=mary, Y=oscar}\n" + "{X=people3, Y=oscar}\n" + "{X=people4, Y=oscar}\n" + "{X=oscar, Y=mary}\n" + "{X=mary, Y=mary}\n" + "{X=people3, Y=mary}\n" + "{X=people4, Y=mary}\n" + "{X=oscar, Y=people3}\n" + "{X=mary, Y=people3}\n" + "{X=people3, Y=people3}\n" + "{X=people4, Y=people3}\n" + "{X=oscar, Y=people4}\n" + "{X=mary, Y=people4}\n" + "{X=people3, Y=people4}\n" + "{X=people4, Y=people4}";
    Symbol myTypeExpression = makeSymbol(myType.getName());
    registry = registry.makeNewContextWithAddedType(myType);
    registry = registry.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(x, myTypeExpression, y, myTypeExpression));
    AssignmentMapsIterator assignmentsIterator = new AssignmentMapsIterator(list(x, y), registry);
    String actual = join("\n", assignmentsIterator);
    // System.out.println(actual);
    assertEquals(expected, actual);
}
Also used : AssignmentMapsIterator(com.sri.ai.grinder.helper.AssignmentMapsIterator) Type(com.sri.ai.expresso.api.Type) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Symbol(com.sri.ai.expresso.api.Symbol) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Registry(com.sri.ai.grinder.api.Registry) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Aggregations

AssignmentMapsIterator (com.sri.ai.grinder.helper.AssignmentMapsIterator)9 Expression (com.sri.ai.expresso.api.Expression)6 DefaultRegistry (com.sri.ai.grinder.core.DefaultRegistry)5 Symbol (com.sri.ai.expresso.api.Symbol)3 Type (com.sri.ai.expresso.api.Type)3 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)3 Categorical (com.sri.ai.expresso.type.Categorical)3 Registry (com.sri.ai.grinder.api.Registry)3 Test (org.junit.Test)3 Context (com.sri.ai.grinder.api.Context)2 LinkedHashMap (java.util.LinkedHashMap)2 StringJoiner (java.util.StringJoiner)2 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)1 Constraint (com.sri.ai.grinder.api.Constraint)1 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver)1 SingleQuantifierEliminationProblem (com.sri.ai.grinder.api.SingleQuantifierEliminationProblem)1 SingleVariableConstraint (com.sri.ai.grinder.api.SingleVariableConstraint)1 ContextSplitting (com.sri.ai.grinder.core.constraint.ContextSplitting)1 IncompleteMultiVariableConstraint (com.sri.ai.grinder.core.constraint.IncompleteMultiVariableConstraint)1 BruteForceCommonInterpreter (com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter)1