mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-08 10:28:52 -06:00
Refer to variables by varname instead of (vname, index)
This commit is contained in:
@@ -10,6 +10,7 @@ import networkx as nx
|
||||
import pytest
|
||||
from gurobipy import GRB
|
||||
from networkx import Graph
|
||||
from overrides import overrides
|
||||
|
||||
from miplearn.components.dynamic_user_cuts import UserCutsComponent
|
||||
from miplearn.instance.base import Instance
|
||||
@@ -24,6 +25,7 @@ class GurobiStableSetProblem(Instance):
|
||||
super().__init__()
|
||||
self.graph: Graph = graph
|
||||
|
||||
@overrides
|
||||
def to_model(self) -> Any:
|
||||
model = gp.Model()
|
||||
x = [model.addVar(vtype=GRB.BINARY) for _ in range(len(self.graph.nodes))]
|
||||
@@ -32,9 +34,11 @@ class GurobiStableSetProblem(Instance):
|
||||
model.addConstr(x[e[0]] + x[e[1]] <= 1)
|
||||
return model
|
||||
|
||||
@overrides
|
||||
def has_user_cuts(self) -> bool:
|
||||
return True
|
||||
|
||||
@overrides
|
||||
def find_violated_user_cuts(self, model):
|
||||
assert isinstance(model, gp.Model)
|
||||
vals = model.cbGetNodeRel(model.getVars())
|
||||
@@ -44,6 +48,7 @@ class GurobiStableSetProblem(Instance):
|
||||
violations += [frozenset(clique)]
|
||||
return violations
|
||||
|
||||
@overrides
|
||||
def build_user_cut(self, model: Any, cid: Hashable) -> Any:
|
||||
assert isinstance(cid, FrozenSet)
|
||||
x = model.getVars()
|
||||
|
||||
Reference in New Issue
Block a user