Skip to content

Commit

Permalink
raise exception when the rcpsp model is multimode but the model in si…
Browse files Browse the repository at this point in the history
…ngle mode.
  • Loading branch information
g-poveda committed Oct 28, 2024
1 parent dbaf7f0 commit de89370
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 1 addition & 5 deletions discrete_optimization/maximum_independent_set/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
self.edges = self.graph.get_edges()
self.graph_nx = self.graph.graph_nx
else:
self.nodes = sorted(list(self.graph.nodes()))
self.nodes = list(self.graph.nodes())
self.edges = list(self.graph.edges())
self.graph_nx = self.graph

Expand Down Expand Up @@ -100,10 +100,6 @@ def compute_violation(self, variable: MisSolution) -> int:
== variable.chosen[self.nodes_to_index[e[1]]]
== 1
):
print(e)
print(
"violation ", self.nodes_to_index[e[0]], self.nodes_to_index[e[1]]
)
v += 1
return v

Expand Down
8 changes: 8 additions & 0 deletions discrete_optimization/rcpsp/solvers/toulbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def retrieve_solution(
)

def init_model(self, **kwargs: Any) -> None:
try:
assert not self.problem.is_rcpsp_multimode()
except AssertionError as exc:
logging.exception(
f"Your problem is multimode, and this toulbar model can't tackle it. "
f"Please go with ToulbarMultimodeRcpspSolver instead."
)
raise exc
model = pytoulbar2.CFN(ubinit=self.problem.horizon)
n_jobs = self.problem.n_jobs
horizon = self.problem.horizon
Expand Down

0 comments on commit de89370

Please sign in to comment.