| 2440 | } |
| 2441 | |
| 2442 | void HEkk::initialiseCost(const SimplexAlgorithm algorithm, |
| 2443 | const HighsInt solve_phase, const bool perturb) { |
| 2444 | // Copy the cost |
| 2445 | initialiseLpColCost(); |
| 2446 | initialiseLpRowCost(); |
| 2447 | info_.costs_shifted = false; |
| 2448 | info_.costs_perturbed = false; |
| 2449 | analysis_.net_num_single_cost_shift = 0; |
| 2450 | // Primal simplex costs are either from the LP or set specially in phase 1 |
| 2451 | if (algorithm == SimplexAlgorithm::kPrimal) return; |
| 2452 | // Dual simplex costs are either from the LP or perturbed |
| 2453 | if (!perturb || info_.dual_simplex_cost_perturbation_multiplier == 0) return; |
| 2454 | // Perturb the original costs, scale down if is too big |
| 2455 | const bool report_cost_perturbation = |
| 2456 | options_->output_flag; // && analysis_.analyse_simplex_runtime_data; |
| 2457 | HighsInt num_original_nonzero_cost = 0; |
| 2458 | if (report_cost_perturbation) |
| 2459 | highsLogDev(options_->log_options, HighsLogType::kInfo, |
| 2460 | "Cost perturbation for %s\n", lp_.model_name_.c_str()); |
| 2461 | double min_abs_cost = kHighsInf; |
| 2462 | double max_abs_cost = 0; |
| 2463 | double sum_abs_cost = 0; |
| 2464 | for (HighsInt i = 0; i < lp_.num_col_; i++) { |
| 2465 | const double abs_cost = fabs(info_.workCost_[i]); |
| 2466 | if (report_cost_perturbation) { |
| 2467 | if (abs_cost) { |
| 2468 | num_original_nonzero_cost++; |
| 2469 | min_abs_cost = min(min_abs_cost, abs_cost); |
| 2470 | } |
| 2471 | sum_abs_cost += abs_cost; |
| 2472 | } |
| 2473 | max_abs_cost = max(max_abs_cost, abs_cost); |
| 2474 | } |
| 2475 | const HighsInt pct0 = (100 * num_original_nonzero_cost) / lp_.num_col_; |
| 2476 | double average_abs_cost = 0; |
| 2477 | if (report_cost_perturbation) { |
| 2478 | highsLogDev(options_->log_options, HighsLogType::kInfo, |
| 2479 | " Initially have %" HIGHSINT_FORMAT |
| 2480 | " nonzero costs (%3" HIGHSINT_FORMAT "%%)", |
| 2481 | num_original_nonzero_cost, pct0); |
| 2482 | if (num_original_nonzero_cost) { |
| 2483 | average_abs_cost = sum_abs_cost / num_original_nonzero_cost; |
| 2484 | highsLogDev(options_->log_options, HighsLogType::kInfo, |
| 2485 | " with min / average / max = %g / %g / %g\n", min_abs_cost, |
| 2486 | average_abs_cost, max_abs_cost); |
| 2487 | } else { |
| 2488 | min_abs_cost = 1.0; |
| 2489 | max_abs_cost = 1.0; |
| 2490 | average_abs_cost = 1.0; |
| 2491 | highsLogDev(options_->log_options, HighsLogType::kInfo, |
| 2492 | " but perturb as if max cost was 1\n"); |
| 2493 | } |
| 2494 | } |
| 2495 | if (max_abs_cost > 100) { |
| 2496 | max_abs_cost = sqrt(sqrt(max_abs_cost)); |
| 2497 | if (report_cost_perturbation) |
| 2498 | highsLogDev( |
| 2499 | options_->log_options, HighsLogType::kInfo, |
no test coverage detected