Skip to content

Bug about different VarList objects sharing the same components #409

@ZhongkuiMa

Description

@ZhongkuiMa

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions