Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::ModelBuilderHelper Class Reference

#include <model_builder_helper.h>

Public Member Functions

void OverwriteModel (const ModelBuilderHelper &other_helper)
 
std::string ExportToMpsString (const operations_research::MPModelExportOptions &options=MPModelExportOptions())
 
std::string ExportToLpString (const operations_research::MPModelExportOptions &options=MPModelExportOptions())
 
bool WriteToMpsFile (const std::string &filename, const operations_research::MPModelExportOptions &options=MPModelExportOptions())
 
bool ReadModelFromProtoFile (const std::string &filename)
 
bool WriteModelToProtoFile (const std::string &filename)
 
bool ImportFromMpsString (const std::string &mps_string)
 
bool ImportFromMpsFile (const std::string &mps_file)
 
const MPModelProto & model () const
 
MPModelProto * mutable_model ()
 
int AddVar ()
 Direct low level model building API.
 
void SetVarLowerBound (int var_index, double lb)
 
void SetVarUpperBound (int var_index, double ub)
 
void SetVarIntegrality (int var_index, bool is_integer)
 
void SetVarObjectiveCoefficient (int var_index, double coeff)
 
void SetVarName (int var_index, const std::string &name)
 
double VarLowerBound (int var_index) const
 
double VarUpperBound (int var_index) const
 
bool VarIsIntegral (int var_index) const
 
double VarObjectiveCoefficient (int var_index) const
 
std::string VarName (int var_index) const
 
double ConstraintLowerBound (int ct_index) const
 
double ConstraintUpperBound (int ct_index) const
 
int AddLinearConstraint ()
 
std::string ConstraintName (int ct_index) const
 
std::vector< double > ConstraintCoefficients (int ct_index) const
 
std::vector< int > ConstraintVarIndices (int ct_index) const
 
void AddConstraintTerm (int ct_index, int var_index, double coeff)
 
void ClearConstraintTerms (int ct_index)
 
void SafeAddConstraintTerm (int ct_index, int var_index, double coeff)
 
void SetConstraintCoefficient (int ct_index, int var_index, double coeff)
 
void SetConstraintLowerBound (int ct_index, double lb)
 
void SetConstraintName (int ct_index, const std::string &name)
 
void SetConstraintUpperBound (int ct_index, double ub)
 
bool EnforcedIndicatorValue (int ct_index) const
 
bool IsEnforcedConstraint (int ct_index) const
 
double EnforcedConstraintLowerBound (int ct_index) const
 
double EnforcedConstraintUpperBound (int ct_index) const
 
int AddEnforcedLinearConstraint ()
 
int EnforcedIndicatorVariableIndex (int ct_index) const
 
std::string EnforcedConstraintName (int ct_index) const
 
std::vector< double > EnforcedConstraintCoefficients (int ct_index) const
 
std::vector< int > EnforcedConstraintVarIndices (int ct_index) const
 
void AddEnforcedConstraintTerm (int ct_index, int var_index, double coeff)
 
void ClearEnforcedConstraintTerms (int ct_index)
 
void SafeAddEnforcedConstraintTerm (int ct_index, int var_index, double coeff)
 
void SetEnforcedConstraintCoefficient (int ct_index, int var_index, double coeff)
 
void SetEnforcedConstraintLowerBound (int ct_index, double lb)
 
void SetEnforcedConstraintName (int ct_index, const std::string &name)
 
void SetEnforcedConstraintUpperBound (int ct_index, double ub)
 
void SetEnforcedIndicatorValue (int ct_index, bool positive)
 
void SetEnforcedIndicatorVariableIndex (int ct_index, int var_index)
 
int num_constraints () const
 
int num_variables () const
 
std::string name () const
 
void SetName (const std::string &name)
 
void ClearObjective ()
 
bool maximize () const
 
void SetMaximize (bool maximize)
 
double ObjectiveOffset () const
 
void SetObjectiveOffset (double offset)
 
void ClearHints ()
 
void AddHint (int var_index, double var_value)
 

Detailed Description

The arguments of the functions defined below must follow these rules to be wrapped by SWIG correctly: 1) Their types must include the full operations_research:: namespace. 2) Their names must correspond to the ones declared in the .i file (see the java/ and csharp/ subdirectories). Helper for importing/exporting models and model protobufs.

Wrapping global function is brittle with SWIG. It is much easier to wrap static class methods.

