Skip to content

Visual Code Python debugging tool crashes when trying to access "Model" object attributes before optimization #26

Open
@otavio-silva

Description

@otavio-silva

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcbcAll items related to cbc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions