#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.
◆ 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()
Frees interrupter, has no effect when interrupter is NULL.
Definition at line 99 of file solver.cc.
◆ MathOptInterrupt()
Triggers the interrupter.
Will CHECK fail if interrupter is NULL. This is threadsafe.
Definition at line 103 of file solver.cc.
◆ MathOptIsInterrupted()
◆ MathOptNewInterrupter()
◆ 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.