Note
all these methods rely on c++ code that uses absl::Status or absl::StatusOr. Unfortunately, these are inconsistently wrapped in non C++ languages. As a consequence, we need to provide an API that does not involve absl::Status or absl::StatusOr.

Definition at line 47 of file model_builder_helper.h.

Member Function Documentation

◆ AddConstraintTerm()

void operations_research::ModelBuilderHelper::AddConstraintTerm ( int ct_index,
int var_index,
double coeff )

Definition at line 208 of file model_builder_helper.cc.

◆ AddEnforcedConstraintTerm()

void operations_research::ModelBuilderHelper::AddEnforcedConstraintTerm ( int ct_index,
int var_index,
double coeff )

Definition at line 314 of file model_builder_helper.cc.

◆ AddEnforcedLinearConstraint()

int operations_research::ModelBuilderHelper::AddEnforcedLinearConstraint ( )

Create the new general constraint, and force the type to indicator ct.

Definition at line 275 of file model_builder_helper.cc.

◆ AddHint()

void operations_research::ModelBuilderHelper::AddHint ( int var_index,
double var_value )

Definition at line 465 of file model_builder_helper.cc.

◆ AddLinearConstraint()

int operations_research::ModelBuilderHelper::AddLinearConstraint ( )

Definition at line 188 of file model_builder_helper.cc.

◆ AddVar()

int operations_research::ModelBuilderHelper::AddVar ( )

Direct low level model building API.

Definition at line 141 of file model_builder_helper.cc.

◆ ClearConstraintTerms()

void operations_research::ModelBuilderHelper::ClearConstraintTerms ( int ct_index)

Definition at line 202 of file model_builder_helper.cc.

◆ ClearEnforcedConstraintTerms()

void operations_research::ModelBuilderHelper::ClearEnforcedConstraintTerms ( int ct_index)

Definition at line 306 of file model_builder_helper.cc.

◆ ClearHints()

void operations_research::ModelBuilderHelper::ClearHints ( )

Definition at line 463 of file model_builder_helper.cc.

◆ ClearObjective()

void operations_research::ModelBuilderHelper::ClearObjective ( )

Definition at line 443 of file model_builder_helper.cc.

◆ ConstraintCoefficients()

std::vector< double > operations_research::ModelBuilderHelper::ConstraintCoefficients ( int ct_index) const

Definition at line 269 of file model_builder_helper.cc.

◆ ConstraintLowerBound()

double operations_research::ModelBuilderHelper::ConstraintLowerBound ( int ct_index) const

Definition at line 252 of file model_builder_helper.cc.

◆ ConstraintName()

std::string operations_research::ModelBuilderHelper::ConstraintName ( int ct_index) const

Definition at line 260 of file model_builder_helper.cc.

◆ ConstraintUpperBound()

double operations_research::ModelBuilderHelper::ConstraintUpperBound ( int ct_index) const

Definition at line 256 of file model_builder_helper.cc.

◆ ConstraintVarIndices()

std::vector< int > operations_research::ModelBuilderHelper::ConstraintVarIndices ( int ct_index) const

Definition at line 264 of file model_builder_helper.cc.

◆ EnforcedConstraintCoefficients()

std::vector< double > operations_research::ModelBuilderHelper::EnforcedConstraintCoefficients ( int ct_index) const

Definition at line 412 of file model_builder_helper.cc.

◆ EnforcedConstraintLowerBound()

double operations_research::ModelBuilderHelper::EnforcedConstraintLowerBound ( int ct_index) const

Definition at line 383 of file model_builder_helper.cc.

◆ EnforcedConstraintName()

std::string operations_research::ModelBuilderHelper::EnforcedConstraintName ( int ct_index) const

Definition at line 399 of file model_builder_helper.cc.

◆ EnforcedConstraintUpperBound()

double operations_research::ModelBuilderHelper::EnforcedConstraintUpperBound ( int ct_index) const

Definition at line 391 of file model_builder_helper.cc.

◆ EnforcedConstraintVarIndices()

std::vector< int > operations_research::ModelBuilderHelper::EnforcedConstraintVarIndices ( int ct_index) const

Definition at line 404 of file model_builder_helper.cc.

◆ EnforcedIndicatorValue()

bool operations_research::ModelBuilderHelper::EnforcedIndicatorValue ( int ct_index) const

