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

cbgetlpsolution returns assertionerror #171

Closed
elchiconuevo opened this issue Apr 17, 2018 · 7 comments
Closed

cbgetlpsolution returns assertionerror #171

elchiconuevo opened this issue Apr 17, 2018 · 7 comments

Comments

@elchiconuevo
Copy link

I'm trying to collect some info using an infocallback illustrated in the callback section of the JuMP document. When I try to access the fractional lp solution at the root node using cbgetlpsolution within the infocallback function, I get an assertion error. This is the function I use to add the infocallback to the model.
addinfocallback(mdl, infocallback, when = :Intermediate)

The objective is to access the fractional solution similar to this. How can I achieve this in JuMP?

@odow
Copy link
Member

odow commented Apr 17, 2018

Can you provide a complete exmaple that demonstrates the problem? See https://stackoverflow.com/help/mcve

@elchiconuevo
Copy link
Author

elchiconuevo commented Apr 18, 2018

A simple MWE (based on knapsack.jl) of the problem I have. I want to get the fractional LP value of variable x at the root node. However, I get a warning here: Variable value not defined for component of x. Check that the model was solved properly

using JuMP
using CPLEX

type NodeData
  time::Float64  # in seconds since the epoch
  node::Int
  obj::Float64
  bestbound::Float64
  x_val::Array{Float64,1}
end

m = Model(solver=CplexSolver(CPX_PARAM_NODELIM = 0))

@variable(m, x[1:5], Bin)

profit = [ 5, 3, 2, 7, 4 ]
weight = [ 2, 8, 4, 2, 5 ]
capacity = 10

# Objective: maximize profit
@objective(m, Max, dot(profit, x))

# Constraint: can carry all
@constraint(m, dot(weight, x) <= capacity)

bbdata = NodeData[]

function infocallback(cb)
  node      = MathProgBase.cbgetexplorednodes(cb)
  obj       = MathProgBase.cbgetobj(cb)
  bestbound = MathProgBase.cbgetbestbound(cb)
  x_val = getvalue(x)
  push!(bbdata, NodeData(time(),node,obj,bestbound, x_val))
end
addinfocallback(m, infocallback, when = :Intermediate)

solve(m)

In the earlier case, I queried for the lpsolution instead of the values of x. That returned me an assertionerror.

@odow
Copy link
Member

odow commented Apr 19, 2018

I haven't used the callbacks in CPLEX, however it looks like the solution is only available for when=:MIPnode for the infocallback.

https://github.com/JuliaOpt/JuMP.jl/blob/37ab6795eaa269bb762eb11dbba350eb8379bfb1/src/callbacks.jl#L170

You could try addlazycallback(m, infocallback) instead.

The new version of JuMP will not support solver independent callbacks. The behaviour is too solver-dependent.

@odow odow added the callbacks label Apr 19, 2018
@elchiconuevo
Copy link
Author

I haven't used the callbacks in CPLEX, however it looks like the solution is only available for when=:MIPnode for the infocallback

Is this behaviour independent of the solver? I mean if I switch to another solver, lets say Gurobi, the solution would still not be available?

@odow
Copy link
Member

odow commented Apr 19, 2018

Presumably you're trying to follow https://discourse.julialang.org/t/accessing-the-root-node-solution/10371/7?

This is not a CPLEX.jl issue. The infocallback only supports querying the LP solution in the following states
https://github.com/JuliaOpt/CPLEX.jl/blob/81d7dbb9947960f56c81f7b32dcdf612fa99f7ba/src/CplexSolverInterface.jl#L373-L374

The variable values are not available for when=:Intermediate.

I'm not sure what the story with Gurobi is, but according to
https://github.com/JuliaOpt/JuMP.jl/blob/37ab6795eaa269bb762eb11dbba350eb8379bfb1/src/callbacks.jl#L165-L170
the solution will not be available for when=:Intermediate.

@elchiconuevo
Copy link
Author

I tried addlazycallback(m, infocallback) instead of addinfocallback. While it works for the current problem, it shows the same warning for larger problem instances. The reason seems to be that for the simple knapsack problem, the optimal solution was found at node 0 itself.

@odow odow added MBP API and removed callbacks labels Nov 6, 2019
@odow
Copy link
Member

odow commented Nov 6, 2019

Closing this since it relates to the old JuMP callbacks, which we won't be fixing. The new MOI wrapper implements solver-independent MOI callbacks, and provides access to solver-specific generic CPLEX callbacks.

@odow odow closed this as completed Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants