Skip to content

Commit 023eade

Browse files
committed
Rmoved unnecessary methods and erroneous calls
1 parent 57bf420 commit 023eade

File tree

7 files changed

+50
-218
lines changed

7 files changed

+50
-218
lines changed

highs/lp_data/HighsInterface.cpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,6 @@ HighsStatus Highs::addColsInterface(
477477
// matrix columns
478478
local_a_matrix.start_.assign(ext_num_new_col + 1, 0);
479479
}
480-
if (lp.user_cost_scale_ || lp.user_bound_scale_) {
481-
HighsUserScaleData user_scale_data;
482-
initialiseUserScaleData(lp, options_, user_scale_data);
483-
return_status =
484-
userScaleNewCols(local_colCost, local_colLower, local_colUpper,
485-
local_a_matrix, user_scale_data, options.log_options);
486-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
487-
}
488480
// Append the columns to the LP vectors and matrix
489481
appendColsToLpVectors(lp, ext_num_new_col, local_colCost, local_colLower,
490482
local_colUpper);
@@ -615,17 +607,6 @@ HighsStatus Highs::addRowsInterface(HighsInt ext_num_new_row,
615607
// rows
616608
local_ar_matrix.start_.assign(ext_num_new_row + 1, 0);
617609
}
618-
if (lp.user_bound_scale_) {
619-
HighsUserScaleData user_scale_data;
620-
initialiseUserScaleData(lp, options_, user_scale_data);
621-
const bool apply = false;
622-
userScaleNewRows(lp.integrality_, local_rowLower, local_rowUpper,
623-
local_ar_matrix, user_scale_data, apply);
624-
return_status = userScaleStatus(options.log_options, user_scale_data);
625-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
626-
userScaleNewRows(lp.integrality_, local_rowLower, local_rowUpper,
627-
local_ar_matrix, user_scale_data);
628-
}
629610
// Append the rows to the LP vectors
630611
appendRowsToLpVectors(lp, ext_num_new_row, local_rowLower, local_rowUpper);
631612
// Append the rows to LP matrix
@@ -939,13 +920,6 @@ HighsStatus Highs::changeCostsInterface(HighsIndexCollection& index_collection,
939920
return_status, "assessCosts");
940921
if (return_status == HighsStatus::kError) return return_status;
941922
HighsLp& lp = model_.lp_;
942-
if (lp.user_cost_scale_) {
943-
HighsUserScaleData user_scale_data;
944-
initialiseUserScaleData(lp, options_, user_scale_data);
945-
userScaleCosts(lp.integrality_, local_colCost, user_scale_data,
946-
options_.log_options);
947-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
948-
}
949923
changeLpCosts(lp, index_collection, local_colCost, options_.infinite_cost);
950924
// Interpret possible introduction of infinite costs
951925
lp.has_infinite_cost_ = lp.has_infinite_cost_ || local_has_infinite_cost;
@@ -990,14 +964,6 @@ HighsStatus Highs::changeColBoundsInterface(
990964
return_status, "assessBounds");
991965
if (return_status == HighsStatus::kError) return return_status;
992966
HighsLp& lp = model_.lp_;
993-
if (lp.user_bound_scale_) {
994-
HighsUserScaleData user_scale_data;
995-
initialiseUserScaleData(lp, options_, user_scale_data);
996-
return_status =
997-
userScaleColBounds(lp.integrality_, local_colLower, local_colUpper,
998-
user_scale_data, options_.log_options);
999-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
1000-
}
1001967
changeLpColBounds(lp, index_collection, local_colLower, local_colUpper);
1002968
// Update HiGHS basis status and (any) simplex move status of
1003969
// nonbasic variables whose bounds have changed
@@ -1041,13 +1007,6 @@ HighsStatus Highs::changeRowBoundsInterface(
10411007
return_status, "assessBounds");
10421008
if (return_status == HighsStatus::kError) return return_status;
10431009
HighsLp& lp = model_.lp_;
1044-
if (lp.user_bound_scale_) {
1045-
HighsUserScaleData user_scale_data;
1046-
initialiseUserScaleData(lp, options_, user_scale_data);
1047-
return_status = userScaleRowBounds(local_rowLower, local_rowUpper,
1048-
user_scale_data, options_.log_options);
1049-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
1050-
}
10511010
changeLpRowBounds(lp, index_collection, local_rowLower, local_rowUpper);
10521011
// Update HiGHS basis status and (any) simplex move status of
10531012
// nonbasic variables whose bounds have changed
@@ -3032,7 +2991,6 @@ HighsStatus Highs::optionChangeAction() {
30322991
HighsLp& lp = model.lp_;
30332992
HighsInfo& info = this->info_;
30342993
HighsOptions& options = this->options_;
3035-
HighsStatus return_status = HighsStatus::kOk;
30362994
HighsInt dl_user_cost_scale = options.user_cost_scale - lp.user_cost_scale_;
30372995
HighsInt dl_user_bound_scale =
30382996
options.user_bound_scale - lp.user_bound_scale_;
@@ -3042,10 +3000,7 @@ HighsStatus Highs::optionChangeAction() {
30423000
initialiseUserScaleData(lp, options_, user_scale_data);
30433001
user_scale_data.user_cost_scale = dl_user_cost_scale;
30443002
user_scale_data.user_bound_scale = dl_user_bound_scale;
3045-
return_status =
3046-
userScaleLp(lp.integrality_, lp.col_cost_, lp.col_lower_, lp.col_upper_,
3047-
lp.row_lower_, lp.row_upper_, lp.a_matrix_, user_scale_data,
3048-
options.log_options);
3003+
HighsStatus return_status = userScaleModel(model, user_scale_data, options.log_options);
30493004
if (return_status == HighsStatus::kError) {
30503005
options.user_cost_scale = lp.user_cost_scale_;
30513006
options.user_bound_scale = lp.user_bound_scale_;

highs/lp_data/HighsLpUtils.cpp

Lines changed: 23 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -769,86 +769,22 @@ HighsStatus cleanBounds(const HighsOptions& options, HighsLp& lp) {
769769
return HighsStatus::kOk;
770770
}
771771

772-
HighsStatus userScaleLp(const vector<HighsVarType>& integrality,
773-
vector<double>& cost, vector<double>& col_lower,
774-
vector<double>& col_upper, vector<double>& row_lower,
775-
vector<double>& row_upper, HighsSparseMatrix& matrix,
772+
HighsStatus userScaleLp(HighsLp& lp,
776773
HighsUserScaleData& data,
777774
const HighsLogOptions& log_options) {
778-
userScaleLp(integrality, cost, col_lower, col_upper, row_lower, row_upper,
779-
matrix, data, false);
775+
userScaleLp(lp, data, false);
780776
HighsStatus return_status = userScaleStatus(log_options, data);
781777
if (return_status == HighsStatus::kError) return HighsStatus::kError;
782-
userScaleLp(integrality, cost, col_lower, col_upper, row_lower, row_upper,
783-
matrix, data);
778+
userScaleLp(lp, data);
784779
return return_status;
785780
}
786781

787-
void userScaleLp(const vector<HighsVarType>& integrality, vector<double>& cost,
788-
vector<double>& col_lower, vector<double>& col_upper,
789-
vector<double>& row_lower, vector<double>& row_upper,
790-
HighsSparseMatrix& matrix, HighsUserScaleData& data,
782+
void userScaleLp(HighsLp& lp, HighsUserScaleData& data,
791783
const bool apply) {
792-
userScaleCosts(integrality, cost, data, apply);
793-
userScaleColBounds(integrality, col_lower, col_upper, data, apply);
794-
userScaleMatrix(integrality, matrix, data, apply);
795-
userScaleRowBounds(row_lower, row_upper, data, apply);
796-
}
797-
798-
// To check/apply user scaling to data for columns - used in
799-
// Highs::addColsInterface
800-
HighsStatus userScaleNewCols(vector<double>& cost, vector<double>& lower,
801-
vector<double>& upper, HighsSparseMatrix& matrix,
802-
HighsUserScaleData& data,
803-
const HighsLogOptions& log_options) {
804-
userScaleNewCols(cost, lower, upper, matrix, data, false);
805-
HighsStatus return_status = userScaleStatus(log_options, data);
806-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
807-
userScaleNewCols(cost, lower, upper, matrix, data);
808-
return return_status;
809-
}
810-
811-
void userScaleNewCols(vector<double>& cost, vector<double>& lower,
812-
vector<double>& upper, HighsSparseMatrix& matrix,
813-
HighsUserScaleData& data, const bool apply) {
814-
// Set up a dummy integrality vector since there's not yet any
815-
// integrality for these columns
816-
vector<HighsVarType> integrality;
817-
userScaleCosts(integrality, cost, data, apply);
818-
userScaleColBounds(integrality, lower, upper, data, apply);
819-
userScaleMatrix(integrality, matrix, data, apply);
820-
}
821-
822-
// To check/apply user scaling to data for rows - used in
823-
// Highs::addRowsInterface
824-
HighsStatus userScaleNewRows(const vector<HighsVarType>& integrality,
825-
vector<double>& lower, vector<double>& upper,
826-
HighsSparseMatrix& matrix,
827-
HighsUserScaleData& data,
828-
const HighsLogOptions& log_options) {
829-
userScaleNewRows(integrality, lower, upper, matrix, data, false);
830-
HighsStatus return_status = userScaleStatus(log_options, data);
831-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
832-
userScaleNewRows(integrality, lower, upper, matrix, data);
833-
return return_status;
834-
}
835-
836-
void userScaleNewRows(const vector<HighsVarType>& integrality,
837-
vector<double>& lower, vector<double>& upper,
838-
HighsSparseMatrix& matrix, HighsUserScaleData& data,
839-
const bool apply) {
840-
userScaleRowBounds(lower, upper, data, apply);
841-
userScaleMatrix(integrality, matrix, data, apply);
842-
}
843-
844-
HighsStatus userScaleCosts(const vector<HighsVarType>& integrality,
845-
vector<double>& cost, HighsUserScaleData& data,
846-
const HighsLogOptions& log_options) {
847-
userScaleCosts(integrality, cost, data, false);
848-
HighsStatus return_status = userScaleStatus(log_options, data);
849-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
850-
userScaleCosts(integrality, cost, data);
851-
return return_status;
784+
userScaleCosts(lp.integrality_, lp.col_cost_, data, apply);
785+
userScaleColBounds(lp.integrality_, lp.col_lower_, lp.col_upper_, data, apply);
786+
userScaleMatrix(lp.integrality_, lp.a_matrix_, data, apply);
787+
userScaleRowBounds(lp.row_lower_, lp.row_upper_, data, apply);
852788
}
853789

854790
void userScaleCosts(const vector<HighsVarType>& integrality,
@@ -875,17 +811,6 @@ void userScaleCosts(const vector<HighsVarType>& integrality,
875811
}
876812
}
877813

878-
HighsStatus userScaleColBounds(const vector<HighsVarType>& integrality,
879-
vector<double>& lower, vector<double>& upper,
880-
HighsUserScaleData& data,
881-
const HighsLogOptions& log_options) {
882-
userScaleColBounds(integrality, lower, upper, data, false);
883-
HighsStatus return_status = userScaleStatus(log_options, data);
884-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
885-
userScaleColBounds(integrality, lower, upper, data);
886-
return return_status;
887-
}
888-
889814
void userScaleColBounds(const vector<HighsVarType>& integrality,
890815
vector<double>& lower, vector<double>& upper,
891816
HighsUserScaleData& data, const bool apply) {
@@ -916,16 +841,6 @@ void userScaleColBounds(const vector<HighsVarType>& integrality,
916841
}
917842
}
918843

919-
HighsStatus userScaleRowBounds(vector<double>& lower, vector<double>& upper,
920-
HighsUserScaleData& data,
921-
const HighsLogOptions& log_options) {
922-
userScaleRowBounds(lower, upper, data, false);
923-
HighsStatus return_status = userScaleStatus(log_options, data);
924-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
925-
userScaleRowBounds(lower, upper, data);
926-
return return_status;
927-
}
928-
929844
void userScaleRowBounds(vector<double>& lower, vector<double>& upper,
930845
HighsUserScaleData& data, const bool apply) {
931846
data.num_infinite_row_bounds = 0;
@@ -948,16 +863,6 @@ void userScaleRowBounds(vector<double>& lower, vector<double>& upper,
948863
}
949864
}
950865

951-
HighsStatus userScaleMatrix(const vector<HighsVarType>& integrality,
952-
HighsSparseMatrix& matrix, HighsUserScaleData& data,
953-
const HighsLogOptions& log_options) {
954-
userScaleMatrix(integrality, matrix, data, false);
955-
HighsStatus return_status = userScaleStatus(log_options, data);
956-
if (return_status == HighsStatus::kError) return HighsStatus::kError;
957-
userScaleMatrix(integrality, matrix, data);
958-
return return_status;
959-
}
960-
961866
void userScaleMatrix(const vector<HighsVarType>& integrality,
962867
HighsSparseMatrix& matrix, HighsUserScaleData& data,
963868
const bool apply) {
@@ -1837,23 +1742,22 @@ HighsStatus changeLpIntegrality(HighsLp& lp,
18371742
// - which are naturally continuous
18381743
lp.integrality_.assign(lp.num_col_, HighsVarType::kContinuous);
18391744
} else if (lp.user_bound_scale_) {
1745+
// Save a copy of lp.integrality_ in case it needs to be reverted
1746+
// due to ultimate illegal scaling
1747+
save_integrality = lp.integrality_;
18401748
// Revert the user bound scaling to correspond to an LP...
18411749
//
1842-
// Unscale the costs and matrix columns, and the
1843-
// continuous bounds, by scaling with -lp.user_bound_scale_
1750+
// Use -lp.user_bound_scale_U to unscale the costs and matrix
1751+
// columns, and the continuous bounds
18441752
//
18451753
// Set up HighsUserScaleData, noting that any user cost scaling is
18461754
// unaffected
18471755
initialiseUserScaleData(lp, options, user_scale_data);
18481756
user_scale_data.user_cost_scale = 0;
18491757
user_scale_data.user_bound_scale = -lp.user_bound_scale_;
1850-
userScaleCosts(lp.integrality_, lp.col_cost_, user_scale_data);
1851-
userScaleColBounds(lp.integrality_, lp.col_lower_, lp.col_upper_,
1852-
user_scale_data);
1853-
userScaleMatrix(lp.integrality_, lp.a_matrix_, user_scale_data);
1854-
// Save a copy of lp.integrality_ in case it needs to be reverted
1855-
// due to ultimate illegal scaling
1856-
save_integrality = lp.integrality_;
1758+
// Scale, forcing changes of value
1759+
const bool apply = true;
1760+
userScaleLp(lp, user_scale_data, apply);
18571761
}
18581762

18591763
assert(HighsInt(lp.integrality_.size()) == lp.num_col_);
@@ -1879,16 +1783,14 @@ HighsStatus changeLpIntegrality(HighsLp& lp,
18791783
} else if (lp.user_bound_scale_) {
18801784
// ... and then reapply corresponding to the new integrality
18811785
//
1882-
// Scale the costs and matrix columns, and the continuous bounds,
1883-
// by scaling with lp.user_bound_scale_
1786+
// Use lp.user_bound_scale_ to scale the costs and matrix columns,
1787+
// and the continuous bounds
18841788
user_scale_data.user_bound_scale = lp.user_bound_scale_;
1885-
userScaleCosts(lp.integrality_, lp.col_cost_, user_scale_data,
1886-
options.log_options);
1887-
userScaleColBounds(lp.integrality_, lp.col_lower_, lp.col_upper_,
1888-
user_scale_data, options.log_options);
1889-
userScaleMatrix(lp.integrality_, lp.a_matrix_, user_scale_data,
1890-
options.log_options);
1891-
if (user_scale_data.scaleError()) {
1789+
1790+
// Scale, first checking and reporting illegal values, then
1791+
// forcing changes of value if no illegal values
1792+
return_status = userScaleLp(lp, user_scale_data, options.log_options);
1793+
if (return_status == HighsStatus::kError) {
18921794
lp.integrality_ = save_integrality;
18931795
return HighsStatus::kError;
18941796
}

highs/lp_data/HighsLpUtils.h

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -61,67 +61,25 @@ HighsStatus assessBounds(const HighsOptions& options, const char* type,
6161

6262
HighsStatus cleanBounds(const HighsOptions& options, HighsLp& lp);
6363

64-
HighsStatus userScaleLp(const vector<HighsVarType>& integrality,
65-
vector<double>& cost, vector<double>& col_lower,
66-
vector<double>& col_upper, vector<double>& row_lower,
67-
vector<double>& row_upper, HighsSparseMatrix& matrix,
64+
HighsStatus userScaleLp(HighsLp& lp,
6865
HighsUserScaleData& data,
6966
const HighsLogOptions& log_options);
7067

71-
void userScaleLp(const vector<HighsVarType>& integrality, vector<double>& cost,
72-
vector<double>& col_lower, vector<double>& col_upper,
73-
vector<double>& row_lower, vector<double>& row_upper,
74-
HighsSparseMatrix& matrix, HighsUserScaleData& data,
68+
void userScaleLp(HighsLp& lp,
69+
HighsUserScaleData& data,
7570
const bool apply = true);
7671

77-
HighsStatus userScaleNewCols(vector<double>& cost, vector<double>& lower,
78-
vector<double>& upper, HighsSparseMatrix& matrix,
79-
HighsUserScaleData& data,
80-
const HighsLogOptions& log_options);
81-
82-
void userScaleNewCols(vector<double>& cost, vector<double>& lower,
83-
vector<double>& upper, HighsSparseMatrix& matrix,
84-
HighsUserScaleData& data, const bool apply = true);
85-
86-
HighsStatus userScaleNewRows(const vector<HighsVarType>& integrality,
87-
vector<double>& lower, vector<double>& upper,
88-
HighsSparseMatrix& matrix,
89-
HighsUserScaleData& data,
90-
const HighsLogOptions& log_options);
91-
92-
void userScaleNewRows(const vector<HighsVarType>& integrality,
93-
vector<double>& lower, vector<double>& upper,
94-
HighsSparseMatrix& matrix, HighsUserScaleData& data,
95-
const bool apply = true);
96-
97-
HighsStatus userScaleCosts(const vector<HighsVarType>& integrality,
98-
vector<double>& cost, HighsUserScaleData& data,
99-
const HighsLogOptions& log_options);
100-
10172
void userScaleCosts(const vector<HighsVarType>& integrality,
10273
vector<double>& cost, HighsUserScaleData& data,
10374
const bool apply = true);
10475

105-
HighsStatus userScaleColBounds(const vector<HighsVarType>& integrality,
106-
vector<double>& lower, vector<double>& upper,
107-
HighsUserScaleData& data,
108-
const HighsLogOptions& log_options);
109-
11076
void userScaleColBounds(const vector<HighsVarType>& integrality,
11177
vector<double>& lower, vector<double>& upper,
11278
HighsUserScaleData& data, const bool apply = true);
11379

114-
HighsStatus userScaleRowBounds(vector<double>& lower, vector<double>& upper,
115-
HighsUserScaleData& data,
116-
const HighsLogOptions& log_options);
117-
11880
void userScaleRowBounds(vector<double>& lower, vector<double>& upper,
11981
HighsUserScaleData& data, const bool apply = true);
12082

121-
HighsStatus userScaleMatrix(const vector<HighsVarType>& integrality,
122-
HighsSparseMatrix& matrix, HighsUserScaleData& data,
123-
const HighsLogOptions& log_options);
124-
12583
void userScaleMatrix(const vector<HighsVarType>& integrality,
12684
HighsSparseMatrix& matrix, HighsUserScaleData& data,
12785
const bool apply = true);

highs/lp_data/HighsModelUtils.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <vector>
1919

2020
#include "lp_data/HighsSolution.h"
21+
#include "lp_data/HighsLpUtils.h"
22+
#include "model/HighsHessianUtils.h"
2123
#include "util/stringutil.h"
2224

2325
void analyseModelBounds(const HighsLogOptions& log_options, const char* message,
@@ -1588,3 +1590,16 @@ bool repeatedNames(const std::vector<std::string> name) {
15881590
return false;
15891591
}
15901592
*/
1593+
1594+
HighsStatus userScaleModel(HighsModel& model,
1595+
HighsUserScaleData& data,
1596+
const HighsLogOptions& log_options) {
1597+
userScaleLp(model.lp_, data, false);
1598+
userScaleHessian(model.hessian_, data, false);
1599+
HighsStatus return_status = userScaleStatus(log_options, data);
1600+
if (return_status == HighsStatus::kError) return HighsStatus::kError;
1601+
userScaleLp(model.lp_, data);
1602+
userScaleHessian(model.hessian_, data);
1603+
return return_status;
1604+
}
1605+

0 commit comments

Comments
 (0)