Changeset 424 for branches/devel/Cbc/examples/CbcBranchLink.cpp
 Timestamp:
 Sep 15, 2006 4:55:05 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/devel/Cbc/examples/CbcBranchLink.cpp
r134 r424 22 22 numberMembers_(0), 23 23 numberLinks_(0), 24 first_(1)24 which_(NULL) 25 25 { 26 26 } … … 32 32 numberMembers_(numberMembers), 33 33 numberLinks_(numberLinks), 34 first_(first)34 which_(NULL) 35 35 { 36 36 id_=identifier; 37 37 if (numberMembers_) { 38 38 weights_ = new double[numberMembers_]; 39 which_ = new int[numberMembers_*numberLinks_]; 39 40 if (weights) { 40 41 memcpy(weights_,weights,numberMembers_*sizeof(double)); … … 50 51 last=weights_[i]; 51 52 } 53 for (i=0;i<numberMembers_*numberLinks_;i++) { 54 which_[i]=first+i; 55 } 56 } else { 57 weights_ = NULL; 58 } 59 } 60 61 // Useful constructor (which are indices) 62 CbcLink::CbcLink (CbcModel * model, int numberMembers, 63 int numberLinks, const int * which , const double * weights, int identifier) 64 : CbcObject(model), 65 numberMembers_(numberMembers), 66 numberLinks_(numberLinks), 67 which_(NULL) 68 { 69 id_=identifier; 70 if (numberMembers_) { 71 weights_ = new double[numberMembers_]; 72 which_ = new int[numberMembers_*numberLinks_]; 73 if (weights) { 74 memcpy(weights_,weights,numberMembers_*sizeof(double)); 75 } else { 76 for (int i=0;i<numberMembers_;i++) 77 weights_[i]=i; 78 } 79 // weights must be increasing 80 int i; 81 double last=COIN_DBL_MAX; 82 for (i=0;i<numberMembers_;i++) { 83 assert (weights_[i]>last+1.0e12); 84 last=weights_[i]; 85 } 86 for (i=0;i<numberMembers_*numberLinks_;i++) { 87 which_[i]= which[i]; 88 } 52 89 } else { 53 90 weights_ = NULL; … … 61 98 numberMembers_ = rhs.numberMembers_; 62 99 numberLinks_ = rhs.numberLinks_; 63 first_ = rhs.first_;64 100 if (numberMembers_) { 65 weights_ = new double[numberMembers_];66 memcpy(weights_,rhs.weights_,numberMembers_*sizeof(double));101 weights_ = CoinCopyOfArray(rhs.weights_,numberMembers_); 102 which_ = CoinCopyOfArray(rhs.which_,numberMembers_*numberLinks_); 67 103 } else { 68 104 weights_ = NULL; 105 which_ = NULL; 69 106 } 70 107 } … … 84 121 CbcObject::operator=(rhs); 85 122 delete [] weights_; 123 delete [] which_; 86 124 numberMembers_ = rhs.numberMembers_; 87 125 numberLinks_ = rhs.numberLinks_; 88 first_ = rhs.first_;89 126 if (numberMembers_) { 90 weights_ = new double[numberMembers_];91 memcpy(weights_,rhs.weights_,numberMembers_*sizeof(double));127 weights_ = CoinCopyOfArray(rhs.weights_,numberMembers_); 128 which_ = CoinCopyOfArray(rhs.which_,numberMembers_*numberLinks_); 92 129 } else { 93 130 weights_ = NULL; 131 which_ = NULL; 94 132 } 95 133 } … … 101 139 { 102 140 delete [] weights_; 141 delete [] which_; 103 142 } 104 143 … … 112 151 OsiSolverInterface * solver = model_>solver(); 113 152 const double * solution = model_>testSolution(); 114 const double * lower = solver>getColLower();153 //const double * lower = solver>getColLower(); 115 154 const double * upper = solver>getColUpper(); 116 155 double integerTolerance = … … 121 160 // check bounds etc 122 161 double lastWeight=1.0e100; 123 int base= first_;162 int base=0; 124 163 for (j=0;j<numberMembers_;j++) { 125 164 for (int k=0;k<numberLinks_;k++) { 126 int iColumn = base+k;127 if (lower[iColumn])128 165 int iColumn = which_[base+k]; 166 //if (lower[iColumn]) 167 //throw CoinError("Non zero lower bound in CBCLink","infeasibility","CbcLink"); 129 168 if (lastWeight>=weights_[j]1.0e7) 130 169 throw CoinError("Weights too close together in CBCLink","infeasibility","CbcLink"); … … 177 216 double sum =0.0; 178 217 179 int base= first_;218 int base=0; 180 219 for (j=0;j<numberMembers_;j++) { 181 220 for (int k=0;k<numberLinks_;k++) { 182 int iColumn = base+k;221 int iColumn = which_[base+k]; 183 222 double value = CoinMax(0.0,solution[iColumn]); 184 223 sum += value; … … 193 232 } 194 233 assert (lastNonZerofirstNonZero==0) ; 195 base= first_;234 base=0; 196 235 for (j=0;j<firstNonZero;j++) { 197 236 for (int k=0;k<numberLinks_;k++) { 198 int iColumn = base+k;237 int iColumn = which_[base+k]; 199 238 solver>setColUpper(iColumn,0.0); 200 239 } … … 205 244 for (j=lastNonZero+1;j<numberMembers_;j++) { 206 245 for (int k=0;k<numberLinks_;k++) { 207 int iColumn = base+k;246 int iColumn = which_[base+k]; 208 247 solver>setColUpper(iColumn,0.0); 209 248 } … … 229 268 double weight = 0.0; 230 269 double sum =0.0; 231 int base= first_;270 int base=0; 232 271 for (j=0;j<numberMembers_;j++) { 233 272 for (int k=0;k<numberLinks_;k++) { 234 int iColumn = base+k;273 int iColumn = which_[base+k]; 235 274 if (upper[iColumn]) { 236 275 double value = CoinMax(0.0,solution[iColumn]); … … 313 352 int numberLinks = set_>numberLinks(); 314 353 const double * weights = set_>weights(); 354 const int * which = set_>which(); 315 355 OsiSolverInterface * solver = model_>solver(); 316 356 //const double * lower = solver>getColLower(); … … 324 364 } 325 365 assert (i<numberMembers); 326 int base= set_>first()+i*numberLinks;;366 int base=i*numberLinks;; 327 367 for (;i<numberMembers;i++) { 328 368 for (int k=0;k<numberLinks;k++) { 329 int iColumn = base+k;369 int iColumn = which[base+k]; 330 370 solver>setColUpper(iColumn,0.0); 331 371 } … … 335 375 } else { 336 376 int i; 337 int base= set_>first();377 int base=0; 338 378 for ( i=0;i<numberMembers;i++) { 339 379 if (weights[i] >= separator_) { … … 341 381 } else { 342 382 for (int k=0;k<numberLinks;k++) { 343 int iColumn = base+k;383 int iColumn = which[base+k]; 344 384 solver>setColUpper(iColumn,0.0); 345 385 } … … 359 399 int numberLinks = set_>numberLinks(); 360 400 const double * weights = set_>weights(); 401 const int * which = set_>which(); 361 402 OsiSolverInterface * solver = model_>solver(); 362 403 const double * upper = solver>getColUpper(); … … 366 407 int numberOther=0; 367 408 int i; 368 int base= set_>first();409 int base=0; 369 410 for ( i=0;i<numberMembers;i++) { 370 411 for (int k=0;k<numberLinks;k++) { 371 int iColumn = base+k;412 int iColumn = which[base+k]; 372 413 double bound = upper[iColumn]; 373 414 if (bound) { … … 379 420 } 380 421 // *** for way  up means fix all those in down section 381 base= set_>first();422 base=0; 382 423 if (way_<0) { 383 424 printf("SOS Down"); 384 425 for ( i=0;i<numberMembers;i++) { 426 if (weights[i] > separator_) 427 break; 385 428 for (int k=0;k<numberLinks;k++) { 386 int iColumn = base+k;429 int iColumn = which[base+k]; 387 430 double bound = upper[iColumn]; 388 if (weights[i] > separator_) 389 break; 390 else if (bound) 431 if (bound) 391 432 numberOther++; 392 433 } … … 396 437 for (;i<numberMembers;i++) { 397 438 for (int k=0;k<numberLinks;k++) { 398 int iColumn = base+k;439 int iColumn = which[base+k]; 399 440 double bound = upper[iColumn]; 400 441 if (bound) … … 406 447 printf("SOS Up"); 407 448 for ( i=0;i<numberMembers;i++) { 449 if (weights[i] >= separator_) 450 break; 408 451 for (int k=0;k<numberLinks;k++) { 409 int iColumn = base+k;452 int iColumn = which[base+k]; 410 453 double bound = upper[iColumn]; 411 if (weights[i] >= separator_) 412 break; 413 else if (bound) 454 if (bound) 414 455 numberFixed++; 415 456 } … … 419 460 for (;i<numberMembers;i++) { 420 461 for (int k=0;k<numberLinks;k++) { 421 int iColumn = base+k;462 int iColumn = which[base+k]; 422 463 double bound = upper[iColumn]; 423 464 if (bound) … … 428 469 } 429 470 assert ((numberFixed%numberLinks)==0); 430 assert ((number Fixed%numberOther)==0);471 assert ((numberOther%numberLinks)==0); 431 472 printf("  at %g, free range %d (%g) => %d (%g), %d would be fixed, %d other way\n", 432 473 separator_,first,weights[first],last,weights[last],numberFixed/numberLinks,
Note: See TracChangeset
for help on using the changeset viewer.