XiongPengNUS / rsome

Robust Stochastic Optimization Made Easy
GNU General Public License v3.0
281 stars 54 forks source link

duality analysis #58

Closed GalPerelman closed 6 months ago

GalPerelman commented 7 months ago

I'm looking for a way to get the constraints shadow prices (for a deterministic problem) Once I modeled and solved my problem using RSOME and Gurobi, Is there a way to access Gurobi objects (Model, Variables, Constraints) to retrieve information like shadow prices and reduced cost?

XiongPengNUS commented 7 months ago

Hi @GalPerelman in fact we developed an experimental feature for obtaining the dual solution. See the sample code below:

from rsome import ro
from rsome import grb_solver as grb

model = ro.Model() 
x = model.dvar() 
y = model.dvar() 

model.max(-3*x + 4*y)
c1 = model.st(2.5*x + y <= 20)
c2 = model.st(-5*x - 3*y >= -30)
c3 = model.st(x + 2*y <= 16)
c4 = model.st(y <= 1.6, y >= -2)
c5 = model.st(y <= 8)
c6 = model.st(x >= 5)

model.solve(grb)

After solving the model, you may access the dual solution of the linear constraints or bounds using the dual() method, e.g., c1.dual() and c4[0].dual(). Since this is still an experimental feature, it is not included in our documentation, and it only works for linear constraints and bounds. The functional tool is also subject to changes in the future.

As for the reduced cost, so far it cannot be accessed.

GalPerelman commented 6 months ago

Thank you @XiongPengNUS This is very helpful!