Hier ist mein ganzes Problem:Wie kann ich eine if-Bedingung für meine Variable in GLPK schreiben?
Information:
* Max. Gesamtinvestition: $ 125
* Pay-off ist die Summe der Einheiten gekauft x Pay-off/Einheit
* Kosten pro Anlage: Buy-in Kosten + Kosten/Einheit x Anzahl der Einheiten, wenn Sie kaufen bei mindestens eine Einheit
* Die Kosten Summe der Kosten pro Investition
Constraints:
* Sie beide investieren nicht in 2 und 5
* Y Sie können nur in 1 investieren, wenn Sie mindestens eines von 2 und 3 investieren.
* Sie müssen mindestens zwei von 3,4,5 investieren.
* Sie dürfen nicht mehr als die maximale Anzahl von Einheiten investieren.
Problem: Gewinn maximieren: Pay-off - kosten
xi: # of units i ∈ {1,2,3,4,5}
yi=1 if xi>0 else yi=0
cost = sum{i in I} buyInCost_i * yi + cost-unit_i*xi
pay-off = sum{i in I} (pay-off/unit)_i*xi
profit = pay-off - cost
Maximize profit
Subject to
y2+y5 <= 1
y1<= y2+y3
y3+y4+y5 >= 2
x1<=5, x2<=4, x3<=5, x4<=7, x5<=3
cost<=125
Hier meine Frage:
Zum Beispiel habe ich diese binäre Variable y
yi=1 if xi>0 else yi=0 and i ∈ {1,2,3,4,5}
I i als ein erklärter Datensatz
set I;
data;
set I := 1 2 3 4 5;
Ich weiß nicht, wie man eine andere Variable in glpk als y-Bedingung hinzufügt. Kannst du mir bitte helfen?
Meine Modellierung:
set I;
/*if x[i]>0 y[i]=1 else y[i]=0 ?????*/
var y{i in I}, binary;
param a{i in I};
/* buy-in cost of investment i */
param b{i in I};
/* cost per unit of investment i */
param c{i in I};
/* pay-off per unit of investment i */
param d{i in I};
/* max number of units of investment i */
var x{i in I} >=0;
/* Number of units that is bought of investment i */
var po := sum{i in I} c[i]*x[i];
var cost := sum{i in I} a[i]*y[i] + b[i]*x[i];
maximize profit: po-cost;
s.t. c1: y[2]+y[5]<=1;
s.t. c2: y[1]<y[2]+y[3];
s.t. c3: y[3]+y[4]+y[5]>=2;
s.t. c4: x[1]<=5
x[2]<=4
x[3]<=5
x[4]<=7
x[5]<=3;
s.t. c5: cost <=125;
s.t. c6{i in I}: M * y[i] > x[i]; // if condition of y[i]
set I := 1 2 3 4 5;
param a :=
1 25
2 35
3 28
4 20
5 40;
param b :=
1 5
2 7
3 6
4 4
5 8;
param c :=
1 15
2 25
3 17
4 13
5 18;
param d :=
1 5
2 4
3 5
4 7
5 3;
param M := 10000;
ich diese Syntax Störung erhalte:
problem.mod:21: syntax error in variable statement
Context: ...I } ; param d { i in I } ; var x { i in I } >= 0 ; var po :=
MathProg model processing error
ist x_i? Ist es eine kontinuierliche, ganze oder binäre Variable, oder handelt es sich um Eingabedaten? – raoulcousins
xi ist die Anzahl der Produkte, die gekauft werden. Diese Werte sollten vom Programm zur Optimierung gefunden werden. –
Ich denke, Ihre Antwort hier sein kann, aber ich habe GLPK nie benutzt: http://en.wikibooks.org/wiki/GLPK/GMPL_Workarounds – raoulcousins