Skip to content

Commit 24d2a0d

Browse files
authored
[Bridges] fix various docstrings for CSP (#1931)
1 parent 91af9a6 commit 24d2a0d

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

src/Bridges/Constraint/bridges/bin_packing.jl

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,27 @@
99
1010
`BinPackingToMILPBridge` implements the following reformulation:
1111
12-
* ``x \\in BinPacking(c, w)`` into
13-
```math
14-
\\begin{aligned}
15-
z_{ij} \\in \\{0, 1\\} & \\forall i, j \\\\
16-
\\sum\\limits_{j} z_{ij} = 1 & \\forall i \\\\
17-
\\sum\\limits_{i} w_i z_{ij} \\le c & \\forall j \\\\
18-
\\sum\\limits_{j} j z_{ij} == x_i & \\forall i
19-
\\end{aligned}
20-
```
12+
* ``x \\in BinPacking(c, w)`` into a mixed-integer linear program.
13+
14+
## Reformulation
15+
16+
The reformulation is non-trivial, and it depends on the finite domain of each
17+
variable ``x_i``, which we as define ``S_i = \\{l_i,\\ldots,u_i\\}``.
18+
19+
First, we introduce new binary variables ``z_{ij}``, which are ``1`` if variable
20+
``x_i`` takes the value ``j`` in the optimal solution and ``0`` otherwise:
21+
```math
22+
\\begin{aligned}
23+
z_{ij} \\in \\{0, 1\\} & \\;\\; \\forall i \\in 1\\ldots d, j \\in S_i \\\\
24+
x_i - \\sum\\limits_{j\\in S_i} j \\cdot z_{ij} = 0 & \\;\\; \\forall i \\in 1\\ldots d \\\\
25+
\\sum\\limits_{j\\in S_i} z_{ij} = 1 & \\;\\; \\forall i \\in 1\\ldots d \\\\
26+
\\end{aligned}
27+
```
28+
29+
Then, we add the capacity constraint for all possible bins ``j``:
30+
```math
31+
\\sum\\limits_{i} w_i z_{ij} \\le c \\forall j \\in \\bigcup_{i=1,\\ldots,d} S_i
32+
```
2133
2234
## Source node
2335

src/Bridges/Constraint/bridges/count_at_least.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
1010
`CountAtLeastToCountBelongsBridge` implements the following reformulation:
1111
12-
* ``x \\in \\textsf{CountAtLeast}(n, d, set)`` to
13-
``(n_i, x_{d_i}) \\in \\textsf{CountBelongs}(1+d)``
14-
and ``n_i \\ge n``
12+
* ``x \\in \\textsf{CountAtLeast}(n, d, \\mathcal{S})`` to
13+
``(n_i, x_{d_i}) \\in \\textsf{CountBelongs}(1+d, \\mathcal{S})``
14+
and ``n_i \\ge n`` for all ``i``.
1515
1616
## Source node
1717

src/Bridges/Constraint/bridges/count_belongs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ x_i - \\sum\\limits_{j\\in S_i} j \\cdot z_{ij} = 0 & \\;\\; \\forall i \\in 1\\
3030
Finally, ``n`` is constrained to be the number of ``z_{ij}`` elements that are
3131
in ``\\mathcal{S}``:
3232
```math
33-
n - \\sum\\limits_{j \\in \\mathcal{S}} y_{j} = 0
33+
n - \\sum\\limits_{i\\in 1\\ldots d, j \\in \\mathcal{S}} z_{ij} = 0
3434
```
3535
3636
## Source node

src/Bridges/Constraint/bridges/table.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
* ``x \\in Table(t)`` into
1313
```math
1414
\\begin{aligned}
15-
z_{j} \\in \\{0, 1\\} & \\forall i, j \\\\
15+
z_{j} \\in \\{0, 1\\} & \\quad \\forall i, j \\\\
1616
\\sum\\limits_{j=1}^n z_{j} = 1 \\\\
17-
\\sum\\limits_{j=1}^n t_{ij} z_{j} == x_i & \\forall i
17+
\\sum\\limits_{j=1}^n t_{ij} z_{j} = x_i & \\quad \\forall i
1818
\\end{aligned}
1919
```
2020
@@ -30,7 +30,6 @@
3030
3131
* [`MOI.VariableIndex`](@ref) in [`MOI.ZeroOne`](@ref)
3232
* [`MOI.ScalarAffineFunction{T}`](@ref) in [`MOI.EqualTo{T}`](@ref)
33-
* [`MOI.ScalarAffineFunction{T}`](@ref) in [`MOI.LessThan{T}`](@ref)
3433
"""
3534
struct TableToMILPBridge{T,F<:MOI.AbstractVectorFunction} <: AbstractBridge
3635
z::Vector{MOI.VariableIndex}

src/sets.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ end
11631163
"""
11641164
BinPacking(c::T, w::Vector{T}) where {T}
11651165
1166-
The set ``\\{x \\in \\mathbb{R}^d\\}`` where `d = length(w)`, such that each
1166+
The set ``\\{x \\in \\mathbb{Z}^d\\}`` where `d = length(w)`, such that each
11671167
item `i` in `1:d` of weight `w[i]` is put into bin `x[i]`, and the total weight
11681168
of each bin does not exceed `c`.
11691169
@@ -1225,7 +1225,8 @@ Graphs with multiple independent circuits, such as `[2, 1, 3]` and
12251225
12261226
## Also known as
12271227
1228-
This constraint is called `circuit` in MiniZinc.
1228+
This constraint is called `circuit` in MiniZinc, and it is equivalent to forming
1229+
a (potentially sub-optimal) tour in the travelling salesperson problem.
12291230
12301231
## Example
12311232
@@ -1417,8 +1418,8 @@ end
14171418
"""
14181419
Cumulative(dimension::Int)
14191420
1420-
The set ``\\{(s, d, r, b) \\in \\mathbb{R}^{3n+1}\\}``, representing the
1421-
`cumulative`` global constraint, where
1421+
The set ``\\{(s, d, r, b) \\in \\mathbb{Z}^{3n+1}\\}``, representing the
1422+
`cumulative` global constraint, where
14221423
`n == length(s) == length(r) == length(b)` and `dimension = 3n + 1`.
14231424
14241425
`Cumulative` requires that a set of tasks given by start times ``s``, durations
@@ -1456,7 +1457,7 @@ end
14561457
Given a graph comprised of a set of nodes `1..N` and a set of arcs `1..E`
14571458
represented by an edge from node `from[i]` to node `to[i]`, `Path` constrains
14581459
the set
1459-
``(s, t, ns, es) \\in (1..N)\\times(1..N)\\times\\{0,1\\}^N\\times\\{0,1\\}^E``,
1460+
``(s, t, ns, es) \\in (1..N)\\times(1..E)\\times\\{0,1\\}^N\\times\\{0,1\\}^E``,
14601461
to form subgraph that is a path from node `s` to node `t`, where node `n` is in
14611462
the path if `ns[n]` is `1`, and edge `e` is in the path if `es[e]` is `1`.
14621463

0 commit comments

Comments
 (0)