Scippy

SCIP

Solving Constraint Integer Programs

AMPLProblemHandler Class Reference

Detailed Description

implementation of AMPL/MPs NLHandler that constructs a SCIP problem while a .nl file is read

Definition at line 114 of file reader_nl.cpp.

implementation of AMPL/MPs NLHandler that constructs a SCIP problem while a .nl file is read More...

Data Structures

class  LinearExprHandler
 
class  LinearPartHandler
 
class  NumericArgHandler
 
class  SuffixHandler
 

Public Types

typedef SuffixHandler< int > IntSuffixHandler
 
typedef SuffixHandler< SCIP_RealDblSuffixHandler
 
typedef LinearPartHandler LinearObjHandler
 
typedef LinearPartHandler LinearConHandler
 

Public Member Functions

 AMPLProblemHandler (SCIP *scip_, const char *filename)
 
 AMPLProblemHandler (const AMPLProblemHandler &)=delete
 
AMPLProblemHandleroperator= (const AMPLProblemHandler &)=delete
 
 ~AMPLProblemHandler ()
 
void OnHeader (const mp::NLHeader &h)
 
SCIP_EXPROnNumber (double value)
 receive notification of a number in a nonlinear expression More...
 
SCIP_EXPROnVariableRef (int variableIndex)
 receive notification of a variable reference in a nonlinear expression More...
 
SCIP_EXPROnUnary (mp::expr::Kind kind, SCIP_EXPR *child)
 receive notification of a unary expression More...
 
SCIP_EXPROnBinary (mp::expr::Kind kind, SCIP_EXPR *firstChild, SCIP_EXPR *secondChild)
 receive notification of a binary expression More...
 
NumericArgHandler BeginSum (int num_args)
 receive notification of the beginning of a summation More...
 
SCIP_EXPREndSum (NumericArgHandler handler)
 receive notification of the end of a summation More...
 
void OnObj (int objectiveIndex, mp::obj::Type type, SCIP_EXPR *nonlinearExpression)
 receive notification of an objective type and the nonlinear part of an objective expression More...
 
void OnAlgebraicCon (int constraintIndex, SCIP_EXPR *expr)
 receive notification of an algebraic constraint expression More...
 
void OnLogicalCon (int index, LogicalExpr expr)
 receives notification of a logical constraint expression More...
 
LinearExprHandler BeginCommonExpr (int index, int num_linear_terms)
 receive notification of the beginning of a common expression (defined variable) More...
 
void EndCommonExpr (int index, SCIP_EXPR *expr, int)
 receive notification of the end of a common expression More...
 
SCIP_EXPROnCommonExprRef (int expr_index)
 receive notification of a common expression (defined variable) reference More...
 
void OnVarBounds (int variableIndex, double variableLB, double variableUB)
 receive notification of variable bounds More...
 
void OnConBounds (int index, double lb, double ub)
 receive notification of constraint sides More...
 
void OnInitialValue (int var_index, double value)
 receive notification of the initial value for a variable More...
 
void OnInitialDualValue (int, double)
 receives notification of the initial value for a dual variable More...
 
ColumnSizeHandler OnColumnSizes ()
 receives notification of Jacobian column sizes More...
 
IntSuffixHandler OnIntSuffix (fmt::StringRef name, mp::suf::Kind kind, int)
 receive notification of an integer suffix More...
 
DblSuffixHandler OnDblSuffix (fmt::StringRef name, mp::suf::Kind kind, int)
 receive notification of a double suffix More...
 
LinearPartHandler OnLinearObjExpr (int objectiveIndex, int)
 receive notification of the linear part of an objective More...
 
LinearConHandler OnLinearConExpr (int constraintIndex, int)
 receive notification of the linear part of a constraint More...
 
LogicalExpr OnBool (bool value)
 receives notification of a Boolean value <mp::expr::BOOL> More...
 
LogicalExpr OnNot (LogicalExpr arg)
 receives notification of a logical not <mp::expr::NOT> More...
 
LogicalExpr OnBinaryLogical (mp::expr::Kind kind, LogicalExpr lhs, LogicalExpr rhs)
 receives notification of a binary logical expression <mp::expr::FIRST_BINARY_LOGICAL> More...
 
LogicalExpr OnRelational (mp::expr::Kind kind, NumericExpr lhs, NumericExpr rhs)
 
void EndInput ()
 
SCIP_RETCODE cleanup ()
 

Member Typedef Documentation

◆ IntSuffixHandler

Definition at line 1115 of file reader_nl.cpp.

◆ DblSuffixHandler

◆ LinearObjHandler

◆ LinearConHandler

Constructor & Destructor Documentation

◆ AMPLProblemHandler() [1/2]

AMPLProblemHandler::AMPLProblemHandler ( SCIP scip_,
const char *  filename 
)
inline

constructor

initializes SCIP problem and problem data

Parameters
scip_SCIP data structure
filenamename of .nl file that is read

Definition at line 245 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, SCIPallocBlockMemoryArray, SCIPallocClearMemory, and SCIPcreateProb().

◆ AMPLProblemHandler() [2/2]

AMPLProblemHandler::AMPLProblemHandler ( const AMPLProblemHandler )
delete

◆ ~AMPLProblemHandler()

AMPLProblemHandler::~AMPLProblemHandler ( )
inline

destructor

only asserts that cleanup() has been called, as we cannot throw an exception or return a SCIP_RETCODE here

Definition at line 312 of file reader_nl.cpp.

Member Function Documentation

◆ operator=()

AMPLProblemHandler& AMPLProblemHandler::operator= ( const AMPLProblemHandler )
delete

◆ OnHeader()

void AMPLProblemHandler::OnHeader ( const mp::NLHeader &  h)
inline

◆ OnNumber()

SCIP_EXPR* AMPLProblemHandler::OnNumber ( double  value)
inline

receive notification of a number in a nonlinear expression

Parameters
valuevalue

Definition at line 455 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, and SCIPcreateExprValue().

◆ OnVariableRef()

SCIP_EXPR* AMPLProblemHandler::OnVariableRef ( int  variableIndex)
inline

receive notification of a variable reference in a nonlinear expression

Parameters
variableIndexAMPL index of variable

Definition at line 470 of file reader_nl.cpp.

References NULL.

◆ OnUnary()

SCIP_EXPR* AMPLProblemHandler::OnUnary ( mp::expr::Kind  kind,
SCIP_EXPR child 
)
inline

receive notification of a unary expression

Parameters
kindexpression operator
childargument

Definition at line 482 of file reader_nl.cpp.

References ABS, NULL, SCIP_CALL_THROW, SCIP_Real, SCIPcreateExprAbs(), SCIPcreateExprCos(), SCIPcreateExprExp(), SCIPcreateExprLog(), SCIPcreateExprPow(), SCIPcreateExprSin(), SCIPcreateExprSum(), and SCIPreleaseExpr().

◆ OnBinary()

SCIP_EXPR* AMPLProblemHandler::OnBinary ( mp::expr::Kind  kind,
SCIP_EXPR firstChild,
SCIP_EXPR secondChild 
)
inline

receive notification of a binary expression

Parameters
kindexpression operand
firstChildfirst argument
secondChildsecond argument

Definition at line 550 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, SCIP_Real, SCIPcreateExprExp(), SCIPcreateExprLog(), SCIPcreateExprPow(), SCIPcreateExprProduct(), SCIPcreateExprSum(), SCIPgetValueExprValue(), SCIPisExprValue(), and SCIPreleaseExpr().

◆ BeginSum()

NumericArgHandler AMPLProblemHandler::BeginSum ( int  num_args)
inline

receive notification of the beginning of a summation

Parameters
num_argsnumber of terms to expect

Definition at line 663 of file reader_nl.cpp.

References h.

◆ EndSum()

SCIP_EXPR* AMPLProblemHandler::EndSum ( NumericArgHandler  handler)
inline

receive notification of the end of a summation

Parameters
handlerhandler that handled the sum

Definition at line 672 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, SCIPcreateExprSum(), and AMPLProblemHandler::NumericArgHandler::v.

◆ OnObj()

void AMPLProblemHandler::OnObj ( int  objectiveIndex,
mp::obj::Type  type,
SCIP_EXPR nonlinearExpression 
)
inline

receive notification of an objective type and the nonlinear part of an objective expression

Parameters
objectiveIndexindex of objective
typeobjective sense
nonlinearExpressionnonlinear part of objective function

Definition at line 684 of file reader_nl.cpp.

