| 1575 | } |
| 1576 | |
| 1577 | std::string findModelObjectiveName(const HighsLp* lp, |
| 1578 | const HighsHessian* hessian) { |
| 1579 | // Return any non-trivial current objective name |
| 1580 | if (lp->objective_name_ != "") return lp->objective_name_; |
| 1581 | |
| 1582 | std::string objective_name = ""; |
| 1583 | // Determine whether there is a nonzero cost vector |
| 1584 | bool has_objective = false; |
| 1585 | for (HighsInt iCol = 0; iCol < lp->num_col_; iCol++) { |
| 1586 | if (lp->col_cost_[iCol]) { |
| 1587 | has_objective = true; |
| 1588 | break; |
| 1589 | } |
| 1590 | } |
| 1591 | if (!has_objective && hessian) { |
| 1592 | // Zero cost vector, so only chance of an objective comes from any |
| 1593 | // Hessian |
| 1594 | has_objective = (hessian->dim_ != 0); |
| 1595 | } |
| 1596 | HighsInt pass = 0; |
| 1597 | for (;;) { |
| 1598 | // Loop until a valid name is found. Vanishingly unlikely to have |
| 1599 | // to pass more than once, since check for objective name |
| 1600 | // duplicating a row name is very unlikely to fail |
| 1601 | // |
| 1602 | // So set up an appropriate name (stem) |
| 1603 | if (has_objective) { |
| 1604 | objective_name = "Obj"; |
| 1605 | } else { |
| 1606 | objective_name = "NoObj"; |
| 1607 | } |
| 1608 | // If there are no row names, then the objective name is certainly |
| 1609 | // OK |
| 1610 | if (lp->row_names_.size() == 0) break; |
| 1611 | if (pass != 0) objective_name += std::to_string(pass); |
| 1612 | // Ensure that the objective name doesn't clash with any row names |
| 1613 | bool ok_objective_name = true; |
| 1614 | for (HighsInt iRow = 0; iRow < lp->num_row_; iRow++) { |
| 1615 | std::string trimmed_name = lp->row_names_[iRow]; |
| 1616 | trimmed_name = trim(trimmed_name); |
| 1617 | if (objective_name == trimmed_name) { |
| 1618 | ok_objective_name = false; |
| 1619 | break; |
| 1620 | } |
| 1621 | } |
| 1622 | if (ok_objective_name) break; |
| 1623 | pass++; |
| 1624 | } |
| 1625 | assert(objective_name != ""); |
| 1626 | return objective_name; |
| 1627 | } |
| 1628 | |
| 1629 | /* |
| 1630 | void print_map(std::string comment, const std::map<std::string, HighsInt>& m) |
no test coverage detected