Commit 78381ecc authored by Romain Wallon's avatar Romain Wallon
Browse files

🐛 Fixes some bugs with probing.

parent 8efbe6a9
Pipeline #19524 passed with stages
in 39 minutes and 29 seconds
......@@ -234,4 +234,22 @@ public class PBPreprocessingConstraint implements ITransformConstraint {
weight.subtract(other.getWeight()));
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < literals.size(); i++) {
int lit = literals.get(i);
BigInteger coef = coeffs.get(i);
builder.append(coef).append(" ");
if (lit < 0) {
builder.append("~");
}
builder.append("x").append(Math.abs(lit)).append(" ");
}
builder.append(type == PBPreprocessingConstraintType.EQ ? "= "
: type == PBPreprocessingConstraintType.LE ? "<= " : ">= ");
builder.append(weight);
return builder.toString();
}
}
......@@ -42,8 +42,8 @@ public class ProbingPBPreprocessing extends AbstractPBPreprocessing {
return new PBSearchListenerAdapter<ISolverService>() {
@Override
public void enqueueing(int p, org.sat4j.specs.IConstr reason) {
propagatedLiterals[LiteralsUtils.toInternal(lit)]
.push(LiteralsUtils.toDimacs(p));
if (reason != null)
propagatedLiterals[LiteralsUtils.toInternal(lit)].push(p);
}
};
}
......@@ -69,9 +69,7 @@ public class ProbingPBPreprocessing extends AbstractPBPreprocessing {
int lit = i * j;
try {
solver.setSearchListener(listener(lit));
if (solver.isSatisfiable(VecInt.of(lit))) {
// the problem is satisfiable
} else {
if (!solver.isSatisfiable(VecInt.of(lit))) {
if (!literals.contains(lit)) {
literals.push(lit);
coeffs.push(BigInteger.ONE);
......@@ -89,23 +87,25 @@ public class ProbingPBPreprocessing extends AbstractPBPreprocessing {
}
checkRequiredLiterals(i, literals, coeffs);
}
if (literals.isEmpty()) {
return constraints;
}
List<PBPreprocessingConstraint> outConstraint = new ArrayList<>(
constraints);
outConstraint.addAll(inferredConstraints);
outConstraint.add(PBPreprocessingConstraint.newAtLeast(literals, coeffs,
BigInteger.valueOf(literals.size())));
if (!literals.isEmpty()) {
PBPreprocessingConstraint requiredLits = PBPreprocessingConstraint
.newAtLeast(literals, coeffs,
BigInteger.valueOf(literals.size()));
outConstraint.add(requiredLits);
}
return outConstraint;
}
private void checkRequiredLiterals(int i, IVecInt literals,
private void checkRequiredLiterals(int variable, IVecInt literals,
IVec<BigInteger> coeffs) {
for (IteratorInt it = propagatedLiterals[LiteralsUtils.posLit(i)]
for (IteratorInt it = propagatedLiterals[LiteralsUtils.posLit(variable)]
.iterator(); it.hasNext();) {
int l = it.next();
if (propagatedLiterals[LiteralsUtils.negLit(i)].contains(l)) {
if (propagatedLiterals[LiteralsUtils.negLit(variable)]
.contains(l)) {
if (!literals.contains(l)) {
literals.push(l);
coeffs.push(BigInteger.ONE);
......@@ -131,8 +131,9 @@ public class ProbingPBPreprocessing extends AbstractPBPreprocessing {
BigInteger degree = BigInteger.valueOf(literals.size());
literals.push(-lit);
coeffs.push(degree);
return Optional.of(
PBPreprocessingConstraint.newAtLeast(literals, coeffs, degree));
PBPreprocessingConstraint constr = PBPreprocessingConstraint
.newAtLeast(literals, coeffs, degree);
return Optional.of(constr);
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June, 2010</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available at <a href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/legal/epl-v10.html</a>. For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may apply to your use of any object code in the Content. Check the Redistributor&rsquo;s license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise indicated below, the terms and conditions of the EPL still apply to any source code in the Content and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
<h3>Third Party Content</h3>
<p>The Content includes items that have been sourced from third parties as set out below. If you did not receive this Content directly from the Eclipse Foundation, the following is provided for informational purposes only, and you should look to the Redistributor&rsquo;s license for terms and conditions of use.</p>
<h4>SAT4J 3.0.0-SNAPSHOT SUBSET (Pseudo) </h4>
<p>The SAT4J project makes available all content in this plug-in ("Content"). Your use of the Content is governed by the terms and conditions of the Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. For purposes of the EPL, "Program" will mean the Content. </p>
<p>Alternatively, the Content may be obtained from the SAT4J project website at <a href="http://www.sat4j.org/">http://www.sat4j.org/</a> for use 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 the Content only under the terms of the LGPL, and not to allow others to use your version of this Content 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.</p>
<p>The Eclipse Foundation elects to include this software in this distribution under the EPL license. The source code for this plug-in can be obtained from the SAT4J project website at <a href="http://www.sat4j.org/">http://www.sat4j.org/</a></p>
<p>SAT4J includes content that was obtained under licenses that differ from the SAT4J licenses. <br />
The content in the following classes</br>
<ul>
<li>org/sat4j/pb/reader/OPBReader2005.java</li>
<li>org/sat4j/pb/reader/OPBReader2007.java</li>
</ul>
<p>is based on a parser for pseudo-Boolean instances (the &quot;Official&quot; reader for the Pseudo Boolean evaluation 2005) and was obtained from
<ul><li><a href="http://www.cril.univ-artois.fr/PB05/parser/SimpleParser.java">http://www.cril.univ-artois.fr/PB05/parser/SimpleParser.java</a> and </li>
<li><a href="http://www.cril.univ-artois.fr/PB07/parser/SimpleParser.java">http://www.cril.univ-artois.fr/PB07/parser/SimpleParser.java</a></li> </ul></br>under the following permissive license:<br />
<br />
Copyright (c) 2005-2007 Olivier ROUSSEL and Vasco MANQUINHO<br />
<br />
Permission is hereby granted, free of charge, to any person obtaining a copy<br />
of this software and associated documentation files (the &quot;Software&quot;), to deal<br />
in the Software without restriction, including without limitation the rights<br />
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br />
copies of the Software, and to permit persons to whom the Software is<br />
furnished to do so, subject to the following conditions:<br />
<br />
The above copyright notice and this permission notice shall be included in<br />
all copies or substantial portions of the Software.<br />
<br />
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br />
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br />
THE SOFTWARE.<br />
</p>
</body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June, 2010</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available at <a href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/legal/epl-v10.html</a>. For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may apply to your use of any object code in the Content. Check the Redistributor&rsquo;s license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise indicated below, the terms and conditions of the EPL still apply to any source code in the Content and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
<h3>Third Party Content</h3>
<p>The Content includes items that have been sourced from third parties as set out below. If you did not receive this Content directly from the Eclipse Foundation, the following is provided for informational purposes only, and you should look to the Redistributor&rsquo;s license for terms and conditions of use.</p>
<h4>SAT4J 3.0.0-SNAPSHOT SUBSET (Pseudo) </h4>
<p>The SAT4J project makes available all content in this plug-in ("Content"). Your use of the Content is governed by the terms and conditions of the Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. For purposes of the EPL, "Program" will mean the Content. </p>
<p>Alternatively, the Content may be obtained from the SAT4J project website at <a href="http://www.sat4j.org/">http://www.sat4j.org/</a> for use 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 the Content only under the terms of the LGPL, and not to allow others to use your version of this Content 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.</p>
<p>The Eclipse Foundation elects to include this software in this distribution under the EPL license. The source code for this plug-in can be obtained from the SAT4J project website at <a href="http://www.sat4j.org/">http://www.sat4j.org/</a></p>
<p>SAT4J includes content that was obtained under licenses that differ from the SAT4J licenses. <br />
The content in the following classes</br>
<ul>
<li>org/sat4j/pb/reader/OPBReader2005.java</li>
<li>org/sat4j/pb/reader/OPBReader2007.java</li>
</ul>
<p>is based on a parser for pseudo-Boolean instances (the &quot;Official&quot; reader for the Pseudo Boolean evaluation 2005) and was obtained from
<ul><li><a href="http://www.cril.univ-artois.fr/PB05/parser/SimpleParser.java">http://www.cril.univ-artois.fr/PB05/parser/SimpleParser.java</a> and </li>
<li><a href="http://www.cril.univ-artois.fr/PB07/parser/SimpleParser.java">http://www.cril.univ-artois.fr/PB07/parser/SimpleParser.java</a></li> </ul></br>under the following permissive license:<br />
<br />
Copyright (c) 2005-2007 Olivier ROUSSEL and Vasco MANQUINHO<br />
<br />
Permission is hereby granted, free of charge, to any person obtaining a copy<br />
of this software and associated documentation files (the &quot;Software&quot;), to deal<br />
in the Software without restriction, including without limitation the rights<br />
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br />
copies of the Software, and to permit persons to whom the Software is<br />
furnished to do so, subject to the following conditions:<br />
<br />
The above copyright notice and this permission notice shall be included in<br />
all copies or substantial portions of the Software.<br />
<br />
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br />
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br />
THE SOFTWARE.<br />
</p>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment