Skip to content

Commit

Permalink
Merge pull request #80 from StructJuMP/kibaekkim-patch-1
Browse files Browse the repository at this point in the history
Allowing constant objective function
kibaekkim authored Jun 29, 2020
2 parents 3343052 + 2201c8a commit 1976d8c
Showing 7 changed files with 47 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@ os:
julia:
- 1.0
- 1.1
- 1.2
- 1.3
- 1.4
notifications:
email: false
sudo: false
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"]
10 changes: 8 additions & 2 deletions src/StructJuMP.jl
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/examples_smoketest.jl
Original file line number Diff line number Diff line change
@@ -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")
11 changes: 0 additions & 11 deletions test/farmer.jl

This file was deleted.

23 changes: 23 additions & 0 deletions test/objective.jl
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -2,6 +2,6 @@ include("printhook.jl")

include("benderstest.jl")

# include("farmer.jl")

include("examples_smoketest.jl")

include("objective.jl")

1 comment on commit 1976d8c

@kibaekkim
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.