Go to the documentation of this file.
57 void parse(
int& argc,
char* argv[]) {
71 std::cerr <<
"\t(string) " << std::endl
72 <<
"\t\tdimacs file to parse (.cnf)" << std::endl;
119 parseDIMACS(
opt.filename.c_str());
131 return new Sat(*
this);
137 os <<
"solution:\n" <<
x << std::endl;
144 std::ifstream dimacs(
f);
146 std::cerr <<
"error: file '" <<
f <<
"' not found" << std::endl;
149 std::cout <<
"Solving problem from DIMACS file '" <<
f <<
"'"
153 while (dimacs.good()) {
154 std::getline(dimacs,line);
156 if (line[0] ==
'c' || line ==
"") {
159 else if (variables == 0 && clauses == 0 &&
160 line[0] ==
'p' && line[1] ==
' ' &&
161 line[2] ==
'c' && line[3] ==
'n' &&
162 line[4] ==
'f' && line[5] ==
' ') {
164 while (line[
i] >=
'0' && line[
i] <=
'9') {
165 variables = 10*variables + line[
i] -
'0';
169 while (line[
i] >=
'0' && line[
i] <=
'9') {
170 clauses = 10*clauses + line[
i] -
'0';
173 std::cout <<
"(" << variables <<
" variables, "
174 << clauses <<
" clauses)" << std::endl << std::endl;
179 else if (variables > 0 &&
180 ((line[0] >=
'0' && line[0] <=
'9') || line[0] ==
'-' || line[0] ==
' ')) {
182 std::vector<int>
pos;
183 std::vector<int>
neg;
185 while (line[
i] != 0) {
186 if (line[
i] ==
' ') {
191 if (line[
i] ==
'-') {
196 while (line[
i] >=
'0' && line[
i] <=
'9') {
197 value = 10 * value + line[
i] -
'0';
202 pos.push_back(value-1);
204 neg.push_back(value-1);
211 for (
int i=
pos.size();
i--;)
215 for (
int i=
neg.size();
i--;)
222 std::cerr <<
"format error in dimacs file" << std::endl;
223 std::cerr <<
"context: '" << line <<
"'" << std::endl;
224 std::exit(EXIT_FAILURE);
229 std::cerr <<
"error: number of specified clauses seems to be wrong."
231 std::exit(EXIT_FAILURE);
240 int main(
int argc,
char* argv[]) {
247 std::cerr <<
"Could not parse all arguments." << std::endl;
249 std::exit(EXIT_FAILURE);
253 Script::run<Sat,DFS,SatOptions>(
opt);
Post propagator for SetVar x
Sat(Sat &s)
Constructor for cloning.
void 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.
Options for SAT problems.
Gecode toplevel namespace
virtual void help(void)
Print help message.
virtual void print(std::ostream &os) const
Print solution.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Passing Boolean variables.
Parametric base-class for scripts.
virtual Space * copy(void)
Perform copying during cloning.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
void parseDIMACS(const char *f)
Post constraints according to DIMACS file f.
BoolValBranch BOOL_VAL_MIN(void)
Select smallest value.
void positive(int n, const char *l)
Check whether n is in range and strictly positive, otherwise throw out of limits with information l.
BoolVarBranch BOOL_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
Sat(const SatOptions &opt)
The actual problem.
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
virtual void help(void)
Print help text.
SatOptions(const char *s)
Initialize options with file name s.
std::string filename
Name of the DIMACS file to parse.
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
void clause(Home home, BoolOpType o, const BoolVarArgs &x, const BoolVarArgs &y, int n, IntPropLevel)
Post domain consistent propagator for Boolean clause with positive variables x and negative variables...
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Gecode::FloatVal c(-8, 8)
int main(int argc, char *argv[])
Gecode::IntArgs i({1, 2, 3, 4})
bool pos(const View &x)
Test whether x is postive.