Professional Documents
Culture Documents
RESUMEN
En este documento se encuentra un problema de Localizacin
de Hospitales el cual ser resuelto por tres mtodos, el primero es
programacin Lineal utilizando GAMS, el segundo de templado
simulado y el tercero de Algoritmos genticos. Finalmente se
presenta la comparacin entre los mtodos para solucionar el
problema.
Palabras
ClaveOptimizacin,
Algoritmos
Templado Simulado, Problemas de Localizacin.
Gneticos,
Variables de decisin:
Funcin Objetivo:
2
//Inv(j) Inversin necesaria para la implementacin de cada tipo de centro
prestador de servicios de salud de nivel j
Inv=[10000 20000 30000]
Restricciones:
3
]
V(:,:,16)=[
9 9 9 9 9 9 9 9 9 9 0.05 0.05 9 9 9 0.05 0.05 9 9 9;
9 9 9 9 9 9 9 9 9 9 0.1 0.1 9 9 9 0.1 0.1 9 9 9;
9 9 9 9 9 9 9 9 9 9 0.15 0.15 9 9 9 0.15 0.15 9 9 9;
]
V(:,:,17)=[
9 9 9 9 9 9 9 9 9 9 0.05 0.05 0.05 9 9 0.05 0.05 0.05 9 9;
9 9 9 9 9 9 9 9 9 9 0.1 0.1 0.1 9 9 0.1 0.1 0.1 9 9;
9 9 9 9 9 9 9 9 9 9 0.15 0.15 0.15 9 9 0.15 0.15 0.15 9 9;
]
V(:,:,18)=[
9 9 9 9 9 9 9 9 9 9 9 0.05 0.05 0.05 9 9 0.05 0.05 0.05 9;
9 9 9 9 9 9 9 9 9 9 9 0.1 0.1 0.1 9 9 0.1 0.1 0.1 9;
9 9 9 9 9 9 9 9 9 9 9 0.15 0.15 0.15 9 9 0.15 0.15 0.15 9;
]
V(:,:,19)=[
9 9 9 9 9 9 9 9 9 9 9 9 0.05 0.05 0.05 9 9 0.05 0.05 0.05;
9 9 9 9 9 9 9 9 9 9 9 9 0.1 0.1 0.1 9 9 0.1 0.1 0.1;
9 9 9 9 9 9 9 9 9 9 9 9 0.15 0.15 0.15 9 9 0.15 0.15 0.15;
]
V(:,:,20)=[
9 9 9 9 9 9 9 9 9 9 9 9 9 0.05 0.05 9 9 9 0.05 0.05;
9 9 9 9 9 9 9 9 9 9 9 9 9 0.1 0.1 9 9 9 0.1 0.1;
9 9 9 9 9 9 9 9 9 9 9 9 9 0.15 0.15 9 9 9 0.15 0.15;
]
//D(i,j) nmero de usuarios de la localidad i esperado que requieren servicios de
nivel j
D=[
10000 1000 800;
5000 1000 700;
3000 600 500;
4000 700 500;
7000 1200 1000;
6000 1000 900;
8000 1300 1100;
1000 200 100;
2000 400 200;
5000 900 700;
2000 1000 800;
3000 1000 700;
5000 600 500;
5000 400 700;
7000 1200 900;
6000 800 1000;
7000 1300 1100;
1000 100 200;
2000 400 300;
8000 900 800;
]
//x(i,j) NVariable binaria de abrir un hospital en la localidad i prestando el nivel
de servicio j
//c(i,k,j) Numero de personas atendidas de la localidad i provenientes de la
localidad k para el nivel de servicio j
//z funcion objetivo
function z=Hospitales(x, c)//Define la funcin Objetivo Minimizar el costo fijo de
montar un hospital mas el costo variable de cada persona atendida
//z = sum((i,j),x(i,j)*Inv(j))+ sum((i,k,j),c(i,k,j)*InvxPer(j));
z=0
for i=1:20
for j=1:3
z=z+(x(i,j)*Inv(j));
end
end
for i=1:20
for k=1:20
for j=1:3
z=z+(c(j,i,k)*V(j,i,k));
end
end
end
endfunction
//Define el cubo inicial de soluciones de c y la matriz inicial de soluciones de x
c0=[
0 0 0 0 0 0 0 0 0 0 1000 0 0 0 0 0 0 0 0 0;
1000 1000 0 0 0 1000 1300 0 0 0 0 0 0 0 0 0 0 0 0 0;
800 700 0 0 0 900 1100 0 0 0 0 0 0 0 0 0 0 0 0 0;
]
c0(:,:,2)=[
0 0 0 0 0 0 0 0 0 0 0 0 2000 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 4000 0 0 0 0 0;
]
c0(:,:,3)=[
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6000 0 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 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1230 0 4210 0 0 0 0 0 4110 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
]
c0(:,:,19)=[
0 0 0 0 0 0 0 100 0 0 0 0 0 0 0 0 0 800 0 0;
0 0 4000 0 0 0 0 0 0 0 0 0 0 0 0 600 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
]
c0(:,:,20)=[
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 4000 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
]
for i=1:20
for k=1:20
for j=1:3
c1(j,i,k)=c0(j,i,k)
copt(j,i,k)=c0(j,i,k)
if c0(j,i,k)>0 then
x0(i,j)=1
x1(i,j)=1
xopt(i,j)=1
else
x0(i,j)=0
end
end
end
end
fopt=Hospitales(x0,c0)
printf("Estado INICIAl= %f\n", fopt);
Proba_start = 0.7; // probabilidad inicial de aceptar una mala solucin (por lo
general alrededor de 0.7)
It_Pre = 5; //# de iteraciones de caminata aleatoria
It_extern = 10; // # de decremento en la Temperatura
It_intern = 50; //# de iteraciones durante un escaln de Temperatura
fc=0.8 //Factor decrecimiento temperatura
for l=1:It_Pre
printf("Numero de interaccion de caminata aleatoria= %f\n", l);
T=100; //Temperatura inicial
for temp=1:It_extern
T=T*fc
printf("Numero de decremento temperatura= %f\n", temp);
printf("Nueva temperatura= %f\n", T);
for It_int=1:It_intern
//Seleccionar vecino
ACP= int(rand()*10)//Cuantos cambios de posicion
for vec=1:ACP
Aleatorio_Vecino_j=int(rand()*3)
while Aleatorio_Vecino_j==0
Aleatorio_Vecino_j=int(rand()*3)
end
Aleatorio_Vecino_i=int(rand()*20)
while Aleatorio_Vecino_i==0
Aleatorio_Vecino_i=int(rand()*20)
end
Aleatorio_Vecino_k=int(rand()*20)
while Aleatorio_Vecino_k==0
Aleatorio_Vecino_k=int(rand()*20)
end
ACod=int(rand()*1000)
if c0(Aleatorio_Vecino_j,Aleatorio_Vecino_i,Aleatorio_Vecino_k)
- ACod<0 then
c1(Aleatorio_Vecino_j,Aleatorio_Vecino_i,Aleatorio_Vecino_k)=c0(Aleatorio_Ve
cino_j,Aleatorio_Vecino_i,Aleatorio_Vecino_k) + ACod
else
c1(Aleatorio_Vecino_j,Aleatorio_Vecino_i,Aleatorio_Vecino_k)=c0(Aleatorio_Ve
cino_j,Aleatorio_Vecino_i,Aleatorio_Vecino_k) - ACod
end
end
//Rellenamos la matriz x1 de acuerdo a si utiliza o no un sevicio de
localidad i de nivel j
for j=1:3
for i=1:20
Atendidos=0
for k=1:20
Atendidos=Atendidos+c1(j,i,k)
end
if Atendidos==0 then
x1(i,j)=0
else
x1(i,j)=1
end
end
end
//Evaluamos la funcin F
if Hospitales(x1,c1)<= Hospitales(x0,c0) then
c0=c1
x0=x1
if Hospitales(x0,c0)<= fopt then
fopt=Hospitales(x0,c0)
xopt=x0
copt=c0
printf("Nuevo Optimo= %f\n", fopt);
end
else
p_aleatorio=rand()
p_calculado=exp(-(1/T)*(Hospitales(x0,c0)-Hospitales(x1,c1)))
if p_aleatorio <=p_calculado then
c0=c1
x0=x1
end
end
end
end
end
5
3000 600 500;
4000 700 500;
7000 1200 1000;
6000 1000 900;
8000 1300 1100;
1000 200 100;
2000 400 200;
5000 900 700;
2000 1000 800;
3000 1000 700;
5000 600 500;
5000 400 700;
7000 1200 900;
6000 800 1000;
7000 1300 1100;
1000 100 200;
2000 400 300;
8000 900 800;
]
//x(i,j) NVariable binaria de abrir un hospital en la localidad i prestando el nivel
de servicio j
//c(i,k,j) Numero de personas atendidas de la localidad i provenientes de la
localidad k para el nivel de servicio j
//z funcion objetivo
cx=[1,0,0;0,1,0;1,1,0;0,1,1;1,0,0;0,0,0;1,1,1;0,1,1;0,1,0;1,0,1;1,0,1;1,0,0;0,0,1;1,1,0
;1,1,1;0,0,1;1,1,0;1,0,1;0,1,0;1,1,1];
cy=[1,0,0;1,0,0;1,0,0;0,0,1;1,0,1;0,1,0;1,0,0;0,1,0;0,1,0;1,0,1;1,0,1;1,0,0;0,1,1;1,1,0
;1,1,1;0,0,1;1,1,0;1,0,1;0,1,1;1,1,1];
function y=f(x)
z=0
for i=1:20
for j=1:3
z=z+(x(i,j)*Inv(j))+(D(i,j)*V(j)*x(i,j));
end
end
endfunction
PopSize = 100;
Proba_cross = 0.5;
Proba_mut = 0.2;
NbGen = 10;
NbCouples = 110;
Log = %T;
ga_params = init_param();
// Parameters to control the initial population.
ga_params = add_param(ga_params,"dimension",60);
ga_params = add_param(ga_params,"minbound",0*ones(1,60));
ga_params = add_param(ga_params,"maxbound",1*ones(1,60));
[pop_opt, fobj_pop_opt] = ..
optim_ga(f, PopSize, NbGen, Proba_mut, Proba_cross, Log, ga_params);
disp([min(fobj_pop_opt) mean(fobj_pop_opt) max(fobj_pop_opt)]);
// Get the best x (i.e. the one which achieves the minimum function value)
[fmin ,k] = min(fobj_pop_opt);
xmin = matrix(round(pop_opt(k)),20,3);
[atendidos noAtendidos]=calcUsos(xmin);
// Get the worst x
[fmax ,k] = max(fobj_pop_opt);
xmax = matrix(round(pop_opt(k)),20,3);
V. CONCLUSIN
El mejor resultado obtenido fue por programacin lineal, con
un valor de 248475 $(en miles), seguido por el obtenido por
templado simulado 345256,6 $ (en miles) y finalmente el de
Algoritmos genticos 406821.5$(en miles). El primer mtodo
utilizado asegura el optimo ya qu es un mtodo exacto y no
aleatorio. En los otros dos mtodos hay procesos estocsticos
que pueden irse acercando progresivamente al ptimo, pero no
se puede garantizar.