Kakuro Class Reference
Example scripts (models)

Example: Kakuro More...

## Public Types

enum | { MODEL_DECOMPOSE , MODEL_COMBINE }
| Model variants. More...

## Public Member Functions

IntVar | init (IntVar &x)
| Init the variable x if necessary.
void | distinctlinear (Cache &dc, const IntVarArgs &x, int c, const SizeOptions &opt)
| Post a distinct-linear constraint on variables x with sum c.
| Kakuro (const SizeOptions &opt)
| The actual problem.
| Kakuro (Kakuro &s)
| Constructor for cloning s.
virtual Space * | copy (void)
| Perform copying during cloning.
virtual void | print (std::ostream &os) const
| Print solution.
Public Member Functions inherited from Gecode::Driver::ScriptBase< Driver::IgnoreStepOption< Space > >
| ScriptBase (const Options &opt)
| Constructor.
| ScriptBase (ScriptBase &e)
| Constructor used for cloning.
virtual void | compare (const Space &home, std::ostream &os) const
| Compare with s.
Public Member Functions inherited from Gecode::Driver::IgnoreStepOption< BaseSpace >
| IgnoreStepOption (const Options &)
| Constructor.
| IgnoreStepOption (BaseSpace &e)
| Constructor used for cloning.

## Protected Attributes

const int | w
| Width of board.
const int | h
| Height of board.
IntVarArray | f
| Variables for fields of board.

## Related Symbols

(Note that these are not member symbols.)
int | main (int argc, char *argv[])
| Main-function.

## Kakuro specifications

Each specification starts with two integers for width and height, followed by entries for vertical constraints, an integer -1 (signalling the end of the vertical constraints), entries for the horizontal constraints, and, finally, an integer -1.

Each entry consists of four integers:

- the x-coordinate of the hint
- the y-coordinate of the hint
- the number of fields in the respective direction
- the sum of the fields

The example are taken from the website of Nikoli (from the free section). Thanks to Nikoli for their great puzzles and their brilliant website: www.nikoli.com.

const int | k0 []
| Array of all examples.
const int | k1 []
| Array of all examples.
const int | k2 []
| Array of all examples.
const int | k3 []
| Array of all examples.
const int | k4 []
| Array of all examples.
const int | k5 []
| Array of all examples.
const int | k6 []
| Array of all examples.
const int | k7 []
| Array of all examples.
const int | k8 []
| Array of all examples.
const int | k9 []
| Array of all examples.
const int * | examples []
| Array of all examples.
const unsigned int | n_examples = sizeof(examples)/sizeof(const int*)
| Number of examples.
TupleSet | generate (int n, int c)
| Generate tuple set for n distinct variables with sum c.

## Additional Inherited Members

Static Public Member Functions inherited from Gecode::Driver::ScriptBase< Driver::IgnoreStepOption< Space > >
static std::ostream & | select_ostream (const char *sn, std::ofstream &ofs)
| Choose output stream according to sn.
static void | run (const Options &opt, Script *s=NULL)

## Detailed Description

Example: Kakuro

Another puzzle in the style of Sudoku.

Note that "Modeling and Programming with Gecode" uses this example as a case study.

Definition at line 473 of file kakuro.cpp.

## Member Enumeration Documentation

## anonymous enum

anonymous enum

Model variants.

Enumerator
MODEL_DECOMPOSE | Decompose constraints.
MODEL_COMBINE | Combine distinct and linear constraint.

Definition at line 480 of file kakuro.cpp.

## Constructor & Destructor Documentation

## Kakuro() [1/2]

Kakuro::Kakuro | ( | const SizeOptions & | opt | ) |

inline

The actual problem.

Definition at line 537 of file kakuro.cpp.

## Kakuro() [2/2]

Kakuro::Kakuro | ( | Kakuro & | s | ) |

inline

Constructor for cloning s.

Definition at line 577 of file kakuro.cpp.

## Member Function Documentation

## init()

IntVar Kakuro::init | ( | IntVar & | x | ) |

inline

Init the variable x if necessary.

