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

Access to dual value of constraints of the master problem #591

Closed
diHnguyen opened this issue Aug 23, 2021 · 4 comments · Fixed by #594
Closed

Access to dual value of constraints of the master problem #591

diHnguyen opened this issue Aug 23, 2021 · 4 comments · Fixed by #594
Assignees
Labels
enhancement New feature or request

Comments

@diHnguyen
Copy link

Hello,

I would like to access the duals associated with the constraints in the master problem for a separate model, and it seems like I can't if they are added as lazy constraints. (I could be completely wrong about this, but I did not see a solution when looking into the topic.)

Would it be possible to iteratively add constraints to the master problem without the use of lazy constraints, perhaps something similar to @constraint() in JuMP?

Thank you so much!

@diHnguyen diHnguyen added the enhancement New feature or request label Aug 23, 2021
@guimarqu
Copy link
Contributor

guimarqu commented Aug 24, 2021

Hello,

The only way to generate constraints during optimization is to use the method MOI.submit in a pricing callback (non-lazy or user cuts).
At the moment, it's indeed not possible to retrieve the dual of the constraint added during the optimisation.
However, last month, we implemented a feature (#547) which will allow us to implement this very easily.

As I'm going to be busy the next 2/3 weeks, I don't think I'll have time to implement that and write the tests.
If you need this feature very quickly, I would be very grateful if you could share a very little example with some expected dual values of the constraints. I'll put this example in the unit tests and I'll make it work in the master branch.

Thanks for the report !

@guimarqu guimarqu added this to the v0.4 milestone Aug 24, 2021
@diHnguyen
Copy link
Author

Hi @guimarqu ! Thank you for the quick response. Here is a tiny example of what I can see

#Variables
@variable(model, 0<= x[1:7] <= 1)
@variable(model, y[1:2] >= 0)
@variable(model, u >=0)

#Constraints
xCon = @constraint(model, sum(x[i] for i = 1:7) <= 1)
yCon = @constraint(model, sum(y[i] for i = 1:2) == 1)
initCon1 = @constraint(model, u >= 0.9*y[1] + y[2] - x[1] - x[2] - x[3])
initCon2 = @constraint(model u >= y[1] + y[2] - x[7])

#Objective function
@objective(model, Min, u)

Solving model with no additional constraint added:

#Solutions
u = 0.45
x = [0.45,0,0,0,0,0,0.55]
y = [1,0]

#Corresponding dual solutions to the following constraints
xCon : -0.5
yCon : 0.95
initCon1 : 0.5
initCon2 : 0.5

Some additional results in case they can be useful. If we solve model with an additional constraint, newCon, added:

newCon = @constraint(model, u >= y[1] + 0.9*y[2] - x[5] - x[6])

then the solution is:

#Solutions
u = 0.6333
x = [0.3667,0,0,0,0.2667,0,0.3667]
y = [0,1]

#Corresponding dual solutions to the following constraints
xCon : -0.333
yCon : 0.9667
initCon1 : 0.333
initCon2 : 0.333
newCon: 0.333

Thanks again for your help!

@guimarqu guimarqu changed the title Adding (non-lazy) constraints to the master problem Access to dual value of constraints of the master problem Sep 4, 2021
@guimarqu
Copy link
Contributor

guimarqu commented Sep 8, 2021

Hi,

thanks for the MWE,

In the tests, you have an example of how you can retrieve the dual value of the cut :

The callback

callback_called = false
constrid = nothing
function my_callback_function(cbdata)
if !callback_called
con = @build_constraint(u >= y[1] + 0.9*y[2] - x[5] - x[6])
constrid = MOI.submit(model, MOI.LazyConstraint(cbdata), con)
callback_called = true
end
return
end
MOI.set(model, MOI.LazyConstraintCallback(), my_callback_function)

The line to get the dual value

@test MOI.get(JuMP.unsafe_backend(model), MOI.ConstraintDual(), constrid) 0.33333333

It will be available in the next release (very soon).

@diHnguyen
Copy link
Author

This is wonderful! Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants