#include <OSLindoSolver.h>
Public Member Functions | |
LindoSolver () | |
the LindoSolver class constructor | |
~LindoSolver () | |
the LindoSolver class destructor | |
virtual void | solve () |
solve results in an instance being read into the Knitro data structrues and optimized | |
virtual void | buildSolverInstance () throw (ErrorClass) |
buildSolverInstance is a virtual function -- the actual solvers will implement their own solve method -- the solver instance is the instance the individual solver sees in its api | |
bool | optimize () |
invoke the Lindo API solver | |
bool | processVariables () |
read the OSiL instance variables and put these into the LINDO API variables | |
bool | processConstraints () |
read the OSiL instance constraints and put these into the LINDO API constraints | |
bool | generateLindoModel () |
create the LINDO environment and read the problem into the internal LINDO data structures | |
bool | addSlackVars () |
LINDO does not handle constraints with upper and lower bounds this method is part of kludge where we add a new variable to handle the bounds. | |
bool | processQuadraticTerms () |
read the quadratic terms in the model | |
bool | processNonlinearExpressions () |
read the nonlinear terms in the model | |
void | dataEchoCheck () |
use this for debugging, print out the instance that the solver thinks it has and compare this with the OSiL file | |
Public Attributes | |
OSiLReader * | m_osilreader |
m_osilreader is an OSiLReader object used to create an osinstance from an osil string if needed | |
Protected Member Functions | |
void | lindoAPIErrorCheck (std::string errormsg) |
Lindo's generalized error Reporting function. | |
Private Attributes | |
pLSenv | pEnv_ |
declare an instance of the LINDO environment object | |
pLSmodel | pModel_ |
declare an instance of the LINDO model object | |
int | m_iLindoErrorCode |
m_iErrorCode is a variable for LINDO error codes | |
int * | m_miSlackIdx |
because LINDO API does not take row ranges we need some extra suff m_miSlackIdx indexes the rows that get additional slack variable | |
int | m_iNumberNewSlacks |
m_iNumberNewSlacks is the number of slack variables to add | |
double * | m_mdRhsValue |
m_mdRhsValue is used to the store the constraint rhs if we do not use row upper and lower bounds | |
char * | m_mcRowType |
m_mcRowType - E for equality, L for less than, G for greater than -- used if we do not store rows using upper and lower bounds | |
double * | m_mdVarLB |
m_mdLb holds an array of variable lower bounds. | |
double * | m_mdVarUB |
m_mdUb holds an array of variable upper bounds. | |
double * | m_mdConLB |
m_mdLhs holds an array of the constraint lower bounds. | |
double * | m_mdConUB |
m_mdRhs holds an array of the constraint upper bounds. | |
char ** | m_mmcVarName |
m_mmcVarName holds an array of char arrays. | |
std::string * | m_msVarName |
m_msVarName holds an array of variable std::string names. | |
std::string * | m_msConName |
m_msConName holds an array of constraint std::string names. | |
char * | m_mcVarType |
m_vcVarType holds an array of variable types (character), e.g. | |
double | m_mdObjConstant |
m_mdObjConstant holds an array of objective function constants. | |
OSrLWriter * | osrlwriter |
osrlwriter object used to write osrl from and OSResult object |
Definition at line 50 of file OSLindoSolver.h.
LindoSolver::LindoSolver | ( | ) |
the LindoSolver class constructor
Definition at line 81 of file OSLindoSolver.cpp.
References osrlwriter.
LindoSolver::~LindoSolver | ( | ) |
the LindoSolver class destructor
Definition at line 106 of file OSLindoSolver.cpp.
References m_mcRowType, m_mcVarType, m_mdConLB, m_mdConUB, m_mdRhsValue, m_miSlackIdx, m_mmcVarName, m_msConName, m_msVarName, m_osilreader, DefaultSolver::osresult, osrlwriter, and pEnv_.
void LindoSolver::solve | ( | ) | [virtual] |
solve results in an instance being read into the Knitro data structrues and optimized
Implements DefaultSolver.
Definition at line 186 of file OSLindoSolver.cpp.
References buildSolverInstance(), ErrorClass::errormsg, optimize(), DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), and OSrLWriter::writeOSrL().
void LindoSolver::buildSolverInstance | ( | ) | throw (ErrorClass) [virtual] |
buildSolverInstance is a virtual function -- the actual solvers will implement their own solve method -- the solver instance is the instance the individual solver sees in its api
Implements DefaultSolver.
Definition at line 138 of file OSLindoSolver.cpp.
References OSInstance::addConstraint(), addSlackVars(), DefaultSolver::bCallbuildSolverInstance, InstanceData::constraints, ErrorClass::errormsg, generateLindoModel(), OSInstance::getNumberOfNonlinearExpressions(), OSInstance::getNumberOfQuadraticTerms(), OSInstance::getVariableNumber(), OSInstance::instanceData, m_iNumberNewSlacks, Constraints::numberOfConstraints, DefaultSolver::osil, DefaultSolver::osinstance, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, processConstraints(), processNonlinearExpressions(), processVariables(), OSiLReader::readOSiL(), OSInstance::setConstraintNumber(), OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), and OSrLWriter::writeOSrL().
Referenced by solve().
bool LindoSolver::optimize | ( | ) |
invoke the Lindo API solver
Definition at line 443 of file OSLindoSolver.cpp.
References ErrorClass::errormsg, OSInstance::getConstraintNumber(), OSInstance::getInstanceName(), OSInstance::getNumberOfBinaryVariables(), OSInstance::getNumberOfIntegerVariables(), OSInstance::getNumberOfNonlinearConstraints(), OSInstance::getNumberOfNonlinearObjectives(), OSInstance::getObjectiveNumber(), OSInstance::getVariableNumber(), lindoAPIErrorCheck(), m_iLindoErrorCode, m_iNumberNewSlacks, DefaultSolver::osinstance, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, pModel_, OSResult::setAnOtherVariableResult(), OSResult::setConstraintNumber(), OSResult::setDualVariableValues(), OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), OSResult::setInstanceName(), OSResult::setNumberOfOtherVariableResult(), OSResult::setObjectiveNumber(), OSResult::setObjectiveValues(), OSResult::setPrimalVariableValues(), OSResult::setServiceName(), OSResult::setSolutionNumber(), OSResult::setSolutionStatus(), OSResult::setVariableNumber(), and OSrLWriter::writeOSrL().
Referenced by solve().
bool LindoSolver::processVariables | ( | ) |
read the OSiL instance variables and put these into the LINDO API variables
Definition at line 327 of file OSLindoSolver.cpp.
References ErrorClass::errormsg, OSInstance::getVariableLowerBounds(), OSInstance::getVariableNames(), OSInstance::getVariableNumber(), OSInstance::getVariableTypes(), OSInstance::getVariableUpperBounds(), m_mcVarType, m_mdVarLB, m_mdVarUB, m_mmcVarName, DefaultSolver::osinstance, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), and OSrLWriter::writeOSrL().
Referenced by buildSolverInstance().
bool LindoSolver::processConstraints | ( | ) |
read the OSiL instance constraints and put these into the LINDO API constraints
Definition at line 202 of file OSLindoSolver.cpp.
References ErrorClass::errormsg, OSInstance::getConstraintLowerBounds(), OSInstance::getConstraintNames(), OSInstance::getConstraintNumber(), OSInstance::getConstraintTypes(), OSInstance::getConstraintUpperBounds(), m_iNumberNewSlacks, m_mcRowType, m_mdConLB, m_mdConUB, m_mdRhsValue, m_miSlackIdx, m_msConName, DefaultSolver::osinstance, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), and OSrLWriter::writeOSrL().
Referenced by buildSolverInstance().
bool LindoSolver::generateLindoModel | ( | ) |
create the LINDO environment and read the problem into the internal LINDO data structures
Definition at line 352 of file OSLindoSolver.cpp.
References ErrorClass::errormsg, OSInstance::getConstraintNumber(), OSInstance::getDenseObjectiveCoefficients(), OSInstance::getLinearConstraintCoefficientNumber(), OSInstance::getLinearConstraintCoefficientsInColumnMajor(), OSInstance::getObjectiveConstants(), OSInstance::getObjectiveMaxOrMins(), OSInstance::getVariableNumber(), SparseMatrix::indexes, lindoAPIErrorCheck(), m_iLindoErrorCode, m_mcRowType, m_mcVarType, m_mdRhsValue, m_mdVarLB, m_mdVarUB, DefaultSolver::osinstance, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, pEnv_, pModel_, OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), SparseMatrix::starts, SparseMatrix::values, and OSrLWriter::writeOSrL().
Referenced by buildSolverInstance().
bool LindoSolver::addSlackVars | ( | ) |
LINDO does not handle constraints with upper and lower bounds this method is part of kludge where we add a new variable to handle the bounds.
Definition at line 250 of file OSLindoSolver.cpp.
References m_iNumberNewSlacks, m_mdConLB, m_mdConUB, m_miSlackIdx, and pModel_.
Referenced by buildSolverInstance().
bool LindoSolver::processQuadraticTerms | ( | ) |
read the quadratic terms in the model
Definition at line 611 of file OSLindoSolver.cpp.
References QuadraticTerms::coefficients, ErrorClass::errormsg, OSInstance::getNumberOfQuadraticTerms(), OSInstance::getQuadraticTerms(), DefaultSolver::osinstance, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, pModel_, QuadraticTerms::rowIndexes, OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), QuadraticTerms::varOneIndexes, QuadraticTerms::varTwoIndexes, and OSrLWriter::writeOSrL().
bool LindoSolver::processNonlinearExpressions | ( | ) |
read the nonlinear terms in the model
LINDO wants a unique list of the nonzero elements that appear in the nonlinear terms. To do this we index on the nonzero element and point to a number that counts where this unique element is in the list
pos is an iteratior for mapNewNumber
We don't know at compile time the number of instructions in a problem use a vector to dynamically allocate the instructions (OP_Codes). This eventually gets copied into a LINDO array paiInsList
We get a map of all of the Expression trees where the index is row or objective number that points to an expression tree for that row or objective function that contains at least one nonlinear term.
The map allExpTrees indexes by row and objective function all of the expression trees. For each nonlinear constraint or objective function we convert the associated expresssion tree into a vector of OSnLNodes in postfix format
define an iterator for the expression trees map allExpTrees
KEY ASSUMPTION: We have already defined the model including all variables, constraints, bounds, objective functions, etc.
Define the local variables used by LINDO
Direction of optimization
Lower bounds of variables. Since we aren't adding any new variables to our model, we can set this to NULL
Upper bounds of variables. Since we aren't adding any new variables to our model, we can set this to NULL
The initial values of the variables
Variable type. Since we aren't adding any new variables to our model, we can set this to NULL
Constraint type Since we aren't changing or adding the constraint types in our model, we can set this to NULL
The number of nonzeros in the nonlinear terms is given by iNumNonlinearNonz
A pointer to the nonzeros in the nonlinear terms is given by padNonlinearNonz
The number of constraints with nonlinear terms is given by iNumberOfNonlinearConstraints
A pointer to the start of each nonlinear constraint in the instructions list paiOp_Codes is given by paiConsBegin
A pointer to the length of each nonlinear constraint in the instructions list paiOp_Codes is given by paiConsLength
The number of objectives with nonlinear terms is given by iNumberOfNonlinearObjectives
A pointer to the start of each objective function in the instructions list paiOp_Codes is given by paiObjsBegin
A pointer to the length of each objective function in the instructions list paiOp_Codes is given by paiObjsLength
The number of new variables in the nonlinear terms is given by iNumberOfNewVariables In our implementation we assume all the variables are added prior to adding the nonlinear terms so this should always be zero
The nonlinear terms are held in postfix format via op codes in the pointer array paiInsList
The length the instruction list, paiInstList is iInstListLength
The length the instruction list, paiInstList is iInstListLength
Definition at line 696 of file OSLindoSolver.cpp.
References OSnLNodeVariable::coef, ErrorClass::errormsg, OSInstance::getAllNonlinearExpressionTreesMod(), OSInstance::getNumberOfNonlinearConstraints(), OSInstance::getNumberOfNonlinearObjectives(), OSnLNodeVariable::idx, OSInstance::initializeNonLinearStructures(), DefaultSolver::insList, LINDO_OP_CODE_CONVERSION, lindoAPIErrorCheck(), m_iLindoErrorCode, OS_MAX, OS_NUMBER, OS_PRODUCT, OS_SUM, OS_VARIABLE, DefaultSolver::osinstance, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, pModel_, OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), OSnLNodeNumber::value, and OSrLWriter::writeOSrL().
Referenced by buildSolverInstance().
void LindoSolver::dataEchoCheck | ( | ) |
use this for debugging, print out the instance that the solver thinks it has and compare this with the OSiL file
Definition at line 1020 of file OSLindoSolver.cpp.
References QuadraticTerms::coefficients, OSInstance::getConstraintLowerBounds(), OSInstance::getConstraintNames(), OSInstance::getConstraintNumber(), OSInstance::getConstraintUpperBounds(), OSInstance::getDenseObjectiveCoefficients(), OSInstance::getInstanceDescription(), OSInstance::getInstanceName(), OSInstance::getInstanceSource(), OSInstance::getLinearConstraintCoefficientNumber(), OSInstance::getLinearConstraintCoefficientsInColumnMajor(), OSInstance::getNumberOfQuadraticTerms(), OSInstance::getObjectiveMaxOrMins(), OSInstance::getQuadraticTerms(), OSInstance::getVariableLowerBounds(), OSInstance::getVariableNames(), OSInstance::getVariableNumber(), OSInstance::getVariableTypes(), OSInstance::getVariableUpperBounds(), SparseMatrix::indexes, OSInstance::instanceData, Objectives::numberOfObjectives, Objectives::obj, InstanceData::objectives, DefaultSolver::osinstance, QuadraticTerms::rowIndexes, SparseMatrix::starts, SparseMatrix::values, QuadraticTerms::varOneIndexes, and QuadraticTerms::varTwoIndexes.
void LindoSolver::lindoAPIErrorCheck | ( | std::string | errormsg | ) | [protected] |
Lindo's generalized error Reporting function.
Definition at line 1081 of file OSLindoSolver.cpp.
References ErrorClass::errormsg, m_iLindoErrorCode, and pEnv_.
Referenced by generateLindoModel(), optimize(), and processNonlinearExpressions().
m_osilreader is an OSiLReader object used to create an osinstance from an osil string if needed
Definition at line 124 of file OSLindoSolver.h.
Referenced by ~LindoSolver().
pLSenv LindoSolver::pEnv_ [private] |
declare an instance of the LINDO environment object
Definition at line 138 of file OSLindoSolver.h.
Referenced by generateLindoModel(), lindoAPIErrorCheck(), and ~LindoSolver().
pLSmodel LindoSolver::pModel_ [private] |
declare an instance of the LINDO model object
Definition at line 141 of file OSLindoSolver.h.
Referenced by addSlackVars(), generateLindoModel(), optimize(), processNonlinearExpressions(), and processQuadraticTerms().
int LindoSolver::m_iLindoErrorCode [private] |
m_iErrorCode is a variable for LINDO error codes
Definition at line 144 of file OSLindoSolver.h.
Referenced by generateLindoModel(), lindoAPIErrorCheck(), optimize(), and processNonlinearExpressions().
int* LindoSolver::m_miSlackIdx [private] |
because LINDO API does not take row ranges we need some extra suff m_miSlackIdx indexes the rows that get additional slack variable
Definition at line 148 of file OSLindoSolver.h.
Referenced by addSlackVars(), processConstraints(), and ~LindoSolver().
int LindoSolver::m_iNumberNewSlacks [private] |
m_iNumberNewSlacks is the number of slack variables to add
Definition at line 151 of file OSLindoSolver.h.
Referenced by addSlackVars(), buildSolverInstance(), optimize(), and processConstraints().
double* LindoSolver::m_mdRhsValue [private] |
m_mdRhsValue is used to the store the constraint rhs if we do not use row upper and lower bounds
Definition at line 156 of file OSLindoSolver.h.
Referenced by generateLindoModel(), processConstraints(), and ~LindoSolver().
char* LindoSolver::m_mcRowType [private] |
m_mcRowType - E for equality, L for less than, G for greater than -- used if we do not store rows using upper and lower bounds
Definition at line 161 of file OSLindoSolver.h.
Referenced by generateLindoModel(), processConstraints(), and ~LindoSolver().
double* LindoSolver::m_mdVarLB [private] |
m_mdLb holds an array of variable lower bounds.
Definition at line 166 of file OSLindoSolver.h.
Referenced by generateLindoModel(), and processVariables().
double* LindoSolver::m_mdVarUB [private] |
m_mdUb holds an array of variable upper bounds.
Definition at line 171 of file OSLindoSolver.h.
Referenced by generateLindoModel(), and processVariables().
double* LindoSolver::m_mdConLB [private] |
m_mdLhs holds an array of the constraint lower bounds.
Definition at line 176 of file OSLindoSolver.h.
Referenced by addSlackVars(), processConstraints(), and ~LindoSolver().
double* LindoSolver::m_mdConUB [private] |
m_mdRhs holds an array of the constraint upper bounds.
Definition at line 181 of file OSLindoSolver.h.
Referenced by addSlackVars(), processConstraints(), and ~LindoSolver().
char** LindoSolver::m_mmcVarName [private] |
m_mmcVarName holds an array of char arrays.
Definition at line 186 of file OSLindoSolver.h.
Referenced by processVariables(), and ~LindoSolver().
std::string* LindoSolver::m_msVarName [private] |
m_msVarName holds an array of variable std::string names.
Definition at line 191 of file OSLindoSolver.h.
Referenced by ~LindoSolver().
std::string* LindoSolver::m_msConName [private] |
m_msConName holds an array of constraint std::string names.
Definition at line 196 of file OSLindoSolver.h.
Referenced by processConstraints(), and ~LindoSolver().
char* LindoSolver::m_mcVarType [private] |
m_vcVarType holds an array of variable types (character), e.g.
'C' for continuous type, 'I' for integer type, 'B' for binary type, 'S' for std::string type).
Definition at line 202 of file OSLindoSolver.h.
Referenced by generateLindoModel(), processVariables(), and ~LindoSolver().
double LindoSolver::m_mdObjConstant [private] |
m_mdObjConstant holds an array of objective function constants.
Definition at line 206 of file OSLindoSolver.h.
OSrLWriter* LindoSolver::osrlwriter [private] |
osrlwriter object used to write osrl from and OSResult object
Definition at line 209 of file OSLindoSolver.h.
Referenced by buildSolverInstance(), generateLindoModel(), LindoSolver(), optimize(), processConstraints(), processNonlinearExpressions(), processQuadraticTerms(), processVariables(), solve(), and ~LindoSolver().