Contains the functions used to turn a Slitherlink puzzle into a CNF formula. More...
Go to the source code of this file.
Classes | |
struct | coord |
Rather self explanatory: it is used to easily store and retrieve coordinates in the grid. More... | |
Defines | |
#define | HORIZONTAL 0 |
#define | VERTICAL 1 |
#define | HORIZONTAL_EDGE_INDEX 2 |
#define | VERTICAL_EDGE_INDEX 3 |
#define | HORIZONTAL_EDGE_SENSE 4 |
#define | VERTICAL_EDGE_SENSE 5 |
#define | NUMBERING 2 |
#define | SENSE 4 |
Functions | |
void | getHneighbours (Slitherlink *sl, unsigned int i, unsigned int j, std::vector< coord > *neighbours1, std::vector< coord > *neighbours2) |
Retrieves the codes of the neighbours of a given horizontal edge depending on its position in the grid. | |
void | getVneighbours (Slitherlink *sl, unsigned int i, unsigned int j, std::vector< coord > *neighbours1, std::vector< coord > *neighbours2) |
Retrieves the codes of the neighbours of a given vertical edge depending on its position in the grid. | |
void | addContinuityAxioms (cnf::Formula *form, int edgeCode, std::vector< coord > neighbours) |
Writes axioms enforcing the loop to be continuous, i.e. that if an edge is in the loop then exactly one of its neighbous is. | |
std::vector< int > | hintNeighbours (cnf::VariableSet *vars, unsigned int i, unsigned int j) |
Returns a vector containing the code of the positive literals corresponding to the $x_e$ variables for each $e$ around the cell at $(i,j)$. | |
void | addHintAxioms0 (cnf::Formula *form, Slitherlink *sl, cnf::VariableSet *vars, unsigned int i, unsigned int j) |
Add the clauses corresponding to a hint equal to zero, i.e. that all edges around it should be set to false. | |
void | addHintAxioms1 (cnf::Formula *form, Slitherlink *sl, cnf::VariableSet *vars, unsigned int i, unsigned int j) |
Add the clauses corresponding to a hint equal to 1, i.e. the following set of clauses: | |
void | addHintAxioms2 (cnf::Formula *form, Slitherlink *sl, cnf::VariableSet *vars, unsigned int i, unsigned int j) |
Adds the clauses corresponding to a hint being equal to 2, namely these: | |
void | addHintAxioms3 (cnf::Formula *form, Slitherlink *sl, cnf::VariableSet *vars, unsigned int i, unsigned int j) |
Adds clauses corresponding to a hint being equal to 3, namely: | |
void | addHintAxioms (cnf::Formula *form, Slitherlink *sl, cnf::VariableSet *vars, unsigned int i, unsigned int j) |
void | addContinuityAndNumberingAxioms (cnf::Formula *form, int orientation, unsigned int i, unsigned int j, unsigned int maxLoopSize) |
Adds axioms stating that if an edge is activated then it has a unique index. | |
void | addIncreasingIndexAxioms (cnf::Formula *form, int orientation, unsigned int i, unsigned int j, unsigned int index, bool isNeighboursGreater, bool sense, std::vector< coord > neighbours) |
Adds axioms stating that the if the edge at $(i,j)$ with orientation $orientation$ has index $index$ then: | |
void | placeZero (cnf::Formula *form, Slitherlink *sl, cnf::VariableSet *vars, unsigned int i, unsigned int j) |
It, well, places the zero obviously. It adds clauses to the formula enforcing that the edge with index zero has to touch a non-zero hint (the first one encountered) and that there can only be one around this hint. It then sets all the other edges to be non-zero. | |
int | main (int argc, char *argv[]) |
Contains the functions used to turn a Slitherlink puzzle into a CNF formula.
Definition in file slitherlink2formula.cpp.
#define HORIZONTAL 0 |
Definition at line 17 of file slitherlink2formula.cpp.
#define HORIZONTAL_EDGE_INDEX 2 |
Definition at line 19 of file slitherlink2formula.cpp.
#define HORIZONTAL_EDGE_SENSE 4 |
Definition at line 21 of file slitherlink2formula.cpp.
#define NUMBERING 2 |
Definition at line 24 of file slitherlink2formula.cpp.
#define SENSE 4 |
Definition at line 25 of file slitherlink2formula.cpp.
#define VERTICAL 1 |
Definition at line 18 of file slitherlink2formula.cpp.
#define VERTICAL_EDGE_INDEX 3 |
Definition at line 20 of file slitherlink2formula.cpp.
#define VERTICAL_EDGE_SENSE 5 |
Definition at line 22 of file slitherlink2formula.cpp.
void addContinuityAndNumberingAxioms | ( | cnf::Formula * | form, |
int | orientation, | ||
unsigned int | i, | ||
unsigned int | j, | ||
unsigned int | maxLoopSize | ||
) |
Adds axioms stating that if an edge is activated then it has a unique index.
form | The formula where to put the clauses |
orientation | The orientation of the edge (HORIZONTAL or not?) |
i | Abscissa of the edge |
j | Ordena of the edge |
maxLoopSize | The maximum index it can have |
Definition at line 359 of file slitherlink2formula.cpp.
void addContinuityAxioms | ( | cnf::Formula * | form, |
int | edgeCode, | ||
std::vector< coord > | neighbours | ||
) |
Writes axioms enforcing the loop to be continuous, i.e. that if an edge is in the loop then exactly one of its neighbous is.
The idea is to run this on the two sets of neighbours of a given edge. It will add the following axioms:
form | |
edgeCode | |
neighbours |
Definition at line 169 of file slitherlink2formula.cpp.
void addHintAxioms | ( | cnf::Formula * | form, |
Slitherlink * | sl, | ||
cnf::VariableSet * | vars, | ||
unsigned int | i, | ||
unsigned int | j | ||
) |
Definition at line 329 of file slitherlink2formula.cpp.
void addHintAxioms0 | ( | cnf::Formula * | form, |
Slitherlink * | sl, | ||
cnf::VariableSet * | vars, | ||
unsigned int | i, | ||
unsigned int | j | ||
) |
Add the clauses corresponding to a hint equal to zero, i.e. that all edges around it should be set to false.
Definition at line 227 of file slitherlink2formula.cpp.
void addHintAxioms1 | ( | cnf::Formula * | form, |
Slitherlink * | sl, | ||
cnf::VariableSet * | vars, | ||
unsigned int | i, | ||
unsigned int | j | ||
) |
Add the clauses corresponding to a hint equal to 1, i.e. the following set of clauses:
Definition at line 247 of file slitherlink2formula.cpp.
void addHintAxioms2 | ( | cnf::Formula * | form, |
Slitherlink * | sl, | ||
cnf::VariableSet * | vars, | ||
unsigned int | i, | ||
unsigned int | j | ||
) |
Adds the clauses corresponding to a hint being equal to 2, namely these:
Definition at line 275 of file slitherlink2formula.cpp.
void addHintAxioms3 | ( | cnf::Formula * | form, |
Slitherlink * | sl, | ||
cnf::VariableSet * | vars, | ||
unsigned int | i, | ||
unsigned int | j | ||
) |
Adds clauses corresponding to a hint being equal to 3, namely:
Definition at line 307 of file slitherlink2formula.cpp.
void addIncreasingIndexAxioms | ( | cnf::Formula * | form, |
int | orientation, | ||
unsigned int | i, | ||
unsigned int | j, | ||
unsigned int | index, | ||
bool | isNeighboursGreater, | ||
bool | sense, | ||
std::vector< coord > | neighbours | ||
) |
Adds axioms stating that the if the edge at $(i,j)$ with orientation $orientation$ has index $index$ then:
Definition at line 391 of file slitherlink2formula.cpp.
void getHneighbours | ( | Slitherlink * | sl, |
unsigned int | i, | ||
unsigned int | j, | ||
std::vector< coord > * | neighbours1, | ||
std::vector< coord > * | neighbours2 | ||
) |
Retrieves the codes of the neighbours of a given horizontal edge depending on its position in the grid.
[out] | neighbours1 | When the call is done, contains the coordinates of the variables on the right of the vertex. |
[out] | neighbours2 | When the call is done, contains the coordinates of the variables on the left of the vertex. |
Definition at line 58 of file slitherlink2formula.cpp.
void getVneighbours | ( | Slitherlink * | sl, |
unsigned int | i, | ||
unsigned int | j, | ||
std::vector< coord > * | neighbours1, | ||
std::vector< coord > * | neighbours2 | ||
) |
Retrieves the codes of the neighbours of a given vertical edge depending on its position in the grid.
[out] | neighbours1 | When the call is done, contains the coordinates of the variables on top of the vertex. |
[out] | neighbours2 | When the call is done, contains the coordinates of the variables below the vertex. |
Definition at line 112 of file slitherlink2formula.cpp.
std::vector<int> hintNeighbours | ( | cnf::VariableSet * | vars, |
unsigned int | i, | ||
unsigned int | j | ||
) |
Returns a vector containing the code of the positive literals corresponding to the $x_e$ variables for each $e$ around the cell at $(i,j)$.
vars | The variable set. |
i | The first coordinate of the cell. |
j | The second one. |
Definition at line 211 of file slitherlink2formula.cpp.
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 475 of file slitherlink2formula.cpp.
void placeZero | ( | cnf::Formula * | form, |
Slitherlink * | sl, | ||
cnf::VariableSet * | vars, | ||
unsigned int | i, | ||
unsigned int | j | ||
) |
It, well, places the zero obviously. It adds clauses to the formula enforcing that the edge with index zero has to touch a non-zero hint (the first one encountered) and that there can only be one around this hint. It then sets all the other edges to be non-zero.
Definition at line 426 of file slitherlink2formula.cpp.