/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OS/OS/examples/osTestCode/OSTestCode.cpp

Go to the documentation of this file.
00001 
00022 #include <cppad/cppad.hpp> 
00023 #include "OSConfig.h"
00024 #include "OSCoinSolver.h"
00025 #include "OSResult.h" 
00026 #include "OSiLReader.h"        
00027 #include "OSiLWriter.h"   
00028 #include "OSrLReader.h"          
00029 #include "OSrLWriter.h"      
00030 #include "OSInstance.h"  
00031 #include "OSFileUtil.h"   
00032 #include "OSDefaultSolver.h"  
00033 #include "OSWSUtil.h" 
00034 #include "OSSolverAgent.h"   
00035 #include "OShL.h"     
00036 #include "OSErrorClass.h"
00037 #include "OSmps2osil.h"   
00038 #include "OSBase64.h"
00039 #include "OSCommonUtil.h"
00040 #include "OSErrorClass.h"
00041 #include "OSMathUtil.h"
00042 
00043 #include<iostream> 
00044 using std::cout;   
00045 using std::endl;
00046 
00047 
00048 
00049 
00050 
00051 //int main(int argC, char* argV[]){
00052 int main( ){
00053 // test OS code samples here
00054         FileUtil *fileUtil = NULL; 
00055         fileUtil = new FileUtil();
00056         cout << "Start Building the Model" << endl;
00057         try{
00058                 OSInstance *osinstance;
00059                 osinstance = new OSInstance();
00060                 //
00061                 // put in some of the OSInstance <instanceHeader> information
00062                 osinstance->setInstanceSource("From Anderson, Sweeney, Williams, and Martin");
00063                 osinstance->setInstanceDescription("The Par Inc. Problem");
00064                 //
00065                 // now put in the OSInstance <instanceData> information
00066                 // 
00067                 // first the variables
00068                 osinstance->setVariableNumber( 2);   
00069                 //addVariable(int index, string name, double lowerBound, double upperBound, char type, double init, string initString);
00070                 // we could use setVariables() and add all the variable with one method call -- below is easier
00071                 osinstance->addVariable(0, "x0", 0, OSDBL_MAX, 'C', OSNAN, "");
00072                 osinstance->addVariable(1, "x1", 0, OSDBL_MAX, 'C', OSNAN, "");
00073                 //
00074                 // now add the objective function
00075                 osinstance->setObjectiveNumber( 1);
00076                 // now the coefficient
00077                 SparseVector *objcoeff;
00078                 objcoeff = new SparseVector(2);   
00079                 objcoeff->indexes[ 0] = 0;
00080                 objcoeff->values[ 0] = 10;
00081                 objcoeff->indexes[ 1] = 1;
00082                 objcoeff->values[ 1] = 9;
00083                 //bool addObjective(int index, string name, string maxOrMin, double constant, double weight, SparseVector* objectiveCoefficients);
00084                 osinstance->addObjective(-1, "objfunction", "max", 0.0, 1.0, objcoeff);
00085                 objcoeff->bDeleteArrays = true;
00086                 delete objcoeff;
00087                 //
00088                 // now the constraints
00089                 osinstance->setConstraintNumber( 4); 
00090                 //bool addConstraint(int index, string name, double lowerBound, double upperBound, double constant);
00091                 // note: we could use setConstraints() and add all the constraints with one method call -- below is easier
00092                 osinstance->addConstraint(0, "row0", -OSDBL_MAX, 630, 0); 
00093                 osinstance->addConstraint(1, "row1", -OSDBL_MAX, 600, 0);
00094                 osinstance->addConstraint(2, "row2", -OSDBL_MAX, 708, 0);
00095                 osinstance->addConstraint(3, "row3", -OSDBL_MAX, 135, 0); 
00096                 //
00097                 //
00098                 // now add the <linearConstraintCoefficients>
00099                 //bool setLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor, 
00100                 //double* values, int valuesBegin, int valuesEnd, 
00101                 //int* indexes, int indexesBegin, int indexesEnd,                       
00102                 //int* starts, int startsBegin, int startsEnd); 
00103                 double *values = new double[ 8];
00104                 int *indexes = new int[ 8];
00105                 int *starts = new int[ 3];  
00106                 values[ 0] = .7;
00107                 values[ 1] = .5;
00108                 values[ 2] = 1.0;
00109                 values[ 3] = .1;
00110                 values[ 4] = 1.0;
00111                 values[ 5] = 5./6.;
00112                 values[ 6] = 2./3.;
00113                 values[ 7] = .25;
00114                 indexes[ 0] = 0;
00115                 indexes[ 1] = 1;
00116                 indexes[ 2] = 2;
00117                 indexes[ 3] = 3;
00118                 indexes[ 4] = 0;
00119                 indexes[ 5] = 1;
00120                 indexes[ 6] = 2;
00121                 indexes[ 7] = 3;
00122                 starts[ 0] = 0;
00123                 starts[ 1] = 4;
00124                 starts[ 2] = 8; 
00125                 cout << "Call setLinearConstraintCoefficients" << endl;
00126                 osinstance->setLinearConstraintCoefficients(8, true, values, 0, 7, 
00127                         indexes, 0, 7, starts, 0, 2);   
00128                 cout << "End Building the Model" << endl; 
00129                 // Write out the model
00130                 OSiLWriter *osilwriter;
00131                 osilwriter = new OSiLWriter();
00132                 cout << osilwriter->writeOSiL( osinstance);
00133                 // done writing the model
00134                 cout << "Done writing the Model" << endl;
00135                 // now solve the model
00136                 CoinSolver *solver  = NULL;
00137                 solver = new CoinSolver();
00138                 solver->osinstance = osinstance;
00139                 solver->sSolverName ="clp"; 
00140                 cout << "call the COIN - Clp Solver" << endl;
00141                 // we want a fractional solution
00142                 //osinstance->instanceData->constraints->con[0]->ub = 620;
00143                 solver->buildSolverInstance();
00144                 solver->solve();
00145                 std::cout << solver->osrl << std::endl;
00146 
00147                 // do garbage collection
00148                 delete osinstance;
00149                 osinstance = NULL;
00150                 delete osilwriter;
00151                 osilwriter = NULL;
00152                 cout << "Done with garbage collection" << endl;
00153                 return 0;
00154         }
00155         catch(const ErrorClass& eclass){
00156                 delete fileUtil;
00157                 std::cout << eclass.errormsg <<  std::endl;
00158                 return 0;
00159         } 
00160 }// end main
00161 

Generated on Sat Mar 29 22:38:01 2008 by  doxygen 1.5.3