References MAX, NULL, SCIP_CALL_THROW, SCIP_OBJSENSE_MAXIMIZE, SCIP_OBJSENSE_MINIMIZE, SCIP_Real, SCIP_VARTYPE_CONTINUOUS, SCIPaddVar(), SCIPcreateVarBasic(), SCIPgetValueExprValue(), SCIPisExprValue(), SCIPreleaseVar(), and SCIPsetObjsense().

◆ OnAlgebraicCon()

void AMPLProblemHandler::OnAlgebraicCon ( int  constraintIndex,
SCIP_EXPR expr 
)
inline

receive notification of an algebraic constraint expression

Parameters
constraintIndexindex of constraint
exprnonlinear part of constraint

Definition at line 714 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, and SCIPchgExprNonlinear().

◆ OnLogicalCon()

void AMPLProblemHandler::OnLogicalCon ( int  index,
LogicalExpr  expr 
)
inline

receives notification of a logical constraint expression

Definition at line 726 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, SCIPaddCons(), SCIPcreateConsBasicNonlinear(), and SCIPreleaseCons().

◆ BeginCommonExpr()

LinearExprHandler AMPLProblemHandler::BeginCommonExpr ( int  index,
int  num_linear_terms 
)
inline

receive notification of the beginning of a common expression (defined variable)

Parameters
indexindex of common expression
num_linear_termsnumber of terms to expect

Definition at line 794 of file reader_nl.cpp.

◆ EndCommonExpr()

void AMPLProblemHandler::EndCommonExpr ( int  index,
SCIP_EXPR expr,
int   
)
inline

receive notification of the end of a common expression

Parameters
indexindex of common expression
exprnonlinear part of common expression

Definition at line 806 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, and SCIPappendExprSumExpr().

◆ OnCommonExprRef()

SCIP_EXPR* AMPLProblemHandler::OnCommonExprRef ( int  expr_index)
inline

receive notification of a common expression (defined variable) reference

Parameters
expr_indexindex of common expression

Definition at line 827 of file reader_nl.cpp.

References NULL.

◆ OnVarBounds()

void AMPLProblemHandler::OnVarBounds ( int  variableIndex,
double  variableLB,
double  variableUB 
)
inline

receive notification of variable bounds

Parameters
variableIndexAMPL index of variable
variableLBvariable lower bound
variableUBvariable upper bound

Definition at line 838 of file reader_nl.cpp.

References SCIP_CALL_THROW, SCIP_VARTYPE_BINARY, SCIPchgVarLbGlobal(), SCIPchgVarUbGlobal(), SCIPinfinity(), and SCIPvarGetType().

◆ OnConBounds()

void AMPLProblemHandler::OnConBounds ( int  index,
double  lb,
double  ub 
)
inline

receive notification of constraint sides

Parameters
indexAMPL index of constraint
lbconstraint left-hand-side
ubconstraint right-hand-side

Definition at line 861 of file reader_nl.cpp.

References SCIP_CALL_THROW, SCIPchgLhsLinear(), SCIPchgLhsNonlinear(), SCIPchgRhsLinear(), SCIPchgRhsNonlinear(), and SCIPisInfinity().

◆ OnInitialValue()

void AMPLProblemHandler::OnInitialValue ( int  var_index,
double  value 
)
inline

receive notification of the initial value for a variable

Parameters
var_indexAMPL index of variable
valueinitial primal value of variable

Definition at line 896 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, SCIPcreateSol(), and SCIPsetSolVal().

◆ OnInitialDualValue()

void AMPLProblemHandler::OnInitialDualValue ( int  ,
double   
)
inline

receives notification of the initial value for a dual variable

Definition at line 910 of file reader_nl.cpp.

◆ OnColumnSizes()

ColumnSizeHandler AMPLProblemHandler::OnColumnSizes ( )
inline

receives notification of Jacobian column sizes

use ColumnSizeHandler from upper class, which does nothing

Definition at line 919 of file reader_nl.cpp.

◆ OnIntSuffix()

IntSuffixHandler AMPLProblemHandler::OnIntSuffix ( fmt::StringRef  name,
mp::suf::Kind  kind,
int   
)
inline

receive notification of an integer suffix

Parameters
namesuffix name, not null-terminated
kindsuffix kind

Definition at line 1117 of file reader_nl.cpp.

◆ OnDblSuffix()

