00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include<iomanip>
00015
00016
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
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
00053 std::cout << "OSBranchCutPrice terminates normally" << std::endl;
00054 return retCode;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064 void OS_tm::readInput(const char* filename){
00065
00066
00067
00068
00069
00070
00071 FileUtil *fileUtil = NULL;
00072 fileUtil = new FileUtil();
00073 const char dirsep = CoinFindDirSeparator();
00074
00075 std::string dataDir;
00076 dataDir = dirsep == '/' ? "../data/" : "..\\data\\";
00077 cout << "Start Building the Model" << endl;
00078
00079 try{
00080
00081 std::string osilFileName;
00082
00083 osilFileName = dataDir + "p0033.osil";
00084 std::cout << "Try to read a sample file" << std::endl;
00085 std::cout << "The file is: " << osilFileName << std::endl <<std::endl ;
00086 std::string osil = fileUtil->getFileAsString( osilFileName.c_str() );
00087
00088
00089 os_prob.osilreader = new OSiLReader();
00090 os_prob.osinstance = os_prob.osilreader->readOSiL( osil);
00091 delete fileUtil;
00092 }
00093
00094
00095 catch(const ErrorClass& eclass){
00096 delete fileUtil;
00097 std::cout << eclass.errormsg << std::endl;
00098 return ;
00099 }
00100
00101
00102
00103 }
00104
00105
00106 void OS_tm::pack_module_data(BCP_buffer& buf, BCP_process_t ptype) {
00107
00108
00109 switch (ptype) {
00110 case BCP_ProcessType_LP:
00111 {
00112
00113
00114 buf.pack(&os_prob);
00115 }
00116 break;
00117 default:
00118 abort();
00119 }
00120 }
00121
00122
00123
00124 void OS_tm::initialize_core(BCP_vec<BCP_var_core*>& vars,
00125 BCP_vec<BCP_cut_core*>& cuts,
00126 BCP_lp_relax*& matrix){
00127
00128
00129 std::cout << "INITIALIZE THE CORE " << std::endl;
00130 int i;
00131 int num_vars = os_prob.osinstance->getVariableNumber();
00132 double objsign = 1;
00133
00134 objsign = ( os_prob.osinstance->getObjectiveMaxOrMins()[0] == "min") ? 1 : -1;
00135
00136 for (i = 0; i < num_vars; ++i) {
00137 os_prob.osinstance->getDenseObjectiveCoefficients()[0][i] = objsign*(os_prob.osinstance->getDenseObjectiveCoefficients()[0][i]);
00138 if ( os_prob.osinstance->getVariableTypes()[i] == 'B' || os_prob.osinstance->getVariableTypes()[i] == 'I') {
00139 if ( os_prob.osinstance->getVariableTypes()[i] == 'B' ) {
00140 vars.push_back(new BCP_var_core(BCP_BinaryVar, os_prob.osinstance->getDenseObjectiveCoefficients()[0][i], 0, 1));
00141 }
00142 else {
00143 vars.push_back(new BCP_var_core(BCP_IntegerVar, os_prob.osinstance->getDenseObjectiveCoefficients()[0][i],
00144 os_prob.osinstance->getVariableLowerBounds()[ i],
00145 os_prob.osinstance->getVariableUpperBounds()[ i]) );
00146 }
00147 }
00148 else {
00149 vars.push_back(new BCP_var_core(BCP_ContinuousVar, os_prob.osinstance->getDenseObjectiveCoefficients()[0][i],
00150 os_prob.osinstance->getVariableLowerBounds()[ i],
00151 os_prob.osinstance->getVariableUpperBounds()[ i] ));
00152 }
00153
00154 }
00155
00156 const int num_cons = os_prob.osinstance->getConstraintNumber();
00157
00158
00159
00160 for (i=0; i < num_cons; ++i) {
00161 cuts.push_back(new BCP_cut_core( os_prob.osinstance->getConstraintLowerBounds()[ i],
00162 os_prob.osinstance->getConstraintUpperBounds()[ i]));
00163 }
00164
00165 matrix = new BCP_lp_relax;
00166 bool columnMajor = os_prob.osinstance->getLinearConstraintCoefficientMajor();
00167 int maxGap = 0;
00168 CoinPackedMatrix* core_matrix = new CoinPackedMatrix(
00169 columnMajor,
00170 columnMajor? os_prob.osinstance->getConstraintNumber() : os_prob.osinstance->getVariableNumber(),
00171 columnMajor? os_prob.osinstance->getVariableNumber() : os_prob.osinstance->getConstraintNumber(),
00172 os_prob.osinstance->getLinearConstraintCoefficientNumber(),
00173 columnMajor? os_prob.osinstance->getLinearConstraintCoefficientsInColumnMajor()->values :
00174 os_prob.osinstance->getLinearConstraintCoefficientsInRowMajor()->values,
00175 columnMajor? os_prob.osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes :
00176 os_prob.osinstance->getLinearConstraintCoefficientsInRowMajor()->indexes,
00177 columnMajor? os_prob.osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts :
00178 os_prob.osinstance->getLinearConstraintCoefficientsInRowMajor()->starts,
00179 0, 0, maxGap );
00180
00181
00182 matrix->copyOf(*core_matrix, os_prob.osinstance->getDenseObjectiveCoefficients()[0], os_prob.osinstance->getVariableLowerBounds(),
00183 os_prob.osinstance->getVariableUpperBounds(), os_prob.osinstance->getConstraintLowerBounds(),
00184 os_prob.osinstance->getConstraintUpperBounds());
00185
00186
00187 delete core_matrix;
00188
00189 }
00190
00191
00192 void OS_tm::create_root(BCP_vec<BCP_var*>& added_vars,
00193 BCP_vec<BCP_cut*>& added_cuts, BCP_user_data*& user_data) {
00194
00195 #ifdef USER_DATA
00196 user_data = new MY_user_data(os_prob.colnum);
00197 #endif
00198
00199 }
00200
00201
00202 void OS_tm::display_feasible_solution(const BCP_solution *soln) {
00203
00204
00205 std::cout << "Default BCP display of the feasible solution: ***************" << std::endl << std::endl;
00206 BCP_tm_user::display_feasible_solution( soln);
00207
00208 }
00209
00210
00211
00212
00213 OS_tm::OS_tm(){
00214
00215 }
00216
00217
00218
00219
00220
00221 OS_tm::~OS_tm(){
00222 std::cout << "Inside OS_tm destructor" << std::endl;
00223 delete os_prob.osilreader;
00224 }