mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
GurobiModel: Capture static_var_obj_coeffs_quad
This commit is contained in:
@@ -80,6 +80,7 @@ class MaxCutGenerator:
|
||||
def _generate_graph(self) -> Graph:
|
||||
return nx.generators.random_graphs.binomial_graph(self.n.rvs(), self.p.rvs())
|
||||
|
||||
|
||||
def build_maxcut_model_gurobipy(
|
||||
data: Union[str, MaxCutData],
|
||||
params: Optional[dict[str, Any]] = None,
|
||||
@@ -97,13 +98,16 @@ def build_maxcut_model_gurobipy(
|
||||
x = model.addVars(nodes, vtype=gp.GRB.BINARY, name="x")
|
||||
|
||||
# Add the objective function
|
||||
model.setObjective(quicksum(
|
||||
- data.weights[i] * x[e[0]] * (1 - x[e[1]]) for (i, e) in enumerate(edges)
|
||||
))
|
||||
model.setObjective(
|
||||
quicksum(
|
||||
-data.weights[i] * x[e[0]] * (1 - x[e[1]]) for (i, e) in enumerate(edges)
|
||||
)
|
||||
)
|
||||
|
||||
model.update()
|
||||
return GurobiModel(model)
|
||||
|
||||
|
||||
def _maxcut_read(data: Union[str, MaxCutData]) -> MaxCutData:
|
||||
if isinstance(data, str):
|
||||
data = read_pkl_gz(data)
|
||||
|
||||
@@ -264,6 +264,13 @@ class GurobiModel(AbstractModel):
|
||||
h5.put_array(
|
||||
h5_field, np.array(self.inner.getAttr(gp_field, gp_vars), dtype=float)
|
||||
)
|
||||
obj = self.inner.getObjective()
|
||||
if isinstance(obj, gp.QuadExpr):
|
||||
nvars = len(self.inner.getVars())
|
||||
obj_q = np.zeros((nvars, nvars))
|
||||
for i in range(obj.size()):
|
||||
obj_q[obj.getVar1(i).index, obj.getVar2(i).index] = obj.getCoeff(i)
|
||||
h5.put_array("static_var_obj_coeffs_quad", obj_q)
|
||||
|
||||
def _extract_after_load_constrs(self, h5: H5File) -> None:
|
||||
gp_constrs = self.inner.getConstrs()
|
||||
|
||||
Reference in New Issue
Block a user