Skip to content

Commit

Permalink
Consider sequential/repeated solve
Browse files Browse the repository at this point in the history
  • Loading branch information
hitonanode committed Apr 26, 2024
1 parent d588aef commit 3391bbf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lpmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ def set_objective(self, objective: LPExpressionLike) -> None:
self.objective = LPExpression.build(objective)

def solve(self) -> None:
if self.has_impossible_constraints:
self.status = LPStatus.INFEASIBLE
return

var_dict: dict[int, LPVar] = {}
for constraint in self.constraints:
for term in constraint.lhs.terms:
Expand All @@ -292,6 +288,18 @@ def solve(self) -> None:
for term in self.objective.terms:
var_dict.setdefault(id(term.variable), term.variable)

# Reset status
self.objective._value = None
self.status = None
for var in var_dict.values():
var._value = None

# Obviously infeasible
if self.has_impossible_constraints:
self.status = LPStatus.INFEASIBLE
return

# Obviously optimal
if not var_dict:
self.status = LPStatus.OPTIMAL
self.objective._value = self.objective.const
Expand Down

0 comments on commit 3391bbf

Please sign in to comment.