Commit b7cdc0b0 authored by Thibault Falque's avatar Thibault Falque
Browse files

Add PureLiterals

parent 09d77cdf
......@@ -40,6 +40,12 @@ public class PreprocessibleSolver extends PBSolverDecorator {
}
@Override
public int newVar(int howmany) {
this.preprocessor.setNumberVariable(howmany);
return super.newVar(howmany);
}
@Override
public IConstr addAtMost(IVecInt literals, IVecInt coeffs, int degree)
throws ContradictionException {
......
......@@ -15,6 +15,7 @@ public abstract class AbstractPBPreprocessing implements PBPreprocessing {
private final PBPreprocessing next;
protected PBSolverStats stats;
protected int nbVar;
public AbstractPBPreprocessing(PBPreprocessing next) {
this.next = next;
......@@ -50,4 +51,10 @@ public abstract class AbstractPBPreprocessing implements PBPreprocessing {
return sb.toString();
}
@Override
public void setNumberVariable(int nvar) {
this.nbVar = nvar;
next.setNumberVariable(nvar);
}
}
......@@ -38,4 +38,9 @@ public final class NullPBPreprocessing implements PBPreprocessing {
return "";
}
@Override
public void setNumberVariable(int nvar) {
}
}
......@@ -18,4 +18,6 @@ public interface PBPreprocessing {
void setStats(PBSolverStats stats);
String toString(String prefix);
void setNumberVariable(int nvar);
}
......@@ -31,6 +31,10 @@ public class PBPreprocessingConstraint implements ITransformConstraint {
return literals;
}
public boolean isEqualConstraint() {
return type == PBPreprocessingConstraintType.EQ;
}
public BigInteger getCoeff(int lit) {
int index = literals.indexOf(lit);
if (index == -1) {
......
......@@ -61,9 +61,9 @@ public class ProbingPBPreprocessing extends AbstractPBPreprocessing {
});
IVecInt literals = new VecInt();
IVec<BigInteger> coeffs = new Vec<>();
propagatedLiterals = new IVecInt[(solver.nVars() << 1) + 2];
propagatedLiterals = new IVecInt[(this.nbVar << 1) + 2];
for (int i = 1; i <= solver.nVars(); i++) {
for (int i = 1; i <= this.nbVar; i++) {
int nb = 0;
for (int j = -1; j <= 1; j += 2) {
int lit = i * j;
......
/**
* Sat4j-CSP, a CSP solver based on the Sat4j platform.
* Copyright (c) 2021-2022 - Thibault Falque and Romain Wallon.
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* If not, see {@link http://www.gnu.org/licenses}.
*/
package org.sat4j.pb.preprocessing;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.sat4j.core.LiteralsUtils;
import org.sat4j.core.Vec;
import org.sat4j.core.VecInt;
import org.sat4j.specs.IVec;
import org.sat4j.specs.IVecInt;
import org.sat4j.specs.IteratorInt;
/**
* The PureLiteralsPBPreprocessing
*
* @author Thibault Falque
* @author Romain Wallon
*
* @version 0.1.0
*/
public class PureLiteralsPBPreprocessing extends AbstractPBPreprocessing {
private boolean[] lits;
public PureLiteralsPBPreprocessing(PBPreprocessing preproc) {
super(preproc);
}
/*
* (non-Javadoc)
*
* @see
* org.sat4j.pb.preprocessing.AbstractPBPreprocessing#internalPreprocess(
* java.util.List)
*/
@Override
protected List<PBPreprocessingConstraint> internalPreprocess(
List<PBPreprocessingConstraint> constraints) {
lits = new boolean[(this.nbVar << 1) + 2];
List<PBPreprocessingConstraint> finalConstraint = new ArrayList<>(
constraints);
for (PBPreprocessingConstraint ctr : constraints) {
if (ctr.isEqualConstraint()) {
for (IteratorInt it = ctr.getLiterals().iterator(); it
.hasNext();) {
int l = it.next();
lits[LiteralsUtils.toInternal(l)] = true;
lits[LiteralsUtils.toInternal(-l)] = true;
}
} else {
PBPreprocessingConstraint normalizeCtr = ctr.normalize();
for (IteratorInt it = normalizeCtr.getLiterals().iterator(); it
.hasNext();) {
int l = it.next();
lits[LiteralsUtils.toInternal(l)] = true;
}
}
}
IVecInt tmpLits = new VecInt();
IVec<BigInteger> coeffs = new Vec<>();
for (int i = 2; i < lits.length; i += 2) {
if (lits[i] && lits[i + 1]) {
continue;
}
int tmpLit = lits[i] ? LiteralsUtils.toDimacs(i)
: LiteralsUtils.toDimacs(i + 1);
tmpLits.push(tmpLit);
coeffs.push(BigInteger.ONE);
}
if (!tmpLits.isEmpty()) {
finalConstraint.add(PBPreprocessingConstraint.newAtLeast(tmpLits,
coeffs, BigInteger.valueOf(tmpLits.size())));
}
return finalConstraint;
}
}
<!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>
<body>
SAT4J: a SATisfiability library for Java.
<pre>
/*******************************************************************************
* 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++.
*
*******************************************************************************/
</pre>
</body>
\ No newline at end of file
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