Skip to content

Commit fb32f5b

Browse files
committed
Moved formSimplexLpBasisAndFactor, accommodateAlienBasis and considerScaling from lp_data/HighsSolution to simplex/HSimplex
1 parent 89e7186 commit fb32f5b

File tree

7 files changed

+825
-820
lines changed

7 files changed

+825
-820
lines changed

highs/lp_data/HighsLpSolverObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* Available as open-source under the MIT License */
66
/* */
77
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8-
/**@file simplex/HighsLpSolverObject.h
8+
/**@file lp_data/HighsLpSolverObject.h
99
* @brief Collection of class instances required to solve an LP
1010
*/
1111
#ifndef LP_DATA_HIGHS_LP_SOLVER_OBJECT_H_

highs/lp_data/HighsLpUtils.cpp

Lines changed: 0 additions & 662 deletions
Large diffs are not rendered by default.

highs/lp_data/HighsLpUtils.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ void relaxSemiVariables(HighsLp& lp, bool& made_semi_variable_mods);
9292
bool activeModifiedUpperBounds(const HighsOptions& options, const HighsLp& lp,
9393
const std::vector<double> col_value);
9494

95-
bool considerScaling(const HighsOptions& options, HighsLp& lp);
96-
void scaleLp(const HighsOptions& options, HighsLp& lp,
97-
const bool force_scaling = false);
98-
bool equilibrationScaleMatrix(const HighsOptions& options, HighsLp& lp,
99-
const HighsInt use_scale_strategy);
100-
bool maxValueScaleMatrix(const HighsOptions& options, HighsLp& lp,
101-
const HighsInt use_scale_strategy);
102-
103-
HighsStatus applyScalingToLpCol(HighsLp& lp, const HighsInt col,
104-
const double colScale);
105-
106-
HighsStatus applyScalingToLpRow(HighsLp& lp, const HighsInt row,
107-
const double rowScale);
108-
109-
void unscaleSolution(HighsSolution& solution, const HighsScale& scale);
110-
11195
void appendColsToLpVectors(HighsLp& lp, const HighsInt num_new_col,
11296
const vector<double>& colCost,
11397
const vector<double>& colLower,

highs/lp_data/HighsSolution.cpp

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,139 +1503,6 @@ HighsStatus ipxBasicSolutionToHighsBasicSolution(
15031503
return HighsStatus::kOk;
15041504
}
15051505

1506-
HighsStatus formSimplexLpBasisAndFactorReturn(
1507-
const HighsStatus return_status, HighsLpSolverObject& solver_object) {
1508-
HighsLp& lp = solver_object.lp_;
1509-
HighsLp& ekk_lp = solver_object.ekk_instance_.lp_;
1510-
if (lp.is_moved_) lp.moveBackLpAndUnapplyScaling(ekk_lp);
1511-
return return_status;
1512-
}
1513-
1514-
HighsStatus formSimplexLpBasisAndFactor(HighsLpSolverObject& solver_object,
1515-
const bool only_from_known_basis) {
1516-
// Ideally, forms a SimplexBasis from the HighsBasis in the
1517-
// HighsLpSolverObject
1518-
//
1519-
// If only_from_known_basis is true and
1520-
// initialiseSimplexLpBasisAndFactor finds that there is no simplex
1521-
// basis, then its error return is passed down
1522-
//
1523-
// If only_from_known_basis is false, then the basis is completed
1524-
// with logicals if it is rank deficient (from singularity or being
1525-
// incomplete)
1526-
//
1527-
HighsStatus return_status = HighsStatus::kOk;
1528-
HighsStatus call_status;
1529-
HighsLp& lp = solver_object.lp_;
1530-
HighsBasis& basis = solver_object.basis_;
1531-
HighsOptions& options = solver_object.options_;
1532-
HEkk& ekk_instance = solver_object.ekk_instance_;
1533-
HighsSimplexStatus& ekk_status = ekk_instance.status_;
1534-
lp.ensureColwise();
1535-
const bool passed_scaled = lp.is_scaled_;
1536-
// Consider scaling the LP
1537-
if (!passed_scaled) considerScaling(options, lp);
1538-
const bool check_basis = basis.alien || (!basis.valid && basis.useful);
1539-
if (check_basis) {
1540-
// The basis needs to be checked for rank deficiency, and possibly
1541-
// completed if it is rectangular
1542-
//
1543-
// If it's not valid but useful, but not alien,
1544-
// accommodateAlienBasis will assert, so make the basis alien
1545-
basis.alien = true;
1546-
assert(!only_from_known_basis);
1547-
accommodateAlienBasis(solver_object);
1548-
basis.alien = false;
1549-
// Unapply any scaling used only for factorization to check and
1550-
// complete the basis
1551-
if (!passed_scaled) lp.unapplyScale();
1552-
// Check that any scaling the LP arrived with has not been removed
1553-
assert(lp.is_scaled_ == passed_scaled);
1554-
return HighsStatus::kOk;
1555-
}
1556-
// Move the HighsLpSolverObject's LP to EKK
1557-
ekk_instance.moveLp(solver_object);
1558-
if (!ekk_status.has_basis) {
1559-
// The Ekk instance has no simplex basis, so pass the HiGHS basis
1560-
HighsStatus call_status = ekk_instance.setBasis(basis);
1561-
return_status = interpretCallStatus(options.log_options, call_status,
1562-
return_status, "setBasis");
1563-
if (return_status == HighsStatus::kError)
1564-
return formSimplexLpBasisAndFactorReturn(return_status, solver_object);
1565-
}
1566-
// Now form the invert
1567-
assert(ekk_status.has_basis);
1568-
call_status =
1569-
ekk_instance.initialiseSimplexLpBasisAndFactor(only_from_known_basis);
1570-
// If the current basis cannot be inverted, return an error
1571-
if (call_status != HighsStatus::kOk)
1572-
return formSimplexLpBasisAndFactorReturn(HighsStatus::kError,
1573-
solver_object);
1574-
// Once the invert is formed, move back the LP and remove any scaling.
1575-
return formSimplexLpBasisAndFactorReturn(HighsStatus::kOk, solver_object);
1576-
}
1577-
1578-
void accommodateAlienBasis(HighsLpSolverObject& solver_object) {
1579-
HighsLp& lp = solver_object.lp_;
1580-
HighsBasis& basis = solver_object.basis_;
1581-
HighsOptions& options = solver_object.options_;
1582-
assert(basis.alien);
1583-
HighsInt num_row = lp.num_row_;
1584-
HighsInt num_col = lp.num_col_;
1585-
assert((int)basis.col_status.size() >= num_col);
1586-
assert((int)basis.row_status.size() >= num_row);
1587-
std::vector<HighsInt> basic_index;
1588-
for (HighsInt iCol = 0; iCol < num_col; iCol++) {
1589-
if (basis.col_status[iCol] == HighsBasisStatus::kBasic)
1590-
basic_index.push_back(iCol);
1591-
}
1592-
for (HighsInt iRow = 0; iRow < num_row; iRow++) {
1593-
if (basis.row_status[iRow] == HighsBasisStatus::kBasic)
1594-
basic_index.push_back(num_col + iRow);
1595-
}
1596-
HighsInt num_basic_variables = basic_index.size();
1597-
HFactor factor;
1598-
factor.setupGeneral(&lp.a_matrix_, num_basic_variables, basic_index.data(),
1599-
kDefaultPivotThreshold, kDefaultPivotTolerance,
1600-
kHighsDebugLevelMin, &options.log_options);
1601-
HighsInt rank_deficiency = factor.build();
1602-
// Must not have timed out
1603-
assert(rank_deficiency >= 0);
1604-
// Deduce the basis from basic_index
1605-
//
1606-
// Set all basic variables to nonbasic
1607-
for (HighsInt iCol = 0; iCol < num_col; iCol++) {
1608-
if (basis.col_status[iCol] == HighsBasisStatus::kBasic)
1609-
basis.col_status[iCol] = HighsBasisStatus::kNonbasic;
1610-
}
1611-
for (HighsInt iRow = 0; iRow < num_row; iRow++) {
1612-
if (basis.row_status[iRow] == HighsBasisStatus::kBasic)
1613-
basis.row_status[iRow] = HighsBasisStatus::kNonbasic;
1614-
}
1615-
// Set at most the first num_row variables in basic_index to basic
1616-
const HighsInt use_basic_variables = std::min(num_row, num_basic_variables);
1617-
// num_basic_variables is no longer needed, so can be used as a check
1618-
num_basic_variables = 0;
1619-
for (HighsInt iRow = 0; iRow < use_basic_variables; iRow++) {
1620-
HighsInt iVar = basic_index[iRow];
1621-
if (iVar < num_col) {
1622-
basis.col_status[iVar] = HighsBasisStatus::kBasic;
1623-
} else {
1624-
basis.row_status[iVar - num_col] = HighsBasisStatus::kBasic;
1625-
}
1626-
num_basic_variables++;
1627-
}
1628-
// Complete the assignment of basic variables using the logicals of
1629-
// non-pivotal rows
1630-
const HighsInt num_missing = num_row - num_basic_variables;
1631-
for (HighsInt k = 0; k < num_missing; k++) {
1632-
HighsInt iRow = factor.row_with_no_pivot[rank_deficiency + k];
1633-
basis.row_status[iRow] = HighsBasisStatus::kBasic;
1634-
num_basic_variables++;
1635-
}
1636-
assert(num_basic_variables == num_row);
1637-
}
1638-
16391506
void resetModelStatusAndHighsInfo(HighsLpSolverObject& solver_object) {
16401507
resetModelStatusAndHighsInfo(solver_object.model_status_,
16411508
solver_object.highs_info_);

highs/lp_data/HighsSolution.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ HighsStatus ipxBasicSolutionToHighsBasicSolution(
135135
const IpxSolution& ipx_solution, HighsBasis& highs_basis,
136136
HighsSolution& highs_solution);
137137

138-
HighsStatus formSimplexLpBasisAndFactorReturn(
139-
const HighsStatus return_status, HighsLpSolverObject& solver_object);
140-
HighsStatus formSimplexLpBasisAndFactor(
141-
HighsLpSolverObject& solver_object,
142-
const bool only_from_known_basis = false);
143-
144-
void accommodateAlienBasis(HighsLpSolverObject& solver_object);
145-
146138
void resetModelStatusAndHighsInfo(HighsLpSolverObject& solver_object);
147139
void resetModelStatusAndHighsInfo(HighsModelStatus& model_status,
148140
HighsInfo& highs_info);

0 commit comments

Comments
 (0)