Changeset 2385 for trunk/Clp/src/AbcNonLinearCost.cpp
 Timestamp:
 Jan 6, 2019 2:43:06 PM (19 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Clp/src/AbcNonLinearCost.cpp
r1910 r2385 20 20 // Default Constructor 21 21 // 22 AbcNonLinearCost::AbcNonLinearCost () : 23 changeCost_(0.0), 24 feasibleCost_(0.0), 25 infeasibilityWeight_(1.0), 26 largestInfeasibility_(0.0), 27 sumInfeasibilities_(0.0), 28 averageTheta_(0.0), 29 numberRows_(0), 30 numberColumns_(0), 31 model_(NULL), 32 numberInfeasibilities_(1), 33 status_(NULL), 34 bound_(NULL), 35 cost_(NULL) 36 { 37 22 AbcNonLinearCost::AbcNonLinearCost() 23 : changeCost_(0.0) 24 , feasibleCost_(0.0) 25 , infeasibilityWeight_(1.0) 26 , largestInfeasibility_(0.0) 27 , sumInfeasibilities_(0.0) 28 , averageTheta_(0.0) 29 , numberRows_(0) 30 , numberColumns_(0) 31 , model_(NULL) 32 , numberInfeasibilities_(1) 33 , status_(NULL) 34 , bound_(NULL) 35 , cost_(NULL) 36 { 38 37 } 39 38 //#define VALIDATE 40 39 #ifdef VALIDATE 41 static double * 42 static double * 40 static double *saveLowerV = NULL; 41 static double *saveUpperV = NULL; 43 42 #ifdef NDEBUG 44 43 Validate should not be set if no debug 45 44 #endif 46 45 #endif 47 46 /* Constructor from simplex. 48 47 This will just set up wasteful arrays for linear, but 49 48 later may do dual analysis and even finding duplicate columns 50 49 */ 51 AbcNonLinearCost::AbcNonLinearCost (AbcSimplex * model)50 AbcNonLinearCost::AbcNonLinearCost(AbcSimplex * model) 52 51 { 53 52 model_ = model; … … 60 59 feasibleCost_ = 0.0; 61 60 infeasibilityWeight_ = 1.0; 62 double * 61 double *cost = model_>costRegion(); 63 62 // check if all 0 64 63 int iSequence; … … 85 84 } 86 85 // Refresh  assuming regions OK 87 void 88 AbcNonLinearCost::refresh() 86 void AbcNonLinearCost::refresh() 89 87 { 90 88 int numberTotal = numberRows_ + numberColumns_; … … 94 92 double infeasibilityCost = model_>infeasibilityCost(); 95 93 double primalTolerance = model_>currentPrimalTolerance(); 96 double * 97 double * 98 double * 99 double * 94 double *cost = model_>costRegion(); 95 double *upper = model_>upperRegion(); 96 double *lower = model_>lowerRegion(); 97 double *solution = model_>solutionRegion(); 100 98 for (int iSequence = 0; iSequence < numberTotal; iSequence++) { 101 99 cost_[iSequence] = cost[iSequence]; … … 105 103 if (value  upperValue <= primalTolerance) { 106 104 if (value  lowerValue >= primalTolerance) { 107 108 status_[iSequence] = static_cast<unsigned char>(CLP_FEASIBLE  (CLP_SAME << 4));109 105 // feasible 106 status_[iSequence] = static_cast< unsigned char >(CLP_FEASIBLE  (CLP_SAME << 4)); 107 bound_[iSequence] = 0.0; 110 108 } else { 111 112 113 114 115 116 117 status_[iSequence] = static_cast<unsigned char>(CLP_BELOW_LOWER  (CLP_SAME << 4));118 119 120 109 // below 110 double infeasibility = lowerValue  value  primalTolerance; 111 sumInfeasibilities_ += infeasibility; 112 largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility); 113 cost[iSequence] = infeasibilityCost; 114 numberInfeasibilities_++; 115 status_[iSequence] = static_cast< unsigned char >(CLP_BELOW_LOWER  (CLP_SAME << 4)); 116 bound_[iSequence] = upperValue; 117 upper[iSequence] = lowerValue; 118 lower[iSequence] = COIN_DBL_MAX; 121 119 } 122 120 } else { … … 127 125 cost[iSequence] += infeasibilityCost; 128 126 numberInfeasibilities_++; 129 status_[iSequence] = static_cast< unsigned char>(CLP_ABOVE_UPPER  (CLP_SAME << 4));127 status_[iSequence] = static_cast< unsigned char >(CLP_ABOVE_UPPER  (CLP_SAME << 4)); 130 128 bound_[iSequence] = lowerValue; 131 129 lower[iSequence] = upperValue; … … 134 132 } 135 133 // checkInfeasibilities(model_>primalTolerance()); 136 137 134 } 138 135 // Refresh  from original 139 void 140 AbcNonLinearCost::refreshFromPerturbed(double tolerance) 136 void AbcNonLinearCost::refreshFromPerturbed(double tolerance) 141 137 { 142 138 // original costs and perturbed bounds 143 model_>copyFromSaved(32 +2);139 model_>copyFromSaved(32 + 2); 144 140 refresh(); 145 141 //checkInfeasibilities(tolerance); 146 142 } 147 143 // Refreshes costs always makes row costs zero 148 void 149 AbcNonLinearCost::refreshCosts(const double * columnCosts) 150 { 151 double * cost = model_>costRegion(); 144 void AbcNonLinearCost::refreshCosts(const double *columnCosts) 145 { 146 double *cost = model_>costRegion(); 152 147 // zero row costs 153 148 memset(cost + numberColumns_, 0, numberRows_ * sizeof(double)); … … 161 156 // Copy constructor 162 157 // 163 AbcNonLinearCost::AbcNonLinearCost (const AbcNonLinearCost & rhs) :164 changeCost_(0.0),165 feasibleCost_(0.0),166 infeasibilityWeight_(1.0),167 largestInfeasibility_(0.0),168 sumInfeasibilities_(0.0),169 averageTheta_(0.0),170 numberRows_(rhs.numberRows_),171 numberColumns_(rhs.numberColumns_),172 model_(NULL),173 numberInfeasibilities_(1),174 status_(NULL),175 bound_(NULL),176 cost_(NULL)158 AbcNonLinearCost::AbcNonLinearCost(const AbcNonLinearCost &rhs) 159 : changeCost_(0.0) 160 , feasibleCost_(0.0) 161 , infeasibilityWeight_(1.0) 162 , largestInfeasibility_(0.0) 163 , sumInfeasibilities_(0.0) 164 , averageTheta_(0.0) 165 , numberRows_(rhs.numberRows_) 166 , numberColumns_(rhs.numberColumns_) 167 , model_(NULL) 168 , numberInfeasibilities_(1) 169 , status_(NULL) 170 , bound_(NULL) 171 , cost_(NULL) 177 172 { 178 173 if (numberRows_) { … … 195 190 // Destructor 196 191 // 197 AbcNonLinearCost::~AbcNonLinearCost 198 { 199 delete 200 delete 201 delete 192 AbcNonLinearCost::~AbcNonLinearCost() 193 { 194 delete[] status_; 195 delete[] bound_; 196 delete[] cost_; 202 197 } 203 198 … … 206 201 // 207 202 AbcNonLinearCost & 208 AbcNonLinearCost::operator=(const AbcNonLinearCost &rhs)203 AbcNonLinearCost::operator=(const AbcNonLinearCost &rhs) 209 204 { 210 205 if (this != &rhs) { 211 206 numberRows_ = rhs.numberRows_; 212 207 numberColumns_ = rhs.numberColumns_; 213 delete 214 delete 215 delete 208 delete[] status_; 209 delete[] bound_; 210 delete[] cost_; 216 211 status_ = NULL; 217 212 bound_ = NULL; … … 238 233 // We will also need a 2 bit per variable array for some 239 234 // purpose which will come to me later 240 void 241 AbcNonLinearCost::checkInfeasibilities(double oldTolerance) 235 void AbcNonLinearCost::checkInfeasibilities(double oldTolerance) 242 236 { 243 237 numberInfeasibilities_ = 0; … … 248 242 double primalTolerance = model_>currentPrimalTolerance(); 249 243 int iSequence; 250 double * 251 double * 252 double * 253 double * 244 double *solution = model_>solutionRegion(); 245 double *upper = model_>upperRegion(); 246 double *lower = model_>lowerRegion(); 247 double *cost = model_>costRegion(); 254 248 bool toNearest = oldTolerance <= 0.0; 255 249 feasibleCost_ = 0.0; … … 261 255 double value = solution[iSequence]; 262 256 unsigned char iStatus = status_[iSequence]; 263 assert 257 assert(currentStatus(iStatus) == CLP_SAME); 264 258 double lowerValue = lower[iSequence]; 265 259 double upperValue = upper[iSequence]; … … 281 275 if (upperValue == lowerValue && status != AbcSimplex::isFixed) { 282 276 if (status != AbcSimplex::basic) { 283 284 277 model_>setInternalStatus(iSequence, AbcSimplex::isFixed); 278 status = AbcSimplex::isFixed; 285 279 } 286 280 } 287 switch (status) {288 281 switch (status) { 282 289 283 case AbcSimplex::basic: 290 284 case AbcSimplex::superBasic: 291 285 if (value  upperValue <= primalTolerance) { 292 293 294 295 296 297 298 assert(fabs(lowerValue) < 1.0e100);299 300 301 302 303 304 305 286 if (value  lowerValue >= primalTolerance) { 287 // feasible 288 //newWhere=CLP_FEASIBLE; 289 } else { 290 // below 291 newWhere = CLP_BELOW_LOWER; 292 assert(fabs(lowerValue) < 1.0e100); 293 double infeasibility = lowerValue  value  primalTolerance; 294 sumInfeasibilities_ += infeasibility; 295 largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility); 296 costValue = trueCost  infeasibilityCost; 297 changeCost_ = lowerValue * (costValue  cost[iSequence]); 298 numberInfeasibilities_++; 299 } 306 300 } else { 307 308 309 310 311 312 313 314 301 // above 302 newWhere = CLP_ABOVE_UPPER; 303 double infeasibility = value  upperValue  primalTolerance; 304 sumInfeasibilities_ += infeasibility; 305 largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility); 306 costValue = trueCost + infeasibilityCost; 307 changeCost_ = upperValue * (costValue  cost[iSequence]); 308 numberInfeasibilities_++; 315 309 } 316 310 break; … … 319 313 case AbcSimplex::atUpperBound: 320 314 if (!toNearest) { 321 322 323 324 if(fabs(value  lowerValue) > primalTolerance) {325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 } else if(fabs(value  upperValue) > primalTolerance) {346 347 348 315 // With increasing tolerances  we may be at wrong place 316 if (fabs(value  upperValue) > oldTolerance * 1.0001) { 317 if (fabs(value  lowerValue) <= oldTolerance * 1.0001) { 318 if (fabs(value  lowerValue) > primalTolerance) { 319 solution[iSequence] = lowerValue; 320 value = lowerValue; 321 } 322 model_>setInternalStatus(iSequence, AbcSimplex::atLowerBound); 323 } else { 324 if (value < upperValue) { 325 if (value > lowerValue) { 326 model_>setInternalStatus(iSequence, AbcSimplex::superBasic); 327 } else { 328 // set to lower bound as infeasible 329 solution[iSequence] = lowerValue; 330 value = lowerValue; 331 model_>setInternalStatus(iSequence, AbcSimplex::atLowerBound); 332 } 333 } else { 334 // set to upper bound as infeasible 335 solution[iSequence] = upperValue; 336 value = upperValue; 337 } 338 } 339 } else if (fabs(value  upperValue) > primalTolerance) { 340 solution[iSequence] = upperValue; 341 value = upperValue; 342 } 349 343 } else { 350 351 352 353 354 355 356 357 358 344 // Set to nearest and make at bound 345 if (fabs(value  lowerValue) < fabs(value  upperValue)) { 346 solution[iSequence] = lowerValue; 347 value = lowerValue; 348 model_>setInternalStatus(iSequence, AbcSimplex::atLowerBound); 349 } else { 350 solution[iSequence] = upperValue; 351 value = upperValue; 352 } 359 353 } 360 354 break; 361 355 case AbcSimplex::atLowerBound: 362 356 if (!toNearest) { 363 364 365 366 if(fabs(value  upperValue) > primalTolerance) {367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 } else if(fabs(value  lowerValue) > primalTolerance) {388 389 390 357 // With increasing tolerances  we may be at wrong place 358 if (fabs(value  lowerValue) > oldTolerance * 1.0001) { 359 if (fabs(value  upperValue) <= oldTolerance * 1.0001) { 360 if (fabs(value  upperValue) > primalTolerance) { 361 solution[iSequence] = upperValue; 362 value = upperValue; 363 } 364 model_>setInternalStatus(iSequence, AbcSimplex::atUpperBound); 365 } else { 366 if (value < upperValue) { 367 if (value > lowerValue) { 368 model_>setInternalStatus(iSequence, AbcSimplex::superBasic); 369 } else { 370 // set to lower bound as infeasible 371 solution[iSequence] = lowerValue; 372 value = lowerValue; 373 } 374 } else { 375 // set to upper bound as infeasible 376 solution[iSequence] = upperValue; 377 value = upperValue; 378 model_>setInternalStatus(iSequence, AbcSimplex::atUpperBound); 379 } 380 } 381 } else if (fabs(value  lowerValue) > primalTolerance) { 382 solution[iSequence] = lowerValue; 383 value = lowerValue; 384 } 391 385 } else { 392 393 394 395 396 397 398 399 400 386 // Set to nearest and make at bound 387 if (fabs(value  lowerValue) < fabs(value  upperValue)) { 388 solution[iSequence] = lowerValue; 389 value = lowerValue; 390 } else { 391 solution[iSequence] = upperValue; 392 value = upperValue; 393 model_>setInternalStatus(iSequence, AbcSimplex::atUpperBound); 394 } 401 395 } 402 396 break; … … 409 403 setOriginalStatus(status_[iSequence], newWhere); 410 404 if (newWhere == CLP_BELOW_LOWER) { 411 412 413 414 405 bound_[iSequence] = upperValue; 406 upperValue = lowerValue; 407 lowerValue = COIN_DBL_MAX; 408 costValue = trueCost  infeasibilityCost; 415 409 } else if (newWhere == CLP_ABOVE_UPPER) { 416 417 418 419 410 bound_[iSequence] = lowerValue; 411 lowerValue = upperValue; 412 upperValue = COIN_DBL_MAX; 413 costValue = trueCost + infeasibilityCost; 420 414 } else { 421 415 costValue = trueCost; 422 416 } 423 417 lower[iSequence] = lowerValue; … … 431 425 } 432 426 // Puts feasible bounds into lower and upper 433 void 434 AbcNonLinearCost::feasibleBounds() 427 void AbcNonLinearCost::feasibleBounds() 435 428 { 436 429 int iSequence; 437 double * 438 double * 439 double * 430 double *upper = model_>upperRegion(); 431 double *lower = model_>lowerRegion(); 432 double *cost = model_>costRegion(); 440 433 int numberTotal = numberColumns_ + numberRows_; 441 434 for (iSequence = 0; iSequence < numberTotal; iSequence++) { 442 435 unsigned char iStatus = status_[iSequence]; 443 assert 436 assert(currentStatus(iStatus) == CLP_SAME); 444 437 double lowerValue = lower[iSequence]; 445 438 double upperValue = upper[iSequence]; … … 449 442 lowerValue = upperValue; 450 443 upperValue = bound_[iSequence]; 451 assert 444 assert(fabs(lowerValue) < 1.0e100); 452 445 } else if (iWhere == CLP_ABOVE_UPPER) { 453 446 upperValue = lowerValue; … … 460 453 } 461 454 } 462 void 463 AbcNonLinearCost::goBackAll(const CoinIndexedVector * update) 464 { 465 assert (model_ != NULL); 466 const int * pivotVariable = model_>pivotVariable(); 455 void AbcNonLinearCost::goBackAll(const CoinIndexedVector *update) 456 { 457 assert(model_ != NULL); 458 const int *pivotVariable = model_>pivotVariable(); 467 459 int number = update>getNumElements(); 468 const int * 460 const int *index = update>getIndices(); 469 461 for (int i = 0; i < number; i++) { 470 462 int iRow = index[i]; … … 473 465 } 474 466 } 475 void 476 AbcNonLinearCost::checkInfeasibilities(int numberInArray, const int * index) 477 { 478 assert (model_ != NULL); 467 void AbcNonLinearCost::checkInfeasibilities(int numberInArray, const int *index) 468 { 469 assert(model_ != NULL); 479 470 double primalTolerance = model_>currentPrimalTolerance(); 480 const int * 481 double * 482 double * 483 double * 484 double * 485 double * 486 double * 487 double * 471 const int *pivotVariable = model_>pivotVariable(); 472 double *upper = model_>upperRegion(); 473 double *lower = model_>lowerRegion(); 474 double *cost = model_>costRegion(); 475 double *solutionBasic = model_>solutionBasic(); 476 double *upperBasic = model_>upperBasic(); 477 double *lowerBasic = model_>lowerBasic(); 478 double *costBasic = model_>costBasic(); 488 479 for (int i = 0; i < numberInArray; i++) { 489 480 int iRow = index[i]; … … 491 482 double value = solutionBasic[iRow]; 492 483 unsigned char iStatus = status_[iSequence]; 493 assert 484 assert(currentStatus(iStatus) == CLP_SAME); 494 485 double lowerValue = lowerBasic[iRow]; 495 486 double upperValue = upperBasic[iRow]; … … 500 491 upperValue = bound_[iSequence]; 501 492 numberInfeasibilities_; 502 assert 493 assert(fabs(lowerValue) < 1.0e100); 503 494 } else if (iWhere == CLP_ABOVE_UPPER) { 504 495 upperValue = lowerValue; … … 510 501 if (value  upperValue <= primalTolerance) { 511 502 if (value  lowerValue >= primalTolerance) { 512 513 503 // feasible 504 //newWhere=CLP_FEASIBLE; 514 505 } else { 515 516 517 assert(fabs(lowerValue) < 1.0e100);518 519 506 // below 507 newWhere = CLP_BELOW_LOWER; 508 assert(fabs(lowerValue) < 1.0e100); 509 costValue = infeasibilityWeight_; 510 numberInfeasibilities_++; 520 511 } 521 512 } else { … … 528 519 setOriginalStatus(status_[iSequence], newWhere); 529 520 if (newWhere == CLP_BELOW_LOWER) { 530 531 532 521 bound_[iSequence] = upperValue; 522 upperValue = lowerValue; 523 lowerValue = COIN_DBL_MAX; 533 524 } else if (newWhere == CLP_ABOVE_UPPER) { 534 535 536 525 bound_[iSequence] = lowerValue; 526 lowerValue = upperValue; 527 upperValue = COIN_DBL_MAX; 537 528 } 538 529 lower[iSequence] = lowerValue; … … 551 542 changed costs will be stored as normal CoinIndexedVector 552 543 */ 553 void 554 AbcNonLinearCost::checkChanged(int numberInArray, CoinIndexedVector * update) 555 { 556 assert (model_ != NULL); 544 void AbcNonLinearCost::checkChanged(int numberInArray, CoinIndexedVector *update) 545 { 546 assert(model_ != NULL); 557 547 double primalTolerance = model_>currentPrimalTolerance(); 558 const int * 548 const int *pivotVariable = model_>pivotVariable(); 559 549 int number = 0; 560 int * 561 double * 562 double * 563 double * 564 double * 565 double * 566 double * 567 double * 568 double * 550 int *index = update>getIndices(); 551 double *work = update>denseVector(); 552 double *upper = model_>upperRegion(); 553 double *lower = model_>lowerRegion(); 554 double *cost = model_>costRegion(); 555 double *solutionBasic = model_>solutionBasic(); 556 double *upperBasic = model_>upperBasic(); 557 double *lowerBasic = model_>lowerBasic(); 558 double *costBasic = model_>costBasic(); 569 559 for (int i = 0; i < numberInArray; i++) { 570 560 int iRow = index[i]; … … 572 562 double value = solutionBasic[iRow]; 573 563 unsigned char iStatus = status_[iSequence]; 574 assert 564 assert(currentStatus(iStatus) == CLP_SAME); 575 565 double lowerValue = lowerBasic[iRow]; 576 566 double upperValue = upperBasic[iRow]; … … 581 571 upperValue = bound_[iSequence]; 582 572 numberInfeasibilities_; 583 assert 573 assert(fabs(lowerValue) < 1.0e100); 584 574 } else if (iWhere == CLP_ABOVE_UPPER) { 585 575 upperValue = lowerValue; … … 591 581 if (value  upperValue <= primalTolerance) { 592 582 if (value  lowerValue >= primalTolerance) { 593 594 583 // feasible 584 //newWhere=CLP_FEASIBLE; 595 585 } else { 596 597 598 599 600 assert(fabs(lowerValue) < 1.0e100);586 // below 587 newWhere = CLP_BELOW_LOWER; 588 costValue = infeasibilityWeight_; 589 numberInfeasibilities_++; 590 assert(fabs(lowerValue) < 1.0e100); 601 591 } 602 592 } else { … … 611 601 setOriginalStatus(status_[iSequence], newWhere); 612 602 if (newWhere == CLP_BELOW_LOWER) { 613 614 615 603 bound_[iSequence] = upperValue; 604 upperValue = lowerValue; 605 lowerValue = COIN_DBL_MAX; 616 606 } else if (newWhere == CLP_ABOVE_UPPER) { 617 618 619 607 bound_[iSequence] = lowerValue; 608 lowerValue = upperValue; 609 upperValue = COIN_DBL_MAX; 620 610 } 621 611 lower[iSequence] = lowerValue; … … 633 623 AbcNonLinearCost::setOne(int iSequence, double value) 634 624 { 635 assert 625 assert(model_ != NULL); 636 626 double primalTolerance = model_>currentPrimalTolerance(); 637 627 // difference in cost 638 628 double difference = 0.0; 639 double * 640 double * 641 double * 629 double *upper = model_>upperRegion(); 630 double *lower = model_>lowerRegion(); 631 double *cost = model_>costRegion(); 642 632 unsigned char iStatus = status_[iSequence]; 643 assert 633 assert(currentStatus(iStatus) == CLP_SAME); 644 634 double lowerValue = lower[iSequence]; 645 635 double upperValue = upper[iSequence]; … … 650 640 upperValue = bound_[iSequence]; 651 641 numberInfeasibilities_; 652 assert 642 assert(fabs(lowerValue) < 1.0e100); 653 643 } else if (iWhere == CLP_ABOVE_UPPER) { 654 644 upperValue = lowerValue; … … 667 657 costValue = infeasibilityWeight_; 668 658 numberInfeasibilities_++; 669 assert 659 assert(fabs(lowerValue) < 1.0e100); 670 660 } 671 661 } else { … … 695 685 model_>setInternalStatus(iSequence, AbcSimplex::isFixed); 696 686 } 697 switch (status) {698 687 switch (status) { 688 699 689 case AbcSimplex::basic: 700 690 case AbcSimplex::superBasic: … … 722 712 AbcNonLinearCost::setOneBasic(int iRow, double value) 723 713 { 724 assert 725 int iSequence =model_>pivotVariable()[iRow];714 assert(model_ != NULL); 715 int iSequence = model_>pivotVariable()[iRow]; 726 716 double primalTolerance = model_>currentPrimalTolerance(); 727 717 // difference in cost 728 718 double difference = 0.0; 729 double * 730 double * 731 double * 732 double * 733 double * 734 double * 719 double *upper = model_>upperRegion(); 720 double *lower = model_>lowerRegion(); 721 double *cost = model_>costRegion(); 722 double *upperBasic = model_>upperBasic(); 723 double *lowerBasic = model_>lowerBasic(); 724 double *costBasic = model_>costBasic(); 735 725 unsigned char iStatus = status_[iSequence]; 736 assert 726 assert(currentStatus(iStatus) == CLP_SAME); 737 727 double lowerValue = lowerBasic[iRow]; 738 728 double upperValue = upperBasic[iRow]; … … 743 733 upperValue = bound_[iSequence]; 744 734 numberInfeasibilities_; 745 assert 735 assert(fabs(lowerValue) < 1.0e100); 746 736 } else if (iWhere == CLP_ABOVE_UPPER) { 747 737 upperValue = lowerValue; … … 760 750 costValue = infeasibilityWeight_; 761 751 numberInfeasibilities_++; 762 assert 752 assert(fabs(lowerValue) < 1.0e100); 763 753 } 764 754 } else { … … 793 783 may change value 794 784 Returns direction */ 795 int 796 AbcNonLinearCost::setOneOutgoing(int iRow, double & value) 797 { 798 assert (model_ != NULL); 799 int iSequence=model_>pivotVariable()[iRow]; 785 int AbcNonLinearCost::setOneOutgoing(int iRow, double &value) 786 { 787 assert(model_ != NULL); 788 int iSequence = model_>pivotVariable()[iRow]; 800 789 double primalTolerance = model_>currentPrimalTolerance(); 801 790 // difference in cost 802 791 double difference = 0.0; 803 792 int direction = 0; 804 double * 805 double * 806 double * 807 double * 808 double * 793 double *upper = model_>upperRegion(); 794 double *lower = model_>lowerRegion(); 795 double *cost = model_>costRegion(); 796 double *upperBasic = model_>upperBasic(); 797 double *lowerBasic = model_>lowerBasic(); 809 798 unsigned char iStatus = status_[iSequence]; 810 assert 799 assert(currentStatus(iStatus) == CLP_SAME); 811 800 double lowerValue = lowerBasic[iRow]; 812 801 double upperValue = upperBasic[iRow]; … … 826 815 upperValue = bound_[iSequence]; 827 816 numberInfeasibilities_; 828 assert 817 assert(fabs(lowerValue) < 1.0e100); 829 818 } else if (iWhere == CLP_ABOVE_UPPER) { 830 819 upperValue = lowerValue; … … 846 835 costValue = infeasibilityWeight_; 847 836 numberInfeasibilities_++; 848 assert 837 assert(fabs(lowerValue) < 1.0e100); 849 838 } 850 839 } else { … … 891 880 AbcNonLinearCost::nearest(int iRow, double solutionValue) 892 881 { 893 assert 894 int iSequence =model_>pivotVariable()[iRow];882 assert(model_ != NULL); 883 int iSequence = model_>pivotVariable()[iRow]; 895 884 double nearest = 0.0; 896 const double * 897 const double * 885 const double *upperBasic = model_>upperBasic(); 886 const double *lowerBasic = model_>lowerBasic(); 898 887 double lowerValue = lowerBasic[iRow]; 899 888 double upperValue = upperBasic[iRow]; … … 902 891 lowerValue = upperValue; 903 892 upperValue = bound_[iSequence]; 904 assert 893 assert(fabs(lowerValue) < 1.0e100); 905 894 } else if (iWhere == CLP_ABOVE_UPPER) { 906 895 upperValue = lowerValue; … … 919 908 double value; 920 909 model_>getDblParam(ClpObjOffset, value); 921 return (feasibleCost_ + model_>objectiveAsObject()>nonlinearOffset()) * model_>optimizationDirection() / 922 (model_>objectiveScale() * model_>rhsScale())  value; 910 return (feasibleCost_ + model_>objectiveAsObject()>nonlinearOffset()) * model_>optimizationDirection() / (model_>objectiveScale() * model_>rhsScale())  value; 923 911 } 924 912 // Get rid of real costs (just for moment) 925 void 926 AbcNonLinearCost::zapCosts() 913 void AbcNonLinearCost::zapCosts() 927 914 { 928 915 } 929 916 #ifdef VALIDATE 930 917 // For debug 931 void 932 AbcNonLinearCost::validate() 918 void AbcNonLinearCost::validate() 933 919 { 934 920 double primalTolerance = model_>currentPrimalTolerance(); 935 921 int iSequence; 936 const double * 937 const double * 938 const double * 939 const double * 922 const double *solution = model_>solutionRegion(); 923 const double *upper = model_>upperRegion(); 924 const double *lower = model_>lowerRegion(); 925 const double *cost = model_>costRegion(); 940 926 double infeasibilityCost = model_>infeasibilityCost(); 941 927 int numberTotal = numberRows_ + numberColumns_; 942 928 int numberInfeasibilities = 0; 943 929 double sumInfeasibilities = 0.0; 944 930 945 931 for (iSequence = 0; iSequence < numberTotal; iSequence++) { 946 932 double value = solution[iSequence]; 947 933 int iStatus = status_[iSequence]; 948 assert 934 assert(currentStatus(iStatus) == CLP_SAME); 949 935 double lowerValue = lower[iSequence]; 950 936 double upperValue = upper[iSequence]; 951 double costValue = cost_[iSequence]; 937 double costValue = cost_[iSequence]; 952 938 int iWhere = originalStatus(iStatus); 953 939 if (iWhere == CLP_BELOW_LOWER) { 954 940 lowerValue = upperValue; 955 941 upperValue = bound_[iSequence]; 956 assert 942 assert(fabs(lowerValue) < 1.0e100); 957 943 costValue = infeasibilityCost; 958 assert 944 assert(value <= lowerValue  primalTolerance); 959 945 numberInfeasibilities++; 960 946 sumInfeasibilities += lowerValue  value  primalTolerance; 961 assert 947 assert(model_>getInternalStatus(iSequence) == AbcSimplex::basic); 962 948 } else if (iWhere == CLP_ABOVE_UPPER) { 963 949 upperValue = lowerValue; 964 950 lowerValue = bound_[iSequence]; 965 951 costValue += infeasibilityCost; 966 assert 952 assert(value >= upperValue + primalTolerance); 967 953 numberInfeasibilities++; 968 954 sumInfeasibilities += value  upperValue  primalTolerance; 969 assert 955 assert(model_>getInternalStatus(iSequence) == AbcSimplex::basic); 970 956 } else { 971 assert 972 } 973 assert 974 assert 975 assert 957 assert(value >= lowerValue  primalTolerance && value <= upperValue + primalTolerance); 958 } 959 assert(lowerValue == saveLowerV[iSequence]); 960 assert(upperValue == saveUpperV[iSequence]); 961 assert(costValue == cost[iSequence]); 976 962 } 977 963 if (numberInfeasibilities) 978 964 printf("JJ %d infeasibilities summing to %g\n", 979 965 numberInfeasibilities, sumInfeasibilities); 980 966 } 981 967 #endif 968 969 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2 970 */
Note: See TracChangeset
for help on using the changeset viewer.