DblSuffixHandler AMPLProblemHandler::OnDblSuffix ( fmt::StringRef  name,
mp::suf::Kind  kind,
int   
)
inline

receive notification of a double suffix

Parameters
namesuffix name, not null-terminated
kindsuffix kind

Definition at line 1128 of file reader_nl.cpp.

◆ OnLinearObjExpr()

LinearPartHandler AMPLProblemHandler::OnLinearObjExpr ( int  objectiveIndex,
int   
)
inline

receive notification of the linear part of an objective

Parameters
objectiveIndexindex of objective

Definition at line 1199 of file reader_nl.cpp.

◆ OnLinearConExpr()

LinearConHandler AMPLProblemHandler::OnLinearConExpr ( int  constraintIndex,
int   
)
inline

receive notification of the linear part of a constraint

Parameters
constraintIndexindex of constraint

Definition at line 1213 of file reader_nl.cpp.

◆ OnBool()

LogicalExpr AMPLProblemHandler::OnBool ( bool  value)
inline

receives notification of a Boolean value <mp::expr::BOOL>

Definition at line 1222 of file reader_nl.cpp.

References NULL, SCIP_CALL_THROW, and SCIPcreateExprValue().

◆ OnNot()

LogicalExpr AMPLProblemHandler::OnNot ( LogicalExpr  arg)
inline

receives notification of a logical not <mp::expr::NOT>

Definition at line 1237 of file reader_nl.cpp.

References NULL, SCIP_Bool, SCIP_CALL_THROW, SCIPcreateExprValue(), SCIPcreateExprVar(), and SCIPgetNegatedVar().

◆ OnBinaryLogical()

LogicalExpr AMPLProblemHandler::OnBinaryLogical ( mp::expr::Kind  kind,
LogicalExpr  lhs,
LogicalExpr  rhs 
)
inline

◆ OnRelational()

LogicalExpr AMPLProblemHandler::OnRelational ( mp::expr::Kind  kind,
NumericExpr  lhs,
NumericExpr  rhs 
)
inline

receives notification of a relational expression <mp::expr::FIRST_RELATIONAL> we only handle equality or inequality between binary variables and boolean values here

Definition at line 1464 of file reader_nl.cpp.

References FALSE, NULL, SCIP_Bool, SCIP_CALL_THROW, SCIP_VARTYPE_BINARY, SCIPaddCons(), SCIPaddVar(), SCIPcreateConsBasicXor(), SCIPcreateExprValue(), SCIPcreateExprVar(), SCIPcreateVarBasic(), SCIPgetNegatedVar(), SCIPreleaseCons(), SCIPreleaseVar(), and TRUE.

◆ EndInput()

void AMPLProblemHandler::EndInput ( )
inline

receive notification of the end of the input

  • setup all nonlinear constraints and add them to SCIP
  • add linear constraints to SCIP (should be after nonlinear ones to respect order in .nl file)
  • add initial solution, if initial values were given

Definition at line 1557 of file reader_nl.cpp.

References NULL, SCIP_Bool, SCIP_CALL_THROW, SCIP_INVALID, SCIP_OBJSENSE_MAXIMIZE, SCIP_OBJSENSE_MINIMIZE, SCIP_Real, SCIP_VARTYPE_CONTINUOUS, SCIPaddCons(), SCIPaddLinearVarNonlinear(), SCIPaddSolFree(), SCIPaddVar(), SCIPcreateConsBasicNonlinear(), SCIPcreateConsBasicSOS1(), SCIPcreateConsBasicSOS2(), SCIPcreateVarBasic(), SCIPevalExpr(), SCIPexprGetEvalValue(), SCIPgetObjsense(), SCIPinfinity(), SCIPreleaseCons(), SCIPreleaseVar(), SCIPsetSolVal(), SCIPsnprintf(), and SCIPwarningMessage().

◆ cleanup()

SCIP_RETCODE AMPLProblemHandler::cleanup ( )
inline

releases expressions and linear constraints from data

should be called if there was an error while reading the .nl file this is not in the destructor, because we want to return SCIP_RETCODE

Definition at line 1678 of file reader_nl.cpp.

References NULL, SCIP_CALL, SCIP_OKAY, SCIPfreeSol(), and SCIPreleaseExpr().

Referenced by SCIP_DECL_READERREAD().