Commit f6815808 authored by Daniel Le Berre's avatar Daniel Le Berre
Browse files

removed deprecated methods Reader.parseInstance() and Reader.decode()

parent 33b77655
Pipeline #20208 failed with stages
in 32 minutes and 3 seconds
......@@ -49,6 +49,11 @@ import org.sat4j.tools.GateTranslator;
@Feature(value = "reader", parent = "expert")
public class AAGReader extends Reader {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final int FALSE = 0;
private static final int TRUE = 1;
......@@ -63,15 +68,6 @@ public class AAGReader extends Reader {
this.solver = new GateTranslator(s);
}
@Override
public String decode(int[] model) {
var stb = new StringBuilder();
for (var i = 0; i < this.nbinputs; i++) {
stb.append(model[i] > 0 ? 1 : 0);
}
return stb.toString();
}
@Override
public void decode(int[] model, PrintWriter out) {
for (var i = 0; i < this.nbinputs; i++) {
......
......@@ -67,15 +67,6 @@ public class AIGReader extends Reader {
this.solver = new GateTranslator(s);
}
@Override
public String decode(int[] model) {
var stb = new StringBuilder();
for (var i = 0; i < this.nbinputs; i++) {
stb.append(model[i] > 0 ? 1 : 0);
}
return stb.toString();
}
@Override
public void decode(int[] model, PrintWriter out) {
for (var i = 0; i < this.nbinputs; i++) {
......
......@@ -263,17 +263,6 @@ public class DimacsReader extends Reader implements Serializable {
}
}
@Override
public String decode(int[] model) {
var stb = new StringBuilder();
for (int element : model) {
stb.append(element);
stb.append(" ");
}
stb.append("0");
return stb.toString();
}
@Override
public void decode(int[] model, PrintWriter out) {
for (int element : model) {
......
......@@ -49,6 +49,11 @@ import org.sat4j.specs.ISolver;
@Feature(value = "reader", parent = "expert")
public class InstanceReader extends Reader {
/**
*
*/
private static final long serialVersionUID = 1L;
private AAGReader aag;
private AIGReader aig;
......@@ -145,12 +150,6 @@ public class InstanceReader extends Reader {
return getDefaultSATReader();
}
@Override
@Deprecated
public String decode(int[] model) {
return this.reader.decode(model);
}
@Override
public void decode(int[] model, PrintWriter out) {
this.reader.decode(model, out);
......
......@@ -177,15 +177,6 @@ public class JSONReader<S extends ISolver> extends Reader {
return solver;
}
/**
* @deprecated use {@link #decode(int[], PrintWriter)} instead
*/
@Override
@Deprecated
public String decode(int[] model) {
return "[" + new VecInt(model) + "]";
}
@Override
public void decode(int[] model, PrintWriter out) {
out.print("[");
......
......@@ -287,17 +287,6 @@ public class LecteurDimacs extends Reader implements Serializable {
return car;
}
@Override
public String decode(int[] model) {
var stb = new StringBuilder();
for (int element : model) {
stb.append(element);
stb.append(" ");
}
stb.append("0");
return stb.toString();
}
@Override
public void decode(int[] model, PrintWriter out) {
if (isUsingMapping() && hasAMapping()) {
......
......@@ -148,48 +148,6 @@ public abstract class Reader implements Serializable {
public abstract IProblem parseInstance(final InputStream in)
throws ParseFormatException, ContradictionException, IOException;
/**
* Read a file from a reader.
*
* Do not use that method, it is no longer supported.
*
* @param in
* a stream containing the benchmark.
* @return the problem to solve (an ISolver in fact).
* @throws ParseFormatException
* if an error occurs during parsing.
* @throws IOException
* if an I/O error occurs.
* @throws ContradictionException
* if the problem is found trivially inconsistent.
* @see #parseInstance(InputStream)
* @deprecated use {@link #parseInstance(InputStream)} instead
*/
@Deprecated
public IProblem parseInstance(java.io.Reader in)
throws ParseFormatException, ContradictionException, IOException {
throw new UnsupportedOperationException(
"Use #parseInstance(InputStream) instead");
}
/**
* Produce a model using the reader format.
*
* Note that the approach of building a string representation of the model
* may be quite inefficient when the model is rather large. For that reason,
* the preferred way to proceed is to directly output the textual
* representation in a specific PrintWriter using
* {@link #decode(int[], PrintWriter)}
*
* @param model
* a model using the Dimacs format.
* @return a human readable view of the model.
* @see #decode(int[], PrintWriter)
* @deprecated use {@link #decode(int[], PrintWriter)} instead
*/
@Deprecated
public abstract String decode(int[] model);
/**
* Produce a model using the reader format on a provided printwriter.
*
......
......@@ -754,7 +754,6 @@ public class OPBReader2005 extends Reader implements Serializable {
}
}
@Override
public IProblem parseInstance(final java.io.Reader input)
throws ParseFormatException, ContradictionException {
IProblem problem = parseInstance(new LineNumberReader(input));
......@@ -783,23 +782,6 @@ public class OPBReader2005 extends Reader implements Serializable {
}
}
@Override
public String decode(int[] model) {
StringBuilder stb = new StringBuilder();
for (int i = 0; i < model.length; i++) {
if (model[i] < 0) {
stb.append("-x");
stb.append(-model[i]);
} else {
stb.append("x");
stb.append(model[i]);
}
stb.append(" ");
}
return stb.toString();
}
@Override
public void decode(int[] model, PrintWriter out) {
for (int i = 0; i < model.length; i++) {
......
......@@ -317,26 +317,6 @@ public class OPBReader2007 extends OPBReader2006 {
return null;
}
@Override
public String decode(int[] model) {
StringBuilder stb = new StringBuilder();
int p;
for (int element : model) {
p = element;
if (Math.abs(p) <= this.nbVars) {
if (p < 0) {
stb.append("-x");
stb.append(-p);
} else {
stb.append("x");
stb.append(p);
}
stb.append(" ");
}
}
return stb.toString();
}
@Override
public void decode(int[] model, PrintWriter out) {
int p;
......
......@@ -8,7 +8,6 @@ import java.io.StringReader;
import org.junit.Test;
import org.sat4j.pb.reader.OPBReader2012;
import org.sat4j.reader.ParseFormatException;
import org.sat4j.reader.Reader;
import org.sat4j.specs.ContradictionException;
public class BugJo {
......@@ -17,7 +16,7 @@ public class BugJo {
public void testJoUnit()
throws ParseFormatException, ContradictionException, IOException {
IPBSolver solver = SolverFactory.newDefault();
Reader reader = new OPBReader2012(
OPBReader2012 reader = new OPBReader2012(
new PBSolverHandle(new PseudoOptDecorator(solver)));
reader.parseInstance(new StringReader(
"* #variable= 1 #constraint= 1\n*\n+1 x1 >= 1 ;\n"));
......@@ -30,7 +29,7 @@ public class BugJo {
public void testJoBinary()
throws ParseFormatException, ContradictionException, IOException {
IPBSolver solver = SolverFactory.newDefault();
Reader reader = new OPBReader2012(
OPBReader2012 reader = new OPBReader2012(
new PBSolverHandle(new PseudoOptDecorator(solver)));
reader.parseInstance(new StringReader(
"* #variable= 2 #constraint= 1\n*\n+1 x1 +1 x2 >= 1 ;\n"));
......
......@@ -79,7 +79,6 @@ public class GoodOPBReader extends Reader implements Serializable {
this.solver = solver;
}
@Override
public final IProblem parseInstance(final java.io.Reader in)
throws ParseFormatException, ContradictionException, IOException {
return parseInstance(new LineNumberReader(in));
......@@ -199,21 +198,6 @@ public class GoodOPBReader extends Reader implements Serializable {
}
}
@Override
public String decode(int[] model) {
StringBuilder stb = new StringBuilder();
for (int i = 0; i < model.length; i++) {
if (model[i] < 0) {
stb.append("-");
stb.append(this.decode.get(-model[i] - 1));
} else {
stb.append(this.decode.get(model[i] - 1));
}
stb.append(" ");
}
return stb.toString();
}
@Override
public void decode(int[] model, PrintWriter out) {
for (int i = 0; i < model.length; i++) {
......
......@@ -67,6 +67,8 @@ import org.sat4j.tools.DotSearchTracing;
*/
public class KTHLauncher {
private static final PrintWriter out = new PrintWriter(System.out);
public static Options createCLIOptions() {
Options options = new Options();
options.addOption("cl", "coeflim", true,
......@@ -520,7 +522,7 @@ public class KTHLauncher {
// stop the solver before displaying solutions
optimizer.expireTimeout();
optimizer.printStat(new PrintWriter(System.out));
optimizer.printStat(out);
}
};
Runtime.getRuntime().addShutdownHook(shutdownHook);
......@@ -541,7 +543,9 @@ public class KTHLauncher {
} else {
log("SATISFIABLE", "s ");
}
log(reader.decode(optimizer.model()) + " 0", "v ");
out.print("v ");
reader.decode(optimizer.model(),out);
out.println(" 0");
} else {
log("UNSATISFIABLE", "s ");
}
......
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