00001
00015 #include "OSConfig.h"
00016 #include "OSCoinSolver.h"
00017 #include "OSIpoptSolver.h"
00018 #include "OSResult.h"
00019 #include "OSiLReader.h"
00020 #include "OSiLWriter.h"
00021 #include "OSrLReader.h"
00022 #include "OSrLWriter.h"
00023 #include "OSInstance.h"
00024 #include "OSOption.h"
00025 #include "OSoLWriter.h"
00026 #include "OSFileUtil.h"
00027 #include "OSDefaultSolver.h"
00028 #include "OShL.h"
00029 #include "OSErrorClass.h"
00030 #include "OSmps2osil.h"
00031 #include "OSBase64.h"
00032 #include "OSErrorClass.h"
00033 #include "OSMathUtil.h"
00034
00035
00036 #include "CoinError.hpp"
00037 #include "CoinHelperFunctions.hpp"
00038 #include<iostream>
00039
00040
00041 using std::string;
00042 using std::cout;
00043 using std::endl;
00044
00045
00046 int main( ){
00047 WindowsErrorPopupBlocker();
00048 FileUtil *fileUtil = NULL;
00049 fileUtil = new FileUtil();
00050 cout << "Start Building the Model" << endl;
00051 try{
00052
00053
00054 const char dirsep = CoinFindDirSeparator();
00055
00056 std::string dataDir;
00057 std::string osilFileName;
00058 dataDir = dirsep == '/' ? "../data/" : "..\\data\\";
00059
00060 osilFileName = dataDir + "parincLinear.osil";
00061 std::cout << "Try to read a sample file" << std::endl;
00062 std::cout << "The file is: " ;
00063 std::cout << osilFileName << std::endl;
00064 std::string osil = fileUtil->getFileAsString( osilFileName.c_str() );
00065
00066 OSiLReader *osilreader = NULL;
00067 osilreader = new OSiLReader();
00068 OSInstance *osinstance;
00069 osinstance = osilreader->readOSiL( osil);
00070 CoinSolver *solver = new CoinSolver();
00071 solver->osinstance = osinstance;
00072 solver->sSolverName ="clp";
00073 solver->buildSolverInstance();
00074 solver->solve();
00075
00076
00077
00078
00079 OSrLReader *osrlreader = NULL;
00080 OSResult *osresult = NULL;
00081 osrlreader = new OSrLReader();
00082 osresult = osrlreader->readOSrL( solver->osrl);
00083
00084
00085
00086 std::string solStatus;
00087 double optSolValue;
00088
00089 solStatus = osresult->getSolutionStatusType( 0 );
00090
00091 if( solStatus.find("ptimal") != string::npos ){
00092
00093 optSolValue = osresult->getOptimalObjValue( -1, 0);
00094 std::cout << "OPTIMAL SOLUTION VALUE " << optSolValue << std::endl;
00095 }else{
00096 std::cout << "NO OPTIMAL SOLUTION FOUND " << std::endl;
00097 }
00098
00099 int i;
00100 int j;
00101 int k;
00102 int vecSize;
00103
00104 std::vector<IndexValuePair*> primalValPair;
00105 primalValPair = osresult->getOptimalPrimalVariableValues( 0);
00106 vecSize = primalValPair.size();
00107 for(i = 0; i < vecSize; i++){
00108 std::cout << "index = " << primalValPair[ i]->idx << std::endl;
00109 std::cout << "value = " << primalValPair[ i]->value << std::endl;
00110 }
00111
00112 std::vector<IndexValuePair*> dualValPair;
00113 dualValPair = osresult->getOptimalDualVariableValues( 0);
00114 vecSize = dualValPair.size();
00115 for(i = 0; i < vecSize; i++){
00116 std::cout << "index = " << dualValPair[ i]->idx << std::endl;
00117 std::cout << "value = " << dualValPair[ i]->value << std::endl;
00118 }
00119
00120
00121 int numSolutions;
00122 int numberOfOtherVariableResults;
00123 int numberOfOtherVar;
00124 numSolutions =osresult-> getSolutionNumber();
00125 for(i = 0; i < numSolutions; i++){
00126 numberOfOtherVariableResults = osresult->
00127 getNumberOfOtherVariableResults( i);
00128 for(j = 0; j < numberOfOtherVariableResults; j++){
00129 std::cout << "Other Name = " << osresult->optimization->solution[ i]->variables->other[ j]->name << std::endl;
00130 std::cout << "Other Description = " << osresult->optimization->solution[ i]->variables->other[ j]->description << std::endl;
00131 std::cout << "Other NumberOfVar = " << osresult->optimization->solution[ i]->variables->other[ j]->numberOfVar << std::endl;
00132 numberOfOtherVar = osresult->optimization->solution[ i]->variables->other[ j]->numberOfVar;
00133 for(k = 0; k < numberOfOtherVar; k++){
00134 std::cout << "Other Variable index = " << osresult->optimization->solution[ i]->variables->other[ j]->var[ k]->idx << std::endl;
00135 std::cout << "Other Variable value = " << osresult->optimization->solution[ i]->variables->other[ j]->var[ k]->value << std::endl;
00136 }
00137 }
00138 }
00139
00140 delete solver;
00141 solver = NULL;
00142 delete fileUtil;
00143 fileUtil = NULL;
00144 delete osrlreader;
00145 osrlreader = NULL;
00146 delete osilreader;
00147 osilreader = NULL;
00148 cout << "Done with garbage collection" << endl;
00149 return 0;
00150
00151 }
00152 catch(const ErrorClass& eclass){
00153 delete fileUtil;
00154 std::cout << eclass.errormsg << std::endl;
00155 return 0;
00156 }
00157 }