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

- File List
- File Members

# /home/coin/SVN-release/OS-2.3.5/ApplicationTemplates/branchCutPrice/TM/OS_tm.cpp

Go to the documentation of this file.

    00001 /* $Id: OS_tm.cpp 2904 2009-09-06 06:47:42Z kmartin $ */
    00002 // Last edit: 1/6/07
    00003 //
    00004 // Name:     OS_tm.cpp
    00005 // Author:   Francois Margot
    00006 //           Tepper School of Business
    00007 //           Carnegie Mellon University, Pittsburgh, PA 15213
    00008 //           email: fmargot@andrew.cmu.edu
    00009 // Date:     12/28/03
    00010 //-----------------------------------------------------------------------------
    00011 // Copyright (C) 2003, Francois Margot, International Business Machines
    00012 // Corporation and others.  All Rights Reserved.
    00013
    00014 #include<iomanip>
    00015
    00016 //OS Stuff
    00017 #include "OSConfig.h"
    00018 #include "OSResult.h"
    00019 #include "OSiLReader.h"
    00020 #include "OSiLWriter.h"
    00021 #include "OSrLReader.h"
    00022 #include "OSrLWriter.h"
    00023 #include "OSFileUtil.h"
    00024 #include "OSErrorClass.h"
    00025 #include "OSErrorClass.h"
    00026 //end OS Stuff
    00027
    00028 #include <CoinHelperFunctions.hpp>
    00029 #include <CoinFileIO.hpp>
    00030 #include <OsiClpSolverInterface.hpp>
    00031 #include <cassert>
    00032
    00033 #include "OS_init.hpp"
    00034 #include "BCP_tm.hpp"
    00035 #include "OS_tm.hpp"
    00036 #include "OS_user_data.hpp"
    00037 #include "OS.hpp"
    00038
    00039 #include "BCP_math.hpp"
    00040
    00041 using namespace std;
    00042
    00043 /*************************************************************************/
    00044
    00045 int main(int argc, char* argv[]) {
    00046         WindowsErrorPopupBlocker();
    00047         OS_init os_init;
    00048         int retCode = -1;
    00049         std::cout << "Call bcp_main  "  << std::endl;
    00050         retCode =  bcp_main(argc, argv, &os_init);
    00051         std::cout << "Return from call to bcp_main  "<< retCode << std::endl;
    00052         //delete os_init.tm;
    00053         return retCode;
    00054 }
    00055
    00056 /*************************************************************************/
    00057
    00058
    00059
    00060 //kipp where is the constructon
    00061
    00062
    00063 void OS_tm::readInput(const char* filename){
    00064
    00065
    00066
    00067    // Create OSInstance and feed into class OS_prob
    00068
    00069         // get the file
    00070         FileUtil *fileUtil = NULL;
    00071         fileUtil = new FileUtil();
    00072         const char dirsep =  CoinFindDirSeparator();
    00073         // Set directory containing mps data files.
    00074         std::string dataDir;
    00075         dataDir = dirsep == '/' ? "../data/" : "..\\data\\";
    00076         cout << "Start Building the Model" << endl;
    00077
    00078         try{
    00079                 // get the parincLinear problem
    00080                 std::string osilFileName;
    00081                 //osilFileName =  dataDir  +   "parincLinear.osil";
    00082                 osilFileName =  dataDir + "p0033.osil";
    00083                 std::cout << "Try to read a sample file" << std::endl;
    00084                 std::cout << "The file is: " << osilFileName << std::endl <<std::endl ;
    00085                 std::string osil = fileUtil->getFileAsString( osilFileName.c_str() );
    00086                 //if(filename == NULL) throw ErrorClass("put file name on command line");
    00087                 //osil = fileUtil->getFileAsString( osilFileName);
    00088                 os_prob.osilreader = new OSiLReader();
    00089                 os_prob.osinstance = os_prob.osilreader->readOSiL( osil);
    00090                 delete fileUtil;
    00091         }// end the try
    00092
    00093
    00094         catch(const ErrorClass& eclass){
    00095                 delete fileUtil;
    00096                 std::cout << eclass.errormsg <<  std::endl;
    00097                 return ;
    00098         }
    00099
    00100
    00101
    00102 }
    00103
    00104 /*************************************************************************/
    00105 void OS_tm::pack_module_data(BCP_buffer& buf, BCP_process_t ptype) {
    00106   // possible process types looked up in BCP_enum_process_t.hpp
    00107
    00108   switch (ptype) {
    00109   case BCP_ProcessType_LP:
    00110     {
    00111       // Pack a pointer; does not work for parallel machines
    00112       // this make make the os_prob object available to the os_lp object
    00113       buf.pack(&os_prob);
    00114     }
    00115     break;
    00116   default:
    00117     abort();
    00118   }
    00119 }
    00120
    00121
    00122
    00123 void OS_tm::initialize_core(BCP_vec<BCP_var_core*>& vars,
    00124                        BCP_vec<BCP_cut_core*>& cuts,
    00125                        BCP_lp_relax*& matrix){
    00126
    00127 // Transmit the core constraints and variables to BCP
    00128         std::cout << "INITIALIZE THE CORE " << std::endl;
    00129         int i;
    00130         int num_vars = os_prob.osinstance->getVariableNumber();
    00131         double objsign = 1;
    00132
    00133         objsign = ( os_prob.osinstance->getObjectiveMaxOrMins()[0] == "min") ? 1 : -1;
    00134
    00135         for (i = 0; i < num_vars; ++i) {
    00136                 os_prob.osinstance->getDenseObjectiveCoefficients()[0][i] = objsign*(os_prob.osinstance->getDenseObjectiveCoefficients()[0][i]);
    00137                 if ( os_prob.osinstance->getVariableTypes()[i] == 'B'    ||   os_prob.osinstance->getVariableTypes()[i] == 'I') {
    00138                         if ( os_prob.osinstance->getVariableTypes()[i] == 'B' ) {
    00139                                 vars.push_back(new BCP_var_core(BCP_BinaryVar, os_prob.osinstance->getDenseObjectiveCoefficients()[0][i], 0, 1));
    00140                         }
    00141                         else {
    00142                                 vars.push_back(new BCP_var_core(BCP_IntegerVar, os_prob.osinstance->getDenseObjectiveCoefficients()[0][i],
    00143                                                 os_prob.osinstance->getVariableLowerBounds()[ i],
    00144                                                 os_prob.osinstance->getVariableUpperBounds()[ i]) );
    00145                         }
    00146                 }
    00147                 else {
    00148                         vars.push_back(new BCP_var_core(BCP_ContinuousVar, os_prob.osinstance->getDenseObjectiveCoefficients()[0][i],
    00149                                         os_prob.osinstance->getVariableLowerBounds()[ i],
    00150                                         os_prob.osinstance->getVariableUpperBounds()[ i] ));
    00151                 }
    00152
    00153         }
    00154
    00155         const int num_cons = os_prob.osinstance->getConstraintNumber();
    00156
    00157     // core constraints
    00158
    00159         for (i=0; i < num_cons; ++i) {
    00160                 cuts.push_back(new BCP_cut_core( os_prob.osinstance->getConstraintLowerBounds()[ i],
    00161                                 os_prob.osinstance->getConstraintUpperBounds()[ i]));
    00162         }
    00163
    00164         matrix = new BCP_lp_relax;
    00165         bool columnMajor = os_prob.osinstance->getLinearConstraintCoefficientMajor();
    00166         int maxGap = 0;
    00167         CoinPackedMatrix*  core_matrix = new CoinPackedMatrix(
    00168                 columnMajor, //Column or Row Major
    00169                 columnMajor? os_prob.osinstance->getConstraintNumber() : os_prob.osinstance->getVariableNumber(), //Minor Dimension
    00170                 columnMajor? os_prob.osinstance->getVariableNumber() : os_prob.osinstance->getConstraintNumber(), //Major Dimension
    00171                 os_prob.osinstance->getLinearConstraintCoefficientNumber(), //Number of nonzeroes
    00172                 columnMajor? os_prob.osinstance->getLinearConstraintCoefficientsInColumnMajor()->values :
    00173                         os_prob.osinstance->getLinearConstraintCoefficientsInRowMajor()->values, //Pointer to matrix nonzeroes
    00174                 columnMajor? os_prob.osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes :
    00175                         os_prob.osinstance->getLinearConstraintCoefficientsInRowMajor()->indexes, //Pointer to start of minor dimension indexes -- change to allow for row storage
    00176                 columnMajor? os_prob.osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts :
    00177                         os_prob.osinstance->getLinearConstraintCoefficientsInRowMajor()->starts, //Pointers to start of columns.
    00178                         0,   0, maxGap );
    00179
    00180         //os_prob.core is a coin packed matrix
    00181         matrix->copyOf(*core_matrix, os_prob.osinstance->getDenseObjectiveCoefficients()[0], os_prob.osinstance->getVariableLowerBounds(),
    00182                         os_prob.osinstance->getVariableUpperBounds(), os_prob.osinstance->getConstraintLowerBounds(),
    00183                         os_prob.osinstance->getConstraintUpperBounds());
    00184
    00185         //do the garbage collection
    00186         delete core_matrix;
    00187
    00188 }//end initialize_core
    00189
    00190 /**************************************************************************/
    00191 void  OS_tm::create_root(BCP_vec<BCP_var*>& added_vars,
    00192                 BCP_vec<BCP_cut*>& added_cuts, BCP_user_data*& user_data) {
    00193
    00194 #ifdef USER_DATA
    00195   user_data = new MY_user_data(os_prob.colnum);
    00196 #endif
    00197
    00198 }
    00199
    00200 /*************************************************************************/
    00201 void  OS_tm::display_feasible_solution(const BCP_solution *soln) {
    00202
    00203         //kipp:  -- later write the OSiL file from here
    00204         std::cout << "Default BCP display of the feasible solution: ***************" << std::endl << std::endl;
    00205         BCP_tm_user::display_feasible_solution(  soln);
    00206
    00207 }
    00208
    00209
    00210 /*************************************************************************/
    00211
    00212 OS_tm::OS_tm(){
    00213
    00214 }
    00215
    00216
    00217
    00218 /*************************************************************************/
    00219
    00220 OS_tm::~OS_tm(){
    00221         std::cout << "Inside OS_tm destructor" << std::endl;
    00222         delete os_prob.osilreader;
    00223 }