# SmiScnModel Class Reference

SmiScnModel: COIN-SMI Scenario Model Class. More...

`#include <SmiScnModel.hpp>`

Collaboration diagram for SmiScnModel:
[legend]

List of all members.

## Public Member Functions
Read SMPS files.
There should be three files: {name}. [core, time, stoch]. If you have different extension conventions, then you can hack the method yourself. The files can be compressed. The object that reads the files is derived from CoinMpsIO. The optional argument SmiCoreCombineRule allows user to pass in a class to override the default methods to combine core and stochastic data.
int | readSmps (const char *name, SmiCoreCombineRule *r=NULL)
Writes SMPS files.
  This method generates three files {name}. [core, time, stoch] or {name}.[cor, tim, sto] (see second parameter). Parameters:
  | name | The name for the model and the written files
  | winFileExtensions | optional; false by default, so extensions will be [core, time, stoch]. With this parameter set to true, it will be [cor, tim, sto].
  | strictFormat | optional, true by default. Set to false if SMPS files should be written in free format.
Returns: -1 in case of no existing SMI model, otherwise 0
int | writeSmps (const char *name, bool winFileExtensions=false, bool strictFormat=true)
SmiCoreData * | getCore ()
Direct methods.
Direct methods require the user to create instances of Core data and Scenario data. Currently, the dimension of the core nodes determines the dimension of the scenario nodes, but this is something that could easily be changed.
void | processDiscreteDistributionIntoScenarios (SmiDiscreteDistribution *s, bool test=false)
| generate scenarios from discrete distribution
void | setModelProb (double p)
| generate scenarios from discrete distribution
int | addNodeToSubmodel (SmiScnNode *smiScnNode)
| generate scenarios from discrete distribution
SmiScenarioIndex | generateScenario (SmiCoreData *core, CoinPackedMatrix *matrix, CoinPackedVector *dclo, CoinPackedVector *dcup, CoinPackedVector *dobj, CoinPackedVector *drlo, CoinPackedVector *drup, SmiStageIndex branch, SmiScenarioIndex anc, double prob, SmiCoreCombineRule *r=SmiCoreCombineReplace::Instance())
| generate scenario with ancestor/branch node identification
SmiScenarioIndex | generateScenario (SmiCoreData *core, CoinPackedMatrix *matrix, CoinPackedVector *dclo, CoinPackedVector *dcup, CoinPackedVector *dobj, CoinPackedVector *drlo, CoinPackedVector *drup, std::vector< int >labels, double prob, SmiCoreCombineRule *r=SmiCoreCombineReplace::Instance())
| generate scenario with labels information
## Friends
void | SmiScnModelDiscreteUnitTest ()
void | DecompUnitTest ()
## loadOsiSolverData
Loads deterministic equivalent model into internal osi data structures and return handle. Note: this uses a callback class SmiCoreCombineRule to decide how to combine the core and stochastic data. The user can override the default methods when the scenario is generated (see SmiScnModel::generateScenario) or when SMPS files are processed (see SmiScnModel::readSmps).
CoinMessageHandler * | handler_
SmiMessage * | messages_
OsiSolverInterface * | osiStoch_
int | nrow_
int | ncol_
int | nels_
int | nels_max
double * | drlo_
double * | drup_
double * | dobj_
double * | dclo_
double * | dcup_
CoinPackedMatrix * | matrix_
double * | dels_
int * | indx_
int * | rstrt_
int | minrow_
bool | solve_synch_
double | totalProb_
SmiCoreData * | core_
SmiScenarioTree< SmiScnNode * > | smiTree_
int * | integerInd
int | integerLen
int * | binaryInd
int | binaryLen
std::vector< int > | intIndices
int * | maxNelsPerScenInStage
OsiSolverInterface * | loadOsiSolverData ()
OsiSolverInterface * | loadOsiSolverDataForSubproblem (int stage, int scenStart)
std::vector< std::pair< double, double > > | solveWS (OsiSolverInterface *osiSolver, double objSense)
std::pair< double, double * > | solveEV (OsiSolverInterface *osiSolver, double objSense)
double | solveEEV (OsiSolverInterface *osiSolver, double objSense)
double | getWSValue (OsiSolverInterface *osiSolver, double objSense)
double | getEVValue (OsiSolverInterface *osiSolver, double objSense)
double | getEEVValue (OsiSolverInterface *osiSolver, double objSense)
void | setCore (SmiCoreData *val)
SmiScenarioIndex | getNumScenarios ()
double | getScenarioProb (SmiScenarioIndex ns)
SmiScnNode * | getLeafNode (SmiScenarioIndex i)
SmiScnNode * | getRootNode ()
int * | getIntegerInd ()
int | getIntegerLen ()
int * | getBinaryInd ()
int | getBinaryLen ()
std::vector< int > | getIntIndices ()
void | addIntIndice (int indice)
double | getObjectiveValue (SmiScenarioIndex ns)
double * | getColSolution (SmiScenarioIndex ns, int *length)
double * | getRowSolution (SmiScenarioIndex ns, int *length)
double | getColSolution (SmiScenarioIndex ns, int stage, int colIndex)
double | getRowSolution (SmiScenarioIndex ns, int stage, int colIndex)
void | setOsiSolverHandle (OsiSolverInterface &osi)
void | setOsiSolverHandle (OsiSolverInterface *osi)
OsiSolverInterface * | getOsiSolverInterface ()
void | releaseSolver ()
void | releaseCore ()
| SmiScnModel ()
| ~SmiScnModel ()
void | addNode (SmiScnNode *node, bool notDetEq=false)
void | deleteNode (SmiScnNode *tnode)
void | addNode (SmiNodeData *node)
SmiScenarioTree< SmiScnNode * > * | getSmiTree ()

