ERGO-Code / HiGHS

Linear optimization software
MIT License
989 stars 183 forks source link

How to get variable type (integer or continuous) in python api? #2028

Closed zhouxinsheng closed 2 weeks ago

zhouxinsheng commented 2 weeks ago

I'm using highspy(version,1.8) in python, but can not find a function to access variable type property. I tried to use Highs.getCol(), it returned tuple[highspy._core.HighsStatus, float, float, float, int], the three float are obj, lb and ub, but the int is not type for the int value of continuous and integer variable are the same(0).

import highspy
h = highspy.Highs()
h.addVariable(lb=1, ub=2, obj=3, type=highspy.HighsVarType.kContinuous, name='x1')
h.addVariable(lb=11, ub=22, obj=33, type=highspy.HighsVarType.kInteger, name='x2')
h.getCol(0) # returned (<HighsStatus.kOk: 0>, 3.0, 1.0, 2.0, 0)
h.getCol(1) # returned (<HighsStatus.kOk: 0>, 33.0, 11.0, 22.0, 0)
jajhall commented 2 weeks ago

Indeed, we've not added Highs::getColIntegrality to highspy

The best you can do at the moment is use getLp and inspect the integrality_ data member

zhouxinsheng commented 2 weeks ago

Indeed, we've not added Highs::getColIntegrality to highspy

The best you can do at the moment is use getLp and inspect the integrality_ data member

thanks for your reply, I will try as you suggested. Will more python APIs of highs such as 'getColIntegrality' be accessible in future?

jajhall commented 2 weeks ago

Yes, it's a trivial change that I've already started to make. It'll be in the next release