Skip to content

Commit

Permalink
Update for julia 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoleilhac committed Oct 29, 2018
1 parent 475bb62 commit 13a1074
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 121 deletions.
9 changes: 5 additions & 4 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
julia 0.6
JuMP 0.18
Combinatorics
Suppressor
julia 1.0
JuMP 0.18.4
Combinatorics 0.7.0
Suppressor 0.1.1
MathProgBase 0.7.7
36 changes: 14 additions & 22 deletions src/MOP.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# MIT License
# Copyright (c) 2017: Xavier Gandibleux, Anthony Przybylski, Gauthier Soleilhac, and contributors.
using Printf
varname_generic(m::Model, col::Integer) = "VAR$(col)"

function varname_given(m::Model, col::Integer)
# TODO: deal with non-ascii characters?
name = getname(m, col)
for (pat, sub) in [("[", "_"), ("]", ""), (",", "_")]
name = replace(name, pat, sub)
name = replace(name, pat => sub)
end
name
end
Expand Down Expand Up @@ -40,7 +41,6 @@ function writeMOP(m, fname::AbstractString, genericnames=false)
end

# Objective and constraint names
gc_enable(false)
write(f,"ROWS\n")

for i = 1:length(md.objs)
Expand All @@ -62,7 +62,6 @@ function writeMOP(m, fname::AbstractString, genericnames=false)
end
@printf(f," %c CON%d\n",senseChar,c)
end
gc_enable(true)



Expand All @@ -72,7 +71,6 @@ function writeMOP(m, fname::AbstractString, genericnames=false)
nzval = A.nzval

# Output each column
gc_enable(false)
inintegergroup = false
write(f,"COLUMNS\n")
for col in 1:m.numCols
Expand All @@ -87,60 +85,55 @@ function writeMOP(m, fname::AbstractString, genericnames=false)
end
for ind in colptr[col]:(colptr[col+1]-1)
@printf(f," %s CON%d ",varname(m,col),rowval[ind])
print_shortest(f,nzval[ind])
(Base.Grisu).print_shortest(f,nzval[ind])
println(f)
end
for obj = 1:length(md.objs)
@printf(f," %s OBJ%d ",varname(m,col), obj)
print_shortest(f,objlincoef[obj][col])
(Base.Grisu).print_shortest(f,objlincoef[obj][col])
println(f)
end
end
if inintegergroup
@printf(f," MARKER 'MARKER' 'INTEND'\n")
end
gc_enable(true)

# RHSs
gc_enable(false)
write(f,"RHS\n")
for c in 1:numRows
rowsense = JuMP.sense(m.linconstr[c])
if rowsense != :range
@printf(f," RHS CON%d ",c)
print_shortest(f,JuMP.rhs(m.linconstr[c]))
(Base.Grisu).print_shortest(f,JuMP.rhs(m.linconstr[c]))
else
@printf(f," RHS CON%d ",c)
print_shortest(f,m.linconstr[c].lb)
(Base.Grisu).print_shortest(f,m.linconstr[c].lb)
end
println(f)
end
gc_enable(true)

# RANGES
if hasrange
gc_enable(false)
write(f,"RANGES\n")
for c in 1:numRows
rowsense = JuMP.sense(m.linconstr[c])
if rowsense == :range
@printf(f," rhs CON%d ",c)
print_shortest(f,m.linconstr[c].ub-m.linconstr[c].lb)
(Base.Grisu).print_shortest(f,m.linconstr[c].ub-m.linconstr[c].lb)
println(f)
end
end
end


# BOUNDS
gc_enable(false)
write(f,"BOUNDS\n")
for col in 1:m.numCols
if m.colLower[col] == 0
if m.colUpper[col] != Inf
# Default lower 0, and an upper
@printf(f," UP BOUND %s ", varname(m,col))
print_shortest(f, m.colUpper[col])
(Base.Grisu).print_shortest(f, m.colUpper[col])
println(f)
else
# Default bounds. Explicitly state for solvers like Gurobi. See issue #792
Expand All @@ -153,31 +146,30 @@ function writeMOP(m, fname::AbstractString, genericnames=false)
elseif m.colLower[col] != -Inf && m.colUpper[col] == +Inf
# No upper, but a lower
@printf(f, " PL BOUND %s\n LO BOUND %s ",varname(m,col),varname(m,col))
print_shortest(f,m.colLower[col])
(Base.Grisu).print_shortest(f,m.colLower[col])
println(f)
elseif m.colLower[col] == -Inf && m.colUpper[col] != +Inf
# No lower, but a upper
@printf(f," MI BOUND %s\n UP BOUND %s ",varname(m,col),varname(m,col))
print_shortest(f,m.colUpper[col])
(Base.Grisu).print_shortest(f,m.colUpper[col])
println(f)
else
# Lower and upper
@printf(f, " LO BOUND %s ",varname(m,col))
print_shortest(f,m.colLower[col])
(Base.Grisu).print_shortest(f,m.colLower[col])
println(f)
@printf(f, " UP BOUND %s ",varname(m,col))
print_shortest(f,m.colUpper[col])
(Base.Grisu).print_shortest(f,m.colUpper[col])
println(f)
end
end

