Skip to content

Commit

Permalink
Merge branch 'master' into fix_documenter
Browse files Browse the repository at this point in the history
  • Loading branch information
hdavid16 authored Oct 13, 2023
2 parents 61e352e + 4463d0c commit c146725
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 155 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI
on:
push:
branches:
- master
tags: '*'
pull_request:
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
version:
- '1.6'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v1
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-uploadcodecov@latest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ data = gdp_data(model)

## Logical Variables

Logical variables are JuMP `AbstractVariable`s with two fields: `fix_value` and `start_value`. These can be optionally specified at variable creation. Logical variables are created with the `@variable` JuMP macro by adding the tag `LogicalVariable` as the last keyword argument. As with the regular `@variable` macro, variables can be named and indexed:
Logical variables are JuMP `AbstractVariable`s with two fields: `fix_value` and `start_value`. These can be optionally specified at variable creation. Logical variables are created with the `@variable` JuMP macro by adding the tag `Logical` as the last keyword argument. As with the regular `@variable` macro, variables can be named and indexed:

```julia
@variable(model, Y[1:3], LogicalVariable)
@variable(model, Y[1:3], Logical)
```

## Logical Constraints
Expand Down Expand Up @@ -133,7 +133,7 @@ using DisjunctiveProgramming
m = GDPModel()
@variable(m, 0 ≤ x[1:2] ≤ 20)
@variable(m, Y[1:2], LogicalVariable)
@variable(m, Y[1:2], Logical)
@constraint(m, [i = 1:2], [2,5][i] ≤ x[i] ≤ [6,9][i], DisjunctConstraint(Y[1]))
@constraint(m, [i = 1:2], [8,10][i] ≤ x[i] ≤ [11,15][i], DisjunctConstraint(Y[2]))
@disjunction(m, Y)
Expand Down
2 changes: 1 addition & 1 deletion examples/ex1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using HiGHS
# Disjunction Method 1: Assign Logical Variables Explicitly
m = GDPModel()
@variable(m, -5 x 10)
@variable(m, Y[1:2], LogicalVariable)
@variable(m, Y[1:2], Logical)
@constraint(m, 0 x 3, DisjunctConstraint(Y[1]))
@constraint(m, 5 x, DisjunctConstraint(Y[2]))
@constraint(m, x 9, DisjunctConstraint(Y[2]))
Expand Down
2 changes: 1 addition & 1 deletion examples/ex2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using HiGHS

m = GDPModel(HiGHS.Optimizer)
@variable(m, 0 x[1:2] 20)
@variable(m, Y[1:2], LogicalVariable)
@variable(m, Y[1:2], Logical)
@constraint(m, [i = 1:2], [2,5][i] x[i] [6,9][i], DisjunctConstraint(Y[1]))
@constraint(m, [i = 1:2], [8,10][i] x[i] [11,15][i], DisjunctConstraint(Y[2]))
@disjunction(m, Y)
Expand Down
2 changes: 1 addition & 1 deletion examples/ex3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using DisjunctiveProgramming

m = GDPModel()
@variable(m, -5 x 10)
@variable(m, Y[1:2], LogicalVariable)
@variable(m, Y[1:2], Logical)
@constraint(m, exp(x) <= 2, DisjunctConstraint(Y[1]))
@constraint(m, x >= -3, DisjunctConstraint(Y[1]))
@constraint(m, exp(x) >= 3, DisjunctConstraint(Y[2]))
Expand Down
2 changes: 1 addition & 1 deletion examples/ex4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using DisjunctiveProgramming
# ¬((Y[1] ∧ ¬Y[2]) ⇔ (Y[3] ∨ Y[4]))

