diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..14b551e --- /dev/null +++ b/.github/workflows/CI.yml @@ -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 }} diff --git a/README.md b/README.md index f86511a..6970132 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/examples/ex1.jl b/examples/ex1.jl index e92344c..df28508 100644 --- a/examples/ex1.jl +++ b/examples/ex1.jl @@ -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])) diff --git a/examples/ex2.jl b/examples/ex2.jl index c023525..ba8fbf9 100644 --- a/examples/ex2.jl +++ b/examples/ex2.jl @@ -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) diff --git a/examples/ex3.jl b/examples/ex3.jl index c429e9d..e01ab5b 100644 --- a/examples/ex3.jl +++ b/examples/ex3.jl @@ -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])) diff --git a/examples/ex4.jl b/examples/ex4.jl index b7bdb21..ab0641d 100644 --- a/examples/ex4.jl +++ b/examples/ex4.jl @@ -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) diff --git a/examples/ex5.jl b/examples/ex5.jl index 52cb002..92bbb31 100644 --- a/examples/ex5.jl +++ b/examples/ex5.jl @@ -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])) diff --git a/examples/ex6.jl b/examples/ex6.jl index 0f9f89a..114f78f 100644 --- a/examples/ex6.jl +++ b/examples/ex6.jl @@ -4,7 +4,7 @@ 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])) @@ -12,14 +12,14 @@ m = GDPModel() @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])) diff --git a/src/datatypes.jl b/src/datatypes.jl index b477358..292b495 100644 --- a/src/datatypes.jl +++ b/src/datatypes.jl @@ -16,6 +16,8 @@ struct LogicalVariable <: JuMP.AbstractVariable start_value::Union{Nothing, Bool} end +const Logical = LogicalVariable + """ LogicalVariableData diff --git a/src/variables.jl b/src/variables.jl index a3f79a8..922e2cb 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -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, diff --git a/test/constraints/bigm.jl b/test/constraints/bigm.jl index b1666b9..d31d9e3 100644 --- a/test/constraints/bigm.jl +++ b/test/constraints/bigm.jl @@ -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)) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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])) diff --git a/test/constraints/disjunct.jl b/test/constraints/disjunct.jl index c840199..6b7c80b 100644 --- a/test/constraints/disjunct.jl +++ b/test/constraints/disjunct.jl @@ -1,10 +1,10 @@ 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 @@ -12,7 +12,7 @@ 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 @@ -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 @@ -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 @@ -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 @@ -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" @@ -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) diff --git a/test/constraints/hull.jl b/test/constraints/hull.jl index a6be5c1..460f60c 100644 --- a/test/constraints/hull.jl +++ b/test/constraints/hull.jl @@ -38,7 +38,7 @@ function test_disaggregate_variables() model = GDPModel() @variable(model, 10 <= x <= 100) @variable(model, y, Bin) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) vrefs = Set([x,y]) DP._reformulate_logical_variables(model) method = DP._Hull(Hull(1e-3, Dict(x => (0., 100.))), vrefs) @@ -64,7 +64,7 @@ end function test_aggregate_variable() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) vrefs = Set([x]) DP._reformulate_logical_variables(model) method = DP._Hull(Hull(1e-3, Dict(x => (0., 100.))), vrefs) @@ -79,7 +79,7 @@ end function test_disaggregate_expression_affine() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) DP._reformulate_logical_variables(model) bvrefs = DP._indicator_to_binary(model) @@ -96,7 +96,7 @@ end function test_disaggregate_expression_quadratic() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) DP._reformulate_logical_variables(model) bvrefs = DP._indicator_to_binary(model) @@ -119,7 +119,7 @@ end function test_disaggregate_nl_expression_c() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) DP._reformulate_logical_variables(model) bvrefs = DP._indicator_to_binary(model) @@ -134,7 +134,7 @@ end function test_disaggregate_nl_expression_var() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) DP._reformulate_logical_variables(model) bvrefs = DP._indicator_to_binary(model) @@ -154,7 +154,7 @@ end function test_disaggregate_nl_expression_aff() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) DP._reformulate_logical_variables(model) bvrefs = DP._indicator_to_binary(model) @@ -177,7 +177,7 @@ end function test_disaggregate_nl_expression_quad() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) DP._reformulate_logical_variables(model) bvrefs = DP._indicator_to_binary(model) @@ -200,7 +200,7 @@ end function test_disaggregate_nl_expession() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) DP._reformulate_logical_variables(model) bvrefs = DP._indicator_to_binary(model) @@ -228,7 +228,7 @@ end function test_scalar_var_hull_1sided(moiset) model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, x in moiset(5), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -245,7 +245,7 @@ end function test_scalar_affine_hull_1sided(moiset) model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, 1x in moiset(5), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -262,7 +262,7 @@ end function test_vector_var_hull_1sided(moiset) model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, [x; x] in moiset(2), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -278,7 +278,7 @@ end function test_vector_affine_hull_1sided(moiset) model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, [x - 5; x - 5] in moiset(2), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -294,7 +294,7 @@ end function test_scalar_quadratic_hull_1sided(moiset) model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, x^2 in moiset(5), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -319,7 +319,7 @@ end function test_vector_quadratic_hull_1sided(moiset) model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, [x^2 - 5; x^2 - 5] in moiset(2), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -344,7 +344,7 @@ end function test_scalar_nonlinear_hull_1sided(moiset) model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, x^3 in moiset(5), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -374,7 +374,7 @@ end function test_vector_nonlinear_hull_1sided(moiset) model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, [x^3 - 5; x^3 - 5] in moiset(2), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -407,7 +407,7 @@ end function test_scalar_var_hull_2sided() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, x in MOI.Interval(5,5), DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -427,7 +427,7 @@ end function test_scalar_affine_hull_2sided() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, 5 <= x <= 5, DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -447,7 +447,7 @@ end function test_scalar_quadratic_hull_2sided() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, 5 <= x^2 <= 5, DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") @@ -474,7 +474,7 @@ end function test_scalar_nonlinear_hull_2sided() model = GDPModel() @variable(model, 10 <= x <= 100) - @variable(model, z, LogicalVariable) + @variable(model, z, Logical) @constraint(model, con, 5 <= x^3 <= 5, DisjunctConstraint(z)) DP._reformulate_logical_variables(model) zbin = variable_by_name(model, "z") diff --git a/test/constraints/indicator.jl b/test/constraints/indicator.jl index f4f7c0a..2c17f03 100644 --- a/test/constraints/indicator.jl +++ b/test/constraints/indicator.jl @@ -1,7 +1,7 @@ function test_indicator_scalar_constraints() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, x == 5, DisjunctConstraint(y[1])) @constraint(model, x <= 5, DisjunctConstraint(y[1])) @constraint(model, x >= 5, DisjunctConstraint(y[1])) @@ -23,7 +23,7 @@ function test_indicator_vector_constraints() model = GDPModel() A = [1 0; 0 1] @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, A*[x,x] == [5,5], DisjunctConstraint(y[1])) @constraint(model, A*[x,x] == [10,10], DisjunctConstraint(y[2])) @disjunction(model, y) @@ -40,7 +40,7 @@ end function test_indicator_array() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, [1:3, 1:2], x <= 6, DisjunctConstraint(y[1])) @constraint(model, [1:3, 1:2], x >= 6, DisjunctConstraint(y[2])) @disjunction(model, y) @@ -57,7 +57,7 @@ end function test_indicator_dense_axis() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, [["a","b","c"],[1,2]], x <= 7, DisjunctConstraint(y[1])) @constraint(model, [["a","b","c"],[1,2]], x >= 7, DisjunctConstraint(y[2])) @disjunction(model, y) @@ -74,7 +74,7 @@ end function test_indicator_sparse_axis() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, [i = 1:3, j = 1:3; j > i], x <= 7, DisjunctConstraint(y[1])) @constraint(model, [i = 1:3, j = 1:3; j > i], x >= 7, DisjunctConstraint(y[2])) @disjunction(model, y) @@ -91,8 +91,8 @@ end function test_indicator_nested() model = GDPModel() @variable(model, x) - @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, y, DisjunctConstraint(z[1])) diff --git a/test/constraints/proposition.jl b/test/constraints/proposition.jl index 75cfb46..429eb77 100644 --- a/test/constraints/proposition.jl +++ b/test/constraints/proposition.jl @@ -1,6 +1,6 @@ function test_proposition_add_fail() m = GDPModel() - @variable(m, y[1:3], LogicalVariable) + @variable(m, y[1:3], Logical) @test_throws ErrorException @constraint(Model(), logical_or(y...) in IsTrue()) @test_throws ErrorException @constraint(m, logical_or(y...) == 2) @test_throws ErrorException @constraint(m, logical_or(y...) <= 1) @@ -13,7 +13,7 @@ end function test_negation_add_success() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) c1 = @constraint(model, logical_not(y) in IsTrue()) @constraint(model, c2, ¬y in IsTrue()) @test is_valid(model, c1) @@ -40,7 +40,7 @@ end function test_implication_add_success() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, c1, implies(y...) in IsTrue()) @constraint(model, c2, (y[1] ⟹ y[2]) in IsTrue()) @test_macro_throws ErrorException @constraint(model, y[1] ⟹ y[2] in IsTrue()) @@ -54,7 +54,7 @@ end function test_equivalence_add_success() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, c1, iff(y...) in IsTrue()) @constraint(model, c2, (y[1] ⇔ y[2]) in IsTrue()) @test_macro_throws ErrorException @constraint(model, y[1] ⇔ y[2] in IsTrue()) @@ -68,7 +68,7 @@ end function test_intersection_and_flatten_add_success() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, c1, logical_and(y...) in IsTrue()) @constraint(model, c2, ∧(y...) in IsTrue()) @constraint(model, c3, y[1] ∧ y[2] ∧ y[3] in IsTrue()) @@ -88,7 +88,7 @@ end function test_union_and_flatten_add_success() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, c1, logical_or(y...) in IsTrue()) @constraint(model, c2, ∨(y...) in IsTrue()) @constraint(model, c3, y[1] ∨ y[2] ∨ y[3] in IsTrue()) @@ -108,7 +108,7 @@ end function test_proposition_add_array() model = GDPModel() - @variable(model, y[1:2, 1:3, 1:4], LogicalVariable) + @variable(model, y[1:2, 1:3, 1:4], Logical) @constraint(model, con[i=1:2,j=1:3], ∨(y[i,j,:]...) in IsTrue()) @test con isa Matrix{LogicalConstraintRef} @test length(con) == 6 @@ -118,7 +118,7 @@ function test_proposition_add_dense_axis() model = GDPModel() I = ["a", "b", "c"] J = [1, 2] - @variable(model, y[I, J, 1:4], LogicalVariable) + @variable(model, y[I, J, 1:4], Logical) @constraint(model, con[i=I,j=J], ∨(y[i,j,:]...) in IsTrue()) @test con isa Containers.DenseAxisArray @test con.axes[1] == ["a","b","c"] @@ -128,7 +128,7 @@ end function test_proposition_add_sparse_axis() model = GDPModel() - @variable(model, y[1:3, 1:3, 1:4], LogicalVariable) + @variable(model, y[1:3, 1:3, 1:4], Logical) @constraint(model, con[i=1:3,j=1:3; j > i], ∨(y[i,j,:]...) in IsTrue()) @test con isa Containers.SparseAxisArray @test length(con) == 3 @@ -138,7 +138,7 @@ end function test_proposition_set_name() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) c1 = @constraint(model, logical_not(y...) in IsTrue()) set_name(c1, "proposition") @test name(c1) == "proposition" @@ -146,7 +146,7 @@ end function test_proposition_delete() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) c1 = @constraint(model, logical_not(y...) in IsTrue()) @test_throws AssertionError delete(GDPModel(), c1) @@ -157,7 +157,7 @@ end function test_negation_reformulation() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @constraint(model, ¬y in IsTrue()) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] @@ -169,7 +169,7 @@ end function test_implication_reformulation() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, implies(y[1], y[2]) in IsTrue()) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] @@ -183,14 +183,14 @@ end function test_implication_reformulation_fail() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, implies(y...) in IsTrue()) @test_throws ErrorException reformulate_model(model, DummyReformulation()) end function test_equivalence_reformulation() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, iff(y[1], y[2]) in IsTrue()) reformulate_model(model, DummyReformulation()) ref_cons = DP._reformulation_constraints(model) @@ -208,7 +208,7 @@ end function test_intersection_reformulation() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, ∧(y[1], y[2]) in IsTrue()) reformulate_model(model, DummyReformulation()) ref_cons = DP._reformulation_constraints(model) @@ -224,7 +224,7 @@ end function test_implication_reformulation() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, ∨(y[1], y[2]) in IsTrue()) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] @@ -238,7 +238,7 @@ end function test_lvar_cnf_functions() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test DP._eliminate_equivalence(y) == y @test DP._eliminate_implication(y) == y @test DP._move_negations_inward(y) == y @@ -251,7 +251,7 @@ end function test_eliminate_equivalence() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) ex = y[1] ⇔ y[2] new_ex = DP._eliminate_equivalence(ex) @test new_ex.head == :&& @@ -264,7 +264,7 @@ end function test_eliminate_equivalence_flat() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) ex = iff(y...) new_ex = DP._eliminate_equivalence(ex) @test new_ex.head == :&& @@ -281,7 +281,7 @@ end function test_eliminate_equivalence_nested() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) ex = iff(y[1], iff(y[2],y[3])) new_ex = DP._eliminate_equivalence(ex) @test new_ex.head == :&& @@ -298,7 +298,7 @@ end function test_eliminate_implication() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) ex = y[1] ⟹ y[2] new_ex = DP._eliminate_implication(ex) @test new_ex.head == :|| @@ -309,14 +309,14 @@ end function test_eliminate_implication_error() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) ex = implies(y...) @test_throws ErrorException DP._eliminate_implication(ex) end function test_eliminate_implication_nested() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) ex = (y[1] ⟹ y[2]) ⟹ y[3] new_ex = DP._eliminate_implication(ex) @test new_ex.head == :|| @@ -330,14 +330,14 @@ end function test_move_negation_inward_error() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) ex = ¬(y, y) @test_throws ErrorException DP._move_negations_inward(ex) end function test_move_negation_inward() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) ex = ¬y new_ex = DP._move_negations_inward(ex) @test new_ex.head == :! @@ -346,20 +346,20 @@ end function test_move_negation_inward_nested() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) ex = ¬¬y @test DP._move_negations_inward(ex) == y end function test_negate_error() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test_throws ErrorException DP._negate(iff(y,y)) end function test_negate_or() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) ex = ∨(y...) new_ex = DP._negate_or(ex) @test new_ex.head == :&& @@ -371,13 +371,13 @@ end function test_negate_or_error() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test_throws ErrorException DP._negate_or(∨(y)) end function test_negate_and() model = GDPModel() - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) ex = ∧(y...) new_ex = DP._negate_and(ex) @test new_ex.head == :|| @@ -389,25 +389,25 @@ end function test_negate_and_error() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test_throws ErrorException DP._negate_or(∧(y)) end function test_negate_negation() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test DP._negate_negation(¬y) == y end function test_negate_negation_error() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test_throws ErrorException DP._negate_negation(¬(y,y)) end function test_distribute_and_over_or() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) ex = y[1] ∨ (y[2] ∧ y[3]) new_ex = DP._distribute_and_over_or(ex) @test new_ex.head == :&& @@ -421,7 +421,7 @@ end function test_distribute_and_over_or_nested() model = GDPModel() - @variable(model, y[1:4], LogicalVariable) + @variable(model, y[1:4], Logical) ex = (y[1] ∧ y[2]) ∨ (y[3] ∧ y[4]) new_ex = DP._flatten(DP._distribute_and_over_or(ex)) for arg in new_ex.args @@ -450,7 +450,7 @@ end function test_to_cnf() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) ex = iff(y...) new_ex = DP._to_cnf(ex) @test new_ex.head == :&& diff --git a/test/constraints/selector.jl b/test/constraints/selector.jl index ab7ae37..cfbc521 100644 --- a/test/constraints/selector.jl +++ b/test/constraints/selector.jl @@ -1,6 +1,6 @@ function test_selector_add_fail() m = GDPModel() - @variable(m, y[1:3], LogicalVariable) + @variable(m, y[1:3], Logical) @test_throws ErrorException @constraint(Model(), y in AtMost(2)) @test_throws ErrorException @constraint(m, logical_or(y...) in Exactly(1)) @test_throws ErrorException @constraint(m, sin.(y) in Exactly(1)) @@ -11,7 +11,7 @@ end function test_selector_add_success() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) c1 = @constraint(model, y in Exactly(1)) @constraint(model, c2, y in Exactly(1)) @test owner_model(c1) == model @@ -34,7 +34,7 @@ end function test_nested_selector_add_success() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) c1 = @constraint(model, y[1:2] in Exactly(y[3])) @test is_valid(model, c1) @test length(constraint_object(c1).func) == 3 @@ -45,7 +45,7 @@ end function test_selector_add_array() model = GDPModel() - @variable(model, y[1:2, 1:3, 1:4], LogicalVariable) + @variable(model, y[1:2, 1:3, 1:4], Logical) @constraint(model, con[i=1:2, j=1:3], y[i,j,:] in Exactly(1)) @test con isa Matrix{LogicalConstraintRef} @test length(con) == 6 @@ -55,7 +55,7 @@ function test_selector_add_dense_axis() model = GDPModel() I = ["a", "b", "c"] J = [1, 2] - @variable(model, y[I, J, 1:4], LogicalVariable) + @variable(model, y[I, J, 1:4], Logical) @constraint(model, con[i=I, j=J], y[i,j,:] in Exactly(1)) @test con isa Containers.DenseAxisArray @test con.axes[1] == ["a","b","c"] @@ -65,7 +65,7 @@ end function test_selector_add_sparse_axis() model = GDPModel() - @variable(model, y[1:3, 1:3, 1:4], LogicalVariable) + @variable(model, y[1:3, 1:3, 1:4], Logical) @constraint(model, con[i=1:3, j=1:3; j > i], y[i,j,:] in Exactly(1)) @test con isa Containers.SparseAxisArray @test length(con) == 3 @@ -75,7 +75,7 @@ end function test_selector_set_name() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) c1 = @constraint(model, y in Exactly(1)) set_name(c1, "selector") @test name(c1) == "selector" @@ -83,7 +83,7 @@ end function test_selector_delete() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) c1 = @constraint(model, y in Exactly(1)) @test_throws AssertionError delete(GDPModel(), c1) @@ -95,7 +95,7 @@ end function test_exactly_reformulation() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, y in Exactly(1)) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] @@ -107,7 +107,7 @@ end function test_atleast_reformulation() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, y in AtLeast(1)) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] @@ -119,7 +119,7 @@ end function test_atmost_reformulation() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, y in AtMost(1)) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] @@ -131,7 +131,7 @@ end function test_nested_exactly_reformulation() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, y[1:2] in Exactly(y[3])) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] @@ -146,7 +146,7 @@ end function test_nested_atleast_reformulation() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, y[1:2] in AtLeast(y[3])) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] @@ -161,7 +161,7 @@ end function test_nested_atmost_reformulation() model = GDPModel() - @variable(model, y[1:3], LogicalVariable) + @variable(model, y[1:3], Logical) @constraint(model, y[1:2] in AtMost(y[3])) reformulate_model(model, DummyReformulation()) ref_con = DP._reformulation_constraints(model)[1] diff --git a/test/disjunction.jl b/test/disjunction.jl index 1032e6e..b44620f 100644 --- a/test/disjunction.jl +++ b/test/disjunction.jl @@ -1,7 +1,7 @@ function test_disjunction_add_fail() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, x == 5, DisjunctConstraint(y[1])) @test_macro_throws ErrorException @disjunction(model) #not enough arguments @@ -26,7 +26,7 @@ end function test_disjunction_add_success() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, x == 5, DisjunctConstraint(y[1])) @constraint(model, x == 10, DisjunctConstraint(y[2])) disj = @disjunction(model, y) @@ -47,8 +47,8 @@ end function test_disjunction_add_nested() model = GDPModel() @variable(model, x) - @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])) @@ -69,7 +69,7 @@ end function test_disjunction_add_array() model=GDPModel() @variable(model, x) - @variable(model, y[1:2, 1:3, 1:4], LogicalVariable) + @variable(model, y[1:2, 1:3, 1:4], Logical) @constraint(model, con[i=1:2, j=1:3, k=1:4], x==i+j+k, DisjunctConstraint(y[i,j,k])) @disjunction(model, disj[i=1:2, j=1:3], y[i,j,:]) @@ -83,7 +83,7 @@ function test_disjunciton_add_dense_axis() @variable(model, x) I = ["a", "b", "c"] J = [1, 2] - @variable(model, y[I, J, 1:4], LogicalVariable) + @variable(model, y[I, J, 1:4], Logical) @constraint(model, con[i=I, j=J, k=1:4], x==k, DisjunctConstraint(y[i,j,k])) @disjunction(model, disj[i=I, j=J], y[i,j,:]) @@ -96,7 +96,7 @@ end function test_disjunction_add_sparse_axis() model = GDPModel() @variable(model, x) - @variable(model, y[1:3, 1:3, 1:4], LogicalVariable) + @variable(model, y[1:3, 1:3, 1:4], Logical) @constraint(model, con[i=1:3, j=1:3, k=1:4; j > i], x==i+j+k, DisjunctConstraint(y[i,j,k])) @disjunction(model, disj[i=1:3, j=1:3; j > i], y[i,j,:]) @@ -109,8 +109,8 @@ end function test_disjunctions_add_success() model = GDPModel() @variable(model, x) - @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])) @constraint(model, x <= 10, DisjunctConstraint(z[1])) @@ -136,7 +136,7 @@ end function test_disjunction_set_name() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, x == 5, DisjunctConstraint(y[1])) @constraint(model, x == 10, DisjunctConstraint(y[2])) @disjunction(model, disj, y) @@ -147,7 +147,7 @@ end function test_disjunction_delete() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, x == 5, DisjunctConstraint(y[1])) @constraint(model, x == 10, DisjunctConstraint(y[2])) @disjunction(model, disj, y) @@ -161,7 +161,7 @@ end function test_disjunction_function() model = GDPModel() @variable(model, x) - @variable(model, y[1:2], LogicalVariable) + @variable(model, y[1:2], Logical) @constraint(model, x == 5, DisjunctConstraint(y[1])) @constraint(model, x == 10, DisjunctConstraint(y[2])) disj = disjunction(model, y, "name") @@ -176,8 +176,8 @@ end function test_disjunction_function_nested() model = GDPModel() @variable(model, x) - @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])) @constraint(model, x <= 10, DisjunctConstraint(z[1])) diff --git a/test/solve.jl b/test/solve.jl index 697ccde..32a2c40 100644 --- a/test/solve.jl +++ b/test/solve.jl @@ -4,8 +4,8 @@ function test_linear_gdp_example() m = GDPModel(HiGHS.Optimizer) set_attribute(m, MOI.Silent(), true) @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])) diff --git a/test/variables/logical.jl b/test/variables/logical.jl index 489474f..b57a024 100644 --- a/test/variables/logical.jl +++ b/test/variables/logical.jl @@ -1,12 +1,12 @@ # test creating, modifying, and reformulating logical variables function test_lvar_add_fail() model = Model() - @test_throws ErrorException @variable(model, y, LogicalVariable) + @test_throws ErrorException @variable(model, y, Logical) end function test_lvar_add_success() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test typeof(y) == LogicalVariableRef @test owner_model(y) == model @test is_valid(model, y) @@ -24,14 +24,14 @@ end function test_lvar_add_array() model = GDPModel() - @variable(model, y[1:3, 1:2], LogicalVariable) + @variable(model, y[1:3, 1:2], Logical) @test y isa Array{LogicalVariableRef, 2} @test length(y) == 6 end function test_lvar_add_dense_axis() model = GDPModel() - @variable(model, y[["a","b","c"],[1,2]], LogicalVariable) + @variable(model, y[["a","b","c"],[1,2]], Logical) @test y isa Containers.DenseAxisArray @test length(y) == 6 @test y.axes[1] == ["a","b","c"] @@ -41,7 +41,7 @@ end function test_lvar_add_sparse_axis() model = GDPModel() - @variable(model, y[i = 1:3, j = 1:3; j > i], LogicalVariable) + @variable(model, y[i = 1:3, j = 1:3; j > i], Logical) @test y isa Containers.SparseAxisArray @test length(y) == 3 @test y.names == (:i, :j) @@ -50,7 +50,7 @@ end function test_lvar_set_name() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) set_name(y, "z") @test name(y) == "z" #reformulate the variable @@ -59,7 +59,7 @@ end function test_lvar_creation_start_value() model = GDPModel() - @variable(model, y, LogicalVariable, start = true) + @variable(model, y, Logical, start = true) @test start_value(y) #reformulate the variable test_lvar_reformulation(model, y) @@ -67,7 +67,7 @@ end function test_lvar_set_start_value() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test isnothing(start_value(y)) set_start_value(y, false) @test !start_value(y) @@ -77,7 +77,7 @@ end function test_lvar_fix_value() model = GDPModel() - @variable(model, y, LogicalVariable) + @variable(model, y, Logical) @test isnothing(fix_value(y)) fix(y, true) @test fix_value(y) @@ -90,8 +90,8 @@ end function test_lvar_delete() model = GDPModel() - @variable(model, y, LogicalVariable) - @variable(model, z, LogicalVariable) + @variable(model, y, Logical) + @variable(model, z, Logical) @variable(model, x) @constraint(model, con, x <= 10, DisjunctConstraint(y)) @constraint(model, con2, x >= 50, DisjunctConstraint(z)) @@ -115,7 +115,7 @@ end function test_lvar_reformulation() model = GDPModel() - @variable(model, y, LogicalVariable, start = false) + @variable(model, y, Logical, start = false) fix(y, true) test_lvar_reformulation(model, y) end diff --git a/test/variables/query.jl b/test/variables/query.jl index 8ed7015..d308a53 100644 --- a/test/variables/query.jl +++ b/test/variables/query.jl @@ -18,7 +18,7 @@ function test_interrogate_variables() f = Base.Fix1(push!, vars) #interrogator m = GDPModel() @variable(m, x) - @variable(m, y, LogicalVariable) + @variable(m, y, Logical) DP._interrogate_variables(f, [x, y]) @test x in vars @test y in vars @@ -30,7 +30,7 @@ function test_interrogate_affexpr() f = Base.Fix1(push!, vars) #interrogator m = GDPModel() @variable(m, x) - @variable(m, y, LogicalVariable) + @variable(m, y, Logical) @variable(m, z) DP._interrogate_variables(f, x + y + z) @test x in vars @@ -44,7 +44,7 @@ function test_interrogate_quadexpr() f = Base.Fix1(push!, vars) #interrogator m = GDPModel() @variable(m, x) - @variable(m, y, LogicalVariable) + @variable(m, y, Logical) @variable(m, z) DP._interrogate_variables(f, x^2 + x*y + z + 1) @test x in vars @@ -59,7 +59,7 @@ function test_interrogate_nonlinear_expr() f = Base.Fix1(push!, vars) #interrogator m = GDPModel() @variable(m, x) - @variable(m, y, LogicalVariable) + @variable(m, y, Logical) @variable(m, z) DP._interrogate_variables(f, sin(exp(x^2 + 1)) + cos(x) + y + 2) @test x in vars @@ -72,8 +72,8 @@ function test_interrogate_logical_expr() vars = Set() f = Base.Fix1(push!, vars) #interrogator m = GDPModel() - @variable(m, y, LogicalVariable) - @variable(m, w[1:5], LogicalVariable) + @variable(m, y, Logical) + @variable(m, w[1:5], Logical) ex = (implies(w[1], w[2]) ∧ w[3]) ⇔ (¬w[4] ∨ y) DP._interrogate_variables(f, ex) @test w[1] in vars @@ -87,8 +87,8 @@ end function test_interrogate_proposition_constraint() m = GDPModel() - @variable(m, y, LogicalVariable) - @variable(m, w[1:5], LogicalVariable) + @variable(m, y, Logical) + @variable(m, w[1:5], Logical) ex = (implies(w[1], w[2]) ∧ w[3]) ⇔ (¬w[4] ∨ y) @constraint(m, con, ex in IsTrue()) obj = constraint_object(con) @@ -104,8 +104,8 @@ end function test_interrogate_selector_constraint() m = GDPModel() - @variable(m, y, LogicalVariable) - @variable(m, w[1:5], LogicalVariable) + @variable(m, y, Logical) + @variable(m, w[1:5], Logical) @constraint(m, con, w[1:4] in AtMost(y)) obj = constraint_object(con) vars = DP._get_constraint_variables(m, obj) @@ -121,7 +121,7 @@ end function test_interrogate_disjunction() m = GDPModel() @variable(m, -5 ≤ x[1:2] ≤ 10) - @variable(m, Y[1:2], LogicalVariable) + @variable(m, Y[1:2], Logical) @constraint(m, [i = 1:2], 0 ≤ x[i] ≤ [3,4][i], DisjunctConstraint(Y[1])) @constraint(m, [i = 1:2], [5,4][i] ≤ x[i] ≤ [9,6][i], DisjunctConstraint(Y[2])) @disjunction(m, Y) @@ -134,17 +134,17 @@ function test_interrogate_nested_disjunction() 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])) @disjunction(m, y) - @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])) @disjunction(m, w, DisjunctConstraint(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]))