Package solver.constraints.nary.cnf

Examples of solver.constraints.nary.cnf.LogOp


            solver.makeLessOrEqual(
                solver.makeDifference(b1, b2), 0));
        */

                // b1 -> b2
                LogOp t = LogOp.implies(b1, b2);
                SatFactory.addClauses(t, solver);

                // solver.post(IntConstraintFactory.arithm(b1, "<=", b2));


            }
        }

        //   forall(w in Women, o in Men)
        //      cp.post(rankWomen[w,o] < rankWomen[w,husband[w]] =>
        //              rankMen[o,wife[o]] < rankMen[o,w]);
        for (int w = 0; w < n; w++) {
            for (int o = 0; o < n; o++) {
        /*
        IntVar b1 = solver.makeIsGreaterCstVar(
                        solver.makeElement(rankWomen[w], husband[w]).var(),
                        rankWomen[w][o]);
        */
                IntVar v1 = enumerated("v1", 0, n - 1, solver);
                solver.post(element(v1, rankWomen[w], husband[w], 0, "detect"));

                BoolVar b1 = bool("b1", solver);
                solver.post(LogicalConstraintFactory.ifThenElse(b1,
                        arithm(v1, ">", rankWomen[w][o]),
                        arithm(v1, "<=", rankWomen[w][o])
                ));


        /*
        IntVar b2 = solver.makeIsLessCstVar(
                        solver.makeElement(rankMen[o], wife[o]).var(),
                        rankMen[o][w]);
        */
                IntVar v2 = enumerated("v2", 0, n - 1, solver);
                solver.post(element(v2, rankMen[o], wife[o], 0, "detect"));

                BoolVar b2 = bool("b2", solver);
                solver.post(LogicalConstraintFactory.ifThenElse(b2,
                        arithm(v2, "<", rankMen[o][w]),
                        arithm(v2, ">=", rankMen[o][w])
                ));


        /*
        solver.addConstraint(
            solver.makeLessOrEqual(
                solver.makeDifference(b1, b2), 0));
        }
        */

                // b1 -> b2
                LogOp t = LogOp.implies(b1, b2);
                SatFactory.addClauses(t, solver);

                // solver.post(IntConstraintFactory.arithm(b1, "<=", b2));

            }
View Full Code Here


        int r = data.getValue("REST");
        for (IntVar[] s : this.shifts) {
            for (int t = 0; t + 2 < data.nbDays(); t++) {
                //solver.post(Options.E_DECOMP, ConstraintFactory.ifThenElse(ConstraintFactory.eq(s[t], n), ConstraintFactory.or(ConstraintFactory.eq(s[t+1], n), ConstraintFactory.and(ConstraintFactory.eq(s[t+1], r), ConstraintFactory.eq(s[t+2], r)))));
                BoolVar[] bvars = VariableFactory.boolArray("b", 4, solver);
                LogOp tree = LogOp.implies(
                        bvars[0],
                        LogOp.or(bvars[1], bvars[2], bvars[3])
                );
                SatFactory.addClauses(tree, solver);
                solver.post(LogicalConstraintFactory.ifThenElse(bvars[0],
                        IntConstraintFactory.arithm(s[t], "=", n), IntConstraintFactory.arithm(s[t], "!=", n)));
                solver.post(LogicalConstraintFactory.ifThenElse(bvars[1],
                        IntConstraintFactory.arithm(s[t + 1], "=", n), IntConstraintFactory.arithm(s[t + 1], "!=", n)));
                solver.post(LogicalConstraintFactory.ifThenElse(bvars[2],
                        IntConstraintFactory.arithm(s[t + 1], "=", r), IntConstraintFactory.arithm(s[t + 1], "!=", r)));
                solver.post(LogicalConstraintFactory.ifThenElse(bvars[3],
                        IntConstraintFactory.arithm(s[t + 2], "=", r), IntConstraintFactory.arithm(s[t + 2], "!=", r)));
            }
            int t = data.nbDays() - 2;
            BoolVar[] bvars = VariableFactory.boolArray("b", 2, solver);
//            solver.post(ConstraintFactory.ifThenElse(ConstraintFactory.eq(s[t], n), ConstraintFactory.eq(s[t + 1], n)));
            LogOp tree = LogOp.implies(bvars[0], bvars[1]);
            SatFactory.addClauses(tree, solver);
            solver.post(LogicalConstraintFactory.ifThenElse(bvars[0],
                    IntConstraintFactory.arithm(s[t], "=", n), IntConstraintFactory.arithm(s[t], "!=", n)));
            solver.post(LogicalConstraintFactory.ifThenElse(bvars[1],
                    IntConstraintFactory.arithm(s[t + 1], "=", n), IntConstraintFactory.arithm(s[t + 1], "!=", n)));
View Full Code Here

        description += "patConsWE[reif] ";
        int r = data.getValue("REST");
        for (IntVar[] s : this.shifts) {
            for (int t = 5; t + 15 < data.nbDays(); t += 7) {
                BoolVar[] bvars = VariableFactory.boolArray("b", 6, solver);
                LogOp tree = LogOp.implies(
                        LogOp.and(
                                LogOp.or(bvars[0], bvars[1]),
                                LogOp.or(bvars[2], bvars[3])),
                        LogOp.and(bvars[4], bvars[5])
                );
View Full Code Here

        description += "patCompWE[reif] ";
        int r = data.getValue("REST");
        for (IntVar[] s : this.shifts) {
            for (int t = 5; t + 1 < data.nbDays(); t += 7) {
                BoolVar[] bvars = VariableFactory.boolArray("b", 2, solver);
                LogOp tree = LogOp.ifOnlyIf(bvars[0], bvars[1]);
                SatFactory.addClauses(tree, solver);
                solver.post(LogicalConstraintFactory.ifThenElse(bvars[0],
                        IntConstraintFactory.arithm(s[t], "=", r),
                        IntConstraintFactory.arithm(s[t], "!=", r)));
                solver.post(LogicalConstraintFactory.ifThenElse(bvars[1],
View Full Code Here

        BoolVar b = VariableFactory.bool("b", solver);
        BoolVar c = VariableFactory.bool("c", solver);
        BoolVar d = VariableFactory.bool("d", solver);


        LogOp root = LogOp.nand(LogOp.nor(a, b), LogOp.or(c, d));

        ILogical l = LogicTreeToolBox.toCNF(root, solver);

        Assert.assertEquals(l.toString(), "((b or a or not(c)) and (b or a or not(d)))");
    }
View Full Code Here

          }else{
            bs[j] = bsource[j];
          }
        }

                LogOp or = LogOp.or(bs);
                log.info(or.toString());
                SatFactory.addClauses(or, s);
                s.set(IntStrategyFactory.lexico_LB(bs));

        s.findAllSolutions();
                long sol = s.getMeasures().getSolutionCount();
View Full Code Here

        Solver s = new Solver();

        BoolVar[] bs = new BoolVar[1];
        bs[0] = VariableFactory.bool("to be", s);

        LogOp and = LogOp.and(bs[0], bs[0].not());

        SatFactory.addClauses(and, s);
        s.set(IntStrategyFactory.lexico_LB(bs));
        s.findAllSolutions();
        long sol = s.getMeasures().getSolutionCount();
View Full Code Here

    public void testBothOr() {
        Solver s = new Solver();

        BoolVar b = VariableFactory.bool("to be", s);

        LogOp or = LogOp.or(b, b.not());

        SatFactory.addClauses(or, s);

        BoolVar[] bs = new BoolVar[]{b};
        s.set(IntStrategyFactory.lexico_LB(bs));
View Full Code Here

    @Test(groups = "1s")
    public void test2() {
        Solver solver = new Solver();
        BoolVar[] bvars = VariableFactory.boolArray("b", 2, solver);
        LogOp tree = LogOp.or(bvars[0], bvars[1]);
        SatFactory.addClauses(tree, solver);

        try {
            solver.propagate();
            bvars[1].instantiateTo(0, Cause.Null);
View Full Code Here

    @Test(groups = "1s")
    public void test30() {
        Solver solver = new Solver();
        BoolVar[] bvars = VariableFactory.boolArray("b", 2, solver);
        LogOp tree = LogOp.or(bvars[0], bvars[1]);
        SatFactory.addClauses(tree, solver);

        try {
            solver.propagate();
            bvars[1].instantiateTo(1, Cause.Null);
View Full Code Here

TOP

Related Classes of solver.constraints.nary.cnf.LogOp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.