I wrote the code using AMPL program, but it contains errors and tried to correct them, but I do not know how Please can you help me write the correct code
The idea in this code is nested transformation model with converts param supply to var supply
MODEL FILE
# write set
set door; # sources ,,, index i
set class; # destinations ,,, index j
set courses; # subject ,,, index k
set building; # number floor ,,, index b
# write parameter
param capacity {i in door} >= 0;
param demand {j in class} >= 0;
param student {k in courses} >= 0;
param number_floor {b in building} >= 0;
param cost {i in door,b in building} >= 0;
param covid; # The possibility of transmission of covid = 2.4%
# write decision varible
var supply {i in door} >= 0;
var trans_1 {i in door,b in building} >= 0;
var trans_2 {b in building,k in courses} >= 0;
var trans_3 {k in courses,j in class} >= 0;
# write objective function
minimize Total_cost: sum {i in door,b in building} cost[i,b] * supply [i] *covid;
# write constrain
subject to c1.supply_student {i in door} : supply [i] = sum student [k];
subject to c2.supply_capacity {i in door} : supply [i] <= capacity [i];
subject to c3.trans1_supply {i in door} : supply [i] = trans_1 [i,b];
subject to c4.trans2_courses {b in building} : sum {k in courses} courses [b,k] = sum {i in door} trans_2 [i,b];
subject to c5.trans3_student {k in courses} : sum {j in class} trans_3 [k,j] = student [k];
subject to c6.trans3_demand : trans_3 [k,j] <= demand [j];
DATA FILE
# write set with element
set door:= D1 D2 D3 D4;
set class := A5 A7-9 A11-13 A14-16 A15-17 A19-21
B8-10 B9-11 B12-14 B13-15 B17-19 B18-20
C1 C8 C9 C10 C11 C12 C13 C14 C16 C17 C18 C19 C20;
set courses := Ordinary_Differential_Equations
Complex_analysis Euclidean_and_Non_Euclidean_Geometry;
set building:= first second third;
# write parameter
param number_floor :=
first 1
second 2
third 3;
param covid := 0.024; # The possibility of transmission of covid = 2.4%
param capacity :=
D1 20
D2 13
D3 9
D4 5;
param demand:=
A5 22
A7-9 30
A11-13 22
A14-16 22
A15-17 22
A18-20 30
A19-21 20
B8-10 30
B9-11 30
B12-14 30
B13-15 30
B17-19 30
B18-20 30
C1 12
C8 12
C9 12
C10 12
C11 12
C12 12
C13 12
C14 12
C16 12
C17 12
C18 12
C19 12
C20 12;
param student:= Ordinary_Differential_Equations 29
Complex_analysis 16 Euclidean_and_Non-Euclidean_Geometry 2;
param cost: # Time taken to arrive
first second third :=
D1 15 20 25
D2 22 17 23
D3 19 18 16
D4 12 15 19;
I think the error is in constraint but I don't know
Aucun commentaire:
Enregistrer un commentaire