diff --git a/.travis.yml b/.travis.yml index 43ba22b..2f9c38a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,9 @@ os: julia: - 1.0 - 1.1 + - 1.2 + - 1.3 + - 1.4 notifications: email: false sudo: false diff --git a/Project.toml b/Project.toml index c38bef5..2f824aa 100644 --- a/Project.toml +++ b/Project.toml @@ -10,16 +10,15 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" ParameterJuMP = "774612a8-9878-5177-865a-ca53ae2495f9" [compat] -JuMP = "0.21" -MathOptInterface = "0.9.1" +JuMP = "0.21.3" +MathOptInterface = "0.9.14" ParameterJuMP = "0.2" julia = "1" [extras] ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199" GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6" -Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["GLPK", "Test", "ECOS", "Ipopt"] +test = ["GLPK", "Test", "ECOS"] diff --git a/src/StructJuMP.jl b/src/StructJuMP.jl index 39cb173..7cb77c6 100644 --- a/src/StructJuMP.jl +++ b/src/StructJuMP.jl @@ -254,11 +254,17 @@ function JuMP.constraint_object(cref::StructuredConstraintRef, F::Type, S::Type) end # Objective -function JuMP.set_objective(m::StructuredModel, sense::MOI.OptimizationSense, - f::JuMP.AbstractJuMPScalar) + +function JuMP.set_objective_sense(m::StructuredModel, sense::MOI.OptimizationSense) m.objective_sense = sense +end + +function JuMP.set_objective_function(m::StructuredModel, f::AbstractJuMPScalar) m.objective_function = f end + +JuMP.set_objective_function(m::StructuredModel, f::Real) = JuMP.set_objective_function(m, convert(AffExpr, f)) + JuMP.objective_sense(m::StructuredModel) = m.objective_sense JuMP.objective_function_type(model::StructuredModel) = typeof(model.objective_function) JuMP.objective_function(model::StructuredModel) = model.objective_function diff --git a/test/examples_smoketest.jl b/test/examples_smoketest.jl index b0147f2..7d15029 100644 --- a/test/examples_smoketest.jl +++ b/test/examples_smoketest.jl @@ -55,6 +55,14 @@ end # optimize!(firststage) end +@testset "farmer" begin + include("../examples/farmer.jl") + # status, objval, soln = DLP(m, GLPK.Optimizer) + # @test status == :Optimal + # @test objval ≈ -108390 + # @test soln ≈ [170, 80, 250] +end + #= @testset "stochpdegas" begin include("../examples/stochpdegas.jl") diff --git a/test/farmer.jl b/test/farmer.jl deleted file mode 100644 index ec589fb..0000000 --- a/test/farmer.jl +++ /dev/null @@ -1,11 +0,0 @@ -using Test - -using GLPK - -@testset "farmer" begin - include("../examples/farmer.jl") - status, objval, soln = DLP(m, GLPK.Optimizer) - @test status == :Optimal - @test objval ≈ -108390 - @test soln ≈ [170, 80, 250] -end diff --git a/test/objective.jl b/test/objective.jl new file mode 100644 index 0000000..fdac563 --- /dev/null +++ b/test/objective.jl @@ -0,0 +1,23 @@ +using Test +using StructJuMP + +@testset "objective functions" begin + m = StructuredModel(num_scenarios = 2) + @variable(m, x >= 0) + @objective(m, Min, x*x) + + sm = StructuredModel(parent = m, id = 1) + @variable(sm, y >= 0) + @objective(sm, Max, y) + + sm = StructuredModel(parent = m, id = 2) + @variable(sm, y >= 0) + @objective(sm, Min, 0) + + @test objective_sense(m) == MOI.MIN_SENSE + @test objective_sense(m.children[1]) == MOI.MAX_SENSE + @test objective_sense(m.children[2]) == MOI.MIN_SENSE + @test objective_function_type(m) == GenericQuadExpr{Float64,StructJuMP.StructuredVariableRef} + @test objective_function_type(m.children[1]) == StructJuMP.StructuredVariableRef + @test objective_function_type(m.children[2]) == GenericAffExpr{Float64,VariableRef} +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index e30a0f6..892bc46 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,6 +2,6 @@ include("printhook.jl") include("benderstest.jl") -# include("farmer.jl") - include("examples_smoketest.jl") + +include("objective.jl") \ No newline at end of file