## Detailed Description

SmiScnModel: COIN-SMI Scenario Model Class.

Concrete class for generating scenario stochastic linear programs.

This class implements the Scenarios format of the Stochastic MPS modeling system (TODO: web pointer). Core data and Scenarios data can be passed using COIN/OSI structures, or can be read from SMPS formatted files.

Typical driver fragment looks like this

    SmiScnModel smi;
    smi.readSmps("app0110R");
    smi.setOsiSolverHandle(new OsiClpSolverInterface());
    OsiSolverInterface *osiStoch = smi.loadOsiSolverData();
    osiStoch->initialSolve();

The setOsiSolverHandle method allows the user to pass in any OSI compatible solver.

Definition at line 47 of file SmiScnModel.hpp.

## Constructor & Destructor Documentation

SmiScnModel::SmiScnModel | ( |  | ) | `[inline]`

Definition at line 219 of file SmiScnModel.hpp.

SmiScnModel::~SmiScnModel | ( |  | ) |

## Member Function Documentation

int SmiScnModel::readSmps | ( | const char * | name,
|  | SmiCoreCombineRule * | r = `NULL` |
| ) |  |  |

int SmiScnModel::writeSmps | ( | const char * | name,
|  | bool | winFileExtensions = `false`,
|  | bool | strictFormat = `true` |
| ) |  |  |

SmiCoreData* SmiScnModel::getCore | ( |  | ) | `[inline]`

Definition at line 83 of file SmiScnModel.hpp.

void SmiScnModel::processDiscreteDistributionIntoScenarios | ( | SmiDiscreteDistribution * | s,
|  | bool | test = `false` |
| ) |  |  |

generate scenarios from discrete distribution

void SmiScnModel::setModelProb | ( | double | p | ) | `[inline]`

generate scenarios from discrete distribution

Definition at line 101 of file SmiScnModel.hpp.

int SmiScnModel::addNodeToSubmodel | ( | SmiScnNode * | smiScnNode | ) |

generate scenarios from discrete distribution

SmiScenarioIndex SmiScnModel::generateScenario | ( | SmiCoreData * | core,
|  | CoinPackedMatrix * | matrix,
|  | CoinPackedVector * | dclo,
|  | CoinPackedVector * | dcup,
|  | CoinPackedVector * | dobj,
|  | CoinPackedVector * | drlo,
|  | CoinPackedVector * | drup,
|  | SmiStageIndex | branch,
|  | SmiScenarioIndex | anc,
|  | double | prob,
|  | SmiCoreCombineRule * | r = `SmiCoreCombineReplace::Instance()` |
| ) |  |  |

generate scenario with ancestor/branch node identification

Core argument must be supplied. Data values combine with corresponding core values, if found, or creates them if not.

Scenario nodes need to have same dimensions as core nodes.

Data field arguments can be NULL, or empty.

branch, anc, arguments must be supplied. These identify the branching node according to the Stochastic MPS standard.

prob is unconditional probability of scenario

