discrete_optimization.lotsizing.generic_solver.cpsat package
Submodules
discrete_optimization.lotsizing.generic_solver.cpsat.backlog module
- class discrete_optimization.lotsizing.generic_solver.cpsat.backlog.BacklogConstraintCpsat(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
LotSizingCpSatSolver[Item]
discrete_optimization.lotsizing.generic_solver.cpsat.changeover module
- class discrete_optimization.lotsizing.generic_solver.cpsat.changeover.ChangeOverConstraintCpsat(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
LotSizingCpSatSolver[Item]- changeover_vars: dict
- create_changeover_constraint_and_cost(modeling: ChangeoverModel)[source]
discrete_optimization.lotsizing.generic_solver.cpsat.generic_lotsizing_cpsat module
- class discrete_optimization.lotsizing.generic_solver.cpsat.generic_lotsizing_cpsat.GenericLotSizingCpsat(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
ProductionConstraintCpsat[Item],InventoryConstraintCpsat[Item],BacklogConstraintCpsat[Item],ChangeOverConstraintCpsat[Item],ParallelProductionConstraintCpsat[Item],WarmstartMixin- add_lexico_constraint(obj: str, value: float) Iterable[Any][source]
Add a constraint on a computed sub-objective
- Parameters:
obj – a string representing the desired objective. Should be one of self.get_lexico_objectives_available().
value – the limiting value. If the optimization direction is maximizing, this is a lower bound, else this is an upper bound.
- Returns:
the created constraints.
- backlog: dict[Item, list[IntVar]]
- delivery: dict[Item, list[IntVar]]
- get_lexico_objective_value(obj: str, res: ResultStorage) float[source]
Get best internal model objective value found by last call to solve().
The default implementation consists in using the fit of the last solution in result_storage. This assumes: - that the last solution is the best one for the objective considered - that no aggregation was performed but rather that the fitness is a TupleFitness
with values in the same order as self.problem.get_objective_names().
- Parameters:
obj – a string representing the desired objective. Should be one of self.get_lexico_objectives_available().
res – result storage returned by last call to solve().
Returns:
- get_lexico_objectives_available() list[str][source]
List objectives available for lexico optimization
It corresponds to the labels accepted for obj argument for - set_lexico_objective() - add_lexico_constraint() - get_lexico_objective_value()
Default to self.problem.get_objective_names().
Returns:
- hyperparameters: list[Hyperparameter] = [CategoricalHyperparameter(name='create_delivery_vars', default=True, depends_on=None, name_in_kwargs='create_delivery_vars'), EnumHyperparameter(name='modeling_changeover', default=<ChangeoverModel.SHORTEST_PATH_BASED: 'shortest_path_based'>, depends_on=None, name_in_kwargs='modeling_changeover')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- implements_lexico_api() bool[source]
Tell whether this solver is implementing the api for lexicographic optimization.
Should return True only if
set_lexico_objective()
add_lexico_constraint()
get_lexico_objective_value()
have been really implemented, i.e. - calling set_lexico_objective() and add_lexico_constraint()
should actually change the next call to solve(),
get_lexico_objective_value() should correspond to the internal model objective
- inventory: dict[Item, list[IntVar]]
- objectives: dict[str, LinearExpr]
- problem: GenericLotSizingProblem[Item]
- production: dict[Item, list[IntVar]]
- production_binary: dict[Item, list[IntVar]]
- retrieve_solution(cpsolvercb: CpSolverSolutionCallback) ProductionBasedSolution[source]
Construct a do solution from the cpsat solver internal solution.
It will be called each time the cpsat solver find a new solution. At that point, value of internal variables are accessible via cpsolvercb.Value(VARIABLE_NAME).
- Parameters:
cpsolvercb – the ortools callback called when the cpsat solver finds a new solution.
- Returns:
the intermediate solution, at do format.
- set_warm_start(solution: ProductionBasedSolution) None[source]
Make the solver warm start from the given solution.
- variables: dict
discrete_optimization.lotsizing.generic_solver.cpsat.generic_lotsizing_cpsat_scheduling module
Generic CP-SAT scheduling solver for lot sizing problems.
This solver uses a scheduling-based formulation where each demand is modeled as an event (interval variable) to be scheduled. This is fundamentally different from the quantity-based formulation in generic_lotsizing_cpsat.py.
Key features: - Interval variables for each demand occurrence - NoOverlap constraints for capacity - Circuit constraints for changeover sequencing - Natural representation of inventory cost as (deadline - production_time) - Efficient for problems with sparse demands or unit demands
The scheduling approach is particularly effective when: - Demands are small relative to horizon (many idle periods) - Strong changeover costs make sequencing important - Backlog is allowed (flexible timing)
- class discrete_optimization.lotsizing.generic_solver.cpsat.generic_lotsizing_cpsat_scheduling.GenericLotSizingCpsatScheduling(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
LotSizingCpSatSolver[Item]Generic CP-SAT scheduling solver for lot sizing.
This solver models lot sizing as a scheduling problem where each demand is an event to be scheduled. This contrasts with the quantity-based formulation in GenericLotSizingCpsat.
Model structure: - For each demand occurrence (item, period, quantity), create demand events - Each event has a start time variable (when to produce) - Interval variables ensure no conflicts - Circuit constraint sequences productions for changeover costs - Inventory cost = (deadline - start) * holding_cost
This formulation is most efficient for: - Unit demands or small demands - Sparse demand patterns (many idle periods) - Strong changeover cost structure
- demand_events: list
- event_deadlines: dict
- get_production_binary_var(item: Item, period: int) Any[source]
Not applicable for scheduling formulation.
- get_production_quantity_var(item: Item, period: int) Any[source]
Not applicable for scheduling formulation.
- hyperparameters: list[Hyperparameter] = [CategoricalHyperparameter(name='unit_demand_aggregation', default=True, depends_on=None, name_in_kwargs='unit_demand_aggregation')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- init_model(**kwargs: Any) None[source]
Initialize the CP-SAT scheduling model.
- Parameters:
**kwargs – Hyperparameters including unit_demand_aggregation
- problem: GenericLotSizingProblem[Item]
- retrieve_solution(cpsolvercb: CpSolverSolutionCallback) ProductionBasedSolution[source]
Extract solution from CP-SAT solver.
- Parameters:
cpsolvercb – CP-SAT solution callback
- Returns:
ProductionBasedSolution with productions and deliveries
- variables: dict
discrete_optimization.lotsizing.generic_solver.cpsat.inventory module
- class discrete_optimization.lotsizing.generic_solver.cpsat.inventory.InventoryConstraintCpsat(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
LotSizingCpSatSolver[Item]
discrete_optimization.lotsizing.generic_solver.cpsat.lotsizing_solver_cpsat module
- class discrete_optimization.lotsizing.generic_solver.cpsat.lotsizing_solver_cpsat.LotSizingCpSatSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
LotSizingGenericSolver[Item],OrtoolsCpSatSolver
discrete_optimization.lotsizing.generic_solver.cpsat.parallel_production module
- class discrete_optimization.lotsizing.generic_solver.cpsat.parallel_production.ParallelProductionConstraintCpsat(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
LotSizingCpSatSolver[Item]
discrete_optimization.lotsizing.generic_solver.cpsat.production module
- class discrete_optimization.lotsizing.generic_solver.cpsat.production.ProductionConstraintCpsat(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
LotSizingCpSatSolver[Item]
Module contents
Generic CP-SAT solvers for lot sizing problems.
This module provides two CP-SAT formulations: - GenericLotSizingCpsat: Quantity-based formulation (standard MIP-like) - GenericLotSizingCpsatScheduling: Scheduling-based formulation (interval variables)
- class discrete_optimization.lotsizing.generic_solver.cpsat.GenericLotSizingCpsat(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
ProductionConstraintCpsat[Item],InventoryConstraintCpsat[Item],BacklogConstraintCpsat[Item],ChangeOverConstraintCpsat[Item],ParallelProductionConstraintCpsat[Item],WarmstartMixin- add_lexico_constraint(obj: str, value: float) Iterable[Any][source]
Add a constraint on a computed sub-objective
- Parameters:
obj – a string representing the desired objective. Should be one of self.get_lexico_objectives_available().
value – the limiting value. If the optimization direction is maximizing, this is a lower bound, else this is an upper bound.
- Returns:
the created constraints.
- backlog: dict[Item, list[IntVar]]
- delivery: dict[Item, list[IntVar]]
- get_lexico_objective_value(obj: str, res: ResultStorage) float[source]
Get best internal model objective value found by last call to solve().
The default implementation consists in using the fit of the last solution in result_storage. This assumes: - that the last solution is the best one for the objective considered - that no aggregation was performed but rather that the fitness is a TupleFitness
with values in the same order as self.problem.get_objective_names().
- Parameters:
obj – a string representing the desired objective. Should be one of self.get_lexico_objectives_available().
res – result storage returned by last call to solve().
Returns:
- get_lexico_objectives_available() list[str][source]
List objectives available for lexico optimization
It corresponds to the labels accepted for obj argument for - set_lexico_objective() - add_lexico_constraint() - get_lexico_objective_value()
Default to self.problem.get_objective_names().
Returns:
- hyperparameters: list[Hyperparameter] = [CategoricalHyperparameter(name='create_delivery_vars', default=True, depends_on=None, name_in_kwargs='create_delivery_vars'), EnumHyperparameter(name='modeling_changeover', default=<ChangeoverModel.SHORTEST_PATH_BASED: 'shortest_path_based'>, depends_on=None, name_in_kwargs='modeling_changeover')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- implements_lexico_api() bool[source]
Tell whether this solver is implementing the api for lexicographic optimization.
Should return True only if
set_lexico_objective()
add_lexico_constraint()
get_lexico_objective_value()
have been really implemented, i.e. - calling set_lexico_objective() and add_lexico_constraint()
should actually change the next call to solve(),
get_lexico_objective_value() should correspond to the internal model objective
- inventory: dict[Item, list[IntVar]]
- objectives: dict[str, LinearExpr]
- problem: GenericLotSizingProblem[Item]
- production: dict[Item, list[IntVar]]
- production_binary: dict[Item, list[IntVar]]
- retrieve_solution(cpsolvercb: CpSolverSolutionCallback) ProductionBasedSolution[source]
Construct a do solution from the cpsat solver internal solution.
It will be called each time the cpsat solver find a new solution. At that point, value of internal variables are accessible via cpsolvercb.Value(VARIABLE_NAME).
- Parameters:
cpsolvercb – the ortools callback called when the cpsat solver finds a new solution.
- Returns:
the intermediate solution, at do format.
- set_warm_start(solution: ProductionBasedSolution) None[source]
Make the solver warm start from the given solution.
- variables: dict
- class discrete_optimization.lotsizing.generic_solver.cpsat.GenericLotSizingCpsatScheduling(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
LotSizingCpSatSolver[Item]Generic CP-SAT scheduling solver for lot sizing.
This solver models lot sizing as a scheduling problem where each demand is an event to be scheduled. This contrasts with the quantity-based formulation in GenericLotSizingCpsat.
Model structure: - For each demand occurrence (item, period, quantity), create demand events - Each event has a start time variable (when to produce) - Interval variables ensure no conflicts - Circuit constraint sequences productions for changeover costs - Inventory cost = (deadline - start) * holding_cost
This formulation is most efficient for: - Unit demands or small demands - Sparse demand patterns (many idle periods) - Strong changeover cost structure
- demand_events: list
- event_deadlines: dict
- get_production_binary_var(item: Item, period: int) Any[source]
Not applicable for scheduling formulation.
- get_production_quantity_var(item: Item, period: int) Any[source]
Not applicable for scheduling formulation.
- hyperparameters: list[Hyperparameter] = [CategoricalHyperparameter(name='unit_demand_aggregation', default=True, depends_on=None, name_in_kwargs='unit_demand_aggregation')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- init_model(**kwargs: Any) None[source]
Initialize the CP-SAT scheduling model.
- Parameters:
**kwargs – Hyperparameters including unit_demand_aggregation
- problem: GenericLotSizingProblem[Item]
- retrieve_solution(cpsolvercb: CpSolverSolutionCallback) ProductionBasedSolution[source]
Extract solution from CP-SAT solver.
- Parameters:
cpsolvercb – CP-SAT solution callback
- Returns:
ProductionBasedSolution with productions and deliveries
- variables: dict