Skip to content

Commit 1976d8c

Browse files
authored
Merge pull request #80 from StructJuMP/kibaekkim-patch-1
Allowing constant objective function
2 parents 3343052 + 2201c8a commit 1976d8c

File tree

7 files changed

+47
-19
lines changed

7 files changed

+47
-19
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ os:
55
julia:
66
- 1.0
77
- 1.1
8+
- 1.2
9+
- 1.3
10+
- 1.4
811
notifications:
912
email: false
1013
sudo: false

Project.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
1010
ParameterJuMP = "774612a8-9878-5177-865a-ca53ae2495f9"
1111

1212
[compat]
13-
JuMP = "0.21"
14-
MathOptInterface = "0.9.1"
13+
JuMP = "0.21.3"
14+
MathOptInterface = "0.9.14"
1515
ParameterJuMP = "0.2"
1616
julia = "1"
1717

1818
[extras]
1919
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
2020
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
21-
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
2221
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2322

2423
[targets]
25-
test = ["GLPK", "Test", "ECOS", "Ipopt"]
24+
test = ["GLPK", "Test", "ECOS"]

src/StructJuMP.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,17 @@ function JuMP.constraint_object(cref::StructuredConstraintRef, F::Type, S::Type)
254254
end
255255

256256
# Objective
257-
function JuMP.set_objective(m::StructuredModel, sense::MOI.OptimizationSense,
258-
f::JuMP.AbstractJuMPScalar)
257+
258+
function JuMP.set_objective_sense(m::StructuredModel, sense::MOI.OptimizationSense)
259259
m.objective_sense = sense
260+
end
261+
262+
function JuMP.set_objective_function(m::StructuredModel, f::AbstractJuMPScalar)
260263
m.objective_function = f
261264
end
265+
266+
JuMP.set_objective_function(m::StructuredModel, f::Real) = JuMP.set_objective_function(m, convert(AffExpr, f))
267+
262268
JuMP.objective_sense(m::StructuredModel) = m.objective_sense
263269
JuMP.objective_function_type(model::StructuredModel) = typeof(model.objective_function)
264270
JuMP.objective_function(model::StructuredModel) = model.objective_function

test/examples_smoketest.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ end
5555
# optimize!(firststage)
5656
end
5757

58+
@testset "farmer" begin
59+
include("../examples/farmer.jl")
60+
# status, objval, soln = DLP(m, GLPK.Optimizer)
61+
# @test status == :Optimal
62+
# @test objval ≈ -108390
63+
# @test soln ≈ [170, 80, 250]
64+
end
65+
5866
#=
5967
@testset "stochpdegas" begin
6068
include("../examples/stochpdegas.jl")

test/farmer.jl

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/objective.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Test
2+
using StructJuMP
3+
4+
@testset "objective functions" begin
5+
m = StructuredModel(num_scenarios = 2)
6+
@variable(m, x >= 0)
7+
@objective(m, Min, x*x)
8+
9+
sm = StructuredModel(parent = m, id = 1)
10+
@variable(sm, y >= 0)
11+
@objective(sm, Max, y)
12+
13+
sm = StructuredModel(parent = m, id = 2)
14+
@variable(sm, y >= 0)
15+
@objective(sm, Min, 0)
16+
17+
@test objective_sense(m) == MOI.MIN_SENSE
18+
@test objective_sense(m.children[1]) == MOI.MAX_SENSE
19+
@test objective_sense(m.children[2]) == MOI.MIN_SENSE
20+
@test objective_function_type(m) == GenericQuadExpr{Float64,StructJuMP.StructuredVariableRef}
21+
@test objective_function_type(m.children[1]) == StructJuMP.StructuredVariableRef
22+
@test objective_function_type(m.children[2]) == GenericAffExpr{Float64,VariableRef}
23+
end

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ include("printhook.jl")
22

33
include("benderstest.jl")
44

5-
# include("farmer.jl")
6-
75
include("examples_smoketest.jl")
6+
7+
include("objective.jl")

0 commit comments

Comments
 (0)