optimize a total lengh of non-crossing paths which connect each pair of points with the same number.
minimize path length maximize path length
┏━━━┳━━━┳━━━┳━━━┳━━━┳━━━┳━━━┓ ┏━━━┳━━━┳━━━┳━━━┳━━━┳━━━┳━━━┓
┃ │ │ 3━━━━━━━┓ │ ┃ ┃ ┏━━━━━━━┓ │ 3━━━━━━━━━━━┓ ┃
┣───┼───┼───┼───┼───┼─┃─┼───┫ ┣─┃─┼───┼─┃─┼───┼───┼───┼─┃─┫
┃ ┏━━━━━━━━━━━━━━━┓ │ ┃ │ ┃ ┃ ┃ │ │ ┗━━━━━━━┓ │ │ ┃ ┃
┣─┃─┼───┼───┼───┼─┃─┼─┃─┼───┫ ┣─┃─┼───┼───┼───┼─┃─┼───┼─┃─┫
┃ ┃ │ ┏━━━━━━━┓ │ ┃ │ ┃ │ ┃ ┃ ┃ │ ┏━━━━━━━┓ │ ┃ │ ┏━━━┛ ┃
┣─┃─┼─┃─┼───┼─┃─┼─┃─┼─┃─┼───┫ ┣─┃─┼─┃─┼───┼─┃─┼─┃─┼─┃─┼───┫
┃ 1 │ ┃ │ 2 │ ┃ │ 1 │ ┃ │ 2 ┃ ┃ 1 │ ┃ │ 2 │ ┃ │ 1 │ ┃ │ 2 ┃
┣───┼─┃─┼─┃─┼─┃─┼───┼─┃─┼─┃─┫ ┣───┼─┃─┼─┃─┼─┃─┼───┼─┃─┼─┃─┫
┃ │ ┃ │ ┃ │ ┗━━━━━━━┛ │ ┃ ┃ ┃ ┏━━━┛ │ ┃ │ ┗━━━━━━━┛ │ ┃ ┃
┣───┼─┃─┼─┃─┼───┼───┼───┼─┃─┫ ┣─┃─┼───┼─┃─┼───┼───┼───┼─┃─┫
┃ │ ┃ │ ┗━━━━━━━━━━━━━━━┛ ┃ ┃ ┃ │ │ ┗━━━━━━━┓ │ │ ┃ ┃
┣───┼─┃─┼───┼───┼───┼───┼───┫ ┣─┃─┼───┼───┼───┼─┃─┼───┼─┃─┫
┃ │ ┗━━━━━━━3 │ │ │ ┃ ┃ ┗━━━━━━━━━━━3 │ ┗━━━━━━━┛ ┃
┗━━━┻━━━┻━━━┻━━━┻━━━┻━━━┻━━━┛ ┗━━━┻━━━┻━━━┻━━━┻━━━┻━━━┻━━━┛
element | formulation | meaning |
---|---|---|
constant | row length of a board | |
constant | column length of a board | |
constant | number of paths | |
index |
|
|
index |
|
|
index | index of paths | |
variable | if a point at |
|
variable | degree of a point $(i,j) along to a |
|
constraint |
if a point |
define sentinel points. |
constraint |
For all paths and points |
define |
constraint |
For all points |
|
constraint |
if a point |
define start/end points. |
constraint |
if a point |
consistent path for each |
constraint |
For all paths and points |
consistent path for each |
objective |
minimize/maximize total path length. |
- add constraints to speed up solving process
-
$n$ -th path must be unique (an isolated closed-loop is prohibited). - turn all-diffrent constraint
$C_3$ into explicit constraint.
-
Distributed under MIT license