kakuro2formula.cpp File Reference
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>
#include "../libcnf/libcnf.h"
#include "kakuro.h"
+ Include dependency graph for kakuro2formula.cpp:

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 $\bar{x_ijk} \land \bar{x_ijk'}$ for k<k'.
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.

Function Documentation

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().

Parameters:
formThe Formula to modify.
nHintsThe rank of the hint to consider.
nValSetsThe rank of the possible subset of [1,9] to consider.
kakThe kakuro grid concerned.
possibleSumsThe 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.

Parameters:
possibleSumsWill contain all the possible ways to obtain the correct sum it is modified recursively.
currentThe possible values of the cells we are currently considering.
nCellsThe number of cells in the summation.
wantedSumObviously, 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.

Parameters:
formThe formula to modify.
kakThe 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 $\bar{x_ijk} \land \bar{x_ijk'}$ for k<k'.

Parameters:
iFirst coordinate of the cell.
jSecond coordinate of the cell.
formThe formula in which clauses will be added.

Definition at line 96 of file kakuro2formula.cpp.

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.

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}.

Parameters:
formThe formula to update.
kakThe kakuro grid to consider.

Definition at line 157 of file kakuro2formula.cpp.

 All Classes Files Functions Variables