View Javadoc

1   /*
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2006 Daniel Le Berre
3    * 
4    * Based on the original minisat specification from:
5    * 
6    * An extensible SAT solver. Niklas E?n and Niklas S?rensson. Proceedings of the
7    * Sixth International Conference on Theory and Applications of Satisfiability
8    * Testing, LNCS 2919, pp 502-518, 2003.
9    * 
10   * This library is free software; you can redistribute it and/or modify it under
11   * the terms of the GNU Lesser General Public License as published by the Free
12   * Software Foundation; either version 2.1 of the License, or (at your option)
13   * any later version.
14   * 
15   * This library is distributed in the hope that it will be useful, but WITHOUT
16   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18   * details.
19   * 
20   * You should have received a copy of the GNU Lesser General Public License
21   * along with this library; if not, write to the Free Software Foundation, Inc.,
22   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23   * 
24   */
25  
26  package org.sat4j.minisat.constraints;
27  
28  import java.io.Serializable;
29  import java.math.BigInteger;
30  
31  import org.sat4j.core.Vec;
32  import org.sat4j.minisat.core.Constr;
33  import org.sat4j.minisat.core.DataStructureFactory;
34  import org.sat4j.minisat.core.ILits;
35  import org.sat4j.minisat.core.Learner;
36  import org.sat4j.minisat.core.Propagatable;
37  import org.sat4j.minisat.core.UnitPropagationListener;
38  import org.sat4j.specs.ContradictionException;
39  import org.sat4j.specs.IVec;
40  import org.sat4j.specs.IVecInt;
41  
42  /**
43   * @author leberre To change the template for this generated type comment go to
44   *         Window>Preferences>Java>Code Generation>Code and Comments
45   */
46  public abstract class AbstractDataStructureFactory<L extends ILits> implements
47          DataStructureFactory<L>, Serializable {
48  
49      /*
50       * (non-Javadoc)
51       * 
52       * @see org.sat4j.minisat.core.DataStructureFactory#conflictDetectedInWatchesFor(int)
53       */
54      public void conflictDetectedInWatchesFor(int p, int i) {
55          for (int j = i + 1; j < tmp.size(); j++) {
56              lits.watch(p, tmp.get(j));
57          }
58      }
59  
60      /*
61       * (non-Javadoc)
62       * 
63       * @see org.sat4j.minisat.core.DataStructureFactory#getWatchesFor(int)
64       */
65      public IVec<Propagatable> getWatchesFor(int p) {
66          tmp.clear();
67          lits.watches(p).moveTo(tmp);
68          return tmp;
69      }
70  
71      protected L lits;
72      
73      protected AbstractDataStructureFactory() {
74          lits = createLits();
75      }
76  
77      protected abstract L createLits(); 
78      
79      private final IVec<Propagatable> tmp = new Vec<Propagatable>();
80  
81      /*
82       * (non-Javadoc)
83       * 
84       * @see org.sat4j.minisat.DataStructureFactory#createVocabulary()
85       */
86      public L getVocabulary() {
87          return lits;
88      }
89  
90      protected UnitPropagationListener solver;
91  
92      protected Learner learner;
93  
94      public void setUnitPropagationListener(UnitPropagationListener s) {
95          solver = s;
96      }
97  
98      public void setLearner(Learner learner) {
99          this.learner = learner;
100     }
101 
102     public void reset() {
103     }
104 
105     public void learnConstraint(Constr constr) {
106         learner.learn(constr);
107     }
108 
109     /*
110      * (non-Javadoc)
111      * 
112      * @see org.sat4j.minisat.core.DataStructureFactory#createCardinalityConstraint(org.sat4j.specs.VecInt,
113      *      int)
114      */
115     public Constr createCardinalityConstraint(IVecInt literals, int degree)
116             throws ContradictionException {
117         throw new UnsupportedOperationException();
118     }
119 
120     /*
121      * (non-Javadoc)
122      * 
123      * @see org.sat4j.minisat.DataStructureFactory#createPseudoBooleanConstraint(org.sat4j.datatype.VecInt,
124      *      org.sat4j.datatype.VecInt, int)
125      */
126     public Constr createPseudoBooleanConstraint(IVecInt literals,
127             IVec<BigInteger> coefs, boolean moreThan, BigInteger degree)
128             throws ContradictionException {
129         throw new UnsupportedOperationException();
130     }
131 
132     public Constr createUnregisteredPseudoBooleanConstraint(IVecInt literals,
133             IVec<BigInteger> coefs, BigInteger degree) {
134         throw new UnsupportedOperationException();
135     }
136 
137 }