scipopt / PySCIPOpt

Python interface for the SCIP Optimization Suite
https://scipopt.github.io/PySCIPOpt
MIT License
786 stars 252 forks source link

how to solve extreme rays from a unbounded LP problem? #615

Closed LipingZhao closed 9 months ago

LipingZhao commented 1 year ago

I'm trying to implement benders decomposition using pyscipopt. I wonder if the pyscipopt class 'Model' can support extreme rays. If there is a certain method, could you provide some examples that can be used. Thank you so much.

fserra commented 1 year ago

Hi. I guess this is not possible right now, but should be simple enough to extend the interface to have access to the following methods from SCIP:

SCIPhasPrimalRay
SCIPgetPrimalRayVal

which I guess are the ones you need

LipingZhao commented 1 year ago

Thanks for your reply very much. If I want to extend the interface, do I have to install the SCIP from source so that it can be compiled successfully after modifying the scip.pyx file?

fserra commented 1 year ago

mmm I don't think so, but you do need to recompile the interface (or somebody @CGraczyk) would need to publish a new version. Maybe @CGraczyk can share more details

LipingZhao commented 1 year ago

mmm I don't think so, but you do need to recompile the interface (or somebody @CGraczyk) would need to publish a new version. Maybe @CGraczyk can share more details

Thanks again for your reply. I have already understood how to extend the interface of SCIPlpigetPrimalRay for python. But I'm still not sure how to write the code in the scip.pyx file. I set the shape of ray to the number of variables, which should be wrong actually.

def getPrimalRay(self):
        cdef SCIP_LPI* lpi
        PY_SCIP_CALL(SCIPgetLPI(self._scip, &lpi))
        cdef int nvars = SCIPgetNVars(self._scip)
        cdef SCIP_Real* ray = <SCIP_Real*> malloc(nvars * sizeof(SCIP_Real))
        PY_SCIP_CALL(SCIPlpiGetPrimalRay(lpi, ray))
        return [ray[i] for i in range(nvars)]

I would appreciate it if somebody could give me some guidance. @CGraczyk

Joao-Dionisio commented 10 months ago

Hello, @LipingZhao! Sorry this took so long, but I think I managed to do what you needed. See the PR #743, where I added hasPrimalRay, getPrimalRay, and getPrimalRayVal.

You probably don't have this issue anymore, but do you think this solved it?

mmghannam commented 9 months ago

Closing this for now, @LipingZhao feel free to reopen if the problem remains.