Search in sources :

Example 16 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class IntersectionExtensionalSetSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval intType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("M", intType.toString(), "N", intType.toString()), Arrays.asList(intType), context);
    simplifier = new IntersectionExtensionalSetSimplifier();
}
Also used : IntersectionExtensionalSetSimplifier(com.sri.ai.grinder.sgdpllt.library.set.invsupport.IntersectionExtensionalSetSimplifier) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) TupleTheory(com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory) Before(org.junit.Before)

Example 17 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class InversionSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    FunctionType gFunctionType = new FunctionType(new IntegerInterval("1..10"), new IntegerInterval("1..10"));
    context = (Context) GrinderUtil.extendRegistryWith(map("g", gFunctionType.toString()), Arrays.asList(gFunctionType), context);
    simplifier = new InversionSimplifier();
}
Also used : InversionSimplifier(com.sri.ai.grinder.sgdpllt.library.set.invsupport.InversionSimplifier) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) FunctionType(com.sri.ai.expresso.type.FunctionType) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) TupleTheory(com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory) Before(org.junit.Before)

Example 18 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class DistributeIntersectionOverUnionSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval intType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("M", intType.toString(), "N", intType.toString()), Arrays.asList(intType), context);
    simplifier = new DistributeIntersectionOverUnionSimplifier();
}
Also used : DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) DistributeIntersectionOverUnionSimplifier(com.sri.ai.grinder.sgdpllt.library.set.invsupport.DistributeIntersectionOverUnionSimplifier) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) TupleTheory(com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory) Before(org.junit.Before)

Example 19 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas.

@Test
public void testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    // using different testing variables and types to test distribution of testing information
    // to sub constraint theories.
    Categorical booleanType = BOOLEAN_TYPE;
    Categorical dogsType = new Categorical("Dogs", 4, arrayList(parse("fido"), parse("rex")));
    IntegerInterval oneTwoThree = new IntegerInterval(1, 3);
    Map<String, Type> variablesAndTypes = map("F", booleanType, "G", booleanType, "R", dogsType, "S", dogsType, "T", oneTwoThree, "U", oneTwoThree);
    theoryTestingSupport.setVariableNamesAndTypesForTesting(variablesAndTypes);
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) Categorical(com.sri.ai.expresso.type.Categorical) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) Test(org.junit.Test)

Example 20 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-praise by aic-sri-international.

the class UAIMARSolver method main.

