Skip to content

Commit

Permalink
QP hierarchical objectives test #239
Browse files Browse the repository at this point in the history
Fails except with Gurobi
  • Loading branch information
glebbelov committed Jun 18, 2024
1 parent f4d8e49 commit 1fc7e68
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/mp/backend-std.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ class StdBackend :
auto get_sol = [this]() {
return GetSolution();
};
int i=0;
while (GetMM().PrepareSolveIteration(get_stt, get_sol)) {
// ExportModel({"/tmp/model" + std::to_string(++i) + ".lp"});
Solve();
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/end2end/cases/categorized/fast/multi_obj/dietobj_pr_3.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
suffix objpriority;
suffix objweight;


let total_cost["A&P"].objpriority := 4;
let total_cost["JEWEL"].objpriority := 3;
let total_cost["VONS"].objpriority := 1;
let total_number.objpriority := 2;

let total_cost["A&P"].objweight := 1;
let total_cost["JEWEL"].objweight := 2;
let total_cost["VONS"].objweight := 1.3;
let total_number.objweight := -5;

35 changes: 35 additions & 0 deletions test/end2end/cases/categorized/fast/multi_obj/dietqobj_1000_2.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Test correct objective value postsolve in MP
## See AutoLinking

set MINREQ; # nutrients with minimum requirements
set MAXREQ; # nutrients with maximum requirements

set NUTR := MINREQ union MAXREQ; # nutrients
set FOOD; # foods
set STORE; # stores

param cost {STORE,FOOD} > 0;
param f_min {FOOD} >= 0;
param f_max {j in FOOD} >= f_min[j];

param n_min {MINREQ} >= 0;
param n_max {MAXREQ} >= 0;

param amt {NUTR,FOOD} >= 0;

var Buy {j in FOOD} >= f_min[j], <= f_max[j];

minimize total_cost {s in STORE}:
sum {j in FOOD} -cost[s,j] * Buy[j]
+ sum {j in FOOD} Uniform(0.01, 0.2) * Buy[j] * Buy[j]
+ 1000;

minimize total_number:
sum {j in FOOD} Buy[j]
- sum {j in FOOD} Uniform(0.01, 0.2) * Buy[j] * Buy[j];

subject to diet_min {i in MINREQ}:
sum {j in FOOD} amt[i,j] * Buy[j] >= n_min[i];

subject to diet_max {i in MAXREQ}:
sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i];
26 changes: 26 additions & 0 deletions test/end2end/cases/categorized/fast/multi_obj/modellist.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,32 @@
"_sobj[4]": 44.80888220421118
}
},
{
"name" : "dietQobj_1000 multiobj=2 obj_pr_2",
"tags" : ["quadraticnonconvex", "quadratic_obj", "multiobj"],
"files" : ["dietqobj_1000.mod", "dietobj.dat", "dietobj_pr_2.inc"],
"options": { "ANYSOLVER_options": "multiobj=2" },
"values": {
"total_cost[\"A&P\"]": 936.6309187422044,
"total_cost[\"JEWEL\"]": 959.3824742719657,
"total_cost[\"VONS\"]": 935.065924552458,
"total_number": 40,
"_sobj[4]": 40
}
},
{
"name" : "dietQobj_1000_2 multiobj=2 obj_pr_3",
"tags" : ["quadratic", "quadratic_obj", "multiobj"],
"files" : ["dietqobj_1000_2.mod", "dietobj.dat", "dietobj_pr_3.inc"],
"options": { "ANYSOLVER_options": "multiobj=2" },
"values": {
"total_cost[\"A&P\"]": 915.7758062677805,
"total_cost[\"JEWEL\"]": 936.0958377754476,
"total_cost[\"VONS\"]": 924.2202858257223,
"total_number": 17.793036329321545,
"_sobj[4]": 17.793036329321545
}
},
{
"name" : "dietobj multiobj=1 obj:2:priority=10",
"Comment": "Modify obj priority via an option",
Expand Down
1 change: 1 addition & 0 deletions test/end2end/scripts/python/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ModelTags(enum.Enum):
quadratic = 2 # obj and con
quadratic_obj = 2.5
quadraticnonconvex = 3
quadratic_obj_nonconvex = 3.5
socp = 4
socp_hard_to_recognize = 4.1 ## For solvers recognizing from quadratics
expcones = 4.4
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/scripts/python/Solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ def __init__(self, exeName, timeout=None, nthreads=None,
ModelTags.continuous, ModelTags.integer, ModelTags.binary,
ModelTags.sos,

ModelTags.quadratic, ModelTags.quadratic_obj, ModelTags.quadraticnonconvex,
ModelTags.quadratic, ModelTags.quadratic_obj, ModelTags.quadratic_obj_nonconvex,
ModelTags.plinear,

ModelTags.socp, ## MP transforms cones to quadratics
Expand Down

0 comments on commit 1fc7e68

Please sign in to comment.