mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Store cuts and lazy constraints as JSON in H5
This commit is contained in:
@@ -170,11 +170,11 @@ def _stab_read(data: Union[str, MaxWeightStableSetData]) -> MaxWeightStableSetDa
|
||||
return data
|
||||
|
||||
|
||||
def _stab_separate(data: MaxWeightStableSetData, x_val: List[float]) -> List[Hashable]:
|
||||
def _stab_separate(data: MaxWeightStableSetData, x_val: List[float]) -> List:
|
||||
# Check that we selected at most one vertex for each
|
||||
# clique in the graph (sum <= 1)
|
||||
violations: List[Hashable] = []
|
||||
violations: List[Any] = []
|
||||
for clique in nx.find_cliques(data.graph):
|
||||
if sum(x_val[i] for i in clique) > 1.0001:
|
||||
violations.append(tuple(sorted(clique)))
|
||||
violations.append(sorted(clique))
|
||||
return violations
|
||||
|
||||
@@ -231,18 +231,18 @@ def _tsp_separate(
|
||||
x_val: dict[Tuple[int, int], float],
|
||||
edges: List[Tuple[int, int]],
|
||||
n_cities: int,
|
||||
) -> List[Tuple[Tuple[int, int], ...]]:
|
||||
) -> List:
|
||||
violations = []
|
||||
selected_edges = [e for e in edges if x_val[e] > 0.5]
|
||||
graph = nx.Graph()
|
||||
graph.add_edges_from(selected_edges)
|
||||
for component in list(nx.connected_components(graph)):
|
||||
if len(component) < n_cities:
|
||||
cut_edges = tuple(
|
||||
(e[0], e[1])
|
||||
cut_edges = [
|
||||
[e[0], e[1]]
|
||||
for e in edges
|
||||
if (e[0] in component and e[1] not in component)
|
||||
or (e[0] not in component and e[1] in component)
|
||||
)
|
||||
]
|
||||
violations.append(cut_edges)
|
||||
return violations
|
||||
|
||||
Reference in New Issue
Block a user