Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
linear programming example
/*****
EXAMPLE OF A LINEAR PROGRAMMING PROBLEM
*****/
/* classes of things */
set CATEGORIES;
/* function discretised over these points */
set POINTS;
/* hack to set points to point values */
param POINT_VALUES {p in POINTS} := p;
/* value of applying a particular point to a particular categoy */
param POINT_OUTCOME_PRIMARY {c in CATEGORIES, p in POINTS};
/* value of applying a particular point to a particular categoy */
param POINT_OUTCOME_SECONDARY {c in CATEGORIES, p in POINTS};
/* apply this point to this category */
var category_point{c in CATEGORIES, p in POINTS} binary;
maximize value: sum{c in CATEGORIES, p in POINTS} category_point[c,p] * POINT_OUTCOME_PRIMARY[c,p] + sum{c in CATEGORIES, p in POINTS} category_point[c,p] * POINT_OUTCOME_SECONDARY[c,p];
one_point_per_category {c in CATEGORIES}: sum{p in POINTS} category_point[c,p] = 1;
positive_primary_outcome: sum{c in CATEGORIES, p in POINTS} category_point[c,p] * POINT_OUTCOME_PRIMARY[c,p] >= 0;
positive_secondary_outcome: sum{c in CATEGORIES, p in POINTS} category_point[c,p] * POINT_OUTCOME_SECONDARY[c,p] >= 0;
data;
set CATEGORIES := A B C D;
set POINTS := 1 2 3 4 5;
param POINT_OUTCOME_PRIMARY :=
[A, 1] 44
[A, 2] 43
[A, 3] -32
[A, 4] -23
[A, 5] 18
[B, 1] 34
[B, 2] -18
[B, 3] -32
[B, 4] -31
[B, 5] -41
[C, 1] -13
[C, 2] -13
[C, 3] 48
[C, 4] -42
[C, 5] 29
[D, 1] 4
[D, 2] -50
[D, 3] 32
[D, 4] 7
[D, 5] 7;
param POINT_OUTCOME_SECONDARY :=
[A, 1] 0
[A, 2] -28
[A, 3] 26
[A, 4] -4
[A, 5] 43
[B, 1] -24
[B, 2] -49
[B, 3] -47
[B, 4] -45
[B, 5] -36
[C, 1] 50
[C, 2] 4
[C, 3] -11
[C, 4] 34
[C, 5] -48
[D, 1] 24
[D, 2] 25
[D, 3] 3
[D, 4] 40
[D, 5] -27;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.