Definition at line 425 of file model_builder_helper.cc.

◆ EnforcedIndicatorVariableIndex()

int operations_research::ModelBuilderHelper::EnforcedIndicatorVariableIndex ( int ct_index) const

Definition at line 420 of file model_builder_helper.cc.

◆ ExportToLpString()

std::string operations_research::ModelBuilderHelper::ExportToLpString ( const operations_research::MPModelExportOptions & options = MPModelExportOptions())

Definition at line 66 of file model_builder_helper.cc.

◆ ExportToMpsString()

std::string operations_research::ModelBuilderHelper::ExportToMpsString ( const operations_research::MPModelExportOptions & options = MPModelExportOptions())

Definition at line 60 of file model_builder_helper.cc.

◆ ImportFromMpsFile()

bool operations_research::ModelBuilderHelper::ImportFromMpsFile ( const std::string & mps_file)

Definition at line 109 of file model_builder_helper.cc.

◆ ImportFromMpsString()

bool operations_research::ModelBuilderHelper::ImportFromMpsString ( const std::string & mps_string)

See comment in the header file why we need to wrap absl::Status code with code having simpler APIs.

Definition at line 101 of file model_builder_helper.cc.

◆ IsEnforcedConstraint()

bool operations_research::ModelBuilderHelper::IsEnforcedConstraint ( int ct_index) const

Definition at line 282 of file model_builder_helper.cc.

◆ maximize()

bool operations_research::ModelBuilderHelper::maximize ( ) const

Definition at line 449 of file model_builder_helper.cc.

◆ model()

const MPModelProto & operations_research::ModelBuilderHelper::model ( ) const

Definition at line 137 of file model_builder_helper.cc.

◆ mutable_model()

MPModelProto * operations_research::ModelBuilderHelper::mutable_model ( )

Definition at line 139 of file model_builder_helper.cc.

◆ name()

std::string operations_research::ModelBuilderHelper::name ( ) const

Definition at line 438 of file model_builder_helper.cc.

◆ num_constraints()

int operations_research::ModelBuilderHelper::num_constraints ( ) const

Definition at line 434 of file model_builder_helper.cc.

◆ num_variables()

int operations_research::ModelBuilderHelper::num_variables ( ) const

Definition at line 432 of file model_builder_helper.cc.

◆ ObjectiveOffset()

double operations_research::ModelBuilderHelper::ObjectiveOffset ( ) const

Definition at line 455 of file model_builder_helper.cc.

◆ OverwriteModel()

void operations_research::ModelBuilderHelper::OverwriteModel ( const ModelBuilderHelper & other_helper)

Definition at line 55 of file model_builder_helper.cc.

◆ ReadModelFromProtoFile()

bool operations_research::ModelBuilderHelper::ReadModelFromProtoFile ( const std::string & filename)

Definition at line 77 of file model_builder_helper.cc.

◆ SafeAddConstraintTerm()

void operations_research::ModelBuilderHelper::SafeAddConstraintTerm ( int ct_index,
int var_index,
double coeff )

If we reach this point, the variable does not exist in the constraint yet, so we add it to the constraint as a new term.

Definition at line 216 of file model_builder_helper.cc.

◆ SafeAddEnforcedConstraintTerm()

void operations_research::ModelBuilderHelper::SafeAddEnforcedConstraintTerm ( int ct_index,
int var_index,
double coeff )

If we reach this point, the variable does not exist in the constraint yet, so we add it to the constraint as a new term.

Definition at line 325 of file model_builder_helper.cc.

◆ SetConstraintCoefficient()

void operations_research::ModelBuilderHelper::SetConstraintCoefficient ( int ct_index,
int var_index,
double coeff )

If we reach this point, the variable does not exist in the constraint yet, so we add it to the constraint as a new term.

Definition at line 237 of file model_builder_helper.cc.

◆ SetConstraintLowerBound()

void operations_research::ModelBuilderHelper::SetConstraintLowerBound ( int ct_index,
double lb )

Definition at line 194 of file model_builder_helper.cc.

◆ SetConstraintName()

void operations_research::ModelBuilderHelper::SetConstraintName ( int ct_index,
const std::string & name )

Definition at line 232 of file model_builder_helper.cc.

◆ SetConstraintUpperBound()

void operations_research::ModelBuilderHelper::SetConstraintUpperBound ( int ct_index,
double ub )

