Commit feac34bb authored by lonca's avatar lonca
Browse files

Made XCSP2 DIMACS output solvers print the encoding in the same way XCSP3 solvers do.

git-svn-id: svn+ssh://svn.forge.ow2.org/svnroot/sat4j/maven/trunk@2544 ba638df5-4473-46d1-82f8-c3ae2a17a6e1
parent 5de927cb
......@@ -27,6 +27,8 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;
import org.sat4j.core.Vec;
import org.sat4j.csp.Clausifiable;
......@@ -46,6 +48,7 @@ import org.sat4j.specs.ContradictionException;
import org.sat4j.specs.IProblem;
import org.sat4j.specs.ISolver;
import org.sat4j.specs.IVec;
import org.sat4j.specs.IteratorInt;
/**
* This class is a CSP to SAT translator that is able to read a CSP problem
......@@ -509,4 +512,25 @@ public class CSPReader extends Reader implements org.sat4j.csp.xml.ICSPCallback
throws ParseFormatException, ContradictionException, IOException {
return parseInstance(new InputStreamReader(in));
}
@Override
public boolean hasAMapping() {
return true;
}
@Override
public Map<Integer, String> getMapping() {
final SortedMap<Integer, String> mapping = new TreeMap<>();
for(Map.Entry<String, Var> entry : this.varmapping.entrySet()) {
final Var var = entry.getValue();
final Domain dom = var.domain();
for(IteratorInt it = dom.iterator(); it.hasNext(); ) {
final int domVal = it.next();
final int solverVar = var.translate(domVal);
mapping.put(solverVar, var+"="+domVal);
}
}
return mapping;
}
}
......@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
......@@ -92,4 +93,12 @@ public class XMLCSPReader extends org.sat4j.reader.Reader {
cspreader.setVerbosity(b);
}
public boolean hasAMapping() {
return cspreader.hasAMapping();
}
public Map<Integer, String> getMapping() {
return cspreader.getMapping();
}
}
Markdown is supported
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