Definition at line 485 of file kakuro.cpp.

## distinctlinear()

void Kakuro::distinctlinear | ( | Cache & | dc,
|  | const IntVarArgs & | x,
|  | int | c,
|  | const SizeOptions & | opt )

inline

Post a distinct-linear constraint on variables x with sum c.

Definition at line 491 of file kakuro.cpp.

## copy()

virtual Space * Kakuro::copy | ( | void |  | ) |

inline virtual

Perform copying during cloning.

Definition at line 582 of file kakuro.cpp.

## print()

virtual void Kakuro::print | ( | std::ostream & | os | ) | const

inline virtual

Print solution.

Reimplemented from Gecode::Driver::ScriptBase< Driver::IgnoreStepOption< Space > >.

Definition at line 587 of file kakuro.cpp.

## Friends And Related Symbol Documentation

## k0

const int k0[]

related

Initial value:
= {
12,10,
2, 0, 5,16, 3, 0, 2, 4, 5, 0, 3, 6, 6, 0, 2, 4,
7, 0, 5,15, 10, 0, 3, 6, 11, 0, 3, 7, 1, 1, 3, 7,
9, 1, 5,16, 4, 2, 2, 5, 8, 2, 2, 3, 3, 3, 5,16,
6, 3, 3, 8, 5, 4, 5,15, 10, 4, 5,15, 4, 5, 2, 3,
8, 5, 2, 4, 11, 5, 3, 7, 1, 6, 3, 6, 2, 6, 3, 7,
7, 6, 3, 7, 6, 7, 2, 3, 9, 7, 2, 4, -1,
1, 1, 2, 7, 4, 1, 3, 9, 9, 1, 2, 4, 0, 2, 3, 7,
4, 2, 3, 7, 8, 2, 3, 6, 0, 3, 2, 3, 3, 3, 2, 4,
6, 3, 5,16, 0, 4, 4,10, 5, 4, 4,10, 1, 5, 2,10,
4, 5, 3, 6, 8, 5, 2, 5, 2, 6, 4,10, 7, 6, 4,12,
0, 7, 5,16, 6, 7, 2, 4, 9, 7, 2, 4, 0, 8, 3, 7,
4, 8, 3, 8, 8, 8, 3, 6, 0, 9, 2, 3, 4, 9, 3, 7,
8, 9, 2, 3, -1
}

Array of all examples.

Definition at line 68 of file kakuro.cpp.

## k1

const int k1[]

related

Initial value:
= {
12,10,
1, 0, 2, 4, 2, 0, 5,15, 5, 0, 5,18, 6, 0, 2,12,
7, 0, 3, 8, 10, 0, 3,24, 11, 0, 3,23, 3, 1, 2, 7,
9, 1, 3,24, 4, 2, 5,16, 8, 2, 5,35, 1, 3, 2,12,
6, 3, 3,17, 7, 4, 5,34, 10, 4, 5,34, 11, 4, 2,16,
3, 5, 3, 6, 1, 6, 3, 7, 2, 6, 3, 6, 5, 6, 3,23,
9, 6, 2,10, 6, 7, 2,14, 11, 7, 2,10, -1,
0, 1, 2, 3, 4, 1, 3,15, 9, 1, 2,16, 0, 2, 3, 6,
4, 2, 3, 7, 8, 2, 3,24, 1, 3, 4,11, 6, 3, 5,34,
0, 4, 2,14, 3, 4, 3,23, 7, 4, 2,14, 0, 5, 2, 7,
3, 5, 5,15, 9, 5, 2,17, 2, 6, 2, 6, 5, 6, 3,23,
9, 6, 2,13, 0, 7, 5,16, 6, 7, 4,30, 0, 8, 3, 6,
4, 8, 3,23, 8, 8, 3, 7, 0, 9, 2, 4, 4, 9, 3,24,
9, 9, 2,17, -1
}

Array of all examples.

Definition at line 89 of file kakuro.cpp.

## k2

const int k2[]

related