write(f,"ENDATA\n")
close(f)
gc_enable(true)
nothing
end

nextline(f) = split(chomp(readline(f)), ' ', keep=false)
nextline(f) = split(chomp(readline(f)), ' ', keepempty=false)
function parseMOP(fname::AbstractString; solver=JuMP.UnsetSolver())

m = vModel(solver = solver)
Expand Down Expand Up @@ -249,7 +241,7 @@ function parseMOP(fname::AbstractString; solver=JuMP.UnsetSolver())
for (k,v) in DicoExpr
expr, expr_type = v
if expr_type == :N
push!(DicoObj, k => QuadExpr(expr))
push!(DicoObj, k => convert(QuadExpr, expr))
else
push!(DicoCstr, k => (LinearConstraint(expr, -Inf, Inf), expr_type) )
end
Expand Down
20 changes: 10 additions & 10 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ function solve_lexico(m::Model, verbose; args...)
@constraintref cstr_obj[1:nbObj]
for i = 1:nbObj
if objSenses[i] == :Max
cstr_obj[i] = @constraint(m, objs[i].aff >= -1e18)
cstr_obj[i] = @constraint(m, objs[i].aff >= -1e16)
else
cstr_obj[i] = @constraint(m, objs[i].aff <= 1e18)
cstr_obj[i] = @constraint(m, objs[i].aff <= 1e16)
end
end

Expand Down Expand Up @@ -66,9 +66,9 @@ function solve_permutation(m::Model, p, cstr_obj ; args...)

for i = 1:length(p)
if objSenses[i] == :Max
JuMP.setRHS(cstr_obj[i], -1e18)
JuMP.setRHS(cstr_obj[i], -1e16)
else
JuMP.setRHS(cstr_obj[i], 1e18)
JuMP.setRHS(cstr_obj[i], 1e16)
end
end

Expand Down Expand Up @@ -148,9 +148,9 @@ function solve_eps(m::Model, ϵ::Float64, round_results, verbose ; args...)
#To leave the model unaltered we change the value of the RHS
###
if f2Sense == :Min
JuMP.setRHS(eps, Float64(typemax(Int)))
JuMP.setRHS(eps, 1e16)
else
JuMP.setRHS(eps, Float64(typemin(Int)))
JuMP.setRHS(eps,-1e16)
end
else
return status
Expand Down Expand Up @@ -356,15 +356,15 @@ function solve_Chalmet(m::Model, step ; args...)


if f1Sense == :Min
JuMP.setRHS(cstrz1, Float64(typemax(Int)))
JuMP.setRHS(cstrz1, 1e16)
else
JuMP.setRHS(cstrz1, Float64(typemin(Int)))
JuMP.setRHS(cstrz1,-1e16)
end

if f2Sense == :Min
JuMP.setRHS(cstrz2, Float64(typemax(Int)))
JuMP.setRHS(cstrz2, 1e16)
else
JuMP.setRHS(cstrz2, Float64(typemin(Int)))
JuMP.setRHS(cstrz2,-1e16)
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions src/vOptGeneric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ __precompile__()
module vOptGeneric
using Combinatorics, Suppressor

importall JuMP
import MathProgBase
using JuMP, MathProgBase

export vModel,
getvOptData,
Expand Down Expand Up @@ -77,8 +76,8 @@ function printhook(io::IO, m::Model)
println(vd.objSenses[i] == :Min ? "Min " : "Max ", vd.objs[i])
end
str = JuMP.model_str(JuMP.REPLMode, m)
index = searchindex(str, "Subject to")
index != 0 && print(str[index:end])
index = findfirst("Subject to", str)
index !== nothing && print(str[first(index):end])
end


Expand All @@ -98,7 +97,7 @@ macro addobjective(m, args...)
!isa(f, JuMP.GenericAffExpr) && error("in @addobjective : vOptGeneric only supports linear objectives")
vd = $m.ext[:vOpt]
push!(vd.objSenses, $(esc(sense)))
push!(vd.objs, QuadExpr(f))
push!(vd.objs, convert(QuadExpr, f))
end
end

Expand Down
Loading

0 comments on commit 13a1074

Please sign in to comment.