Definition at line 198 of file model_builder_helper.cc.

◆ SetEnforcedConstraintCoefficient()

void operations_research::ModelBuilderHelper::SetEnforcedConstraintCoefficient ( int ct_index,
int var_index,
double coeff )

If we reach this point, the variable does not exist in the constraint yet, so we add it to the constraint as a new term.

Definition at line 350 of file model_builder_helper.cc.

◆ SetEnforcedConstraintLowerBound()

void operations_research::ModelBuilderHelper::SetEnforcedConstraintLowerBound ( int ct_index,
double lb )

Definition at line 288 of file model_builder_helper.cc.

◆ SetEnforcedConstraintName()

void operations_research::ModelBuilderHelper::SetEnforcedConstraintName ( int ct_index,
const std::string & name )

Definition at line 345 of file model_builder_helper.cc.

◆ SetEnforcedConstraintUpperBound()

void operations_research::ModelBuilderHelper::SetEnforcedConstraintUpperBound ( int ct_index,
double ub )

Definition at line 297 of file model_builder_helper.cc.

◆ SetEnforcedIndicatorValue()

void operations_research::ModelBuilderHelper::SetEnforcedIndicatorValue ( int ct_index,
bool positive )

Definition at line 376 of file model_builder_helper.cc.

◆ SetEnforcedIndicatorVariableIndex()

void operations_research::ModelBuilderHelper::SetEnforcedIndicatorVariableIndex ( int ct_index,
int var_index )

Definition at line 369 of file model_builder_helper.cc.

◆ SetMaximize()

void operations_research::ModelBuilderHelper::SetMaximize ( bool maximize)

Definition at line 451 of file model_builder_helper.cc.

◆ SetName()

void operations_research::ModelBuilderHelper::SetName ( const std::string & name)

Definition at line 440 of file model_builder_helper.cc.

◆ SetObjectiveOffset()

void operations_research::ModelBuilderHelper::SetObjectiveOffset ( double offset)

Definition at line 459 of file model_builder_helper.cc.

◆ SetVarIntegrality()

void operations_research::ModelBuilderHelper::SetVarIntegrality ( int var_index,
bool is_integer )

Definition at line 155 of file model_builder_helper.cc.

◆ SetVarLowerBound()

void operations_research::ModelBuilderHelper::SetVarLowerBound ( int var_index,
double lb )

Definition at line 147 of file model_builder_helper.cc.

◆ SetVarName()

void operations_research::ModelBuilderHelper::SetVarName ( int var_index,
const std::string & name )

Definition at line 164 of file model_builder_helper.cc.

◆ SetVarObjectiveCoefficient()

void operations_research::ModelBuilderHelper::SetVarObjectiveCoefficient ( int var_index,
double coeff )

Definition at line 159 of file model_builder_helper.cc.

◆ SetVarUpperBound()

void operations_research::ModelBuilderHelper::SetVarUpperBound ( int var_index,
double ub )

Definition at line 151 of file model_builder_helper.cc.

◆ VarIsIntegral()

bool operations_research::ModelBuilderHelper::VarIsIntegral ( int var_index) const

Definition at line 176 of file model_builder_helper.cc.

◆ VarLowerBound()

double operations_research::ModelBuilderHelper::VarLowerBound ( int var_index) const

Definition at line 168 of file model_builder_helper.cc.

◆ VarName()

std::string operations_research::ModelBuilderHelper::VarName ( int var_index) const

Definition at line 184 of file model_builder_helper.cc.

◆ VarObjectiveCoefficient()

double operations_research::ModelBuilderHelper::VarObjectiveCoefficient ( int var_index) const

Definition at line 180 of file model_builder_helper.cc.

◆ VarUpperBound()

double operations_research::ModelBuilderHelper::VarUpperBound ( int var_index) const

Definition at line 172 of file model_builder_helper.cc.

◆ WriteModelToProtoFile()

bool operations_research::ModelBuilderHelper::WriteModelToProtoFile ( const std::string & filename)

Definition at line 91 of file model_builder_helper.cc.

◆ WriteToMpsFile()

bool operations_research::ModelBuilderHelper::WriteToMpsFile ( const std::string & filename,
const operations_research::MPModelExportOptions & options = MPModelExportOptions() )

Definition at line 72 of file model_builder_helper.cc.


The documentation for this class was generated from the following files: