Karin Baumann
unread,Jun 11, 2011, 9:29:37 AM6/11/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to AMPL Modeling Language
Hello!
I've got a simple (P-median) problem to solve in AMPL in the context
of my academic studies, and I really need your help!
Here is my model (which is not working):
reset;
#--------------------------------------------algebraic model
param n; #nb neighborhoods
param P; #nb ambulances to allocate
set I={1..n};
set J={1..n};
param H{I}; #population
param D{I,J}; #distance between the neighborhoods
var X{I}>=0; #emplacement ambulance
var Y{I,J}>=0; #Allocation neighborhoods
maximize z: sum {i in I} (sum{ j in J} Y[i, j]*D [i, j]*H[i]);
subject to restr{i in I, j in J}:
sum{j in J, i in I}Y[i,j]=1;
sum{j in J}X[j]=P;
sum{i in I}Y[i,j]<=n*X[j];
Y[i,j]={0,1};
X[j]={0,1};
#------------------------------------------specify model data
data;
param P:=3;
param n:=12;
param H:= 15 10 12 18 5 24 11 16 13 22 19 20;
param D: 1 2 3 4 5 6 7 8 9 10 11 12 :=
1 0 15 37 55 24 60 18 36 48 40 59 67
2 15 0 22 40 38 52 33 50 42 55 61 61
3 37 22 0 18 16 30 53 28 20 58 39 39
4 55 40 18 0 34 12 71 46 24 62 43 34
5 24 38 16 34 0 36 37 12 24 56 37 43
6 60 52 30 12 36 0 67 42 12 50 31 22
7 18 33 53 71 37 67 0 25 55 22 41 63
8 36 50 28 46 12 42 25 0 30 44 25 47
9 48 42 20 24 24 12 55 30 0 38 19 19
10 40 55 58 62 56 50 22 44 38 0 19 41
11 59 61 39 43 37 31 41 25 19 19 0 22
12 67 61 39 34 43 22 63 47 19 41 22 0;
#------------------------------------------solve the problem
solve;
display z, X, Y;
Do you know what's wrong with it?
AMPL says there is a syntax error in the objective function.
In excel, it's a matrix product of H_i and (d_ij×Y_ij)
mathematically it is (I think): ∑_i〖∑_j h_i ×(d_ij×Y_ij)〗
Do you have an idea? Thanks a lot for your support in advance.
Kind regards,
Karin