m = GDPModel()
@variable(m, Y[1:4], LogicalVariable)
@variable(m, Y[1:4], Logical)
@constraint(m, ¬((Y[1] ¬Y[2]) (Y[3] Y[4])) IsTrue())
reformulate_model(m, BigM())
print(m)
Expand Down
4 changes: 2 additions & 2 deletions examples/ex5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ using DisjunctiveProgramming
##
m = GDPModel()
@variable(m, 1 x[1:2] 9)
@variable(m, Y[1:2], LogicalVariable)
@variable(m, W[1:2], LogicalVariable)
@variable(m, Y[1:2], Logical)
@variable(m, W[1:2], Logical)
@objective(m, Max, sum(x))
@constraint(m, y1[i=1:2], [1,4][i] x[i] [3,6][i], DisjunctConstraint(Y[1]))
@constraint(m, w1[i=1:2], [1,5][i] x[i] [2,6][i], DisjunctConstraint(W[1]))
Expand Down
6 changes: 3 additions & 3 deletions examples/ex6.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ using DisjunctiveProgramming
m = GDPModel()
@variable(m, -5 <= x[1:3] <= 5)

@variable(m, y[1:2], LogicalVariable)
@variable(m, y[1:2], Logical)
@constraint(m, x[1] <= -2, DisjunctConstraint(y[1]))
@constraint(m, x[1] >= 2, DisjunctConstraint(y[2]))
@constraint(m, x[2] == -1, DisjunctConstraint(y[2]))
@constraint(m, x[3] == 1, DisjunctConstraint(y[2]))
@disjunction(m, y)
@constraint(m, y in Exactly(1))

@variable(m, w[1:2], LogicalVariable)
@variable(m, w[1:2], Logical)
@constraint(m, x[2] <= -3, DisjunctConstraint(w[1]))
@constraint(m, x[2] >= 3, DisjunctConstraint(w[2]))
@constraint(m, x[3] == 0, DisjunctConstraint(w[2]))
@disjunction(m, w, DisjunctConstraint(y[1]))
@constraint(m, w in Exactly(y[1]))

@variable(m, z[1:2], LogicalVariable)
@variable(m, z[1:2], Logical)
@constraint(m, x[3] <= -4, DisjunctConstraint(z[1]))
@constraint(m, x[3] >= 4, DisjunctConstraint(z[2]))
@disjunction(m, z, DisjunctConstraint(w[1]))
Expand Down
2 changes: 2 additions & 0 deletions src/datatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct LogicalVariable <: JuMP.AbstractVariable
start_value::Union{Nothing, Bool}
end

const Logical = LogicalVariable

"""
LogicalVariableData
Expand Down
2 changes: 1 addition & 1 deletion src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end
name::String = "")::LogicalVariableRef
Extend `JuMP.add_variable` for [`LogicalVariable`](@ref)s. This
helps enable `@variable(model, [var_expr], LogicalVariable)`.
helps enable `@variable(model, [var_expr], Logical)`.
"""
function JuMP.add_variable(
model::JuMP.Model,
Expand Down
26 changes: 13 additions & 13 deletions test/constraints/bigm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
function test_get_M_1sided()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, 3*x <= 1, DisjunctConstraint(y))
cobj = constraint_object(con)
M = DP._get_M(cobj.func, cobj.set, BigM(100, false))
Expand All @@ -30,7 +30,7 @@ end
function test_get_tight_M_1sided()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, 3*x <= 1, DisjunctConstraint(y))
cobj = constraint_object(con)

Expand All @@ -53,7 +53,7 @@ end
function test_get_M_2sided()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, 3*x == 1, DisjunctConstraint(y))
cobj = constraint_object(con)

Expand All @@ -69,7 +69,7 @@ end
function test_get_tight_M_2sided()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, 3*x == 1, DisjunctConstraint(y))
cobj = constraint_object(con)

Expand Down Expand Up @@ -176,7 +176,7 @@ end
function test_lessthan_bigm()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, x <= 5, DisjunctConstraint(y))

DP._reformulate_logical_variables(model)
Expand All @@ -190,7 +190,7 @@ end
function test_nonpositives_bigm()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, [x; x] <= [5; 5], DisjunctConstraint(y))

DP._reformulate_logical_variables(model)
Expand All @@ -205,7 +205,7 @@ end
function test_greaterhan_bigm()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, x >= 5, DisjunctConstraint(y))

