linopy.model.Model.solve

Contents

linopy.model.Model.solve#

Model.solve(solver_name=None, io_api=None, problem_fn=None, solution_fn=None, log_fn=None, basis_fn=None, warmstart_fn=None, keep_files=False, env=None, sanitize_zeros=True, remote=None, **solver_options)#

Solve the model with possibly different solvers.

The optimal values of the variables are stored in model.solution. The optimal dual variables are stored in model.dual.

Parameters:
  • solver_name (str, optional) – Name of the solver to use, this must be in linopy.available_solvers. Default to the first entry in linopy.available_solvers.

  • io_api (str, optional) – Api to use for communicating with the solver, must be one of {‘lp’, ‘mps’, ‘direct’}. If set to ‘lp’/’mps’ the problem is written to an LP/MPS file which is then read by the solver. If set to ‘direct’ the problem is communicated to the solver via the solver specific API, e.g. gurobipy. This may lead to faster run times. The default is set to ‘lp’ if available.

  • problem_fn (path_like, optional) – Path of the lp file or output file/directory which is written out during the process. The default None results in a temporary file.

  • solution_fn (path_like, optional) – Path of the solution file which is written out during the process. The default None results in a temporary file.

  • log_fn (path_like, optional) – Path of the logging file which is written out during the process. The default None results in the no log file, hence all solver outputs are piped to the python repl.

  • basis_fn (path_like, optional) – Path of the basis file of the solution which is written after solving. The default None results in a temporary file, if the solver/method supports writing out a basis file.

  • warmstart_fn (path_like, optional) – Path of the basis file which should be used to warmstart the solving. The default is None.

  • keep_files (bool, optional) – Whether to keep all temporary files like lp file, solution file. This argument is ignored for the logger file log_fn. The default is False.

  • env (gurobi.Env, optional) – Existing environment passed to the solver (e.g. gurobipy.Env). Currently only in use for Gurobi. The default is None.

  • sanitize_zeros (bool, optional) – Whether to set terms with zero coefficient as missing. This will remove unneeded overhead in the lp file writing. The default is True.

  • remote (linopy.remote.RemoteHandler) – Remote handler to use for solving model on a server. Note that when solving on a rSee linopy.remote.RemoteHandler for more details.

  • **solver_options (kwargs) – Options passed to the solver.

Returns:

linopy.Model – Optimized model.