61 void parse(
int& argc,
char* argv[]) {
75 std::cerr <<
"\t(string) " << std::endl
76 <<
"\t\tdimacs file to parse (.cnf)" << std::endl;
128 x.
update(*
this, share, s.x);
134 return new Sat(share,*
this);
140 os <<
"solution:\n" << x << std::endl;
147 std::ifstream dimacs(f);
149 std::cerr <<
"error: file '" << f <<
"' not found" << std::endl;
152 std::cout <<
"Solving problem from DIMACS file '" << f <<
"'"
156 while (dimacs.good()) {
157 std::getline(dimacs,line);
159 if (line[0] ==
'c' || line ==
"") {
162 else if (variables == 0 && clauses == 0 &&
163 line[0] ==
'p' && line[1] ==
' ' &&
164 line[2] ==
'c' && line[3] ==
'n' &&
165 line[4] ==
'f' && line[5] ==
' ') {
167 while (line[i] >=
'0' && line[i] <=
'9') {
168 variables = 10*variables + line[
i] -
'0';
172 while (line[i] >=
'0' && line[i] <=
'9') {
173 clauses = 10*clauses + line[
i] -
'0';
176 std::cout <<
"(" << variables <<
" variables, "
177 << clauses <<
" clauses)" << std::endl << std::endl;
182 else if (variables > 0 &&
183 ((line[0] >=
'0' && line[0] <=
'9') || line[0] ==
'-' || line[0] ==
' ')) {
185 std::vector<int>
pos;
186 std::vector<int>
neg;
188 while (line[i] != 0) {
189 if (line[i] ==
' ') {
194 if (line[i] ==
'-') {
199 while (line[i] >=
'0' && line[i] <=
'9') {
200 value = 10 * value + line[
i] -
'0';
205 pos.push_back(value-1);
207 neg.push_back(value-1);
214 for (
int i=pos.size(); i--;)
215 positives[i] = x[pos[i]];
218 for (
int i=neg.size(); i--;)
219 negatives[i] = x[neg[i]];
225 std::cerr <<
"format error in dimacs file" << std::endl;
226 std::cerr <<
"context: '" << line <<
"'" << std::endl;
227 std::exit(EXIT_FAILURE);
232 std::cerr <<
"error: number of specified clauses seems to be wrong."
234 std::exit(EXIT_FAILURE);
243 int main(
int argc,
char* argv[]) {
250 std::cerr <<
"Could not parse all arguments." << std::endl;
252 std::exit(EXIT_FAILURE);
256 Script::run<Sat,DFS,SatOptions>(
opt);
std::string filename
Name of the DIMACS file to parse.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Sat(bool share, Sat &s)
Constructor for cloning.
virtual void print(std::ostream &os) const
Print solution.
bool pos(const View &x)
Test whether x is postive.
Options for SAT problems.
Parametric base-class for scripts.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i(4, 1, 2, 3, 4)
void parseDIMACS(const char *f)
Post constraints according to DIMACS file f.
void clause(Home home, BoolOpType o, const BoolVarArgs &x, const BoolVarArgs &y, int n, IntConLevel)
Post domain consistent propagator for Boolean clause with positive variables x and negative variables...
IntValBranch INT_VAL_MIN(void)
Select smallest value.
SatOptions(const char *s)
Initialize options with file name s.
virtual Space * copy(bool share)
Perform copying during cloning.
Passing Boolean variables.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Node * x
Pointer to corresponding Boolean expression node.
virtual void help(void)
Print help message.
int main(int argc, char *argv[])
Gecode toplevel namespace
BrancherHandle branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Sat(const SatOptions &opt)
The actual problem.
void positive(int n, const char *l)
Check whether n is in range and strictly positive, otherwise throw out of limits with information l...
bool neg
Is atomic formula negative.
virtual void help(void)
Print help text.