coin-or / coin-or/python-mip

Bug about different VarList objects sharing the same components

Open
#409 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Linear Programming
Stars
600
Forks
108
PR merge metrics
No merged PRs in 30d

Description

**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**
```python
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.