SmiScenarioIndex SmiScnModel::generateScenario | ( | SmiCoreData * | core,
|  | CoinPackedMatrix * | matrix,
|  | CoinPackedVector * | dclo,
|  | CoinPackedVector * | dcup,
|  | CoinPackedVector * | dobj,
|  | CoinPackedVector * | drlo,
|  | CoinPackedVector * | drup,
|  | std::vector< int > | labels,
|  | double | prob,
|  | SmiCoreCombineRule * | r = `SmiCoreCombineReplace::Instance()` |
| ) |  |  |

generate scenario with labels information

Core argument must be supplied. Data values combine with corresponding core values, if found, or creates them if not.

Scenario nodes need to have same dimensions as core nodes.

Data field arguments can be NULL, or empty.

Labels are passed as vector<int> array. Adds new path using labels to find branching node. The depth (root to leaf) of new path is labels.size().

OsiSolverInterface* SmiScnModel::loadOsiSolverData | ( |  | ) |

OsiSolverInterface* SmiScnModel::loadOsiSolverDataForSubproblem | ( | int | stage,
|  | int | scenStart |
| ) |  |  |

std::vector< std::pair<double,double> > SmiScnModel::solveWS | ( | OsiSolverInterface * | osiSolver,
|  | double | objSense |
| ) |  |  |

std::pair<double,double*> SmiScnModel::solveEV | ( | OsiSolverInterface * | osiSolver,
|  | double | objSense |
| ) |  |  |

double SmiScnModel::solveEEV | ( | OsiSolverInterface * | osiSolver,
|  | double | objSense |
| ) |  |  |

double SmiScnModel::getWSValue | ( | OsiSolverInterface * | osiSolver,
|  | double | objSense |
| ) |  |  |

double SmiScnModel::getEVValue | ( | OsiSolverInterface * | osiSolver,
|  | double | objSense |
| ) |  |  |

double SmiScnModel::getEEVValue | ( | OsiSolverInterface * | osiSolver,
|  | double | objSense |
| ) |  |  |

void SmiScnModel::setCore | ( | SmiCoreData * | val | ) | `[inline]`

Definition at line 176 of file SmiScnModel.hpp.

SmiScenarioIndex SmiScnModel::getNumScenarios | ( |  | ) | `[inline]`

Definition at line 179 of file SmiScnModel.hpp.

double SmiScnModel::getScenarioProb | ( | SmiScenarioIndex | ns | ) |

SmiScnNode* SmiScnModel::getLeafNode | ( | SmiScenarioIndex | i | ) | `[inline]`

Definition at line 181 of file SmiScnModel.hpp.

SmiScnNode* SmiScnModel::getRootNode | ( |  | ) | `[inline]`

Definition at line 182 of file SmiScnModel.hpp.

int* SmiScnModel::getIntegerInd | ( |  | ) | `[inline]`

Definition at line 184 of file SmiScnModel.hpp.

int SmiScnModel::getIntegerLen | ( |  | ) | `[inline]`

Definition at line 185 of file SmiScnModel.hpp.

int* SmiScnModel::getBinaryInd | ( |  | ) | `[inline]`

Definition at line 186 of file SmiScnModel.hpp.

int SmiScnModel::getBinaryLen | ( |  | ) | `[inline]`

Definition at line 187 of file SmiScnModel.hpp.

std::vector<int> SmiScnModel::getIntIndices | ( |  | ) | `[inline]`

Definition at line 189 of file SmiScnModel.hpp.

void SmiScnModel::addIntIndice | ( | int | indice | ) | `[inline]`

Definition at line 192 of file SmiScnModel.hpp.

double SmiScnModel::getObjectiveValue | ( | SmiScenarioIndex | ns | ) |

double* SmiScnModel::getColSolution | ( | SmiScenarioIndex | ns,
|  | int * | length |
| ) |  |  |

double* SmiScnModel::getRowSolution | ( | SmiScenarioIndex | ns,
|  | int * | length |
| ) |  |  |

double SmiScnModel::getColSolution | ( | SmiScenarioIndex | ns,
|  | int | stage,
|  | int | colIndex |
| ) |  |  |

double SmiScnModel::getRowSolution | ( | SmiScenarioIndex | ns,
|  | int | stage,
|  | int | colIndex |
| ) |  |  |

void SmiScnModel::setOsiSolverHandle | ( | OsiSolverInterface & | osi | ) | `[inline]`

Definition at line 204 of file SmiScnModel.hpp.

