Logo Search packages:      
Sourcecode: sat4j version File versions

TernaryClauses.java

/*******************************************************************************
* SAT4J: a SATisfiability library for Java Copyright (C) 2004-2008 Daniel Le Berre
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU Lesser General Public License Version 2.1 or later (the
* "LGPL"), in which case the provisions of the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of the LGPL, and not to allow others to use your version of
* this file under the terms of the EPL, indicate your decision by deleting
* the provisions above and replace them with the notice and other provisions
* required by the LGPL. If you do not delete the provisions above, a recipient
* may use your version of this file under the terms of the EPL or the LGPL.
* 
* Based on the original MiniSat specification from:
* 
* An extensible SAT solver. Niklas Een and Niklas Sorensson. Proceedings of the
* Sixth International Conference on Theory and Applications of Satisfiability
* Testing, LNCS 2919, pp 502-518, 2003.
*
* See www.minisat.se for the original solver in C++.
* 
*******************************************************************************/
package org.sat4j.minisat.constraints.cnf;

import java.io.Serializable;

import org.sat4j.core.VecInt;
import org.sat4j.minisat.core.Constr;
import org.sat4j.minisat.core.ILits;
import org.sat4j.minisat.core.UnitPropagationListener;
import org.sat4j.specs.IVecInt;

/**
 * @author leberre To change the template for this generated type comment go to
 *         Window - Preferences - Java - Code Generation - Code and Comments
 */
00042 public class TernaryClauses implements Constr, Serializable {

    private static final long serialVersionUID = 1L;

    private final IVecInt stubs = new VecInt();

    private final ILits voc;

    private final int phead;

    public TernaryClauses(ILits voc, int p) {
        this.voc = voc;
        this.phead = p;
    }

    public void addTernaryClause(int a, int b) {
        stubs.push(a);
        stubs.push(b);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#remove()
     */
00067     public void remove() {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#propagate(org.sat4j.minisat.UnitPropagationListener,
     *      int)
     */
00077     public boolean propagate(UnitPropagationListener s, int p) {
        assert voc.isSatisfied(p);
        assert voc.isFalsified(phead);
        voc.watch(p, this);
        for (int i = 0; i < stubs.size(); i += 2) {
            int a = stubs.get(i);
            int b = stubs.get(i + 1);
            if (voc.isSatisfied(a) || voc.isSatisfied(b)) {
                continue;
            }
            if (voc.isFalsified(a) && !s.enqueue(b, this)) {
                return false;
            } else if (voc.isFalsified(b) && !s.enqueue(a, this)) {
                return false;
            }
        }
        return true;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#simplify()
     */
00101     public boolean simplify() {
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#undo(int)
     */
    public void undo(int p) {
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#calcReason(int, org.sat4j.datatype.VecInt)
     */
00118     public void calcReason(int p, IVecInt outReason) {
        assert voc.isFalsified(this.phead);
        if (p == ILits.UNDEFINED) {
            int i = 0;
            while (!voc.isFalsified(stubs.get(i))
                    || !voc.isFalsified(stubs.get(i + 1))) {
                i += 2;
            }
            outReason.push(this.phead ^ 1);
            outReason.push(stubs.get(i) ^ 1);
            outReason.push(stubs.get(i + 1) ^ 1);
        } else {
            outReason.push(this.phead ^ 1);
            int i = 0;
            while ((stubs.get(i) != p) || (!voc.isFalsified(stubs.get(i ^ 1)))) {
                i++;
            }
            assert !voc.isFalsified(stubs.get(i));
            outReason.push(stubs.get(i ^ 1) ^ 1);
            assert voc.isFalsified(stubs.get(i ^ 1));
        }

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#learnt()
     */
00147     public boolean learnt() {
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#incActivity(double)
     */
00156     public void incActivity(double claInc) {
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#getActivity()
     */
00164     public double getActivity() {
        return 0;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#locked()
     */
00173     public boolean locked() {
        // TODO Auto-generated method stub
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#setLearnt()
     */
00183     public void setLearnt() {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#register()
     */
00192     public void register() {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#rescaleBy(double)
     */
00201     public void rescaleBy(double d) {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#size()
     */
00210     public int size() {
        return stubs.size();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.sat4j.minisat.Constr#get(int)
     */
00219     public int get(int i) {
        throw new UnsupportedOperationException();
    }

00223     public void assertConstraint(UnitPropagationListener s) {
        throw new UnsupportedOperationException();
    }
}

Generated by  Doxygen 1.6.0   Back to index