-
Notifications
You must be signed in to change notification settings - Fork 24
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is quadratic, it actually doesn't need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I just wanted to know if @NLcontraint works well with SCIP. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK~ There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably a consequence of upgrading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error occurs because CEnum does not have an enum_name field. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this code is auto-generated and should not be edited. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SCIP_Objsense{Int32} type is "Expr" CEnum.jl |
||
SCIP_OBJSENSE_MAXIMIZE = -1, | ||
SCIP_OBJSENSE_MINIMIZE = 1, | ||
) | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
) | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 installedCEnum 0.1.2
as a dependency and the tests passed. Maybe you have some other package that requiresCEnum 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 newClang
etc.