public static void main(String[] args) throws IOException {
    if (args.length != 4) {
        throw new IllegalArgumentException("Usage: UAIMARSolver <file or directory with UAI-format files> <solution directory> <timeout in ms> equalities|difference_arithmetic");
    }
    File uaiInput = new File(args[0]);
    if (!uaiInput.exists()) {
        throw new IllegalArgumentException("File or directory specified does not exist: " + uaiInput.getAbsolutePath());
    }
    File solutionDir = new File(args[1]);
    if (!solutionDir.exists() || !solutionDir.isDirectory()) {
        throw new IllegalArgumentException("Solution directory is invalid: " + solutionDir.getAbsolutePath());
    }
    int maxSolverTimeInSeconds = Integer.parseInt(args[2]);
    Theory theory;
    if (args[3].equals("equalities")) {
        theory = new CompoundTheory(new PropositionalTheory(), new EqualityTheory(true, true));
    } else if (args[3].equals("difference_arithmetic")) {
        theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(true, true));
    } else {
        throw new IllegalArgumentException("4-th argument must be either 'equalities' or 'difference_arithmetic'");
    }
    List<UAIModel> models = new ArrayList<>();
    Map<UAIModel, File> modelToFile = new HashMap<>();
    if (uaiInput.isDirectory()) {
        for (File uaiFile : uaiInput.listFiles((dir, name) -> name.endsWith(".uai"))) {
            UAIModel model = read(uaiFile, solutionDir);
            models.add(model);
            modelToFile.put(model, uaiFile);
        }
    } else {
        UAIModel model = read(uaiInput, solutionDir);
        models.add(model);
        modelToFile.put(model, uaiInput);
    }
    // Sort based on what we consider to be the simplest to hardest
    //Collections.sort(models, (model1, model2) -> Double.compare(model1.ratioUniqueTablesToTables(), model2.ratioUniqueTablesToTables()));
    //Collections.sort(models, (model1, model2) -> Integer.compare(model1.largestNumberOfFunctionTableEntries(), model2.largestNumberOfFunctionTableEntries()));
    Collections.sort(models, (model1, model2) -> Integer.compare(model1.totalNumberEntriesForAllFunctionTables(), model2.totalNumberEntriesForAllFunctionTables()));
    //Collections.sort(models, (model1, model2) -> Integer.compare(model1.numberTables(), model2.numberTables()));
    Map<String, Boolean> modelSolvedStatus = new LinkedHashMap<>();
    Map<String, Long> modelSolvedTime = new LinkedHashMap<>();
    System.out.println("#models read=" + models.size());
    final AtomicInteger cnt = new AtomicInteger(1);
    models.stream().forEach(model -> {
        System.out.println("Starting to Solve: " + modelToFile.get(model).getName() + " (" + cnt.getAndAdd(1) + " of " + models.size() + ")");
        long start = System.currentTimeMillis();
        boolean solved = solve(model, model.getEvidence(), model.getMARSolution(), maxSolverTimeInSeconds, theory);
        long took = (System.currentTimeMillis() - start);
        System.out.println("---- Took " + took + "ms. solved=" + solved);
        modelSolvedStatus.put(modelToFile.get(model).getName(), solved);
        modelSolvedTime.put(modelToFile.get(model).getName(), took);
    });
    System.out.println("MODELS SOLVE STATUS");
    modelSolvedStatus.entrySet().stream().forEach(e -> System.out.printf("%-25s %-5b %12sms.\n", e.getKey(), e.getValue(), modelSolvedTime.get(e.getKey())));
    System.out.println("SUMMARY");
    System.out.println("#models   solved=" + modelSolvedStatus.values().stream().filter(status -> status == true).count());
    System.out.println("#models unsolved=" + modelSolvedStatus.values().stream().filter(status -> status == false).count());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) MultiIndexQuantifierEliminator(com.sri.ai.grinder.sgdpllt.api.MultiIndexQuantifierEliminator) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) Expressions(com.sri.ai.expresso.helper.Expressions) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Expression(com.sri.ai.expresso.api.Expression) FactorsAndTypes(com.sri.ai.praise.sgsolver.solver.FactorsAndTypes) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Future(java.util.concurrent.Future) Not(com.sri.ai.grinder.sgdpllt.library.boole.Not) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InferenceForFactorGraphAndEvidence(com.sri.ai.praise.sgsolver.solver.InferenceForFactorGraphAndEvidence) UAIUtil.convertGenericTableToInstance(com.sri.ai.praise.model.v1.imports.uai.UAIUtil.convertGenericTableToInstance) Map(java.util.Map) And(com.sri.ai.grinder.sgdpllt.library.boole.And) Division(com.sri.ai.grinder.sgdpllt.library.number.Division) ExecutorService(java.util.concurrent.ExecutorService) Equality(com.sri.ai.grinder.sgdpllt.library.Equality) IOException(java.io.IOException) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Collectors(java.util.stream.Collectors) IfThenElse(com.sri.ai.grinder.sgdpllt.library.controlflow.IfThenElse) File(java.io.File) Executors(java.util.concurrent.Executors) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) Beta(com.google.common.annotations.Beta) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) GraphicalNetwork(com.sri.ai.praise.lang.grounded.common.GraphicalNetwork) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) UAIUtil.constructGenericTableExpressionUsingEqualities(com.sri.ai.praise.model.v1.imports.uai.UAIUtil.constructGenericTableExpressionUsingEqualities) FunctionTable(com.sri.ai.praise.lang.grounded.common.FunctionTable) Collections(java.util.Collections) FunctorConstants(com.sri.ai.grinder.sgdpllt.library.FunctorConstants) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) ArrayList(java.util.ArrayList) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) LinkedHashMap(java.util.LinkedHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File)

Aggregations

DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)46 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)34 Context (com.sri.ai.grinder.sgdpllt.api.Context)28 Expression (com.sri.ai.expresso.api.Expression)25 Test (org.junit.Test)25 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)24 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)23 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)22 EqualityTheory (com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory)20 TupleTheory (com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory)16 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)15 Before (org.junit.Before)11 Type (com.sri.ai.expresso.api.Type)8 LinearRealArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory)8 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)7 FunctionType (com.sri.ai.expresso.type.FunctionType)5 LinkedHashMap (java.util.LinkedHashMap)5 StepSolver (com.sri.ai.grinder.sgdpllt.api.StepSolver)4 Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)4 Categorical (com.sri.ai.expresso.type.Categorical)3