Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of SCIP with JuMP #145

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

[compat]
CEnum = "^0.1.0"
CEnum = "^0.1.0, 0.2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what this means. Did you require CEnum in version 0.2?
I don't think it's compatible with our generated wrapper code.

Copy link
Author

Choose a reason for hiding this comment

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

It need version 0.2 or later to install SCIP interface version 7.4 above
Current CEnum version is 0.2
New SCIP interface version not installed without 0.2

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand. The newest version of SCIP.jl is 0.9.2 and the newest version of SCIP is 6.0.2. So what is this 7.4 refering to?

I did not try Julia 1.3.0 yet, so maybe it's related to that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just tried to add SCIP to a fresh Julia 1.3.0 installation, which worked just fine. It installed CEnum 0.1.2 as a dependency and the tests passed. Maybe you have some other package that requires CEnum 0.2?

Also, see #144 for failing tests with CEnum 0.2. Your changes probably fix those.

So, while it does make sense to upgrade CEnum at some point, I would prefer to do it "properly", and regenerate the C wrappers with a new Clang etc.

MathOptInterface = "^0.9.6"
julia = "^1.0.0"

Expand Down
50 changes: 50 additions & 0 deletions example/scip_with_jump_minlp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#=
The following some part of code are excerpt from "Julia Programming for Operations Research 2/e (Changhyun Kwon) - Chap 8"
=#

using JuMP
#using JuMP:MOI
using SCIP

function solve_model(m::Model;mixed::Bool = false)
if mixed
@variable(m, x>=0, Int)
@variable(m, y[1:2], Int)
@variable(m, s[1:5]>=0, Int)
@variable(m, l[1:5]>=0, Int)
else
@variable(m, x>=0)
@variable(m, y[1:2])
@variable(m, s[1:5]>=0)
@variable(m, l[1:5]>=0)
end

@objective(m, Min, -x -3y[1] + 2y[2])