Initial value:
= {
12,10,
2, 0, 5,15, 3, 0, 2, 3, 7, 0, 3, 7, 8, 0, 4,23,
9, 0, 2,12, 10, 0, 3,20, 11, 0, 3, 9, 4, 1, 3, 7,
5, 1, 4,10, 1, 2, 3, 6, 6, 2, 5,15, 9, 3, 2,16,
3, 4, 2, 3, 7, 4, 4,13, 10, 4, 5,35, 11, 4, 3,23,
4, 5, 4,11, 8, 5, 3,23, 1, 6, 3,23, 2, 6, 3,14,
5, 6, 3,11, 3, 7, 2,13, 9, 7, 2,17, -1,
1, 1, 2, 4, 6, 1, 5,15, 1, 2, 4,11, 6, 2, 5,34,
0, 3, 2, 3, 3, 3, 5,15, 9, 3, 2,10, 0, 4, 2, 4,
3, 4, 3, 6, 7, 4, 2,17, 0, 5, 3, 7, 4, 5, 3, 8,
8, 5, 3,18, 2, 6, 2, 3, 5, 6, 3,11, 9, 6, 2,16,
0, 7, 2,16, 3, 7, 5,16, 9, 7, 2,17, 0, 8, 5,16,
6, 8, 4,30, 0, 9, 5,35, 8, 9, 2,17, -1
}

Array of all examples.

Definition at line 110 of file kakuro.cpp.

## k3

const int k3[]

related

Initial value:
= {
12,10,
3, 0, 3, 7, 4, 0, 6,21, 7, 0, 4,29, 8, 0, 2,17,
10, 0, 4,29, 11, 0, 3,23, 2, 1, 3, 6, 6, 1, 2,16,
9, 1, 4,14, 1, 2, 2, 4, 5, 2, 2, 3, 8, 3, 6,22,
3, 4, 4,10, 2, 5, 4,11, 5, 5, 4,10, 7, 5, 2,10,
10, 5, 3,24, 11, 5, 2,16, 1, 6, 3, 7, 6, 6, 2, 9,
9, 6, 3,23, 4, 7, 2, 4, -1,
2, 1, 2, 4, 6, 1, 2,17, 9, 1, 2,16, 1, 2, 3, 6,
5, 2, 6,39, 0, 3, 7,28, 8, 3, 3,24, 0, 4, 2, 3,
3, 4, 2, 3, 6, 4, 4,20, 2, 5, 2, 9, 7, 5, 2, 4,
1, 6, 4,10, 6, 6, 2, 3, 9, 6, 2,16, 0, 7, 3, 6,
4, 7, 7,42, 0, 8, 6,21, 7, 8, 3,21, 0, 9, 2, 4,
3, 9, 2, 3, 7, 9, 2,16, -1
}

Array of all examples.

Definition at line 130 of file kakuro.cpp.

## k4

const int k4[]

related

