Skip to content

Commit b2901cc

Browse files
authored
Merge pull request #8 from kibaekkim/kkim
Binary variable bounds
2 parents b6e6df1 + f4b86b6 commit b2901cc

File tree

6 files changed

+20
-46
lines changed

6 files changed

+20
-46
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
*.mps

src/DSPCInterface.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,4 @@ setIntPtrParam(dsp::DSPProblem, name::String, n::Int, v::Vector{Int}) = @dsp_cca
239239
(Ptr{Cvoid}, Ptr{UInt8}, Cint, Ptr{Cint}),
240240
dsp.p, name, convert(Cint, n), convert(Vector{Cint}, v))
241241

242-
###############################################################################
243-
# Other functions
244-
###############################################################################
245-
writeMps!(dsp::DSPProblem, filename::AbstractString) = @dsp_ccall(
246-
"writeMps", Cvoid,
247-
(Ptr{Cvoid}, Ptr{UInt8}),
248-
dsp.p, "$filename.mps")
249-
250242
# end # end of module

src/DSPopt.jl

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,6 @@ function SJ.optimize!(m::SJ.StructuredModel; options...)
5454
return termination_status(m)
5555
end
5656

57-
" write model into an MPS file "
58-
function writeMps!(m::SJ.StructuredModel, filename::AbstractString; options...)
59-
# free any existing model pointer
60-
freeModel(dspenv)
61-
62-
# set options
63-
setoptions!(options)
64-
65-
# load problem
66-
load_problem!(m)
67-
68-
# write problem into MPS file
69-
writeMps!(dspenv, filename)
70-
71-
return
72-
end
73-
7457
function get_model_data(m::SJ.StructuredModel)
7558

7659
# Get a column-wise sparse matrix
@@ -91,8 +74,13 @@ function get_model_data(m::SJ.StructuredModel)
9174
else
9275
ctype = ctype * "C"
9376
end
94-
clbd[vref.idx] = v.info.has_lb ? v.info.lower_bound : -Inf
95-
cubd[vref.idx] = v.info.has_ub ? v.info.upper_bound : Inf
77+
if v.info.binary
78+
clbd[vref.idx] = 0.0
79+
cubd[vref.idx] = 1.0
80+
else
81+
clbd[vref.idx] = v.info.has_lb ? v.info.lower_bound : -Inf
82+
cubd[vref.idx] = v.info.has_ub ? v.info.upper_bound : Inf
83+
end
9684
cname[vref.idx] = m.varnames[vref.idx]
9785
end
9886

test/dcap.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Parameters (scenario):
3333

3434
using StructJuMP
3535
using Random
36+
using MathOptInterface
3637

3738
function DCAP(nR::Int, nN::Int, nT::Int, nS::Int, seed::Int=1)::StructuredModel
3839

@@ -83,24 +84,20 @@ m = DCAP(2,2,3,3);
8384
@test length(m.variables) == 12
8485
@test length(m.constraints) == 6
8586
start, index, value, rlbd, rubd, obj, clbd, cubd, ctype, cname = DSPopt.get_model_data(m)
86-
@show clbd
87-
@show cubd
88-
@show ctype
87+
@test clbd == zeros(Float64, 12)
88+
@test cubd == [Inf, Inf, Inf, Inf, Inf, Inf, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
89+
@test ctype == "CCCCCCBBBBBB"
8990
# print(m)
9091
end
9192

9293
@testset "Child model $i" for (i,subm) in m.children
9394
start, index, value, rlbd, rubd, obj, clbd, cubd, ctype, cname = DSPopt.get_model_data(subm)
94-
@show clbd
95-
@show cubd
96-
@show ctype
97-
end
98-
99-
@testset "write MPS" begin
100-
DSPopt.writeMps!(m, "dcap")
101-
@test isfile("dcap.mps")
95+
@test clbd == zeros(Float64, 18)
96+
@test cubd == ones(Float64, 18)
97+
@test ctype == "BBBBBBBBBBBBBBBBBB"
10298
end
10399

104100
@testset "optimize!: $j" for j in [DSPopt.ExtensiveForm]
105101
status = DSPopt.optimize!(m, solve_type = j, is_stochastic = true, param = "params.txt")
102+
@test status == MathOptInterface.OPTIMAL
106103
end

test/farmer_stoc.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,3 @@ end
118118
@test dsp.solve_type == DSPopt.Dual
119119
end
120120
end
121-
122-
@testset "writeMps" begin
123-
DSPopt.writeMps!(m, "farmer", is_stochastic = true)
124-
@test isfile("farmer.mps")
125-
end

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ end
4343
include("farmer_block.jl")
4444
end
4545

46-
# @testset "dcap" begin
47-
# include("dcap.jl")
48-
# end
46+
@testset "dcap" begin
47+
include("dcap.jl")
48+
end
4949

5050
@testset "Freeing DSPopt" begin
5151
DSPopt.freeEnv(dsp)

0 commit comments

Comments
 (0)