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  package org.sat4j.minisat.constraints.pb;
26  
27  import java.math.BigInteger;
28  
29  import org.sat4j.minisat.constraints.card.AtLeast;
30  import org.sat4j.minisat.core.ILits;
31  import org.sat4j.minisat.core.UnitPropagationListener;
32  import org.sat4j.specs.ContradictionException;
33  import org.sat4j.specs.IVecInt;
34  
35  public class AtLeastPB extends AtLeast implements PBConstr {
36  
37      /**
38       * 
39       */
40      private static final long serialVersionUID = 1L;
41  
42      private final BigInteger degree;
43  
44      private AtLeastPB(ILits voc, IVecInt ps, int degree) {
45          super(voc, ps, degree);
46          this.degree = BigInteger.valueOf(degree);
47      }
48  
49      public static AtLeastPB atLeastNew(UnitPropagationListener s, ILits voc,
50              IVecInt ps, int n) throws ContradictionException {
51          int degree = niceParameters(s, voc, ps, n);
52          if (degree == 0)
53              return null;
54          return new AtLeastPB(voc, ps, degree);
55      }
56  
57      public static AtLeastPB atLeastNew(ILits voc, IVecInt ps, int n) {
58          return new AtLeastPB(voc, ps, n);
59      }
60  
61      public BigInteger getCoef(int literal) {
62          return BigInteger.ONE;
63      }
64  
65      public BigInteger getDegree() {
66          return degree;
67      }
68  
69      public ILits getVocabulary() {
70          return voc;
71      }
72  
73      public int[] getLits() {
74          int[] tmp = new int[size()];
75          System.arraycopy(lits, 0, tmp, 0, size());
76          return tmp;
77      }
78  
79      public BigInteger[] getCoefs() {
80          BigInteger[] tmp = new BigInteger[size()];
81          for (int i = 0; i < tmp.length; i++)
82              tmp[i] = BigInteger.ONE;
83          return tmp;
84      }
85  
86      /**
87       * 
88       */
89      private boolean learnt = false;
90  
91      /**
92       * D?termine si la contrainte est apprise
93       * 
94       * @return true si la contrainte est apprise, false sinon
95       * @see org.sat4j.specs.IConstr#learnt()
96       */
97      @Override
98      public boolean learnt() {
99          return learnt;
100     }
101 
102     @Override
103     public void setLearnt() {
104         learnt = true;
105     }
106 
107     @Override
108     public void register() {
109         assert learnt;
110         // countFalsified();
111     }
112 
113     @Override
114     public void assertConstraint(UnitPropagationListener s) {
115         for (int i = 0; i < size(); i++) {
116             if (getVocabulary().isUnassigned(get(i))) {
117                 boolean ret = s.enqueue(get(i), this);
118                 assert ret;
119             }
120         }
121     }
122 
123     public IVecInt computeAnImpliedClause() {
124         return null;
125     }
126 
127 }