Skip to content

Commit 4bd175b

Browse files
committed
Added test_get_user_objective_bound_scale to tests/test_highspy.py
1 parent 8b7d187 commit 4bd175b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

check/TestCAPI.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,8 @@ void testUserObjectiveBoundScaling() {
22832283
return_status = Highs_getDualObjectiveValue(highs, &dual_objective_value);
22842284
assert(return_status == kHighsStatusOk);
22852285

2286+
assertDoubleValuesEqual("PDobjective", unscaled_objective_value, dual_objective_value);
2287+
22862288
HighsInt suggested_objective_scale;
22872289
HighsInt suggested_bound_scale;
22882290
return_status = Highs_getObjectiveBoundScaling(highs,

tests/test_highspy.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2222,4 +2222,32 @@ def test_get_objectives(self):
22222222
self.assertEqual(list(map(int, obj_expr2.idxs)), [0, 1, 2])
22232223
self.assertEqual(obj_expr2.vals, [1.0, 2.0, 3.0])
22242224
self.assertEqual(obj_expr2.constant, 5.0)
2225-
self.assertEqual(sense2, highspy.ObjSense.kMaximize)
2225+
self.assertEqual(sense2, highspy.ObjSense.kMaximize)
2226+
2227+
def test_get_user_objective_bound_scale(self):
2228+
inf = highspy.kHighsInf
2229+
h = highspy.Highs()
2230+
h.setOptionValue("output_flag", False)
2231+
h.addVars(2, np.array([1e-8, 1e-8]), np.array([1e8, 1e8]))
2232+
h.changeColsCost(2, np.array([0, 1]), np.array([-4e6, -7e6], dtype=np.double))
2233+
num_cons = 2
2234+
lower = np.array([-inf, -2e+8], dtype=np.double)
2235+
upper = np.array([6e+8, inf], dtype=np.double)
2236+
num_new_nz = 4
2237+
starts = np.array([0, 2])
2238+
indices = np.array([0, 1, 0, 1])
2239+
values = np.array([1, 1, 1, -1], dtype=np.double)
2240+
h.addRows(num_cons, lower, upper, num_new_nz, starts, indices, values)
2241+
h.run()
2242+
unscaled_objective_value = h.getObjectiveValue()
2243+
[status, dual_objective_value] = h.getDualObjectiveValue()
2244+
self.assertAlmostEqual(unscaled_objective_value, dual_objective_value)
2245+
[status, suggested_objective_scale, suggested_bound_scale] = h.getObjectiveBoundScaling();
2246+
h.setOptionValue("user_cost_scale", suggested_objective_scale)
2247+
h.setOptionValue("user_bound_scale", suggested_bound_scale)
2248+
h.run()
2249+
scaled_objective_value = h.getObjectiveValue()
2250+
self.assertAlmostEqual(unscaled_objective_value, scaled_objective_value)
2251+
2252+
2253+

0 commit comments

Comments
 (0)