Search in sources :

Example 1 with RCEStrategy

use of kodkod.engine.ucore.RCEStrategy in project org.alloytools.alloy by AlloyTools.

the class A4Solution method solve.

// ===================================================================================================//
/**
 * Solve for the solution if not solved already; if cmd==null, we will simply
 * use the lowerbound of each relation as its value.
 */
A4Solution solve(final A4Reporter rep, Command cmd, Simplifier simp, boolean tryBookExamples) throws Err, IOException {
    // If already solved, then return this object as is
    if (solved)
        return this;
    // the lower bound of each relation
    if (cmd == null) {
        Instance inst = new Instance(bounds.universe());
        for (int max = max(), i = min(); i <= max; i++) {
            Tuple it = factory.tuple("" + i);
            inst.add(i, factory.range(it, it));
        }
        for (Relation r : bounds.relations()) inst.add(r, bounds.lowerBound(r));
        eval = new Evaluator(inst, solver.options());
        rename(this, null, null, new UniqueNameGenerator());
        solved();
        return this;
    }
    // Otherwise, prepare to do the solve...
    final A4Options opt = originalOptions;
    long time = System.currentTimeMillis();
    rep.debug("Simplifying the bounds...\n");
    if (opt.inferPartialInstance && simp != null && formulas.size() > 0 && !simp.simplify(rep, this, formulas))
        addFormula(Formula.FALSE, Pos.UNKNOWN);
    rep.translate(opt.solver.id(), bitwidth, maxseq, solver.options().skolemDepth(), solver.options().symmetryBreaking());
    Formula fgoal = Formula.and(formulas);
    rep.debug("Generating the solution...\n");
    kEnumerator = null;
    Solution sol = null;
    final Reporter oldReporter = solver.options().reporter();
    final boolean[] solved = new boolean[] { true };
    solver.options().setReporter(new // Set up a
    AbstractReporter() {

        // reporter to
        // catch the
        // type+pos of
        // skolems
        @Override
        public void skolemizing(Decl decl, Relation skolem, List<Decl> predecl) {
            try {
                Type t = kv2typepos(decl.variable()).a;
                if (t == Type.EMPTY)
                    return;
                for (int i = (predecl == null ? -1 : predecl.size() - 1); i >= 0; i--) {
                    Type pp = kv2typepos(predecl.get(i).variable()).a;
                    if (pp == Type.EMPTY)
                        return;
                    t = pp.product(t);
                }
                kr2type(skolem, t);
            }// Exception here is not fatal
             catch (Throwable ex) {
            }
        }

        @Override
        public void solvingCNF(int primaryVars, int vars, int clauses) {
            if (solved[0])
                return;
            else
                // initially solved[0] is true, so we
                solved[0] = true;
            // won't report the # of vars/clauses
            if (rep != null)
                rep.solve(primaryVars, vars, clauses);
        }
    });
    if (!opt.solver.equals(SatSolver.CNF) && !opt.solver.equals(SatSolver.KK) && tryBookExamples) {
        // try
        // book
        // examples
        A4Reporter r = AlloyCore.isDebug() ? rep : null;
        try {
            sol = BookExamples.trial(r, this, fgoal, solver, cmd.check);
        } catch (Throwable ex) {
            sol = null;
        }
    }
    // this allows the reporter to report the # of
    solved[0] = false;
    // vars/clauses
    for (Relation r : bounds.relations()) {
        formulas.add(r.eq(r));
    }
    // Without this, kodkod refuses to grow unmentioned relations
    fgoal = Formula.and(formulas);
    // Now pick the solver and solve it!
    if (opt.solver.equals(SatSolver.KK)) {
        File tmpCNF = File.createTempFile("tmp", ".java", new File(opt.tempDirectory));
        String out = tmpCNF.getAbsolutePath();
        Util.writeAll(out, debugExtractKInput());
        rep.resultCNF(out);
        return null;
    }
    if (opt.solver.equals(SatSolver.CNF)) {
        File tmpCNF = File.createTempFile("tmp", ".cnf", new File(opt.tempDirectory));
        String out = tmpCNF.getAbsolutePath();
        solver.options().setSolver(WriteCNF.factory(out));
        try {
            sol = solver.solve(fgoal, bounds);
        } catch (WriteCNF.WriteCNFCompleted ex) {
            rep.resultCNF(out);
            return null;
        }
        // The formula is trivial (otherwise, it would have thrown an
        // exception)
        // Since the user wants it in CNF format, we manually generate a
        // trivially satisfiable (or unsatisfiable) CNF file.
        Util.writeAll(out, sol.instance() != null ? "p cnf 1 1\n1 0\n" : "p cnf 1 2\n1 0\n-1 0\n");
        rep.resultCNF(out);
        return null;
    }
    if (!solver.options().solver().incremental()) /*
                                                      * || solver.options().solver()==SATFactory. ZChaffMincost
                                                      */
    {
        if (sol == null)
            sol = solver.solve(fgoal, bounds);
    } else {
        kEnumerator = new Peeker<Solution>(solver.solveAll(fgoal, bounds));
        if (sol == null)
            sol = kEnumerator.next();
    }
    if (!solved[0])
        rep.solve(0, 0, 0);
    final Instance inst = sol.instance();
    // To ensure no more output during SolutionEnumeration
    solver.options().setReporter(oldReporter);
    // If unsatisfiable, then retreive the unsat core if desired
    if (inst == null && solver.options().solver() == SATFactory.MiniSatProver) {
        try {
            lCore = new LinkedHashSet<Node>();
            Proof p = sol.proof();
            if (sol.outcome() == UNSATISFIABLE) {
                // only perform the minimization if it was UNSATISFIABLE,
                // rather than TRIVIALLY_UNSATISFIABLE
                int i = p.highLevelCore().size();
                rep.minimizing(cmd, i);
                if (opt.coreMinimization == 0)
                    try {
                        p.minimize(new RCEStrategy(p.log()));
                    } catch (Throwable ex) {
                    }
                if (opt.coreMinimization == 1)
                    try {
                        p.minimize(new HybridStrategy(p.log()));
                    } catch (Throwable ex) {
                    }
                rep.minimized(cmd, i, p.highLevelCore().size());
            }
            for (Iterator<TranslationRecord> it = p.core(); it.hasNext(); ) {
                Object n = it.next().node();
                if (n instanceof Formula)
                    lCore.add((Formula) n);
            }
            Map<Formula, Node> map = p.highLevelCore();
            hCore = new LinkedHashSet<Node>(map.keySet());
            hCore.addAll(map.values());
        } catch (Throwable ex) {
            lCore = hCore = null;
        }
    }
    // If satisfiable, then add/rename the atoms and skolems
    if (inst != null) {
        eval = new Evaluator(inst, solver.options());
        rename(this, null, null, new UniqueNameGenerator());
    }
    // report the result
    solved();
    time = System.currentTimeMillis() - time;
    if (inst != null)
        rep.resultSAT(cmd, time, this);
    else
        rep.resultUNSAT(cmd, time, this);
    return this;
}
Also used : HybridStrategy(kodkod.engine.ucore.HybridStrategy) Instance(kodkod.instance.Instance) Node(kodkod.ast.Node) BinaryFormula(kodkod.ast.BinaryFormula) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) RCEStrategy(kodkod.engine.ucore.RCEStrategy) Solution(kodkod.engine.Solution) A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) AbstractReporter(kodkod.engine.config.AbstractReporter) Reporter(kodkod.engine.config.Reporter) TranslationRecord(kodkod.engine.fol2sat.TranslationRecord) Decl(kodkod.ast.Decl) Evaluator(kodkod.engine.Evaluator) UniqueNameGenerator(edu.mit.csail.sdg.alloy4.UniqueNameGenerator) Type(edu.mit.csail.sdg.ast.Type) Proof(kodkod.engine.Proof) File(java.io.File) Tuple(kodkod.instance.Tuple)

