1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.sat4j.csp;
20
21 import org.sat4j.AbstractLauncher;
22 import org.sat4j.reader.CSPExtSupportReader;
23 import org.sat4j.reader.Reader;
24 import org.sat4j.reader.XMLCSPReader;
25 import org.sat4j.specs.ISolver;
26
27 public class CSPLauncher extends AbstractLauncher {
28
29
30
31
32 private static final long serialVersionUID = 1L;
33
34
35
36
37
38
39 @Override
40 protected ISolver configureSolver(String[] args) {
41 ISolver asolver = SolverFactory.newDefault();
42 log(asolver.toString(COMMENT_PREFIX));
43 return asolver;
44 }
45
46
47
48
49
50
51 @Override
52 protected Reader createReader(final ISolver aSolver, final String problemname) {
53 Reader aReader;
54 if (problemname.endsWith(".txt")) {
55 aReader = new CSPExtSupportReader(aSolver);
56 } else {
57 assert problemname.endsWith(".xml");
58 aReader = new XMLCSPReader(aSolver);
59 }
60 if (System.getProperty("verbose") != null) {
61 log("verbose mode on");
62 aReader.setVerbosity(true);
63 }
64 return aReader;
65 }
66
67 public static void main(String[] args) {
68 AbstractLauncher lanceur = new CSPLauncher();
69 if (args.length != 1) {
70 lanceur.usage();
71 return;
72 }
73 try {
74 lanceur.run(args);
75 } catch (IllegalArgumentException e) {
76 lanceur.log(">>>> " + e.getMessage() + " <<<<");
77 }
78 }
79
80 @Override
81 public void displayLicense() {
82 super.displayLicense();
83 log("That software uses the Rhino library from the Mozilla project.");
84 }
85
86 @Override
87 public void usage() {
88 System.out.println("Please provide a CSP instance file!");
89 }
90
91 @Override
92 protected String getInstanceName(String[] args) {
93 assert args.length == 1;
94 return args[0];
95 }
96
97 }