python-mip icon indicating copy to clipboard operation
python-mip copied to clipboard

Bug about different VarList objects sharing the same components

Open ZhongkuiMa opened this issue 5 months ago • 0 comments

Describe the bug For the same model, if I create two VarList (called list1 and list2), then some cache bugs happen. If I use list1 for storing x_1, x_2, x_3, ... and use list2 for storing y_1, y_2, y_3, ..., then the two lists will sharing elements.

It is very easy to reproduce it.

To Reproduce

import mip # version 1.14.2


model = mip.Model(name="test_model")
var_list = mip.VarList(model=model)
var_list.add(name="x1")
var_list.add(name="x2")
for var in var_list:
    print(var.name)
# print outputs:
# x1
# x2

var_list2 = mip.VarList(model=model)
var_list2.add(name="y1")
var_list2.add(name="y2")
var_list2.add(name="y3")
for var in var_list2:
    print(var.name)

# print outputs:
# x1
# x2
# y1

Expected behavior I expect these two var list of the same model should not have the same components.

Desktop (please complete the following information):

  • Operating System, version: Linux
  • Python version: 3.12
  • Python-MIP version (we recommend you to test with the latest version): 1.14.2

Additional context I have replaced this with the standard Python list in my project to bypass the bug. Appreciate your work. If it is not a bug, could you tell me your design logic?

ZhongkuiMa avatar Jun 30 '25 06:06 ZhongkuiMa