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 package org.sat4j.minisat.constraints.pb;
26
27 import java.math.BigInteger;
28
29 import org.sat4j.minisat.constraints.cnf.DefaultWLClause;
30 import org.sat4j.minisat.core.ILits;
31 import org.sat4j.minisat.core.UnitPropagationListener;
32 import org.sat4j.specs.IVecInt;
33
34 public class WLClausePB extends DefaultWLClause implements PBConstr {
35
36 /**
37 *
38 */
39 private static final long serialVersionUID = 1L;
40
41 public WLClausePB(IVecInt ps, ILits voc) {
42 super(ps, voc);
43 // TODO Auto-generated constructor stub
44 }
45
46 /*
47 * (non-Javadoc)
48 *
49 * @see org.sat4j.minisat.constraints.pb.PBConstr#getCoefficient(int)
50 */
51 public BigInteger getCoef(int literal) {
52 return BigInteger.ONE;
53 }
54
55 /*
56 * (non-Javadoc)
57 *
58 * @see org.sat4j.minisat.constraints.pb.PBConstr#getDegree()
59 */
60 public BigInteger getDegree() {
61 return BigInteger.ONE;
62 }
63
64 public BigInteger[] getCoefs() {
65 BigInteger[] tmp = new BigInteger[size()];
66 for (int i = 0; i < tmp.length; i++)
67 tmp[i] = BigInteger.ONE;
68 return tmp;
69 }
70
71 /**
72 * Creates a brand new clause, presumably from external data. Performs all
73 * sanity checks.
74 *
75 * @param s
76 * the object responsible for unit propagation
77 * @param voc
78 * the vocabulary
79 * @param literals
80 * the literals to store in the clause
81 * @return the created clause or null if the clause should be ignored
82 * (tautology for example)
83 */
84 public static WLClausePB brandNewClause(UnitPropagationListener s,
85 ILits voc, IVecInt literals) {
86 WLClausePB c = new WLClausePB(literals, voc);
87 c.register();
88 return c;
89 }
90
91 @Override
92 public void assertConstraint(UnitPropagationListener s) {
93 for (int i = 0; i < size(); i++)
94 if (getVocabulary().isUnassigned(get(i))) {
95 boolean ret = s.enqueue(get(i), this);
96 assert ret;
97 break;
98 }
99 }
100
101 public IVecInt computeAnImpliedClause() {
102 return null;
103 }
104
105 }