@@ -20,57 +20,37 @@ bool doubleEqual0(const double v0, const double v1) {
2020 return std::fabs (v0 - v1)/std::max (1.0 , std::fabs (v0)) < 1e-12 ;
2121}
2222
23- TEST_CASE (" user-cost-scale-after-run" , " [highs_user_scale]" ) {
23+ TEST_CASE (" user-scale-after-run" , " [highs_user_scale]" ) {
24+ const std::string mip_model = " flugpl" ;// "rgn";//
2425 std::string model = " avgas" ;
2526 Highs highs;
2627 const HighsInfo& info = highs.getInfo ();
2728 highs.setOptionValue (" output_flag" , dev_run);
28- for (HighsInt k = 0 ; k < 2 ; k++) {
29+ // REQUIRE(highs.setOptionValue("presolve", kHighsOffString) == HighsStatus::kOk);
30+ HighsInt num_k = 1 ;
31+ if (num_k == 1 ) model = mip_model;
32+ for (HighsInt k = 0 ; k < num_k; k++) {
2933 std::string filename =
3034 std::string (HIGHS_DIR) + " /check/instances/" + model + " .mps" ;
3135 highs.readModel (filename);
32- highs.writeModel (" " );
33- double col_cost_1 = highs.getLp ().col_cost_ [1 ]; // kInteger for flugpl
34- double col_cost_2 = highs.getLp ().col_cost_ [2 ]; // kContinuous for flugpl
35- double col_upper_1 = highs.getLp ().col_upper_ [1 ];
36- double col_upper_2 = highs.getLp ().col_upper_ [2 ];
37- double row_upper_0 = highs.getLp ().row_upper_ [0 ];
38- double matrix_value_1 = highs.getLp ().a_matrix_ .value_ [highs.getLp ().a_matrix_ .start_ [1 ]];
39- double matrix_value_2 = highs.getLp ().a_matrix_ .value_ [highs.getLp ().a_matrix_ .start_ [2 ]];
4036 HighsLp unscaled_lp = highs.getLp ();
37+ const bool is_lp = !unscaled_lp.isMip ();
38+ highs.writeModel (" unscaled.mps" );
4139
4240 highs.run ();
4341 double unscaled_objective = highs.getInfo ().objective_function_value ;
4442
45- HighsInt user_bound_scale = 1 ;// 8;
43+ HighsInt user_bound_scale = 1 ;
4644 double user_bound_scale_value = std::pow (2 , user_bound_scale);
45+
4746 REQUIRE (highs.setOptionValue (" user_bound_scale" , user_bound_scale) == HighsStatus::kOk );
48- if (k == 0 ) {
49- REQUIRE (highs.getLp ().col_cost_ [1 ] == col_cost_1);
50- REQUIRE (highs.getLp ().col_upper_ [1 ] == user_bound_scale_value*col_upper_1);
51- } else {
52- REQUIRE (highs.getLp ().col_cost_ [1 ] == user_bound_scale_value*col_cost_1);
53- REQUIRE (highs.getLp ().col_upper_ [1 ] == col_upper_1);
54- }
55- REQUIRE (highs.getLp ().col_upper_ [2 ] == user_bound_scale_value*col_upper_2);
56- REQUIRE (highs.getLp ().row_upper_ [0 ] == row_upper_0);
47+
48+ HighsLp bound_scaled_lp = highs.getLp ();
49+ checkLpScaling (user_bound_scale, 0 , unscaled_lp, bound_scaled_lp);
5750
5851 HighsInt user_cost_scale = 4 ;
5952 double user_cost_scale_value = std::pow (2 , user_cost_scale);
6053 REQUIRE (highs.setOptionValue (" user_cost_scale" , user_cost_scale) == HighsStatus::kOk );
61- if (k == 0 ) {
62- REQUIRE (highs.getLp ().col_cost_ [1 ] == user_cost_scale_value*col_cost_1);
63- } else {
64- REQUIRE (highs.getLp ().col_cost_ [1 ] == user_cost_scale_value*user_bound_scale_value*col_cost_1);
65- }
66- REQUIRE (highs.getLp ().col_cost_ [2 ] == user_cost_scale_value*col_cost_2);
67- if (k == 0 ) {
68- REQUIRE (highs.getLp ().col_upper_ [1 ] == user_bound_scale_value*col_upper_1);
69- } else {
70- REQUIRE (highs.getLp ().col_upper_ [1 ] == col_upper_1);
71- }
72- REQUIRE (highs.getLp ().col_upper_ [2 ] == user_bound_scale_value*col_upper_2);
73- REQUIRE (highs.getLp ().row_upper_ [0 ] == user_bound_scale_value*row_upper_0);
7454
7555 HighsLp scaled_lp = highs.getLp ();
7656 checkLpScaling (user_bound_scale, user_cost_scale, unscaled_lp, scaled_lp);
@@ -85,20 +65,23 @@ TEST_CASE("user-cost-scale-after-run", "[highs_user_scale]") {
8565 REQUIRE (info.max_dual_infeasibility == kHighsIllegalInfeasibilityMeasure );
8666 REQUIRE (info.sum_dual_infeasibilities == kHighsIllegalInfeasibilityMeasure );
8767
68+ highs.writeModel (" scaled0.mps" );
69+ highs.passModel (scaled_lp);
8870 highs.run ();
71+
8972 REQUIRE (highs.getModelStatus () == HighsModelStatus::kOptimal );
9073 REQUIRE (doubleEqual0 (highs.getInfo ().objective_function_value ,
91- user_bound_scale_value*user_cost_scale_value*unscaled_objective));
74+ user_bound_scale_value*user_cost_scale_value*unscaled_objective));
9275
93- model = " flugpl " ;
76+ model = mip_model ;
9477 REQUIRE (highs.setOptionValue (" user_bound_scale" , 0 ) == HighsStatus::kOk );
9578 REQUIRE (highs.setOptionValue (" user_cost_scale" , 0 ) == HighsStatus::kOk );
9679 }
9780
9881 highs.resetGlobalScheduler (true );
9982}
10083
101- TEST_CASE (" user-cost- scale-after-load" , " [highs_user_scale]" ) {
84+ TEST_CASE (" user-scale-after-load" , " [highs_user_scale]" ) {
10285 std::string filename =
10386 std::string (HIGHS_DIR) + " /check/instances/adlittle.mps" ;
10487 Highs highs;
@@ -169,72 +152,6 @@ TEST_CASE("user-small-cost-scale", "[highs_user_scale]") {
169152 highs.resetGlobalScheduler (true );
170153}
171154
172- TEST_CASE (" user-cost-scale-in-build" , " [highs_user_scale]" ) {
173- Highs unscaled_highs;
174- Highs scaled_highs;
175- unscaled_highs.setOptionValue (" output_flag" , dev_run);
176- scaled_highs.setOptionValue (" output_flag" , dev_run);
177- const HighsLp& unscaled_lp = unscaled_highs.getLp ();
178- const HighsLp& scaled_lp = scaled_highs.getLp ();
179- const HighsInfo& info = scaled_highs.getInfo ();
180- const HighsSolution& solution = scaled_highs.getSolution ();
181- const HighsInt user_cost_scale = -30 ;
182- const HighsInt user_bound_scale = 10 ;
183- const double unscaled_col0_cost = 1e14 ;
184- unscaled_highs.addVar (0 , inf);
185- scaled_highs.addVar (0 , inf);
186- unscaled_highs.changeColCost (0 , unscaled_col0_cost);
187- scaled_highs.changeColCost (0 , unscaled_col0_cost);
188-
189- scaled_highs.setOptionValue (" user_cost_scale" , user_cost_scale);
190- scaled_highs.setOptionValue (" user_bound_scale" , user_bound_scale);
191- checkLpScaling (user_bound_scale, user_cost_scale, unscaled_lp, scaled_lp);
192-
193- const double unscaled_col1_cost = 1e12 ;
194- unscaled_highs.addVar (1 , inf);
195- scaled_highs.addVar (1 , inf);
196- unscaled_highs.changeColCost (1 , unscaled_col1_cost);
197- scaled_highs.changeColCost (1 , unscaled_col1_cost);
198- checkLpScaling (user_bound_scale, user_cost_scale, unscaled_lp, scaled_lp);
199-
200- std::vector<HighsInt> index = {0 , 1 };
201- std::vector<double > value0 = {1 , 2 };
202- std::vector<double > value1 = {1 , 4 };
203- unscaled_highs.addRow (-inf, 120 , 2 , index.data (), value0.data ());
204- scaled_highs.addRow (-inf, 120 , 2 , index.data (), value0.data ());
205- checkLpScaling (user_bound_scale, user_cost_scale, unscaled_lp, scaled_lp);
206-
207- unscaled_highs.addRow (-inf, 150 , 2 , index.data (), value1.data ());
208- scaled_highs.addRow (-inf, 150 , 2 , index.data (), value1.data ());
209- checkLpScaling (user_bound_scale, user_cost_scale, unscaled_lp, scaled_lp);
210-
211- std::vector<double > cost = {0 , 10 };
212- std::vector<double > lower = {2 , 4 };
213- std::vector<double > upper = {inf, inf};
214- std::vector<HighsInt> matrix_start = {0 , 2 };
215- std::vector<HighsInt> matrix_index = {0 , 1 , 0 , 1 };
216- std::vector<double > matrix_value = {1 , 1 , 2 , 4 };
217- unscaled_highs.addCols (2 , cost.data (), lower.data (), upper.data (), 4 ,
218- matrix_start.data (), matrix_index.data (),
219- matrix_value.data ());
220- scaled_highs.addCols (2 , cost.data (), lower.data (), upper.data (), 4 ,
221- matrix_start.data (), matrix_index.data (),
222- matrix_value.data ());
223- checkLpScaling (user_bound_scale, user_cost_scale, unscaled_lp, scaled_lp);
224-
225- lower = {-inf, 0 };
226- upper = {120 , 150 };
227- matrix_start = {0 , 2 };
228- matrix_index = {0 , 2 , 1 , 3 };
229- matrix_value = {1 , 1 , 2 , 4 };
230- unscaled_highs.addRows (2 , lower.data (), upper.data (), 4 , matrix_start.data (),
231- matrix_index.data (), matrix_value.data ());
232- scaled_highs.addRows (2 , lower.data (), upper.data (), 4 , matrix_start.data (),
233- matrix_index.data (), matrix_value.data ());
234-
235- checkLpScaling (user_bound_scale, user_cost_scale, unscaled_lp, scaled_lp);
236- }
237-
238155void checkModelScaling (const HighsInt user_bound_scale,
239156 const HighsInt user_cost_scale,
240157 const HighsModel& unscaled_model,
0 commit comments