I am learning AMPL for a university project and i don't understand why i'm getting a syntax error, my code:
model:
set FOODS;
param calories;
param proteins;
param calcium;
param vitaminA;
param cost;
param minCalories;
param minProt;
param minCalcium;
param minVit;
var x {FOODS} >=0;
minimize prix:
sum {f in FOODS} cost[f] * x[f];
subject to calories: sum {f in FOODS} calories[f] * x[f]>=minCalories;
subject to proteins: sum {f in FOODS} proteins[f] * x[f]>=minProt;
subject to vitaminA: sum {f in FOODS} vitaminA[f] * x[f]>=minVit;
subject to calcium: sum {f in FOODS} calcium[f] * x[f]>=minCalcium;
data:
data;
set FOODS := Bread Meat Potatoes Cabbage Milk Gelatine;
param calories{FOODS};
param proteins{FOODS};
param calcium{FOODS};
param vitaminA{FOODS};
param cost{FOODS};
param minCalories = 3000;
param minProt = 70;
param minCalcium = 800;
param minVit = 500;
calories:=
Bread 1254
Meat 1457
Potatoes 318
Cabbage 48
Milk 309
Gelatin 1725;
proteins :=
Bread 39
Meat 73
Potatoes 8
Cabbage 4
Milk 16
Gelatin 43;
calcium :=
Bread 418
Meat 41
Potatoes 42
Cabbage 141
Milk 536
Gelatin 0;
vitaminA :=
Bread 0
Meat 0
Potatoes 70
Cabbage 860
Milk 720
Gelatin 0;
cost :=
Bread 0.3
Meat 1
Potatoes 0.05
Cabbage 0.08
Milk 0.23
Gelatin 0.48;
The error i am getting: alimentation.mod, line 16 (offset 222): syntax error context: sum {f in FOODS} >>> cost[ <<< f] * x[f];
i tried different ways of writing it, and even asking chatgpt but nothing changed
cost
is indexed byfood
when you declare the parameter? (similar for other indexed params)?