Package org.sat4j.core

Examples of org.sat4j.core.VecInt


     */
    public void and(int y, IVecInt literals) throws ContradictionException {
        // y <=> AND x1 ... xn

        // y <= x1 .. xn
        IVecInt clause = new VecInt(literals.size() + 2);
        clause.push(y);
        for (int i = 0; i < literals.size(); i++) {
            clause.push(-literals.get(i));
        }
        processClause(clause);
        clause.clear();
        for (int i = 0; i < literals.size(); i++) {
            // y => xi
            clause.clear();
            clause.push(-y);
            clause.push(literals.get(i));
            processClause(clause);
        }
    }
View Full Code Here


     * @param x1
     * @param x2
     * @throws ContradictionException
     */
    public void and(int y, int x1, int x2) throws ContradictionException {
        IVecInt clause = new VecInt(4);
        clause.push(-y);
        clause.push(x1);
        addClause(clause);
        clause.clear();
        clause.push(-y);
        clause.push(x2);
        addClause(clause);
        clause.clear();
        clause.push(y);
        clause.push(-x1);
        clause.push(-x2);
        addClause(clause);
    }
View Full Code Here

     * @throws ContradictionException
     */
    public void or(int y, IVecInt literals) throws ContradictionException {
        // y <=> OR x1 x2 ...xn
        // y => x1 x2 ... xn
        IVecInt clause = new VecInt(literals.size() + 2);
        literals.copyTo(clause);
        clause.push(-y);
        processClause(clause);
        clause.clear();
        for (int i = 0; i < literals.size(); i++) {
            // xi => y
            clause.clear();
            clause.push(y);
            clause.push(-literals.get(i));
            processClause(clause);
        }
    }
View Full Code Here

     * @param y
     * @param x
     * @throws ContradictionException
     */
    public void not(int y, int x) throws ContradictionException {
        IVecInt clause = new VecInt(3);
        // y <=> not x
        // y => not x = not y or not x
        clause.push(-y).push(-x);
        processClause(clause);
        // y <= not x = y or x
        clause.clear();
        clause.push(y).push(x);
        processClause(clause);
    }
View Full Code Here

    }

    private void xor2Clause(int[] f, int prefix, boolean negation)
            throws ContradictionException {
        if (prefix == f.length - 1) {
            IVecInt clause = new VecInt(f.length + 1);
            for (int i = 0; i < f.length - 1; ++i) {
                clause.push(f[i]);
            }
            clause.push(f[f.length - 1] * (negation ? -1 : 1));
            processClause(clause);
            return;
        }

        if (negation) {
View Full Code Here

    }

    private void iff2Clause(int[] f, int prefix, boolean negation)
            throws ContradictionException {
        if (prefix == f.length - 1) {
            IVecInt clause = new VecInt(f.length + 1);
            for (int i = 0; i < f.length - 1; ++i) {
                clause.push(f[i]);
            }
            clause.push(f[f.length - 1] * (negation ? -1 : 1));
            processClause(clause);
            return;
        }

        if (negation) {
View Full Code Here

     * @see org.sat4j.ISolver#model()
     */
    @Override
    public int[] model() {
        int[] last = super.model();
        IVecInt clause = new VecInt(last.length);
        for (int q : last) {
            clause.push(-q);
        }
        try {
            // System.out.println("adding " + clause);
            addClause(clause);
        } catch (ContradictionException e) {
View Full Code Here

     * @see org.sat4j.ISolver#model()
     */
    @Override
    public int[] model() {
        int[] prevmodel = null;
        IVecInt vec = new VecInt();
        // backUp();
        try {
            do {
                prevmodel = super.model();
                vec.clear();
                for (int i = 1; i <= nVars(); i++) {
                    vec.push(-i);
                }
                int counter = 0;
                for (int q : prevmodel) {
                    if (q < 0) {
                        counter++;
View Full Code Here

     */
    @SuppressWarnings("null")
  @Override
    public int[] model() {
        int[] prevmodel = null;
        IVecInt vec = new VecInt();
        IVecInt cube = new VecInt();
        // backUp();
        try {
            do {
                prevmodel = super.model();
                vec.clear();
                cube.clear();
                for (int q : prevmodel) {
                    if (q < 0) {
                        vec.push(-q);
                    } else {
                        cube.push(q);
                    }
                }
                addClause(vec);
            } while (isSatisfiable(cube));
        } catch (TimeoutException e) {
View Full Code Here

        boolean trivialfalsity = false;

        while (!trivialfalsity && isSatisfiable(true)) {
            lowerBound++;
            int[] last = model();
            IVecInt clause = new VecInt(last.length);
            for (int q : last) {
                clause.push(-q);
            }
            try {
                // System.out.println("Sol number "+nbsols+" adding " + clause);
                addClause(clause);
            } catch (ContradictionException e) {
View Full Code Here

TOP

Related Classes of org.sat4j.core.VecInt

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.