Skip to content

Commit b6e0902

Browse files
committed
breaking: replace DisjunctConstraint with Disjunct
1 parent 98f5246 commit b6e0902

File tree

18 files changed

+164
-164
lines changed

18 files changed

+164
-164
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ Two types of logical constraints are supported:
8585

8686
## Disjunctions
8787

88-
Disjunctions are built by first defining the constraints associated with each disjunct. This is done via the `@constraint` JuMP macro with the extra `DisjunctConstraint` tag specifying the Logical variable associated with the constraint:
88+
Disjunctions are built by first defining the constraints associated with each disjunct. This is done via the `@constraint` JuMP macro with the extra `Disjunct` tag specifying the Logical variable associated with the constraint:
8989

9090
```julia
9191
@variable(model, x)
92-
@constraint(model, x ≤ 100, DisjunctConstraint(Y[1]))
93-
@constraint(model, x ≥ 200, DisjunctConstraint(Y[2]))
92+
@constraint(model, x ≤ 100, Disjunct(Y[1]))
93+
@constraint(model, x ≥ 200, Disjunct(Y[2]))
9494
```
9595

9696
After all disjunct constraints associated with a disjunction have been defined, the disjunction is created with the `@disjunction` macro, where the disjunction is defined as a `Vector` of Logical variables associated with each disjunct:
@@ -99,10 +99,10 @@ After all disjunct constraints associated with a disjunction have been defined,
9999
@disjunction(model, [Y[1], Y[2]])
100100
```
101101

102-
Disjunctions can be nested by passing an additional `DisjunctConstraint` tag. The Logical variable in the `DisjunctConstraint` tag specifies which disjunct, the nested disjunction belongs to:
102+
Disjunctions can be nested by passing an additional `Disjunct` tag. The Logical variable in the `Disjunct` tag specifies which disjunct, the nested disjunction belongs to:
103103

104104
```julia
105-
@disjunction(model, Y[1:2], DisjunctConstraint(Y[3]))
105+
@disjunction(model, Y[1:2], Disjunct(Y[3]))
106106
```
107107

108108
Empty disjuncts are supported in GDP models. When used, the only constraints enforced on the model when the empty disjunct is selected are the global constraints and any other disjunction constraints defined.
@@ -139,8 +139,8 @@ using HiGHS
139139
m = GDPModel(HiGHS.Optimizer)
140140
@variable(m, 0 ≤ x[1:2] ≤ 20)
141141
@variable(m, Y[1:2], Logical)
142-
@constraint(m, [i = 1:2], [2,5][i] ≤ x[i] ≤ [6,9][i], DisjunctConstraint(Y[1]))
143-
@constraint(m, [i = 1:2], [8,10][i] ≤ x[i] ≤ [11,15][i], DisjunctConstraint(Y[2]))
142+
@constraint(m, [i = 1:2], [2,5][i] ≤ x[i] ≤ [6,9][i], Disjunct(Y[1]))
143+
@constraint(m, [i = 1:2], [8,10][i] ≤ x[i] ≤ [11,15][i], Disjunct(Y[2]))
144144
@disjunction(m, Y)
145145
@constraint(m, Y in Exactly(1)) #logical constraint
146146
@objective(m, Max, sum(x))

docs/src/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ Two types of logical constraints are supported:
8585

8686
## Disjunctions
8787

88-
Disjunctions are built by first defining the constraints associated with each disjunct. This is done via the `@constraint` JuMP macro with the extra `DisjunctConstraint` tag specifying the Logical variable associated with the constraint:
88+
Disjunctions are built by first defining the constraints associated with each disjunct. This is done via the `@constraint` JuMP macro with the extra `Disjunct` tag specifying the Logical variable associated with the constraint:
8989

9090
```julia
9191
@variable(model, x)
92-
@constraint(model, x ≤ 100, DisjunctConstraint(Y[1]))
93-
@constraint(model, x ≥ 200, DisjunctConstraint(Y[2]))
92+
@constraint(model, x ≤ 100, Disjunct(Y[1]))
93+
@constraint(model, x ≥ 200, Disjunct(Y[2]))
9494
```
9595

9696
After all disjunct constraints associated with a disjunction have been defined, the disjunction is created with the `@disjunction` macro, where the disjunction is defined as a `Vector` of Logical variables associated with each disjunct:
@@ -99,10 +99,10 @@ After all disjunct constraints associated with a disjunction have been defined,
9999
@disjunction(model, [Y[1], Y[2]])
100100
```
101101

102-
Disjunctions can be nested by passing an additional `DisjunctConstraint` tag. The Logical variable in the `DisjunctConstraint` tag specifies which disjunct, the nested disjunction belongs to:
102+
Disjunctions can be nested by passing an additional `Disjunct` tag. The Logical variable in the `Disjunct` tag specifies which disjunct, the nested disjunction belongs to:
103103