void SmiScnModel::setOsiSolverHandle | ( | OsiSolverInterface * | osi | ) | `[inline]`

Definition at line 208 of file SmiScnModel.hpp.

OsiSolverInterface* SmiScnModel::getOsiSolverInterface | ( |  | ) |

void SmiScnModel::releaseSolver | ( |  | ) | `[inline]`

Definition at line 214 of file SmiScnModel.hpp.

void SmiScnModel::releaseCore | ( |  | ) | `[inline]`

Definition at line 215 of file SmiScnModel.hpp.

void SmiScnModel::addNode | ( | SmiScnNode * | node,
|  | bool | notDetEq = `false` |
| ) |  |  |

void SmiScnModel::deleteNode | ( | SmiScnNode * | tnode | ) |

void SmiScnModel::addNode | ( | SmiNodeData * | node | ) |

SmiScenarioTree<SmiScnNode *>* SmiScnModel::getSmiTree | ( |  | ) | `[inline]`

Definition at line 233 of file SmiScnModel.hpp.

## Friends And Related Function Documentation

void SmiScnModelDiscreteUnitTest | ( |  | ) | `[friend]`

void DecompUnitTest | ( |  | ) | `[friend]`

## Member Data Documentation

CoinMessageHandler* SmiScnModel::handler_`[private]`

Definition at line 235 of file SmiScnModel.hpp.

SmiMessage* SmiScnModel::messages_`[private]`

Definition at line 236 of file SmiScnModel.hpp.

OsiSolverInterface* SmiScnModel::osiStoch_`[private]`

Definition at line 239 of file SmiScnModel.hpp.

int SmiScnModel::nrow_`[private]`

Definition at line 241 of file SmiScnModel.hpp.

int SmiScnModel::ncol_`[private]`

Definition at line 242 of file SmiScnModel.hpp.

int SmiScnModel::nels_`[private]`

Definition at line 243 of file SmiScnModel.hpp.

int SmiScnModel::nels_max`[private]`

Definition at line 244 of file SmiScnModel.hpp.

double* SmiScnModel::drlo_`[private]`

Definition at line 246 of file SmiScnModel.hpp.

double* SmiScnModel::drup_`[private]`

Definition at line 247 of file SmiScnModel.hpp.

double* SmiScnModel::dobj_`[private]`

Definition at line 248 of file SmiScnModel.hpp.

double* SmiScnModel::dclo_`[private]`

Definition at line 249 of file SmiScnModel.hpp.

double* SmiScnModel::dcup_`[private]`

Definition at line 250 of file SmiScnModel.hpp.

CoinPackedMatrix* SmiScnModel::matrix_`[private]`

Definition at line 251 of file SmiScnModel.hpp.

double* SmiScnModel::dels_`[private]`

Definition at line 252 of file SmiScnModel.hpp.

int* SmiScnModel::indx_`[private]`

Definition at line 253 of file SmiScnModel.hpp.

int* SmiScnModel::rstrt_`[private]`

Definition at line 254 of file SmiScnModel.hpp.

int SmiScnModel::minrow_`[private]`

Definition at line 258 of file SmiScnModel.hpp.

bool SmiScnModel::solve_synch_`[private]`

Definition at line 260 of file SmiScnModel.hpp.

double SmiScnModel::totalProb_`[private]`

Definition at line 262 of file SmiScnModel.hpp.

SmiCoreData* SmiScnModel::core_`[private]`

Definition at line 266 of file SmiScnModel.hpp.

SmiScenarioTree<SmiScnNode *> SmiScnModel::smiTree_`[private]`

Definition at line 269 of file SmiScnModel.hpp.

int* SmiScnModel::integerInd`[private]`

Definition at line 271 of file SmiScnModel.hpp.

int SmiScnModel::integerLen`[private]`

Definition at line 272 of file SmiScnModel.hpp.

int* SmiScnModel::binaryInd`[private]`

Definition at line 273 of file SmiScnModel.hpp.

int SmiScnModel::binaryLen`[private]`

Definition at line 274 of file SmiScnModel.hpp.

std::vector<int> SmiScnModel::intIndices`[private]`

Definition at line 276 of file SmiScnModel.hpp.

int* SmiScnModel::maxNelsPerScenInStage`[private]`

Definition at line 277 of file SmiScnModel.hpp.

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

- /home/coin/svn-release/Smi-0.93.1/Smi/src/SmiScnModel.hpp