[ library(gfd) | Reference Manual | Alphabetic Index ]
# <ConsistencyModule:> circuit(+Succ,++CostMatrix,+ArcCosts,?Cost)

Constrains elements in Succ to form a Hamiltonian circuit with cost Cost.
*Succ*
- A collection of N different (domain) variables or integers
*CostMatrix*
- A NxN matrix collection of integers
*ArcCosts*
- A collection of N (domain) variables or integers.
*Cost*
- A (domain) variable or integer (array notation accepted).

## Description

Succ is a collection of N elements presenting a digraph of N nodes, where
the i'th element of Succ represents the successor to node i. The constraint
enforces Succ to form a Hamiltonian circuit, a path through every node in
the graph, visiting each node once and forming a circuit. Additionally,
CostMatrix specifies the cost for traversing between each pair of nodes:
CostMatrix[i,j] represents the cost of travelling from node i to j, and
Cost is constrained to the total Cost for the circuit. The i'th element of
ArcCosts is constrained to the cost of the arc in the circuit from node i.

Note that the Gecode implementation of this constraint has index (node id)
starting from 0, rather than 1. This constraint is actually posted
as circuit_offset_g/5 with an offset of 1. A version of this constraint
with native Gecode indexing is available as circuit_g/4.

This constraint can be embedded in a constraint expression in its
functional form (without the last argument).

ConsistencyModule is the optional module specification to give the
consistency level for the propagation for this constraint:
gfd_gac for generalised arc consistency (domain consistency),
and gfd_vc for value consistency.

This constraint is implemented by Gecode's circuit() constraint (variant with
cost and arc costs), using an offset of 1.

## Examples

[eclipse 5]: CostM = []([](0,3,5,7),[](4,0,9,6),[](2,1,0,5),[](-7,8,-2,0)),
circuit([2,3,4,1], CostM, [C1,C2,C3,C4], C).
CostM = []([](0, 3, 5, 7), [](4, 0, 9, 6), [](2, 1, 0, 5), [](-7, 8, -2, 0))
C1 = 3
C2 = 9
C3 = 5
C4 = -7
C = 10

## See Also

circuit / 1, circuit / 3, circuit_g / 4