104104
```julia
105-
@disjunction(model, Y[1:2], DisjunctConstraint(Y[3]))
105+
@disjunction(model, Y[1:2], Disjunct(Y[3]))
106106
```
107107

108108
Empty disjuncts are supported in GDP models. When used, the only constraints enforced on the model when the empty disjunct is selected are the global constraints and any other disjunction constraints defined.
@@ -139,8 +139,8 @@ using HiGHS
139139
m = GDPModel(HiGHS.Optimizer)
140140
@variable(m, 0 ≤ x[1:2] ≤ 20)
141141
@variable(m, Y[1:2], Logical)
142-
@constraint(m, [i = 1:2], [2,5][i] ≤ x[i] ≤ [6,9][i], DisjunctConstraint(Y[1]))
143-
@constraint(m, [i = 1:2], [8,10][i] ≤ x[i] ≤ [11,15][i], DisjunctConstraint(Y[2]))
142+
@constraint(m, [i = 1:2], [2,5][i] ≤ x[i] ≤ [6,9][i], Disjunct(Y[1]))
143+
@constraint(m, [i = 1:2], [8,10][i] ≤ x[i] ≤ [11,15][i], Disjunct(Y[2]))
144144
@disjunction(m, Y)
145145
@constraint(m, Y in Exactly(1)) #logical constraint
146146
@objective(m, Max, sum(x))

examples/ex1.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ using HiGHS
77
m = GDPModel()
88
@variable(m, -5 x 10)
99
@variable(m, Y[1:2], Logical)
10-
@constraint(m, 0 x 3, DisjunctConstraint(Y[1]))
11-
@constraint(m, 5 x, DisjunctConstraint(Y[2]))
12-
@constraint(m, x 9, DisjunctConstraint(Y[2]))
10+
@constraint(m, 0 x 3, Disjunct(Y[1]))
11+
@constraint(m, 5 x, Disjunct(Y[2]))
12+
@constraint(m, x 9, Disjunct(Y[2]))
1313
@disjunction(m, [Y[1], Y[2]])
1414
@constraint(m, Y in Exactly(1))
1515
@objective(m, Max, x)

examples/ex2.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ using HiGHS
55
m = GDPModel(HiGHS.Optimizer)
66
@variable(m, 0 x[1:2] 20)
77
@variable(m, Y[1:2], Logical)
8-
@constraint(m, [i = 1:2], [2,5][i] x[i] [6,9][i], DisjunctConstraint(Y[1]))
9-
@constraint(m, [i = 1:2], [8,10][i] x[i] [11,15][i], DisjunctConstraint(Y[2]))
8+
@constraint(m, [i = 1:2], [2,5][i] x[i] [6,9][i], Disjunct(Y[1]))
9+
@constraint(m, [i = 1:2], [8,10][i] x[i] [11,15][i], Disjunct(Y[2]))
1010
@disjunction(m, Y)
1111
@constraint(m, Y in Exactly(1)) #logical constraint
1212
@objective(m, Max, sum(x))

examples/ex3.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ using DisjunctiveProgramming
33
m = GDPModel()
44
@variable(m, -5 x 10)
55
@variable(m, Y[1:2], Logical)
6-
@constraint(m, exp(x) <= 2, DisjunctConstraint(Y[1]))
7-
@constraint(m, x >= -3, DisjunctConstraint(Y[1]))
8-
@constraint(m, exp(x) >= 3, DisjunctConstraint(Y[2]))
9-
@constraint(m, x >= 5, DisjunctConstraint(Y[2]))
6+
@constraint(m, exp(x) <= 2, Disjunct(Y[1]))
7+
@constraint(m, x >= -3, Disjunct(Y[1]))
8+
@constraint(m, exp(x) >= 3, Disjunct(Y[2]))
9+
@constraint(m, x >= 5, Disjunct(Y[2]))
1010
@disjunction(m, Y)
1111
@constraint(m, Y in Exactly(1)) #logical constraint
1212
@objective(m, Max, x)

