Skip to content

Commit 3cdc8b7

Browse files
chripiermariniMizux
authored andcommitted
fix(sat): correct documentation and validation in cp_model.py
1 parent f49317a commit 3cdc8b7

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

ortools/sat/python/cp_model.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
4040
* [`Constraint`](#cp_model.Constraint): A few utility methods for modifying
4141
constraints created by `CpModel`.
42-
* [`LinearExpr`](#lineacp_model.LinearExpr): Methods for creating constraints
42+
* [`LinearExpr`](#cp_model.LinearExpr): Methods for creating constraints
4343
and the objective from large arrays of coefficients.
4444
4545
Other methods and functions listed are primarily used for developing OR-Tools,
@@ -86,7 +86,6 @@
8686

8787
# CpSolver status (exported to avoid importing cp_model_cp2).
8888
UNKNOWN = cmh.CpSolverStatus.UNKNOWN
89-
UNKNOWN = cmh.CpSolverStatus.UNKNOWN
9089
MODEL_INVALID = cmh.CpSolverStatus.MODEL_INVALID
9190
FEASIBLE = cmh.CpSolverStatus.FEASIBLE
9291
INFEASIBLE = cmh.CpSolverStatus.INFEASIBLE
@@ -829,6 +828,18 @@ def add_reservoir_constraint(
829828
ValueError: if min_level > 0
830829
"""
831830

831+
if max_level < min_level:
832+
raise ValueError("Reservoir constraint must have a max_level >= min_level")
833+
834+
if max_level < 0:
835+
raise ValueError("Reservoir constraint must have a max_level >= 0")
836+
837+
if min_level > 0:
838+
raise ValueError("Reservoir constraint must have a min_level <= 0")
839+
840+
if not times:
841+
raise ValueError("Reservoir constraint must have a non-empty times array")
842+
832843
return self._add_reservoir(
833844
times,
834845
level_changes,
@@ -1570,12 +1581,14 @@ def maximize(self, obj: ObjLinearExprT):
15701581
self._set_objective(obj, maximize=True)
15711582

15721583
def has_objective(self) -> bool:
1584+
"""Returns true if the model has an objective (integer or floating point)."""
15731585
return (
15741586
self.model_proto.has_objective()
15751587
or self.model_proto.has_floating_point_objective()
15761588
)
15771589

15781590
def clear_objective(self):
1591+
"""Clears the objective of the model."""
15791592
self.model_proto.clear_objective()
15801593
self.model_proto.clear_floating_point_objective()
15811594

@@ -2126,7 +2139,7 @@ def boolean_value(self, lit: LiteralT) -> bool:
21262139
return self.BooleanValue(lit)
21272140

21282141
def value(self, expression: LinearExprT) -> int:
2129-
"""Evaluates an linear expression in the current solution.
2142+
"""Evaluates a linear expression in the current solution.
21302143
21312144
Args:
21322145
expression: a linear expression of the model.
@@ -2143,13 +2156,13 @@ def value(self, expression: LinearExprT) -> int:
21432156
return self.Value(expression)
21442157

21452158
def float_value(self, expression: LinearExprT) -> float:
2146-
"""Evaluates an linear expression in the current solution.
2159+
"""Evaluates a linear expression in the current solution.
21472160
21482161
Args:
21492162
expression: a linear expression of the model.
21502163
21512164
Returns:
2152-
An integer value equal to the evaluation of the linear expression
2165+
A float value equal to the evaluation of the linear expression
21532166
against the current solution.
21542167
21552168
Raises:
@@ -2219,7 +2232,7 @@ def num_binary_propagations(self) -> int:
22192232

22202233
@property
22212234
def deterministic_time(self) -> float:
2222-
"""Returns the determistic time in seconds since the creation of the solver."""
2235+
"""Returns the deterministic time in seconds since the creation of the solver."""
22232236
if not self.has_response():
22242237
raise RuntimeError("solve() has not been called.")
22252238
return self.DeterministicTime()

0 commit comments

Comments
 (0)