P-median problem

695 views
Skip to first unread message

Karin Baumann

unread,
Jun 11, 2011, 9:29:37 AM6/11/11
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

Robert Fourer

unread,
Jun 11, 2011, 1:52:23 PM6/11/11
to am...@googlegroups.com
AMPL doesn't give me any syntax errors with your objective function. However the constraints are written in a sort of pseudo-AMPL that is not in a syntax that the AMPL translator can recognize. See for instance the model at

www.ampl.com/BOOK/EXAMPLES/EXAMPLES2/multmip3.mod

for examples of how to define zero-one (binary) variables and how to specify several constraints (each has to start with "subject to"). This model also illustrates the difference between the indexing set for a constraint (before the :) and indexing sets for sums within a constraint.

Bob Fourer
4...@ampl.com

> ...

Reply all
Reply to author
Forward
0 new messages