#include <stdlib.h>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>
#include "../libcnf/libcnf.h"
#include "kakuro.h"
Go to the source code of this file.
Functions | |
void | allSums (std::vector< std::vector< unsigned int > > *possibleSums, std::vector< unsigned int > *current, int nCells, int wantedSum) |
Generates all the subset of [1,9] of size nCells such that the sum of their elements reaches up to wantedSum. In order not to have a huge number of such subsets, we add the constraint that they must be ordered. It is a recusrsive function. | |
void | disjointClauses (Formula *form, Kakuro kak) |
No two cells in the same hint shall have the same value. This function adds to the Formula form the clauses modeling these axioms. | |
void | oneValuePerCell (unsigned int i, unsigned int j, Formula *form) |
We add ![]() | |
void | allowedValues (Formula *form, unsigned int nHints, unsigned int nValSets, Kakuro kak, std::vector< std::vector< unsigned int > > *possibleSums) |
Adds to the Formula form the clauses modeling the fact that each cell must have a value within a certain set. It is subroutine of sumAxioms(). | |
void | sumAxioms (Formula *form, Kakuro kak) |
Adds new closes to the formula, namely those stating that the literals must have a value corresponding to the sum. | |
int | main (int argc, char **argv) |
Main function of this program. |
void allowedValues | ( | Formula * | form, |
unsigned int | nHints, | ||
unsigned int | nValSets, | ||
Kakuro | kak, | ||
std::vector< std::vector< unsigned int > > * | possibleSums | ||
) |
Adds to the Formula form the clauses modeling the fact that each cell must have a value within a certain set. It is subroutine of sumAxioms().
form | The Formula to modify. |
nHints | The rank of the hint to consider. |
nValSets | The rank of the possible subset of [1,9] to consider. |
kak | The kakuro grid concerned. |
possibleSums | The set of all the legal subsets of [1,9]. |
Definition at line 120 of file kakuro2formula.cpp.
void allSums | ( | std::vector< std::vector< unsigned int > > * | possibleSums, |
std::vector< unsigned int > * | current, | ||
int | nCells, | ||
int | wantedSum | ||
) |
Generates all the subset of [1,9] of size nCells such that the sum of their elements reaches up to wantedSum. In order not to have a huge number of such subsets, we add the constraint that they must be ordered. It is a recusrsive function.
possibleSums | Will contain all the possible ways to obtain the correct sum it is modified recursively. |
current | The possible values of the cells we are currently considering. |
nCells | The number of cells in the summation. |
wantedSum | Obviously, the sum we want to reach. |
Definition at line 29 of file kakuro2formula.cpp.
void disjointClauses | ( | Formula * | form, |
Kakuro | kak | ||
) |
No two cells in the same hint shall have the same value. This function adds to the Formula form the clauses modeling these axioms.
form | The formula to modify. |
kak | The kakuro grid to consider. |
Definition at line 72 of file kakuro2formula.cpp.
int main | ( | int | argc, |
char ** | argv | ||
) |
Main function of this program.
Parses the input we want to read a kakuro instance. It then turns it into a CNF formula using a Formula instance from the cnflib.
Definition at line 213 of file kakuro2formula.cpp.
void oneValuePerCell | ( | unsigned int | i, |
unsigned int | j, | ||
Formula * | form | ||
) |
We add for k<k'.
i | First coordinate of the cell. |
j | Second coordinate of the cell. |
form | The formula in which clauses will be added. |
Definition at line 96 of file kakuro2formula.cpp.
Adds new closes to the formula, namely those stating that the literals must have a value corresponding to the sum.
It works by generating, for each hint indexed by nHints, all the possible subsets of [1,9] of the correct size such that sum(subset)=hint[nHints]. For each such valid subset (indexed by nValSets), it creates a new variable y_{nHints,nValSets} which implies that the each cell involved in this hint has a value in that subset. For instance, y_{1,1} => x_{1,1,1} \/ x_{1,1,2}.
form | The formula to update. |
kak | The kakuro grid to consider. |
Definition at line 157 of file kakuro2formula.cpp.