DP._reformulate_logical_variables(model)
Expand All @@ -219,7 +219,7 @@ end
function test_nonnegatives_bigm()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, [x; x] >= [5; 5], DisjunctConstraint(y))

DP._reformulate_logical_variables(model)
Expand All @@ -234,7 +234,7 @@ end
function test_greaterhan_bigm()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, x == 5, DisjunctConstraint(y))

DP._reformulate_logical_variables(model)
Expand All @@ -250,7 +250,7 @@ end
function test_greaterhan_bigm()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, 5 <= x <= 5, DisjunctConstraint(y))

DP._reformulate_logical_variables(model)
Expand All @@ -266,7 +266,7 @@ end
function test_zeros_bigm()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, con, [x; x] == [5; 5], DisjunctConstraint(y))

DP._reformulate_logical_variables(model)
Expand All @@ -284,8 +284,8 @@ end
function test_nested_bigm()
model = GDPModel()
@variable(model, -100 <= x <= 100)
@variable(model, y[1:2], LogicalVariable)
@variable(model, z[1:2], LogicalVariable)
@variable(model, y[1:2], Logical)
@variable(model, z[1:2], Logical)
@constraint(model, x <= 5, DisjunctConstraint(y[1]))
@constraint(model, x >= 5, DisjunctConstraint(y[2]))
@disjunction(model, inner, y, DisjunctConstraint(z[1]))
Expand Down
16 changes: 8 additions & 8 deletions test/constraints/disjunct.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function test_disjunct_add_fail()
model = GDPModel()
@variable(model, x)
@variable(GDPModel(), y, LogicalVariable)
@variable(GDPModel(), y, Logical)
@test_macro_throws UndefVarError @constraint(model, x == 1, DisjunctConstraint(y)) # logical variable from another model

@variable(model, w, LogicalVariable)
@variable(model, w, Logical)
@variable(model, z, Bin)
@test_macro_throws UndefVarError @constraint(model, z == 1, DisjunctConstraint(w)) # binary variable
end

function test_disjunct_add_success()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
c1 = @constraint(model, x == 1, DisjunctConstraint(y))
@constraint(model, c2, x == 1, DisjunctConstraint(y))
@test owner_model(c1) == model
Expand All @@ -34,7 +34,7 @@ end
function test_disjunct_add_array()
model = GDPModel()
@variable(model, x)
@variable(model, y[1:2, 1:3], LogicalVariable)
@variable(model, y[1:2, 1:3], Logical)
@constraint(model, con[i=1:2, j=1:3], x == 1, DisjunctConstraint(y[i,j]))
@test con isa Matrix{DisjunctConstraintRef}
@test length(con) == 6
Expand All @@ -45,7 +45,7 @@ function test_disjunct_add_dense_axis()
@variable(model, x)
I = ["a", "b", "c"]
J = [1, 2]
@variable(model, y[I, J], LogicalVariable)
@variable(model, y[I, J], Logical)
@constraint(model, con[i=I, j=J], x == 1, DisjunctConstraint(y[i,j]))

@test con isa Containers.DenseAxisArray
Expand All @@ -57,7 +57,7 @@ end
function test_disjunct_add_sparse_axis()
model = GDPModel()
@variable(model, x)
@variable(model, y[1:3, 1:3], LogicalVariable)
@variable(model, y[1:3, 1:3], Logical)
@constraint(model, con[i=1:3, j=1:3; j > i], x==i+j, DisjunctConstraint(y[i,j]))

@test con isa Containers.SparseAxisArray
Expand All @@ -69,7 +69,7 @@ end
function test_disjunct_set_name()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
c1 = @constraint(model, x == 1, DisjunctConstraint(y))
set_name(c1, "new name")
@test name(c1) == "new name"
Expand All @@ -78,7 +78,7 @@ end
function test_disjunct_delete()
model = GDPModel()
@variable(model, x)
@variable(model, y, LogicalVariable)
@variable(model, y, Logical)
@constraint(model, c1, x == 1, DisjunctConstraint(y))

@test_throws AssertionError delete(GDPModel(), c1)
Expand Down
Loading

0 comments on commit c146725

Please sign in to comment.