- Main Page
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# LindoSolver Class Reference

the LindoSolver class solves problems using Lindo. More...

`#include <OSLindoSolver.h>`

Inheritance diagram for LindoSolver:

[legend]
Collaboration diagram for LindoSolver:

[legend]
List of all members.

## 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
virtual void | setSolverOptions () throw (ErrorClass)
| The implementation of the virtual functions.
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
double | cpuTime

## Detailed Description

the LindoSolver class solves problems using Lindo.

Author:
  Robert Fourer, Jun Ma, Kipp Martin

Version:
  1.0, 03/14/2004

Since:
  OS 1.0

Remarks:
  this class takes an OSiL instance and optimizes it using the Lindo API

Definition at line 51 of file OSLindoSolver.h.

## Constructor & Destructor Documentation

LindoSolver::LindoSolver | ( |  | ) |

the LindoSolver class constructor

Definition at line 87 of file OSLindoSolver.cpp.

References osrlwriter.

LindoSolver::~LindoSolver | ( |  | ) |

the LindoSolver class destructor

Definition at line 113 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_.

## Member Function Documentation

void LindoSolver::solve | ( |  | ) | `[virtual]`

solve results in an instance being read into the Knitro data structrues and optimized

Implements DefaultSolver.

Definition at line 209 of file OSLindoSolver.cpp.

References buildSolverInstance(), cpuTime, ErrorClass::errormsg, optimize(), DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), OSResult::setTime(), 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 146 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().

void LindoSolver::setSolverOptions | ( |  | ) | throw (ErrorClass)`[virtual]`

The implementation of the virtual functions.

Returns:
  void.

Implements DefaultSolver.

Definition at line 195 of file OSLindoSolver.cpp.

References ErrorClass::errormsg, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), and OSrLWriter::writeOSrL().

bool LindoSolver::optimize | ( |  | ) |

invoke the Lindo API solver

Returns:
  true if an exception is not thrown.

Definition at line 476 of file OSLindoSolver.cpp.

References ErrorClass::errormsg, OSInstance::getConstraintNumber(), OSInstance::getInstanceName(), OSInstance::getNumberOfBinaryVariables(), OSInstance::getNumberOfIntegerVariables(), OSInstance::getNumberOfNonlinearConstraints(), OSInstance::getNumberOfNonlinearObjectives(), OSInstance::getObjectiveNumber(), OSInstance::getVariableNumber(), getVersionInfo(), lindoAPIErrorCheck(), m_iLindoErrorCode, m_iNumberNewSlacks, DefaultSolver::osinstance, DefaultSolver::osresult, DefaultSolver::osrl, osrlwriter, pModel_, OSResult::setAnOtherVariableResultDense(), OSResult::setConstraintNumber(), OSResult::setDualVariableValuesDense(), OSResult::setGeneralMessage(), OSResult::setGeneralStatusType(), OSResult::setInstanceName(), OSResult::setNumberOfOtherVariableResults(), OSResult::setObjectiveNumber(), OSResult::setObjectiveValuesDense(), OSResult::setPrimalVariableValuesDense(), OSResult::setServiceName(), OSResult::setSolutionNumber(), OSResult::setSolutionStatus(), OSResult::setSolverInvoked(), OSResult::setVariableNumber(), and OSrLWriter::writeOSrL().

Referenced by solve().

bool LindoSolver::processVariables | ( |  | ) |

read the OSiL instance variables and put these into the LINDO API variables

Returns:
  true if an exception is not thrown.

Definition at line 353 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

Returns:
  true if an exception is not thrown.

Definition at line 228 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

Returns:
  true if an exception is not thrown.

Definition at line 385 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.

Returns:
  true if an exception is not thrown.

Definition at line 276 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

Returns:
  true if an exception is not thrown.

Definition at line 647 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

Returns:
  true if an exception is not thrown.

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 732 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 1056 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 1117 of file OSLindoSolver.cpp.

References ErrorClass::errormsg, m_iLindoErrorCode, and pEnv_.

Referenced by generateLindoModel(), optimize(), and processNonlinearExpressions().

## Member Data Documentation

OSiLReader* LindoSolver::m_osilreader

m_osilreader is an OSiLReader object used to create an osinstance from an osil string if needed

Definition at line 130 of file OSLindoSolver.h.

Referenced by ~LindoSolver().

pLSenv LindoSolver::pEnv_`[private]`

declare an instance of the LINDO environment object

Definition at line 144 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 147 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 150 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 154 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 157 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 162 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 167 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 172 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 177 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 182 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 187 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 192 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 197 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 202 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 208 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 212 of file OSLindoSolver.h.

OSrLWriter* LindoSolver::osrlwriter`[private]`

osrlwriter object used to write osrl from and OSResult object

Definition at line 215 of file OSLindoSolver.h.

Referenced by buildSolverInstance(), generateLindoModel(), LindoSolver(), optimize(), processConstraints(), processNonlinearExpressions(), processQuadraticTerms(), processVariables(), setSolverOptions(), solve(), and ~LindoSolver().

double LindoSolver::cpuTime`[private]`

Definition at line 217 of file OSLindoSolver.h.

Referenced by solve().

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

- /home/coin/SVN-release/OS-2.3.5/OS/src/OSSolverInterfaces/OSLindoSolver.h
- /home/coin/SVN-release/OS-2.3.5/OS/src/OSSolverInterfaces/OSLindoSolver.cpp