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

Go to the source code of this file.

Defines

#define NONE   100

Functions

void oneValuePerCell (unsigned int i, unsigned int j, Formula *form)
 Adds the clauses encoding the fact that each cell must have one and only one value to the Formula form.
void oneValuePerLine (unsigned int i, Formula *form)
 Adds the clauses corresponding to the uniqueness of each number in a line.
void oneValuePerColumn (unsigned int j, Formula *form)
 Adds the clauses corresponding to the uniqueness of each number in a column.
void oneValuePerSquare (unsigned int i, unsigned int j, Formula *form)
 Adds the clauses corresponding to the fact that each number appears only once in each square.
void grid2restriction (std::vector< std::vector< int > > grid, Formula *form, VariableSet *vars)
 Adds the clauses corresponding to an assignment of the literals known for the sudoku grid.
std::vector< std::vector< int > > parseGrid (std::istream *input)
 Reads a sudoku grid from the input stream and stores it in a std::vector of std::vector of int.
int main (int argc, char **argv)

Define Documentation

#define NONE   100

The value to put in a grid when the value of a cell is not known. It ought to be different from 0..9.

Definition at line 17 of file sudoku2formula.cpp.


Function Documentation

void grid2restriction ( std::vector< std::vector< int > >  grid,
Formula *  form,
VariableSet *  vars 
)

Adds the clauses corresponding to an assignment of the literals known for the sudoku grid.

For each cell of grid, if it is known, adds a one-literal clause to the formula form for each literal corresponding to it.

Definition at line 126 of file sudoku2formula.cpp.

int main ( int  argc,
char **  argv 
)

Definition at line 183 of file sudoku2formula.cpp.

void oneValuePerCell ( unsigned int  i,
unsigned int  j,
Formula *  form 
)

Adds the clauses encoding the fact that each cell must have one and only one value to the Formula form.

First, we add $\bar{x_{ijk}} \land \bar{x_{ijk'}}$ for k<k' and then, second, we add $\lor_{k=0,9} x_{ijk}$

Definition at line 28 of file sudoku2formula.cpp.

void oneValuePerColumn ( unsigned int  j,
Formula *  form 
)

Adds the clauses corresponding to the uniqueness of each number in a column.

We add $\bar{x_{ijk}} \land \bar{x_{i'jk}}$ for i<i', for all k to the Formula form.

Definition at line 79 of file sudoku2formula.cpp.

void oneValuePerLine ( unsigned int  i,
Formula *  form 
)

Adds the clauses corresponding to the uniqueness of each number in a line.

We add $\bar{x_{ijk}} \land \bar{x_{ij'k}}$ for j<j', for all k in the Formula form.

Definition at line 57 of file sudoku2formula.cpp.

void oneValuePerSquare ( unsigned int  i,
unsigned int  j,
Formula *  form 
)

Adds the clauses corresponding to the fact that each number appears only once in each square.

Adds the clauses $\bar{x_{ijk}} \land \bar{x_{i'j'k}}$ for all (i,j) and (i',j') in the square and for all k in [0,8].

Definition at line 102 of file sudoku2formula.cpp.

std::vector< std::vector<int> > parseGrid ( std::istream *  input)

Reads a sudoku grid from the input stream and stores it in a std::vector of std::vector of int.

Returns:
A std::vector of std::vector of int containing the sudoku grid with the NONE value where the number is not known.

Definition at line 149 of file sudoku2formula.cpp.

 All Files Functions Defines