examples/ex5.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ m = GDPModel()
77
@variable(m, Y[1:2], Logical)
88
@variable(m, W[1:2], Logical)
99
@objective(m, Max, sum(x))
10-
@constraint(m, y1[i=1:2], [1,4][i] x[i] [3,6][i], DisjunctConstraint(Y[1]))
11-
@constraint(m, w1[i=1:2], [1,5][i] x[i] [2,6][i], DisjunctConstraint(W[1]))
12-
@constraint(m, w2[i=1:2], [2,4][i] x[i] [3,5][i], DisjunctConstraint(W[2]))
13-
@constraint(m, y2[i=1:2], [8,1][i] x[i] [9,2][i], DisjunctConstraint(Y[2]))
14-
@disjunction(m, inner, [W[1], W[2]], DisjunctConstraint(Y[1]))
10+
@constraint(m, y1[i=1:2], [1,4][i] x[i] [3,6][i], Disjunct(Y[1]))
11+
@constraint(m, w1[i=1:2], [1,5][i] x[i] [2,6][i], Disjunct(W[1]))
12+
@constraint(m, w2[i=1:2], [2,4][i] x[i] [3,5][i], Disjunct(W[2]))
13+
@constraint(m, y2[i=1:2], [8,1][i] x[i] [9,2][i], Disjunct(Y[2]))
14+
@disjunction(m, inner, [W[1], W[2]], Disjunct(Y[1]))
1515
@disjunction(m, outer, [Y[1], Y[2]])
1616
@constraint(m, Y in Exactly(1))
1717
@constraint(m, W in Exactly(Y[1]))

examples/ex6.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ m = GDPModel()
55
@variable(m, -5 <= x[1:3] <= 5)
66

77
@variable(m, y[1:2], Logical)
8-
@constraint(m, x[1] <= -2, DisjunctConstraint(y[1]))
9-
@constraint(m, x[1] >= 2, DisjunctConstraint(y[2]))
10-
@constraint(m, x[2] == -1, DisjunctConstraint(y[2]))
11-
@constraint(m, x[3] == 1, DisjunctConstraint(y[2]))
8+
@constraint(m, x[1] <= -2, Disjunct(y[1]))
9+
@constraint(m, x[1] >= 2, Disjunct(y[2]))
10+
@constraint(m, x[2] == -1, Disjunct(y[2]))
11+
@constraint(m, x[3] == 1, Disjunct(y[2]))
1212
@disjunction(m, y)
1313
@constraint(m, y in Exactly(1))
1414

1515
@variable(m, w[1:2], Logical)
16-
@constraint(m, x[2] <= -3, DisjunctConstraint(w[1]))
17-
@constraint(m, x[2] >= 3, DisjunctConstraint(w[2]))
18-
@constraint(m, x[3] == 0, DisjunctConstraint(w[2]))
19-
@disjunction(m, w, DisjunctConstraint(y[1]))
16+
@constraint(m, x[2] <= -3, Disjunct(w[1]))
17+
@constraint(m, x[2] >= 3, Disjunct(w[2]))
18+
@constraint(m, x[3] == 0, Disjunct(w[2]))
19+
@disjunction(m, w, Disjunct(y[1]))
2020
@constraint(m, w in Exactly(y[1]))
2121

2222
@variable(m, z[1:2], Logical)
23-
@constraint(m, x[3] <= -4, DisjunctConstraint(z[1]))
24-
@constraint(m, x[3] >= 4, DisjunctConstraint(z[2]))
25-
@disjunction(m, z, DisjunctConstraint(w[1]))
23+
@constraint(m, x[3] <= -4, Disjunct(z[1]))
24+
@constraint(m, x[3] >= 4, Disjunct(z[2]))
25+
@disjunction(m, z, Disjunct(w[1]))
2626
@constraint(m, z in Exactly(w[1]))
2727

2828
##