Initial value:
= {
20,12,
3, 0, 3,21, 4, 0, 2, 4, 5, 0, 4,11, 8, 0, 2, 8,
9, 0, 3, 7, 11, 0, 2, 3, 12, 0, 3, 6, 15, 0, 6,39,
16, 0, 2, 3, 17, 0, 3,23, 2, 1, 5,15, 6, 1, 4,10,
10, 1, 4,11, 14, 1, 4,11, 18, 1, 3, 6, 1, 2, 3,24,
7, 2, 4,14, 13, 2, 2,10, 19, 2, 2,16, 4, 3, 5,18,
8, 3, 4,10, 11, 3, 4,12, 16, 3, 5,33, 3, 4, 3,23,
9, 4, 4,29, 12, 4, 4,30, 17, 4, 3,18, 5, 5, 6,38,
13, 5, 4,29, 18, 5, 5,15, 6, 6, 4,25, 10, 6, 4,12,
14, 6, 4,28, 19, 6, 3,21, 1, 7, 2, 4, 2, 7, 3, 7,
7, 7, 2, 7, 15, 7, 4,11, 3, 8, 3,19, 8, 8, 3,24,
11, 8, 3, 7, 17, 8, 3, 6, 4, 9, 2,16, 9, 9, 2,16,
12, 9, 2,17, 16, 9, 2, 5, -1,
2, 1, 3, 7, 7, 1, 2, 4, 10, 1, 2, 4, 14, 1, 3,19,
1, 2, 5,18, 7, 2, 5,15, 13, 2, 5,16, 0, 3, 3,21,
4, 3, 3, 6, 8, 3, 2, 3, 11, 3, 4,11, 16, 3, 3,20,
0, 4, 2,14, 3, 4, 5,15, 9, 4, 2, 3, 12, 4, 4,29,
17, 4, 2, 8, 0, 5, 4,27, 5, 5, 7,42, 13, 5, 4,12,
1, 6, 4,12, 6, 6, 3, 8, 10, 6, 3,20, 14, 6, 4,29,
2, 7, 4,28, 7, 7, 7,28, 15, 7, 4,28, 0, 8, 2, 3,
3, 8, 4,11, 8, 8, 2,10, 11, 8, 5,35, 17, 8, 2,10,
0, 9, 3, 6, 4, 9, 4,30, 9, 9, 2, 3, 12, 9, 3,19,
16, 9, 3, 7, 1,10, 5,34, 7,10, 5,34, 13,10, 5,17,
2,11, 3,23, 7,11, 2,17, 10,11, 2,10, 14,11, 3, 6,
-1
}

Array of all examples.

Definition at line 150 of file kakuro.cpp.

## k5

const int k5[]

related

Array of all examples.

Definition at line 182 of file kakuro.cpp.

## k6

const int k6[]

related

Array of all examples.

Definition at line 216 of file kakuro.cpp.

## k7

const int k7[]

related

Array of all examples.

Definition at line 249 of file kakuro.cpp.

## k8

const int k8[]

related

Array of all examples.

Definition at line 286 of file kakuro.cpp.

## k9

const int k9[]

related

Array of all examples.

Definition at line 325 of file kakuro.cpp.

## examples

const int* examples[]

related

Initial value:
= {
&k0[0], &k1[0], &k2[0], &k3[0], &k4[0],
&k5[0], &k6[0], &k7[0], &k8[0], &k9[0]
}
Kakuro::k5
const int k5[]
Array of all examples.
Definition kakuro.cpp:182
Kakuro::k3
const int k3[]
Array of all examples.
Definition kakuro.cpp:130
Kakuro::k9
const int k9[]
Array of all examples.
Definition kakuro.cpp:325
Kakuro::k2
const int k2[]
Array of all examples.
Definition kakuro.cpp:110
Kakuro::k8
const int k8[]
Array of all examples.
Definition kakuro.cpp:286
Kakuro::k7
const int k7[]
Array of all examples.
Definition kakuro.cpp:249
Kakuro::k6
const int k6[]
Array of all examples.
Definition kakuro.cpp:216
Kakuro::k0
const int k0[]
Array of all examples.
Definition kakuro.cpp:68
Kakuro::k4
const int k4[]
Array of all examples.
Definition kakuro.cpp:150
Kakuro::k1
const int k1[]
Array of all examples.
Definition kakuro.cpp:89

Array of all examples.

Definition at line 361 of file kakuro.cpp.

## n_examples

const unsigned int n_examples = sizeof(examples)/sizeof(const int*)

related

Number of examples.

Definition at line 366 of file kakuro.cpp.

## generate()

TupleSet generate | ( | int | n,
|  | int | c )

related

Generate tuple set for n distinct variables with sum c.

Definition at line 404 of file kakuro.cpp.

## main()

int main | ( | int | argc,
|  | char * | argv[] )

related

Main-function.

Definition at line 606 of file kakuro.cpp.

## Member Data Documentation

## w

const int Kakuro::w

protected

Width of board.

Definition at line 475 of file kakuro.cpp.

## h

const int Kakuro::h

protected

Height of board.

Definition at line 476 of file kakuro.cpp.

## f

IntVarArray Kakuro::f

protected

Variables for fields of board.

Definition at line 477 of file kakuro.cpp.

The documentation for this class was generated from the following file:

- examples/kakuro.cpp