Example 2 with RCEStrategy

use of kodkod.engine.ucore.RCEStrategy in project org.alloytools.alloy by AlloyTools.

the class Hotel method main.

/**
 * Usage: java examples.Hotel [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final Hotel model = new Hotel();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSatProver);
        solver.options().setLogTranslation(1);
        final Formula f = model.checkNoBadEntry();
        final Bounds b = model.bounds(n);
        // System.out.println(PrettyPrinter.print(f, 2, 100));
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
        if (sol.instance() == null) {
            final Proof proof = sol.proof();
            System.out.println("top-level formulas: " + proof.log().roots().size());
            System.out.println("initial core: " + proof.highLevelCore().size());
            System.out.print("\nminimizing core ... ");
            final long start = System.currentTimeMillis();
            proof.minimize(new RCEStrategy(proof.log()));
            final Set<Formula> core = Nodes.minRoots(f, proof.highLevelCore().values());
            final long end = System.currentTimeMillis();
            System.out.println("done (" + (end - start) + " ms).");
            System.out.println("minimal core: " + core.size());
            for (Formula u : core) {
                System.out.println(PrettyPrinter.print(u, 2, 100));
            }
            checkMinimal(core, b);
        } else {
            System.out.println(sol);
        }
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) RCEStrategy(kodkod.engine.ucore.RCEStrategy) Bounds(kodkod.instance.Bounds) Proof(kodkod.engine.Proof) Solution(kodkod.engine.Solution)

Example 3 with RCEStrategy

use of kodkod.engine.ucore.RCEStrategy in project org.alloytools.alloy by AlloyTools.

the class BugTests method testFelix_05192007.

public final void testFelix_05192007() {
    Relation x5 = Relation.nary("this/de", 1);
    Relation x6 = Relation.nary("this/dir", 1);
    Relation x7 = Relation.nary("this/de.contents", 2);
    Relation x8 = Relation.nary("this/dir.entries", 2);
    Relation x9 = Relation.nary("this/dir.parent", 2);
    List<String> atomlist = Arrays.asList("de[0]", "de[1]", "de[2]", "de[3]", "dir[0]", "dir[1]", "dir[2]", "dir[3]");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x5_upper = factory.noneOf(1);
    x5_upper.add(factory.tuple("de[0]"));
    x5_upper.add(factory.tuple("de[1]"));
    x5_upper.add(factory.tuple("de[2]"));
    x5_upper.add(factory.tuple("de[3]"));
    bounds.bound(x5, x5_upper);
    TupleSet x6_upper = factory.noneOf(1);
    x6_upper.add(factory.tuple("dir[0]"));
    x6_upper.add(factory.tuple("dir[1]"));
    x6_upper.add(factory.tuple("dir[2]"));
    x6_upper.add(factory.tuple("dir[3]"));
    bounds.bound(x6, x6_upper);
    TupleSet x7_upper = factory.noneOf(2);
    x7_upper.add(factory.tuple("de[0]").product(factory.tuple("dir[0]")));
    x7_upper.add(factory.tuple("de[0]").product(factory.tuple("dir[1]")));
    x7_upper.add(factory.tuple("de[0]").product(factory.tuple("dir[2]")));
    x7_upper.add(factory.tuple("de[0]").product(factory.tuple("dir[3]")));
    x7_upper.add(factory.tuple("de[1]").product(factory.tuple("dir[0]")));
    x7_upper.add(factory.tuple("de[1]").product(factory.tuple("dir[1]")));
    x7_upper.add(factory.tuple("de[1]").product(factory.tuple("dir[2]")));
    x7_upper.add(factory.tuple("de[1]").product(factory.tuple("dir[3]")));
    x7_upper.add(factory.tuple("de[2]").product(factory.tuple("dir[0]")));
    x7_upper.add(factory.tuple("de[2]").product(factory.tuple("dir[1]")));
    x7_upper.add(factory.tuple("de[2]").product(factory.tuple("dir[2]")));
    x7_upper.add(factory.tuple("de[2]").product(factory.tuple("dir[3]")));
    x7_upper.add(factory.tuple("de[3]").product(factory.tuple("dir[0]")));
    x7_upper.add(factory.tuple("de[3]").product(factory.tuple("dir[1]")));
    x7_upper.add(factory.tuple("de[3]").product(factory.tuple("dir[2]")));
    x7_upper.add(factory.tuple("de[3]").product(factory.tuple("dir[3]")));
    bounds.bound(x7, x7_upper);
    TupleSet x8_upper = factory.noneOf(2);
    x8_upper.add(factory.tuple("dir[0]").product(factory.tuple("de[0]")));
    x8_upper.add(factory.tuple("dir[0]").product(factory.tuple("de[1]")));
    x8_upper.add(factory.tuple("dir[0]").product(factory.tuple("de[2]")));
    x8_upper.add(factory.tuple("dir[0]").product(factory.tuple("de[3]")));
    x8_upper.add(factory.tuple("dir[1]").product(factory.tuple("de[0]")));
    x8_upper.add(factory.tuple("dir[1]").product(factory.tuple("de[1]")));
    x8_upper.add(factory.tuple("dir[1]").product(factory.tuple("de[2]")));
    x8_upper.add(factory.tuple("dir[1]").product(factory.tuple("de[3]")));
    x8_upper.add(factory.tuple("dir[2]").product(factory.tuple("de[0]")));
    x8_upper.add(factory.tuple("dir[2]").product(factory.tuple("de[1]")));
    x8_upper.add(factory.tuple("dir[2]").product(factory.tuple("de[2]")));
    x8_upper.add(factory.tuple("dir[2]").product(factory.tuple("de[3]")));
    x8_upper.add(factory.tuple("dir[3]").product(factory.tuple("de[0]")));
    x8_upper.add(factory.tuple("dir[3]").product(factory.tuple("de[1]")));
    x8_upper.add(factory.tuple("dir[3]").product(factory.tuple("de[2]")));
    x8_upper.add(factory.tuple("dir[3]").product(factory.tuple("de[3]")));
    bounds.bound(x8, x8_upper);
    TupleSet x9_upper = factory.noneOf(2);
    x9_upper.add(factory.tuple("dir[0]").product(factory.tuple("dir[0]")));
    x9_upper.add(factory.tuple("dir[0]").product(factory.tuple("dir[1]")));
    x9_upper.add(factory.tuple("dir[0]").product(factory.tuple("dir[2]")));
    x9_upper.add(factory.tuple("dir[0]").product(factory.tuple("dir[3]")));
    x9_upper.add(factory.tuple("dir[1]").product(factory.tuple("dir[0]")));
    x9_upper.add(factory.tuple("dir[1]").product(factory.tuple("dir[1]")));
    x9_upper.add(factory.tuple("dir[1]").product(factory.tuple("dir[2]")));
    x9_upper.add(factory.tuple("dir[1]").product(factory.tuple("dir[3]")));
    x9_upper.add(factory.tuple("dir[2]").product(factory.tuple("dir[0]")));
    x9_upper.add(factory.tuple("dir[2]").product(factory.tuple("dir[1]")));
    x9_upper.add(factory.tuple("dir[2]").product(factory.tuple("dir[2]")));
    x9_upper.add(factory.tuple("dir[2]").product(factory.tuple("dir[3]")));
    x9_upper.add(factory.tuple("dir[3]").product(factory.tuple("dir[0]")));
    x9_upper.add(factory.tuple("dir[3]").product(factory.tuple("dir[1]")));
    x9_upper.add(factory.tuple("dir[3]").product(factory.tuple("dir[2]")));
    x9_upper.add(factory.tuple("dir[3]").product(factory.tuple("dir[3]")));
    bounds.bound(x9, x9_upper);
    Expression x39 = x5.union(Expression.INTS);
    Expression x38 = x6.union(x39);
    Expression x37 = x38.product(Expression.UNIV);
    Expression x35 = Expression.IDEN.intersection(x37);
    Expression x34 = x35.intersection(x7);
    Formula x33 = x34.no();
    Variable x44 = Variable.nary("functional_x", 1);
    Decls x43 = x44.oneOf(x5);
    Expression x48 = x44.join(x7);
    Formula x47 = x48.lone();
    Formula x45 = Formula.TRUE.implies(x47);
    Formula x42 = x45.forAll(x43);
    Formula x32 = x33.and(x42);
    Variable x51 = Variable.nary("total_x", 1);
    Decls x50 = x51.oneOf(x5);
    Expression x54 = x51.join(x7);
    Formula x53 = x54.some();
    Formula x52 = Formula.TRUE.implies(x53);
    Formula x49 = x52.forAll(x50);
    Formula x31 = x32.and(x49);
    Variable x57 = Variable.nary("injective_x", 1);
    Decls x56 = x57.oneOf(x6);
    Expression x60 = x7.join(x57);
    Formula x59 = x60.lone();
    Formula x58 = Formula.TRUE.implies(x59);
    Formula x55 = x58.forAll(x56);
    Formula x30 = x31.and(x55);
    Expression x63 = x7.join(x8);
    Expression x62 = x63.transpose();
    Formula x61 = x62.in(x63);
    Formula x29 = x30.and(x61);
    Variable x66 = Variable.nary("acyclic_x", 1);
    Decls x65 = x66.oneOf(x5);
    Expression x72 = x7.join(x8);
    Expression x71 = x72.closure();
    Expression x70 = x66.join(x71);
    Formula x69 = x66.in(x70);
    Formula x68 = x69.not();
    Formula x67 = Formula.TRUE.implies(x68);
    Formula x64 = x67.forAll(x65);
    Formula x28 = x29.and(x64);
    Variable x75 = Variable.nary("surjective_x", 1);
    Decls x74 = x75.oneOf(x5);
    Expression x78 = x8.join(x75);
    Formula x77 = x78.some();
    Formula x76 = Formula.TRUE.implies(x77);
    Formula x73 = x76.forAll(x74);
    Formula x27 = x28.and(x73);
    Variable x81 = Variable.nary("functional_x", 1);
    Decls x80 = x81.oneOf(x6);
    Expression x84 = x81.join(x8);
    Formula x83 = x84.lone();
    Formula x82 = Formula.TRUE.implies(x83);
    Formula x79 = x82.forAll(x80);
    Formula x26 = x27.and(x79);
    Variable x87 = Variable.nary("acyclic_x", 1);
    Decls x86 = x87.oneOf(x6);
    Expression x93 = x8.join(x7);
    Expression x92 = x93.closure();
    Expression x91 = x87.join(x92);
    Formula x90 = x87.in(x91);
    Formula x89 = x90.not();
    Formula x88 = Formula.TRUE.implies(x89);
    Formula x85 = x88.forAll(x86);
    Formula x25 = x26.and(x85);
    Expression x96 = x9.transpose();
    Expression x95 = x96.intersection(x9);
    Expression x98 = x38.product(Expression.UNIV);
    Expression x97 = Expression.IDEN.intersection(x98);
    Formula x94 = x95.in(x97);
    Formula x24 = x25.and(x94);
    Expression x102 = x38.product(Expression.UNIV);
    Expression x101 = Expression.IDEN.intersection(x102);
    Expression x100 = x101.intersection(x9);
    Formula x99 = x100.no();
    Formula x23 = x24.and(x99);
    Expression x106 = x38.product(Expression.UNIV);
    Expression x105 = Expression.IDEN.intersection(x106);
    Expression x104 = x105.intersection(x8);
    Formula x103 = x104.no();
    Formula x22 = x23.and(x103);
    Variable x109 = Variable.nary("injective_x", 1);
    Decls x108 = x109.oneOf(x5);
    Expression x112 = x8.join(x109);
    Formula x111 = x112.lone();
    Formula x110 = Formula.TRUE.implies(x111);
    Formula x107 = x110.forAll(x108);
    Formula x21 = x22.and(x107);
    Variable x115 = Variable.nary("acyclic_x", 1);
    Decls x114 = x115.oneOf(x6);
    Expression x120 = x9.closure();
    Expression x119 = x115.join(x120);
    Formula x118 = x115.in(x119);
    Formula x117 = x118.not();
    Formula x116 = Formula.TRUE.implies(x117);
    Formula x113 = x116.forAll(x114);
    Formula x20 = x21.and(x113);
    Variable x123 = Variable.nary("functional_x", 1);
    Decls x122 = x123.oneOf(x6);
    Expression x126 = x123.join(x9);
    Formula x125 = x126.lone();
    Formula x124 = Formula.TRUE.implies(x125);
    Formula x121 = x124.forAll(x122);
    Formula x19 = x20.and(x121);
    Variable x129 = Variable.nary("injective_x", 1);
    Decls x128 = x129.oneOf(x6);
    Expression x132 = x9.join(x129);
    Formula x131 = x132.lone();
    Formula x130 = Formula.TRUE.implies(x131);
    Formula x127 = x130.forAll(x128);
    Formula x18 = x19.and(x127);
    Variable x137 = Variable.nary("rootedOne_root", 1);
    Decls x136 = x137.oneOf(x6);
    Variable x139 = Variable.nary("rootedOne_root", 1);
    Decls x138 = x139.oneOf(x6);
    Decls x135 = x136.and(x138);
    Expression x146 = x9.closure();
    Expression x148 = x38.product(Expression.UNIV);
    Expression x147 = Expression.IDEN.intersection(x148);
    Expression x145 = x146.union(x147);
    Expression x144 = x137.join(x145);
    Formula x143 = x6.in(x144);
    Expression x152 = x9.closure();
    Expression x154 = x38.product(Expression.UNIV);
    Expression x153 = Expression.IDEN.intersection(x154);
    Expression x151 = x152.union(x153);
    Expression x150 = x139.join(x151);
    Formula x149 = x6.in(x150);
    Formula x142 = x143.and(x149);
    Formula x156 = x137.eq(x139);
    Formula x155 = x156.and(Formula.TRUE);
    Formula x141 = x142.implies(x155);
    Formula x140 = Formula.TRUE.implies(x141);
    Formula x134 = x140.forAll(x135);
    Variable x159 = Variable.nary("rootedOne_root", 1);
    Decls x158 = x159.oneOf(x6);
    Expression x164 = x9.closure();
    Expression x166 = x38.product(Expression.UNIV);
    Expression x165 = Expression.IDEN.intersection(x166);
    Expression x163 = x164.union(x165);
    Expression x162 = x159.join(x163);
    Formula x161 = x6.in(x162);
    Formula x160 = Formula.TRUE.and(x161);
    Formula x157 = x160.forSome(x158);
    Formula x133 = x134.and(x157);
    Formula x17 = x18.and(x133);
    Variable x170 = Variable.nary("weaklyConnected_d", 1);
    Decls x169 = x170.oneOf(x6);
    Variable x172 = Variable.nary("weaklyConnected_g", 1);
    Decls x171 = x172.oneOf(x6);
    Decls x168 = x169.and(x171);
    Formula x177 = x170.eq(x172);
    Formula x176 = x177.not();
    Formula x175 = x176.not();
    Expression x182 = x9.transpose();
    Expression x181 = x9.union(x182);
    Expression x180 = x181.closure();
    Expression x179 = x172.join(x180);
    Formula x178 = x170.in(x179);
    Formula x174 = x175.or(x178);
    Formula x173 = Formula.TRUE.implies(x174);
    Formula x167 = x173.forAll(x168);
    Formula x16 = x17.and(x167);
    Expression x187 = x8.join(x7);
    Expression x188 = Expression.UNIV.product(x6);
    Expression x186 = x187.intersection(x188);
    Expression x185 = x9.union(x186);
    Expression x184 = x185.transpose();
    Formula x183 = x184.in(x185);
    Formula x15 = x16.and(x183);
    Variable x191 = Variable.nary("inner_injective_x", 1);
    Variable x197 = Variable.nary("ternary_a", 1);
    Expression x198 = x7.join(x38);
    Decls x196 = x197.oneOf(x198);
    Variable x200 = Variable.nary("ternary_b", 1);
    Expression x202 = x38.join(x7);
    Expression x203 = x8.join(x38);
    Expression x201 = x202.intersection(x203);
    Decls x199 = x200.oneOf(x201);
    Variable x205 = Variable.nary("ternary_c", 1);
    Expression x206 = x38.join(x8);
    Decls x204 = x205.oneOf(x206);
    Decls x195 = x196.and(x199).and(x204);
    Expression x209 = x197.product(x200);
    Formula x208 = x209.in(x7);
    Expression x211 = x200.product(x205);
    Formula x210 = x211.in(x8);
    Formula x207 = x208.and(x210);
    Expression x194 = x207.comprehension(x195);
    Expression x193 = x194.join(x38);
    Expression x192 = x193.join(x38);
    Decls x190 = x191.oneOf(x192);
    Variable x215 = Variable.nary("injective_x", 1);
    Expression x217 = x191.join(x194);
    Expression x216 = x38.join(x217);
    Decls x214 = x215.oneOf(x216);
    Expression x221 = x191.join(x194);
    Expression x220 = x221.join(x215);
    Formula x219 = x220.lone();
    Formula x218 = Formula.TRUE.implies(x219);
    Formula x213 = x218.forAll(x214);
    Formula x212 = Formula.TRUE.implies(x213);
    Formula x189 = x212.forAll(x190);
    Formula x14 = x15.and(x189);
    Variable x224 = Variable.nary("inner_injective_x", 1);
    Variable x230 = Variable.nary("ternary_a", 1);
    Expression x231 = x8.join(x38);
    Decls x229 = x230.oneOf(x231);
    Variable x233 = Variable.nary("ternary_b", 1);
    Expression x235 = x38.join(x8);
    Expression x236 = x7.join(x38);
    Expression x234 = x235.intersection(x236);
    Decls x232 = x233.oneOf(x234);
    Variable x238 = Variable.nary("ternary_c", 1);
    Expression x239 = x38.join(x7);
    Decls x237 = x238.oneOf(x239);
    Decls x228 = x229.and(x232).and(x237);
    Expression x242 = x230.product(x233);
    Formula x241 = x242.in(x8);
    Expression x244 = x233.product(x238);
    Formula x243 = x244.in(x7);
    Formula x240 = x241.and(x243);
    Expression x227 = x240.comprehension(x228);
    Expression x226 = x227.join(x38);
    Expression x225 = x226.join(x38);
    Decls x223 = x224.oneOf(x225);
    Variable x248 = Variable.nary("injective_x", 1);
    Expression x250 = x224.join(x227);
    Expression x249 = x38.join(x250);
    Decls x247 = x248.oneOf(x249);
    Expression x254 = x224.join(x227);
    Expression x253 = x254.join(x248);
    Formula x252 = x253.lone();
    Formula x251 = Formula.TRUE.implies(x252);
    Formula x246 = x251.forAll(x247);
    Formula x245 = Formula.TRUE.implies(x246);
    Formula x222 = x245.forAll(x223);
    Formula x13 = x14.and(x222);
    Variable x259 = Variable.nary("rootedOne_root", 1);
    Decls x258 = x259.oneOf(x6);
    Variable x261 = Variable.nary("rootedOne_root", 1);
    Decls x260 = x261.oneOf(x6);
    Decls x257 = x258.and(x260);
    Variable x272 = Variable.nary("rootedOne_a", 1);
    Decls x271 = x272.oneOf(x6);
    Variable x274 = Variable.nary("rootedOne_b", 1);
    Decls x273 = x274.oneOf(x6);
    Decls x270 = x271.and(x273);
    Variable x277 = Variable.nary("rootedOne_c", 1);
    Decls x276 = x277.oneOf(x38);
    Expression x281 = x277.product(x274);
    Expression x280 = x272.product(x281);
    Variable x285 = Variable.nary("ternary_a", 1);
    Expression x286 = x8.join(x38);
    Decls x284 = x285.oneOf(x286);
    Variable x288 = Variable.nary("ternary_b", 1);
    Expression x290 = x38.join(x8);
    Expression x291 = x7.join(x38);
    Expression x289 = x290.intersection(x291);
    Decls x287 = x288.oneOf(x289);
    Variable x293 = Variable.nary("ternary_c", 1);
    Expression x294 = x38.join(x7);
    Decls x292 = x293.oneOf(x294);
    Decls x283 = x284.and(x287).and(x292);
    Expression x297 = x285.product(x288);
    Formula x296 = x297.in(x8);
    Expression x299 = x288.product(x293);
    Formula x298 = x299.in(x7);
    Formula x295 = x296.and(x298);
    Expression x282 = x295.comprehension(x283);
    Formula x279 = x280.in(x282);
    Formula x278 = Formula.TRUE.and(x279);
    Formula x275 = x278.forSome(x276);
    Expression x269 = x275.comprehension(x270);
    Expression x268 = x269.closure();
    Expression x301 = x38.product(Expression.UNIV);
    Expression x300 = Expression.IDEN.intersection(x301);
    Expression x267 = x268.union(x300);
    Expression x266 = x259.join(x267);
    Formula x265 = x6.in(x266);
    Variable x309 = Variable.nary("rootedOne_a", 1);
    Decls x308 = x309.oneOf(x6);
    Variable x311 = Variable.nary("rootedOne_b", 1);
    Decls x310 = x311.oneOf(x6);
    Decls x307 = x308.and(x310);
    Variable x314 = Variable.nary("rootedOne_c", 1);
    Decls x313 = x314.oneOf(x38);
    Expression x318 = x314.product(x311);
    Expression x317 = x309.product(x318);
    Formula x316 = x317.in(x282);
    Formula x315 = Formula.TRUE.and(x316);
    Formula x312 = x315.forSome(x313);
    Expression x306 = x312.comprehension(x307);
    Expression x305 = x306.closure();
    Expression x320 = x38.product(Expression.UNIV);
    Expression x319 = Expression.IDEN.intersection(x320);
    Expression x304 = x305.union(x319);
    Expression x303 = x261.join(x304);
    Formula x302 = x6.in(x303);
    Formula x264 = x265.and(x302);
    Formula x322 = x259.eq(x261);
    Formula x321 = x322.and(Formula.TRUE);
    Formula x263 = x264.implies(x321);
    Formula x262 = Formula.TRUE.implies(x263);
    Formula x256 = x262.forAll(x257);
    Variable x325 = Variable.nary("rootedOne_root", 1);
    Decls x324 = x325.oneOf(x6);
    Variable x334 = Variable.nary("rootedOne_a", 1);
    Decls x333 = x334.oneOf(x6);
    Variable x336 = Variable.nary("rootedOne_b", 1);
    Decls x335 = x336.oneOf(x6);
    Decls x332 = x333.and(x335);
    Variable x339 = Variable.nary("rootedOne_c", 1);
    Decls x338 = x339.oneOf(x38);
    Expression x343 = x339.product(x336);
    Expression x342 = x334.product(x343);
    Formula x341 = x342.in(x282);
    Formula x340 = Formula.TRUE.and(x341);
    Formula x337 = x340.forSome(x338);
    Expression x331 = x337.comprehension(x332);
    Expression x330 = x331.closure();
    Expression x345 = x38.product(Expression.UNIV);
    Expression x344 = Expression.IDEN.intersection(x345);
    Expression x329 = x330.union(x344);
    Expression x328 = x325.join(x329);
    Formula x327 = x6.in(x328);
    Formula x326 = Formula.TRUE.and(x327);
    Formula x323 = x326.forSome(x324);
    Formula x255 = x256.and(x323);
    Formula x12 = x13.and(x255);
    Expression x348 = x9.join(x9);
    Formula x347 = x348.in(x9);
    Formula x346 = x347.not();
    Formula x11 = x12.and(x346);
    Expression x352 = x6.product(x6);
    Formula x351 = x9.in(x352);
    Expression x355 = x6.product(x5);
    Formula x354 = x8.in(x355);
    Expression x359 = x5.product(x6);
    Formula x358 = x7.in(x359);
    Formula x363 = Formula.TRUE.and(Formula.TRUE);
    Formula x362 = Formula.TRUE.and(x363);
    Formula x361 = Formula.TRUE.and(x362);
    Formula x360 = Formula.TRUE.and(x361);
    Formula x357 = x358.and(x360);
    Formula x356 = Formula.TRUE.and(x357);
    Formula x353 = x354.and(x356);
    Formula x350 = x351.and(x353);
    Formula x349 = Formula.TRUE.and(x350);
    Formula x10 = x11.and(x349);
    Solver solver = new Solver();
    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    Solution sol = solver.solve(x10, bounds);
    // System.out.println(sol.toString());
    Proof proof = sol.proof();
    proof.minimize(new RCEStrategy(proof.log()));
    Set<Formula> core = Nodes.minRoots(x10, sol.proof().highLevelCore().values());
    // final Set<Formula> minCore = new LinkedHashSet<Formula>(core);
    // for(Iterator<Formula> itr = minCore.iterator(); itr.hasNext();) {
    // Formula f = itr.next();
    // Formula noF = Formula.TRUE;
    // for( Formula f1 : minCore ) {
    // if (f!=f1)
    // noF = noF.and(f1);
    // }
    // if (solver.solve(noF, bounds).instance()==null) {
    // itr.remove();
    // }
    // }
    // assertTrue(minCore.size()==core.size());
    assertTrue(isMinimal(solver, bounds, core));
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) RCEStrategy(kodkod.engine.ucore.RCEStrategy) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Proof(kodkod.engine.Proof) Solution(kodkod.engine.Solution)

Aggregations

Formula (kodkod.ast.Formula)3 Proof (kodkod.engine.Proof)3 Solution (kodkod.engine.Solution)3 RCEStrategy (kodkod.engine.ucore.RCEStrategy)3 Relation (kodkod.ast.Relation)2 Solver (kodkod.engine.Solver)2 Bounds (kodkod.instance.Bounds)2 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1 UniqueNameGenerator (edu.mit.csail.sdg.alloy4.UniqueNameGenerator)1 Type (edu.mit.csail.sdg.ast.Type)1 File (java.io.File)1 BinaryFormula (kodkod.ast.BinaryFormula)1 Decl (kodkod.ast.Decl)1 Decls (kodkod.ast.Decls)1 Expression (kodkod.ast.Expression)1 IntExpression (kodkod.ast.IntExpression)1 Node (kodkod.ast.Node)1 Variable (kodkod.ast.Variable)1 Evaluator (kodkod.engine.Evaluator)1 AbstractReporter (kodkod.engine.config.AbstractReporter)1