src/constraints.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,20 @@ end
163163
_error::Function,
164164
func,
165165
set::_MOI.AbstractScalarSet,
166-
tag::DisjunctConstraint
166+
tag::Disjunct
167167
)::_DisjunctConstraint
168168
169169
Extend `JuMP.build_constraint` to add constraints to disjuncts. This in
170170
combination with `JuMP.add_constraint` enables the use of
171171
`@constraint(model, [name], constr_expr, tag)`, where tag is a
172-
`DisjunctConstraint(::Type{LogicalVariableRef})`. The user must specify the
172+
`Disjunct(::Type{LogicalVariableRef})`. The user must specify the
173173
`LogicalVariable` to use as the indicator for the `_DisjunctConstraint` being created.
174174
"""
175175
function JuMP.build_constraint(
176176
_error::Function,
177177
func,
178178
set::_MOI.AbstractScalarSet,
179-
tag::DisjunctConstraint
179+
tag::Disjunct
180180
)
181181
_check_expression(func)
182182
constr = build_constraint(_error, func, set)
@@ -194,7 +194,7 @@ for SetType in (
194194
_error::Function,
195195
func,
196196
set::$($SetType),
197-
tag::DisjunctConstraint
197+
tag::Disjunct
198198
)::_DisjunctConstraint
199199
200200
Extend `JuMP.build_constraint` to add `VectorConstraint`s to disjuncts.
@@ -203,7 +203,7 @@ for SetType in (
203203
_error::Function,
204204
func,
205205
set::$SetType,
206-
tag::DisjunctConstraint
206+
tag::Disjunct
207207
)
208208
_check_expression(func)
209209
constr = build_constraint(_error, func, set)
@@ -218,7 +218,7 @@ function JuMP.build_constraint(
218218
func::AbstractJuMPScalar,
219219
lb::Real,
220220
ub::Real,
221-
tag::DisjunctConstraint
221+
tag::Disjunct
222222
)
223223
_check_expression(func)
224224
constr = build_constraint(_error, func, lb, ub)
@@ -234,7 +234,7 @@ end
234234
name::String = ""
235235
)::DisjunctConstraintRef
236236
237-
Extend `JuMP.add_constraint` to add a [`DisjunctConstraint`](@ref) to a [`GDPModel`](@ref).
237+
Extend `JuMP.add_constraint` to add a [`Disjunct`](@ref) to a [`GDPModel`](@ref).
238238
The constraint is added to the `GDPData` in the `.ext` dictionary of the `GDPModel`.
239239
"""
240240
function JuMP.add_constraint(
@@ -329,7 +329,7 @@ function _disjunction(
329329
model::Model, # TODO: generalize to AbstractModel
330330
structure,
331331
name::String,
332-
tag::DisjunctConstraint
332+
tag::Disjunct
333333
)
334334
dref = _create_disjunction(_error, model, structure, name, true)
335335
obj = constraint_object(dref)
@@ -362,7 +362,7 @@ Function to add a [`Disjunction`](@ref) to a [`GDPModel`](@ref).
362362
disjunction(
363363
model::Model,
364364
disjunct_indicators::Vector{LogicalVariableRef},
365-
nested_tag::DisjunctConstraint,
365+
nested_tag::Disjunct,
366366
name::String = ""
367367
)
368368
@@ -378,7 +378,7 @@ end
378378
function disjunction(
379379
model::Model,
380380
disjunct_indicators,
381-
nested_tag::DisjunctConstraint,
381+
nested_tag::Disjunct,
382382
name::String = ""
383383
) # TODO add kw argument to build exactly 1 constraint
384384
return _disjunction(error, model, disjunct_indicators, name, nested_tag)

src/datatypes.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,20 @@ end
176176
# DISJUNCT CONSTRAINTS
177177
################################################################################
178178
"""
179-
DisjunctConstraint
179+
Disjunct
180180
181181
Used as a tag for constraints that will be used in disjunctions. This is done via
182182
the following syntax:
183183
```julia-repl
184-
julia> @constraint(model, [constr_expr], DisjunctConstraint)
184+
julia> @constraint(model, [constr_expr], Disjunct)
185185
186-
julia> @constraint(model, [constr_expr], DisjunctConstraint(lvref))
186+
julia> @constraint(model, [constr_expr], Disjunct(lvref))
187187
```
188188
where `lvref` is a [`LogicalVariableRef`](@ref) that will ultimately be associated
189189
with the disjunct the constraint is added to. If no `lvref` is given, then one is
190190
generated when the disjunction is created.
191191
"""
192-
struct DisjunctConstraint
192+
struct Disjunct
193193
indicator::LogicalVariableRef
194194
end
195195

@@ -202,7 +202,7 @@ end
202202
"""
203203
DisjunctConstraintIndex
204204
205-
A type for storing the index of a [`DisjunctConstraint`](@ref).
205+
A type for storing the index of a [`Disjunct`](@ref).
206206
207207
**Fields**
208208
- `value::Int64`: The index value.

src/macros.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ macro disjunction(model, args...)
172172
_error("Invalid syntax. Did you mean to use `@disjunctions`?")
173173
end
174174

175-
# TODO: three cases lead to problems when julia variables are used for DisjunctConstraint tags
175+
# TODO: three cases lead to problems when julia variables are used for Disjunct tags
176176
# which violate the cases considered in the table further below. The three cases are
177177
# (i) @disjunction(m, Y[1, :], tag[1]) --> gets confused for @disjunction(m, name[...], Y[1, :]) (Case 2 below)
178178
# (ii) @disjunction(m, Y, tagref) --> gets confused for @disjunction(m, name, Y) (Case 1 below)
@@ -281,8 +281,8 @@ model = GDPModel();
281281
@variable(model, w);
282282
@variable(model, x);
283283
@variable(model, Y[1:4], LogicalVariable);
284-
@constraint(model, [i=1:2], w == i, DisjunctConstraint(Y[i]));
285-
@constraint(model, [i=3:4], x == i, DisjunctConstraint(Y[i]));
284+
@constraint(model, [i=1:2], w == i, Disjunct(Y[i]));
285+
@constraint(model, [i=3:4], x == i, Disjunct(Y[i]));
286286
@disjunctions(model, begin
287287
[Y[1], Y[2]]
288288
[Y[3], Y[4]]

0 commit comments

Comments
 (0)