Changes from stable/2.7/Cbc/examples/sample4.cpp at r1675 to stable/2.8/Cbc/examples/sample4.cpp at r1902
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

stable/2.8/Cbc/examples/sample4.cpp
r1675 r1902 26 26 /************************************************************************ 27 27 28 This main program reads in an SOS r model (ltw) from an mps file.28 This main program reads in an SOS model (rgn) from an mps file. 29 29 30 30 It then solves it three ways : … … 32 32 a) As normal 33 33 b) SOS 1 34 c) SOS 2 (so answer will be different)34 c) SOS 2 (so answer will be different) 35 35 36 36 ************************************************************************/ … … 46 46 model.solver()>setHintParam(OsiDoReducePrint,true,OsiHintTry); 47 47 48 // Read in ltw.mps 49 // and assert that it is a clean model 50 int numMpsReadErrors = model.solver()>readMps("./ltw.mps",""); 51 assert(numMpsReadErrors==0); 48 // Read in rgn.mps 49 std::string mpsFileName; 50 #if defined(MIPLIB3DIR) 51 mpsFileName = MIPLIB3DIR "/rgn"; 52 #else 53 if (argc < 2) { 54 fprintf(stderr, "Do not know where to find miplib3 MPS files.\n"); 55 exit(1); 56 } 57 #endif 58 if (argc>=2) mpsFileName = argv[1]; 59 int numMpsReadErrors = model.solver()>readMps(mpsFileName.c_str(),""); 60 if( numMpsReadErrors != 0 ) 61 { 62 printf("%d errors reading MPS file\n", numMpsReadErrors); 63 return numMpsReadErrors; 64 } 52 65 53 66 // Definition of node choice … … 75 88 } 76 89 77 90 if (numberColumns!=180  numberIntegers!=100) { 91 printf("Incorrect model for example\n"); 92 exit(1); 93 } 94 78 95 double time1 = CoinCpuTime() ; 79 96 80 97 model.branchAndBound(); 81 98 82 std::cout<<" ltw.mps"<<" took "<<CoinCpuTime()time1<<" seconds, "99 std::cout<<"rgn.mps"<<" took "<<CoinCpuTime()time1<<" seconds, " 83 100 <<model.getNodeCount()<<" nodes with objective " 84 101 <<model.getObjValue() … … 104 121 model = model2; 105 122 123 // Convert slacks to variables 124 CoinBigIndex start[5]={0,1,2,3,4}; 125 int row[4]={0,1,2,3}; 126 double element[4]={1.0,1.0,1.0,1.0}; 127 double up[4]={1.0,1.0,1.0,1.0}; 128 model.solver()>addCols(4,start,row,element,NULL,up,NULL); 106 129 // Now use SOS1 107 int numberSets=8; 108 int which[28]={20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38, 109 39,40,41,42,43,44,45,46,47}; 110 double weights[]={1.0,2.0,3.0,4.0,5.0}; 111 int starts[]={0,2,4,6,8,13,18,23,28}; 112 CbcObject ** objects = new CbcObject * [numberSets]; 130 int numberSets=4; 131 int which[104]; 132 double weights[104]; 133 int starts[5]; 134 // load 135 int n=0; 136 starts[0]=0; 137 for (int iSet=0;iSet<4;iSet++) { 138 for (int i=0;i<25;i++) { 139 weights[n]=i+1.0; 140 which[n]=iSet*25+i; 141 n++; 142 } 143 // slack  make sure first branch is on slack 144 weights[n]=1000.0; 145 which[n]=180+iSet; 146 n++; 147 starts[iSet+1]=n; 148 } 113 149 for (i=0;i<numberIntegers;i++) { 114 150 int iColumn = integerVariable[i]; … … 116 152 model.solver()>setContinuous(iColumn); 117 153 } 154 // save model in this state 155 CbcModel modelSOS = model; 156 CbcObject ** objects = new CbcObject * [numberSets]; 118 157 for (i=0;i<numberSets;i++) { 119 158 objects[i]= new CbcSOS(&model,starts[i+1]starts[i],which+starts[i], … … 129 168 model.branchAndBound(); 130 169 131 std::cout<<" ltw.mps"<<" took "<<CoinCpuTime()time1<<" seconds, "170 std::cout<<"rgn.mps"<<" took "<<CoinCpuTime()time1<<" seconds, " 132 171 <<model.getNodeCount()<<" nodes with objective " 133 172 <<model.getObjValue() … … 151 190 152 191 153 // Restore model154 model = model 2;192 // Restore SOS model 193 model = modelSOS; 155 194 156 195 // Now use SOS2 157 196 objects = new CbcObject * [numberSets]; 158 for (i=0;i<numberIntegers;i++) {159 int iColumn = integerVariable[i];160 // Stop being integer161 model.solver()>setContinuous(iColumn);162 }163 197 for (i=0;i<numberSets;i++) { 164 198 objects[i]= new CbcSOS(&model,starts[i+1]starts[i],which+starts[i], … … 174 208 model.branchAndBound(); 175 209 176 std::cout<<" ltw.mps"<<" took "<<CoinCpuTime()time1<<" seconds, "210 std::cout<<"rgn.mps"<<" took "<<CoinCpuTime()time1<<" seconds, " 177 211 <<model.getNodeCount()<<" nodes with objective " 178 212 <<model.getObjValue()
Note: See TracChangeset
for help on using the changeset viewer.