CPLEX - Setting branching priority

Hi all!

I have been trying to set branching priority (in CPLEX) for a set of my variables (z) but I cannot do it. I tried using the linear indices and the internal model, but I get a method not found error.

Source code:

model_indices = zeros(length(indices.V)*length(indices.H))
priorities = zeros(length(indices.V)*length(indices.H))
idx = 1
for i=indices.V_cus, t=indices.H
    lin_idx = linearindex(z[i,t])
    model_indices[idx] = lin_idx
    priorities[idx] = 10
    idx += 1
CPLEX.set_branching_priority(m.internalModel, model_indices, priorities)

LoadError: MethodError: no method matching set_branching_priority(::CPLEX.CplexMathProgModel, ::Array{Float64,1}, ::Array{Float64,1})
Closest candidates are:
set_branching_priority(::Any, ::Any, ::Any, !Matched::Any) at C:\Users\lmano.julia\v0.6\CPLEX\src\cpx_solve.jl:21
set_branching_priority(!Matched::CPLEX.Model, ::Any, ::Any) at C:\Users\lmano.julia\v0.6\CPLEX\src\cpx_solve.jl:18
set_branching_priority(!Matched::CPLEX.Model, ::Any) at C:\Users\lmano.julia\v0.6\CPLEX\src\cpx_solve.jl:15
while loading C:\MyWork[Workspace] MIRP\Julia\MIRP\src\run.jl, in expression starting on line 34

The problem seems to be that CPLEX.jl set_branching_priority function needs a CPLEX.Model object while the internal model is a CPLEX.CplexMathProgModel. Is that a possible mismatch that needs to be fixed or I am doing something wrong. Any ideas on how to fix this?


Hi Lefteris,

You can access the CPLEX Model as JuMP.internalmodel(m).inner.

m.internalModel is actual a MathProgBase wrapper of the internal C model. You can see the struct here:

In regard to set_branching_priority, you seem to know what your are doing. You can find the source in CPLEX.jl here:

You can find the C documentation for copyorder here:

Thank you very much Oscar! Indeed it works when I use the inner field of the internalmodel struct.

Hi Oscar and Lefteris,

Thanks for your post. I’m also using set_branching_priority. I encounter a problem. Before I use CPLEX to solve the model, model.internalModel seems to be Void.

So I tried to solve(model) first, then model.internalModel.inner becomes a CPLEX object. I did the following experiment

priorities = [1, 2]
model_indices = [1, 2]
CPLEX.set_branching_priority(m.internalModel.inner, model_indices, priorities)

Then I got the following error

Root node processing (before b&c):
Real time = 0.00 sec. (0.25 ticks)
Sequential b&c:
Real time = 0.00 sec. (0.00 ticks)
Total (root+branch&cut) = 0.00 sec. (0.25 ticks)
ERROR: CPLEX: error getting error message(!)
[1] get_error_msg(::CPLEX.Env, ::Int32) at /home/canl1/.julia/v0.6/CPLEX/src/cpx_env.jl:71
[2] Type at /home/canl1/.julia/v0.6/CPLEX/src/cpx_env.jl:89 [inlined]
[3] optimize!(::CPLEX.Model) at /home/canl1/.julia/v0.6/CPLEX/src/cpx_solve.jl:11
[4] optimize!(::CPLEX.CplexMathProgModel) at /home/canl1/.julia/v0.6/CPLEX/src/CplexSolverInterface.jl:191
[5] #solve#116(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /home/canl1/.julia/v0.6/JuMP/src/solvers.jl:175
[6] solve(::JuMP.Model) at /home/canl1/.julia/v0.6/JuMP/src/solvers.jl:150

I would appreciate it if you can share some solutions to this problem. Thanks!

Best regards,

Please provide a minimum working example:

using JuMP
using CPLEX
m = Model(solver=CplexSolver())
@variable(m, x[i in 1:2], Bin)
@objective(m, Min, x[1] + x[2])
priorities = [1, 2]
model_indices = [1, 2]
CPLEX.set_branching_priority(m.internalModel.inner, model_indices, priorities)

The error is

ERROR: LoadError: type Void has no field inner
 [1] include_from_node1(::String) at ./loading.jl:576
 [2] include(::String) at ./sysimg.jl:14
 [3] process_options(::Base.JLOptions) at ./client.jl:305
 [4] _start() at ./client.jl:371
while loading /home/canl1/work/learnbranching/temp.jl, in expression starting on line 8

Run JuMP.build(m) prior to setting the branching priority.

Thanks Oscar!