python-mip: Visual Code Python debugging tool crashes when trying to access "Model" object attributes before optimization
Consider the following code to model the maximum independent set problem to solve the maximum clique using MIP and NetworkX:
import mip
import networkx
n = 2 ** 3
g = networkx.binomial_tree(n)
networkx.add_star(g, [i for i in range(n)])
g1 = networkx.complement(g)
model = mip.Model("Independent Set")
x = [model.add_var(var_type=mip.BINARY) for _ in range(len(g1.nodes))]
model.objective = mip.maximize(mip.xsum(x[i] for i in range(len(g1.nodes))))
for (i, j) in g1.edges:
model += x[i] + x[j] <= 1
model.optimize()
selected = [i for i in range(len(g1.nodes)) if x[i].x >= 0.99]
print(selected)
g2 = g.subgraph(selected)
If I try to access the model variables in the watch section, it gives he following message on terminal:
Information not available, model was not optimized yet.
And then, the debugger dies. I believe this is not what should happen, some help with this?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 16 (8 by maintainers)
Hello Otávio !
Currently we throw an exception when an specific property of a variable (the solution value x) is accessed, since the debugger is probably trying to access all properties we have this problem…
I think that the behaviour could be changed to just return None as solution value when no optimization is performed. I’ll include this change in the next release.
Cheers,
Haroldo
–
Haroldo Gambini Santos Computing Department Universidade Federal de Ouro Preto - UFOP email: haroldo@ufop.edu.br Haroldo.GambiniSantos@cs.kuleuven.be home/research page: www.decom.ufop.br/haroldo
It has long been an axiom of mine that the little things are infinitely the most important. – Sir Arthur Conan Doyle, “A Case of Identity”
On Wed, 20 Nov 2019, Otávio Augusto Silva wrote: