35 opt_model: model.Model,
40 msg_cb: Optional[message_callback.SolveMessageCallback] =
None,
42 cb: Optional[SolveCallback] =
None,
44 """Solves an optimization model.
46 Thread-safety: this function must not be called while modifying the Model
47 (adding variables...). Some solvers may add more restriction regarding
48 threading. Please see SolverType::XXX documentation for details.
51 opt_model: The optimization model.
52 solver_type: The underlying solver to use.
53 params: Configuration of the underlying solver.
54 model_params: Configuration of the solver that is model specific.
55 msg_cb: A callback that gives back the underlying solver's logs by the line.
56 callback_reg: Configures when the callback will be invoked (if provided) and
57 what data will be collected to access in the callback.
58 cb: A callback that will be called periodically as the solver runs.
61 A SolveResult containing the termination reason, solution(s) and stats.
64 RuntimeError: On a solve error.
71 model_proto = opt_model.export_model()
74 proto_cb =
lambda x: cb(
75 callback.parse_callback_data(x, opt_model)
79 proto_result = solver.solve(
82 parameters_pb2.SolverInitializerProto(),
84 model_params.to_proto(),
86 callback_reg.to_proto(),
90 except StatusNotOk
as e:
92 return result.parse_solve_result(proto_result, opt_model)
96 opt_model: model.Model,
100 msg_cb: Optional[message_callback.SolveMessageCallback] =
None,
102 """Computes an infeasible subsystem of the input model.
105 opt_model: The optimization model to check for infeasibility.
106 solver_type: Which solver to use to compute the infeasible subsystem. As of
107 August 2023, the only supported solver is Gurobi.
108 params: Configuration of the underlying solver.
109 msg_cb: A callback that gives back the underlying solver's logs by the line.
112 An `ComputeInfeasibleSubsystemResult` where `feasibility` indicates if the
113 problem was proven infeasible.
116 RuntimeError: on invalid inputs or an internal solver error.
119 model_proto = opt_model.export_model()
122 proto_result = solver.compute_infeasible_subsystem(
125 parameters_pb2.SolverInitializerProto(),
130 except StatusNotOk
as e:
133 compute_infeasible_subsystem_result.parse_compute_infeasible_subsystem_result(
134 proto_result, opt_model