@constraint(m, -2x + y[1] + 4y[2] + s[1] == 16)
@constraint(m, 8x + 3y[1] - 2y[2] + s[2] == 48)
@constraint(m, -2x + y[1] - 3y[2] + s[3] == -12)
@constraint(m, -y[1] + s[4] == 0)
@constraint(m, y[1] + s[5] == 4)
@constraint(m, -1 + l[1] + 3l[2] + l[3] - l[4] + l[5] == 0)
@constraint(m, 4l[2] - 2l[2] - 3l[3] == 0)
for i in 1:5
@NLconstraint(m, l[i] * s[i] == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is quadratic, it actually doesn't need the @NLconstraint, and could use @constraint instead. But it should not matter much to SCIP.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I just wanted to know if @NLcontraint works well with SCIP.
The example code refers to Chap8 in "Julia Programming for Operations Research 2 / e".

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are potential copyright issues with copying code verbatim from a book. Please clarify the license of this code.

Copy link
Author

Choose a reason for hiding this comment

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

OK~
I'll check!

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what copyright license my codes carry, but I'm good with this.

Codes were mine, but the actual example is from:

Ex 9.1.1 from Floudas, C.A., Pardalos, P.M., Adjiman, C., Esposito, W.R., Gümüs, Z.H., Harding, S.T., Klepeis, J.L., Meyer, C.A. and Schweiger, C.A., 2013. Handbook of Test Problems in Local and Global Optimization (Vol. 33). Springer Science & Business Media, http://titan.princeton.edu/TestProblems/ 

end

JuMP.optimize!(m)

println("** Optimal objective function value = ", JuMP.objective_value(m))
println("** Optimal x = ", JuMP.value(x))
println("** Optimal y = ", JuMP.value.(y))
println("** Optimal s = ", JuMP.value.(s))
println("** Optimal l = ", JuMP.value.(l))
nothing;
end

model = direct_model(SCIP.Optimizer())
solve_model(model)

model = direct_model(SCIP.Optimizer())
solve_model(model,mixed=true)

2 changes: 1 addition & 1 deletion src/MOI_wrapper/results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function MOI.get(o::Optimizer, ::MOI.ResultCount)::Int
end

function MOI.get(o::Optimizer, ::MOI.RawStatusString)
return String(CEnum.enum_name(SCIPgetStatus(o)))
return String(Symbol(SCIPgetStatus(o)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably a consequence of upgrading CEnum?

Copy link
Author

Choose a reason for hiding this comment

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

The error occurs because CEnum does not have an enum_name field.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, it has in version 0.1.0: CEnum.jl

end

"Make sure that SCIP is currently in one of the allowed stages."
Expand Down
10 changes: 5 additions & 5 deletions src/wrapper/commons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ const SCIP_PRIMAL = SCIP_Primal
# Skipping MacroDefinition: SCIP_DECL_PROBEXITSOL ( x ) SCIP_RETCODE x ( SCIP * scip , SCIP_PROBDATA * probdata , SCIP_Bool restart )
# Skipping MacroDefinition: SCIP_DECL_PROBCOPY ( x ) SCIP_RETCODE x ( SCIP * scip , SCIP * sourcescip , SCIP_PROBDATA * sourcedata , SCIP_HASHMAP * varmap , SCIP_HASHMAP * consmap , SCIP_PROBDATA * * targetdata , SCIP_Bool global , SCIP_RESULT * result )

@cenum(SCIP_Objsense{Int32},
@cenum(SCIP_Objsense,
Copy link
Collaborator

Choose a reason for hiding this comment

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

All of this code is auto-generated and should not be edited.

Copy link
Author

Choose a reason for hiding this comment

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

SCIP_Objsense{Int32} type is "Expr"

CEnum.jl
77 elseif !isa(T, Symbol) ==> ERROR
78 throw(ArgumentError("invalid type expression for Cenum $T"))
79 end

SCIP_OBJSENSE_MAXIMIZE = -1,
SCIP_OBJSENSE_MINIMIZE = 1,
)
Expand Down Expand Up @@ -811,7 +811,7 @@ const REOPT_CONSTYPE = Reopt_ConsType

const SCIP_RESULT = SCIP_Result

@cenum(SCIP_Retcode{Int32},
@cenum(SCIP_Retcode,
SCIP_OKAY = 1,
SCIP_ERROR = 0,
SCIP_NOMEMORY = -1,
Expand Down Expand Up @@ -1111,7 +1111,7 @@ const SCIP_VAR = SCIP_Var
const SCIP_VarData = Cvoid
const SCIP_VARDATA = SCIP_VarData

@cenum(SCIP_VBCColor{Int32},
@cenum(SCIP_VBCColor,
SCIP_VBCCOLOR_UNSOLVED = 3,
SCIP_VBCCOLOR_SOLVED = 2,
SCIP_VBCCOLOR_CUTOFF = 4,
Expand Down Expand Up @@ -1201,7 +1201,7 @@ const SCIP_LINCONSUPGRADE = SCIP_LinConsUpgrade
const SCIP_ORBITOPETYPE = SCIP_OrbitopeType
const ARTIFICIALVARNAMEPREFIX = "andresultant_"

@cenum(SCIP_LinearConsType{Int32},
@cenum(SCIP_LinearConsType,
SCIP_LINEARCONSTYPE_INVALIDCONS = -1,
SCIP_LINEARCONSTYPE_LINEAR = 0,
SCIP_LINEARCONSTYPE_LOGICOR = 1,
Expand Down Expand Up @@ -1265,7 +1265,7 @@ end
const SCIP_INTERVAL = SCIP_Interval
const SCIP_ROUNDMODE = Cint

@cenum(SCIP_ObjSen{Int32},
@cenum(SCIP_ObjSen,
SCIP_OBJSEN_MAXIMIZE = -1,
SCIP_OBJSEN_MINIMIZE = 1,
)
Expand Down