Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solver.cc File Reference
#include "ortools/math_opt/core/c_api/solver.h"
#include <stddef.h>
#include <cstdlib>
#include <cstring>
#include <ios>
#include <limits>
#include <utility>
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "ortools/base/status_builder.h"
#include "ortools/base/status_macros.h"
#include "ortools/math_opt/core/solver.h"
#include "ortools/math_opt/model.pb.h"
#include "ortools/math_opt/parameters.pb.h"
#include "ortools/math_opt/result.pb.h"
#include "ortools/util/solve_interrupter.h"

Go to the source code of this file.

Classes

struct  MathOptInterrupter
 

Namespaces

namespace  operations_research
 In SWIG mode, we don't want anything besides these top-level includes.
 
namespace  operations_research::math_opt
 An object oriented wrapper for quadratic constraints in ModelStorage.
 

Functions

MathOptInterrupterMathOptNewInterrupter ()
 
void MathOptFreeInterrupter (MathOptInterrupter *interrupter)
 Frees interrupter, has no effect when interrupter is NULL.
 
void MathOptInterrupt (MathOptInterrupter *interrupter)
 
int MathOptIsInterrupted (const MathOptInterrupter *interrupter)
 
int MathOptSolve (const void *model, const size_t model_size, const int solver_type, MathOptInterrupter *const interrupter, void **solve_result, size_t *solve_result_size, char **status_msg)
 
void MathOptFree (void *ptr)
 

Function Documentation

◆ MathOptFree()

void MathOptFree ( void * ptr)

Frees memory allocated by the MathOpt C API, e.g. the solve_result or status_msg output arguments from MathOptSolve(). If ptr is NULL, has no effect.

Definition at line 147 of file solver.cc.

◆ MathOptFreeInterrupter()

void MathOptFreeInterrupter ( MathOptInterrupter * interrupter)

Frees interrupter, has no effect when interrupter is NULL.

Definition at line 99 of file solver.cc.

◆ MathOptInterrupt()

void MathOptInterrupt ( struct MathOptInterrupter * interrupter)

Triggers the interrupter.

Will CHECK fail if interrupter is NULL. This is threadsafe.

Definition at line 103 of file solver.cc.

◆ MathOptIsInterrupted()

int MathOptIsInterrupted ( const MathOptInterrupter * interrupter)

Definition at line 107 of file solver.cc.

◆ MathOptNewInterrupter()

MathOptInterrupter * MathOptNewInterrupter ( )

Returns a new interrupter that has not been triggered. The caller must free this with MathOptFreeInterrupter().

Definition at line 97 of file solver.cc.

◆ MathOptSolve()

int MathOptSolve ( const void * model,
size_t model_size,
int solver_type,
struct MathOptInterrupter * interrupter,
void ** solve_result,
size_t * solve_result_size,
char ** status_msg )

Solves an optimization model with MathOpt and returns the result.

Arguments:

  • model: a serialized ModelProto to solve. The function fails if this cannot be parsed, or if this is NULL and model_size > 0.
  • model_size: the size of model in bytes. Must be at most MAX_INT or the the function fails.
  • solver_type: which solver to use, see SolverTypeProto for numeric values.
  • interrupter: ignored if NULL. If interrupted before the solve begins, or from another thread while the solve is running, the solve will terminate early with whatever results are available. MathOptSolve() will not change the state (interrupted or not) of interrupter. It is safe for concurrent calls to MathOptSolve() to share a single interrupter. The interrupter must survive all calls to MathOptSolve().
  • solve_result: an output argument, ignored if NULL. On success, *solve_result is filled with a serialized SolveResultProto from solving model. The caller must free *solve_result in this case with MathOptFree(). On failure, *solve_result is set to NULL.
  • solve_result_size: an output argument, ignored if NULL. On success, *solve_result_size has the size in bytes of the serialized SolveResultProto from solving model (the size of *solve_result if set). On failure, *solve_result_size is set to zero.
  • status_msg: an output argument. If NULL, this output is ignored. On success, *status_msg is set to NULL. On failure, *status_msg is set to a null terminated string describing the error. The caller must free *status_msg with MathOptFree() in this case.
Note
solve_result_size holds the size of the serialized proto returned in solve_result. Typically, you should make solve_result and solve_result_size either both NULL or both not NULL. You cannot safely consume solve_result without solve_result_size.

Returns 0 if successful and a nonzero value on failure (the value is an absl::StatusCode enum).

Warning
failure could be caused by null arguments!

Definition at line 112 of file solver.cc.