Você está na página 1de 26

FACULTAD DE INGENIERA

INTERPRETACION DEL CODIGO DE DESARROLLO DEL MODELO DE


TRANSPORTE PL

ASIGNATURA : PROGRAMACION LINEAL

PROFESOR : JOSE JEREMIAS CABALLERO CANTU

ALUMNO : CALLUPE LLALLICO AARON

CAMPEAN MALLMA OSCAR

CAMARENA TORRES JIMMY

ZAVALA LLANCO MIJAIL

BLAS PORRAS GUSTAVO

NIEVA JORGE JUAN

TARMA PER
2017-I

INTRODUCCION

El conflicto de transporte est encaminado primordialmente para estipular la


manera de mejorar el transporte de bienes del punto inicial a un punto final de
origen, perfeccionando los recursos y localizando el coste ms bajo lo cual
sera de gran ayuda para la empresa.

Para lo cual es obligatorio obtener modelos matemticos que permitan una


buena toma de decisiones, los cuales pueden ser resueltos mediante el
mtodo de la esquina noroeste, para el problema de transporte.
CDIGO DEL MEN PRINCIPAL
clear all
clc

warning off all;

global n_demanda n_oferta Matrizp a b c ;

%HACE Q EL TIPO DE LOS RESULTADOS SEA DE UN VALOR ENTERO


format rat;

%HACE Q EL TIPO DE LOS RESULTADOS SEA PARA UN VALOR DECIMAL


format short;

%CADENAS DE CARACTERES ESTABLECIDAS PARA LAS VENTANAS Y DIALOGOS


C1='Cargando Datos...';
Ca='Cantidad de Ofertas:';
Cb='Cantidad de Demandas:';

%BANDERAS O CENTINELAS
band=0;
cent=1;

%INICIALIZA LAS VARIABLES CON VALOR 0


m_ofer=0;
m_dem=0;

%CICLO WHILE GENERAL DETERMINA EL FIN O PARADA DE LA FUNCION, MIENTRAS LA


VARIABLE cent SEA DIFERENTE DE 0
while(cent~=0)

%DIALOGO: MUESTRA AREA DE CARGA DE DATOS


resp=inputdlg({Ca,Cb},C1,1,{'0','0'});
%centinela verifica si se han introducido datos en la ventana
if((size(resp)~=0) & str2num(char(resp(2)))>=1 & str2num(char(resp(1)))>=1 )

n_oferta=str2num(char(resp(1)));
n_demanda=str2num(char(resp(2)));

% VERIFICA QUE LA CANTIDAD DE OFERTA Y DEMANDA


if (n_oferta>=1 & n_demanda>=2)|(n_oferta>=2 & n_demanda>=1) & (n_oferta<=10 &
n_demanda<=10)

v_oferta=zeros(n_oferta,1);
v_demanda=zeros(1,n_demanda);

Matrizp=zeros(n_oferta,n_demanda);

% LA FUNCION DEL CUADRO


% Descripcin: Ventana de captura de datos que solicita
% la entrada de ofertas y demandas.
% Entradas:
% n_oferta: cantidad de Ofertas
% n_demanda: cantidad de Demandas
% m_ofer: catidad de Ofertas adicionales, inicialmente es cero
% m_dem: catidad de Demandas adicionales, inicialmente es cero

%MUESTRA EN UN CUADRO LAS VARIABLES A INGRESAR


cuadro(n_oferta,n_demanda,m_ofer,m_dem);

band=1;
cent=0;
else

%MENSAJE DE ADVERTENCIA
waitfor(warndlg('La cantidad de Ofetas y Demandas deben estar en un valor entre 2 y
10','ERROR AL INTRODUCIR LOS DATOS'));
end
elseif(length(resp)==0)
cent=0;
else

%MENSAJE DE ADVERTENCIA
waitfor(warndlg(' ERROR AL INTRODUCIR LOS DATOS, POR FAVOR INTENTE DE NUEVO
','ERROR DE PROCESO'));
end
end

AGREGAR
%SE DEFINE UNA FUNCION LLAMADA AGREGAR CON UNA VARIABLE OPCION
function agregar(opcion)
global a b c oferta demanda;

%CADENAS DE CARACTERES ESTABLECIDAS PARA LAS VENTANAS Y DIALOGOS


Cx1='Agregar Ofertas...';
Cx2='Agregar Demandas...';
Cxa='Cantidad de Ofertas:';
Cxb='Cantidad de Demandas:';

mas_demanda=0;
mas_oferta=0;

%ES UNA VARIABLE DE DECISIN QUE NOS QUIERE DECIR.. SI OPCION A ELEGIR ES IGUAL A 1
ENTONCES SE DESARROLLA LA SIGUENTE OPERACIN EN LAS MATRICES QUE EN ESTE CASO EL
AUMENTO DE OFERTAS QUE SE ENCUENTRA EN LAS COLUMNAS Y AADIRA VALORES EN LAS
FILAS Y COLUMNAS PARA PODER SEGUIR CON EL PROCEDIMIENTO.
if(opcion==1)

resp_1=inputdlg({Cxa},Cx1,1,{'0'});
%EN ESTA PARTE SE LE LLAMA IF ANIDADO YA QUE ES UN IF DENTRO DE OTRO IF Y NOS
QUIERE DECIR QUE SI EL TAMAO O LONGITUD DE RESP_1 ES DIFERENTE DE 0 ENTONCES SE
REALIZA UNA OPERACIN.
if(size(resp_1)~=0)
mas_oferta=str2num(char(resp_1(1)));
end

% ESTE ES UN VECTOR QUE TIENE CARACTERES DE ACUERDO AL TAMAO DE LA VARIABLE A


[h,g] = size(a);

%ESTE ES UN BUCLE DONDE SE REPETIRA UNA SECUENCIA DE PASOS HASTA Q CUMPLA LA


CONDICION.. PARA ERSTE CASO ES UN LECTOR DE NUMEROS PARA RELLENAR LA MATRIS DE
ACUERDO A LAS VARIABLES I, J
for i = 1:h
for j = 1:g

%MUESTRA LA MATRIS I,J DEACUERDO A LAS VARIABLES DECLARADAS, CON LA FUNCION GET
QUE SIGNIFICA RECUPERAR VALORES
x_a(i,j)=str2num( get( a(i,j) ,'String'));
end
end

for k = 1:g
x_b(1,k)=str2num( get( b(1,k) ,'String'));
end

for t = 1:h
x_c(t,1)=str2num( get( c(t,1) ,'String'));
end

CLF(gcf);
cuadro(oferta , demanda , mas_oferta, 0);
end

%LLAMA A LA OPCION 2 ES DE LA DEMANDA Y AL PRECIONAR EN ESA OPCION ENTONCES


PERMITIRA AADIR LA DEMANDA QUE USTED GUSTE Y ESTA VALIDADO YA QUE NO ADMITE
NUMEROS NEGATIVOS, EN LOS SIGUIENTES BUCLES Y DESICIONES REALIZARA EL AUMENTO DE
CELDAS EN LAS FIAS DE LA DEMANDA PARA PODER RELLENARLAS Y SEGUIR EL
PROCEDIMIENTO.
if(opcion==2)

resp_1=inputdlg({Cxb},Cx2,1,{'0'});
if(size(resp_1)~=0)
mas_demanda=str2num(char(resp_1(1)));
end

[h,g] = size(a);
for i = 1:h
for j = 1:g
x_a(i,j)=str2num( get( a(i,j) ,'String'));
end
end

for k = 1:g
x_b(1,k)=str2num( get( b(1,k) ,'String'));
end

for t = 1:h
x_c(t,1)=str2num( get( c(t,1) ,'String'));
end

CLF(gcf);
cuadro(oferta , demanda , 0, mas_demanda);
end

[i_top,j_top]=size(a);
for i = 1:i_top-mas_oferta
for j = 1:j_top-mas_demanda
set(a(i,j),'String',x_a(i,j));%num2str(cz(i,j)
end
end
for k = 1:j_top-mas_demanda
set(b(1,k),'String',x_b(1,k));
end

for t = 1:i_top-mas_oferta
set(c(t,1),'String',x_c(t,1));
end

BALANCEAR
%ESTA ES UNA FUNCION CON NOMBRE BALANCEAR Y DE VARIABLE OPCION O TAMBIEN
LLAMADA METODO BALANCEAR.
function balancear(opcion)

global a b c oferta demanda;

%DEFINICION DE VARIABLES
mas_demanda=0;
mas_oferta=0;

sum_b=0;
sum_c=0;
band_a=0;

%ESTA OPCION NOS PERMITE REALIZAR EL BALANCE ENTRE OFERTAS Y DEMANDAS, DECLARA
CONDICIONES DE ACUERDO A LA CANTIDAD DE OFERTA Y DEMANDA EN ESTE CASO SUM_B
QUE ES LA SUMA DE OFERTAS Y SUM_C QUE ES LA SUMA DE DEMANDAS LO CUAL SI LA
OFERTA ES MAYOR SE AGREGA UNA COLUMNA Y EL VALOR QUE FALTA PARA SER
BALANCEADO, Y SIEN CASO LA DEMANDA FUERA MAYOR ENTONCES SE AGREGA UNA FILA
CON EL VALOR QUE FALTA PARAQUE ESTEN BALANCEADOS, CON LA RESTRUICCION DE QUE EL
NUMERO NO SE RESTE.
if(opcion==1)

[h,g] = size(a);
for i = 1:h
for j = 1:g
x_a(i,j)=str2num( get( a(i,j) ,'String'));
end
end

for k = 1:g
x_b(1,k)=str2num( get( b(1,k) ,'String'));
sum_b=sum_b+x_b(1,k);
end

for t = 1:h
x_c(t,1)=str2num( get( c(t,1) ,'String'));
sum_c=sum_c+x_c(t,1);
end

if sum_b~=sum_c

if sum_b > sum_c

mas_oferta=1;
valbal=sum_b-sum_c;
CLF(gcf);
cuadro(oferta , demanda , mas_oferta, 0);
band_a=1;
end
if sum_c > sum_b

mas_demanda=1;
valbal=sum_c-sum_b;
CLF(gcf);
cuadro(oferta , demanda , 0, mas_demanda);
band_a=2;
end
end

end

CALCULO

%LLAMA A LA FUNCION CALCULO LO CUAL VA A CALCULAR EL RESULTADO DE TODO EL


METODO DE TRANSPORTE
function calculo

CICLO
%DECLARANDO LA FUNCION CICLO QUE SERA UN VECTOR DE Y FILAS CON NUEVA_BASICAS
COLUMNAS.
function [y,nueva_basicas]=ciclo(x,fila,col,b)

% [y,nueva_basicas]=ciclo(x,fila,col)
% x: solucin actual (m*n)
% b: variables bsicas que entran (m*n)
% fila,col: ndice para la base del elemento que entra
% y: solucin despus del ciclo del cambio (m*n)
% nueva_basicas: nuevas variables bsicas despus del ciclo del cambio (m*n)

nueva_basicas=b;
y=x;
[m,n]=size(x);
lazo=[fila col]; % describe el ciclo del cambio
x(fila,col)=Inf; % no incluir (fila, columna) en la bsqueda
b(fila,col)=Inf;
busca_fila=1; % comenzar a buscar en la misma fila
while (lazo(1,1)~=fila | lazo(1,2)~=col | length(lazo)==2),
if busca_fila, % bsqueda en fila
j=1;
while busca_fila
if (b(lazo(1,1),j)~=0) & (j~=lazo(1,2))
lazo=[lazo(1,1) j ;lazo]; % agregar los ndices del elemento encontrado al lazo
busca_fila=0; % comenzar a buscar en columnas
elseif j==n, % ningn elemento que se interese en esta fila
b(lazo(1,1),lazo(1,2))=0;
lazo=lazo(2:length(lazo),:); % retrocede
busca_fila=0;
else
j=j+1;
end
end
else % bsqueda de la columna
i=1;
while ~busca_fila
if (b(i,lazo(1,2))~=0) & (i~=lazo(1,1))
lazo=[i lazo(1,2) ; lazo];
busca_fila=1;
elseif i==m
b(lazo(1,1),lazo(1,2))=0;
lazo=lazo(2:length(lazo),:);
busca_fila=1;
else
i=i+1;
end
end
end
end
% CLCULO MXIMO - LAZO DE ENVO
l=length(lazo);
val_tmp=Inf;
menor_val=Inf;
for i=2:2:l
if x(lazo(i,1),lazo(i,2))<val_tmp,
val_tmp=x(lazo(i,1),lazo(i,2));
menor_val=i;
end;
end

% CLCULO DE NUEVA MATRIZ DE TRANSPORTE


y(fila,col)=val_tmp;
for i=2:l-1
y(lazo(i,1),lazo(i,2))=y(lazo(i,1),lazo(i,2))+(-1)^(i-1)*val_tmp;
end
nueva_basicas(fila,col)=1;
nueva_basicas(lazo(menor_val,1),lazo(menor_val,2))=0;

CUADRO
%ESTA FUNCION ES DEL DISEO DEL CUADRO PARA EL INGRESO DE DATOS PARA EL
DESARROLLO DEL METODO DE TRANSPORTE
function cuadro(n_ofe ,n_dem , m_ofe, m_dem)

% entradas:
% n_ofe: cantidad de ofertas
% n_dem: cantidad de demandas
% m_ofe: cantidad de nueva oferta
% m_dem: cantidad de nueva demanda

global a b c band1 calculo Calcular oferta demanda;

oferta=n_ofe + m_ofe;
demanda=n_dem + m_dem;

arr_size = [oferta,demanda];

rz=zeros(oferta,demanda);
bz=zeros(1,demanda);
cz=zeros(oferta,1);

a=zeros(oferta,demanda);
b=zeros(1,demanda);
c=zeros(oferta,1);

if arr_size(2) < 2 & arr_size(1) < 2


fig_dim = [arr_size(1)*25+150, 420];
else
fig_dim = [arr_size(1)*25+150, arr_size(2)*60+160]; %[y,x]
end

% DISEO DE LA INTERFACE
whitebg([1 1 1]); % Coloca las letras en negro
set(gcf,'Name' ,'Transporte - Guillermo Montoya - Versin: 1.0 Beta');
set(gcf,'MenuBar','none');
set(gcf,'Resize','off');
set(gcf,'NumberTitle','off');
set(gcf,'Units', 'pixels');
set(gcf,'position',[100 100 fig_dim(2) fig_dim(1)]);
set(gcf,'Color',[0 0.50 0.50]);

% DANDOLE DISEO, COLOR, TAMAO, FUENTE A LA MATRIZ DE COSTOS


bd_size = 5; %border size
posx = bd_size+70; %posicion horizontal
posxb = posx;
posy = fig_dim(1)-50-bd_size;

%DISEANDO TITULO DE LOS COSTOS


TITULO1 = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',8,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','c o s t o s :',...
'Units', 'pixels',...
'Position',[posx posy+22 (55*demanda)-bd_size 15]);

for i = 1:arr_size(1)
for j = 1:arr_size(2)
a(i,j)=uicontrol('Style','edit','BackgroundColor',[1 1
0],'String',num2str(rz(i,j)),'unit','pixels','position', [posx posy 50 20]); %[posx posy 50 20]
tol_a=sprintf(' X %d,%d ',i,j);
set(a(i,j),'TooltipString',tol_a);
posx = posx+50+bd_size; end
posx = posxb;
posy = posy-20-bd_size;
end

% DISEANDO EL RENGLON DE DEMANDAS


bd_size = 5; %border size
posx_b = bd_size+70; %posicion horizontal
posxb_b = posx_b;
posy_b = posy-10-bd_size;%+posy

%TITULO DEL RENGLON DEMANDA


TITULO2 = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',8,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','Demandas:',...
'Units', 'pixels',...
'Position',[posx_b-65 posy_b 65 15]);

[xt_b,yt_b] = size(bz);
ren_dem_size = [1,yt_b];
for i = 1:ren_dem_size(1)
for j = 1:ren_dem_size(2)
b(i,j)=uicontrol('Style','edit','BackgroundColor',[1 1
1],'String',num2str(bz(i,j)),'unit','pixels','position', [posx_b posy_b 50 20]);
tol_b=sprintf('Demanda n: %d',j);
set(b(i,j),'TooltipString',tol_b);
posx_b = posx_b+50+bd_size; end
posx_b = posxb_b;
posy_b = posy_b-20-bd_size;
end

% COLUMNA DE OFERTAS
bd_size = 5; %border size
posx_c = posx+50*demanda+bd_size*demanda;%posx+(posx*yt_c)+(bd_size*yt_c); %posicion
horizontal
posxb_c = posx_c;
posy_c = fig_dim(1)-50-bd_size;

%TITULO DE LA CCOLUMNA DE OFERTAS


TITULO3 = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',8,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','Ofertas:',...
'Units', 'pixels',...
'Position',[posx_c posy_c+22 50 15]);

[xt_c,yt_c] = size(cz);
col_ofer_size = [xt_c,1];
for i = 1:col_ofer_size(1)
for j = 1:col_ofer_size(2)
c(i,j)=uicontrol('Style','edit','BackgroundColor',[1 1
1],'String',num2str(cz(i,j)),'unit','pixels','position', [posx_c posy_c 50 20]); %[posx posy 50 20]
tol_c=sprintf('Oferta n: %d',i);
set(c(i,j),'TooltipString',tol_c);
posx_c = posx_c+50+bd_size;
end
posx_c = posxb_c;
posy_c = posy_c-20-bd_size;
end
% BOTON DE AGREGAR FILA OFERTA
Addfil = uicontrol(gcf,...
'Style','pushbutton',...
'FontSize',8,'FontName','Arial',...
'Units', 'pixels',...
'Position',[posx_c-165 posy_c-55 105 20],...
'String','Agregar Oferta',...
'CallBack','agregar(1);');

% BOTON DE CALCULO COLOMNA DEMANDA


Addcol = uicontrol(gcf,...
'Style','pushbutton',...
'FontSize',8,'FontName','Arial',...
'Units', 'pixels',...
'Position',[posx_c-55 posy_c-55 105 20],...
'String','Agregar Demanda',...
'CallBack',['agregar(2);']);

% % BOTON DE BALANCEAR
Balan = uicontrol(gcf,...
'Style','pushbutton',...
'FontSize',8,'FontName','Arial',...
'Units', 'pixels',...
'Position',[posx_c-165 posy_c-75 105 20],...
'String','Balancear',...
'CallBack','balancear(1);');

% BOTON DE CALCULO COLOMNA DEMANDA


Salir = uicontrol(gcf,...
'Style','pushbutton',...
'FontSize',8,'FontName','Arial',...
'Units', 'pixels',...
'Position',[posx_c-55 posy_c-75 105 20],...
'String','< Salir >..',...
'CallBack', 'close;');

% BOTON DE CALCULO
Calcular = uicontrol(gcf,...
'Style','pushbutton',...
'FontSize',8,'FontName','Arial',...
'Units', 'pixels',...
'Position',[posx_c posy_c-17 52 20],...
'String','Calcular');%,...
set(Calcular,'callback','calculo;');
MASPOS

function [maxv,fil,col] = maspos(vargin);


% ESTA FUNCIN ENCUENTRA EL VALOR MXIMO
% Y LA POSICIN (FILA, COLUMNA) DE LA MATRIZ DE ENTRADA
% SALIDA: MAXV VALOR MXIMO DE LA MATRIZ DE ENTRADA
% FIL FILA DONDE EXISTE EL VALOR MXIMO
% COL COLUMNA DONDE EXISTE EL VALOR MXIMO

dim = size(vargin);
if length(dim)~=2
error('Matriz Invlida!');
end
maxv=0;
fil=0;
col=0;

% maxv ES EL VALOR MXIMO DE LA MATRIZ DE ENTRADA


maxv = max(vargin(:));
if(maxv>0)

% FIND: ENCUENTRA EL VALOR MXIMO Y LA POSICIN DE LA MATRIZ DE ENTRADA


% 1 INDICA QUE ENCOTRARA UN SOLO VALOR EL PRIMERO QUE ENCUENTRE
[fil,col] = find(vargin==maxv,1);
End

MULTIPLICADORES
%DECLARANDO LA FUNCION MULTIPLICADORES
%ESTA FUNCION NOS PERMITE MULTIPLICAR TODOS LOS VALORES DENTRO DE LA MATRIS E IR
IGUALANDO UNA POR UNA EN EL METODO DE TRANSPORTE PARA QUE LA OFERTA Y
DEMANDA VAYE DESAPARECIENDO

Funcion [u,v]=multiplicadores(x,c,b)

%x= SOLUCION ACTUAL (M*N)


%B=1 PARA CADA VARIABLE BASICA 0 PARA NO BASICA
%C= COSTOS(M*N)
%U=MULTIPLICADORES DE LAGRANGE PARA LAS FILAS (M*1)
% V=MULTIPLICADORES DE LAGRANGE PARA LAS COLUMNAS (N*1)
NOROESTE
%DEFINIENDO LA FUNCION NOROESTE
Funcin [x.b] = noroeste(s,d)

%DONDE X ES ENVIOS USANDO NOROESTE (M*N), S ES OFERTAS (M*1) Y D ES DEMANDA


(N*1).
If (sum(s)~=sum(d)),
Disp.(EROR: El total de la oferta no es igual al total de la demanda.);
Return;
End
M=length(s);
N=length(d);
I=1;
J=1;
X=zeros(m,n);
B=zeros(m,n);

M TRANSPORTE
%DEFINIENDO LA FUNCION M TRANSPORTE
function [x,costo]=m_transporte(s,d,c);
% function [x,cost]=transporte(s,d,c)
%
% s = ofertas (m*1)
% d = demanda (n*1)
% c = costos (m*n)
% x = solucin ptima (m*n)
% cost = costo de transporte mnimo

%DONDE S ES OFERTAS (M*1) , D ES DEMANDA (N*1).


global vs us cuadro nb b2 c2 costo TITULUS TITULVS Calcular;
cost=[];

% Introducir b como una matriz con unos para las variables bsicas
% y ceros para las variables no bsicas.
%clc
disp(' La regla del noroeste da una solucin bsica inicial.');
disp(' Cuadro del transporte [x s;d'' 0]')
[x,b]=noroeste(s,d);
[x s;d' 0]
disp(' ')
costo_ini=num2str(sum(sum(c.*x)));
disp([' Costo de transporte = ',num2str(sum(sum(c.*x)))]);
disp(' ')
[tamx,tamy]=size(x);
resultado(tamx,tamy);
set(nb,'visible','off');
set(vs,'visible','off');
set(us,'visible','off');
set(TITULUS,'visible','off');
set(TITULVS,'visible','off');
vbc=0;%acumulador para imprimir
for i = 1:tamx
for j = 1:tamy
if (x(i,j)~=0)
set(cuadro(i,j),'String',num2str(x(i,j)));
vals1=sprintf('%d',x(i,j));
vals2=sprintf('%d',c(i,j));
vbas{i+j}=sprintf('X %d,%d = %s',i,j,vals1);
mult=sprintf('%d',x(i,j)*c(i,j));
cosbas{i+j}=sprintf('%s x %s = %s',vals1,vals2,mult);
end
set(costo(i,j),'String',num2str(c(i,j)));
end

end
tp=d';
for j = 1:tamy
set(b2(1,j),'String',num2str(tp(1,j)));
end
for i = 1:tamx
set(c2(i,1),'String',num2str(s(i,1)));
end
solbasica(vbas,cosbas,costo_ini);

%PAUSE
waitfor(warndlg('Solucin Bsica Inicial...Precione (OK) para continuar','Cuadro de
Transporte'));
iter=0;
while 1
[u,v]=multiplicadores(x,c,b);
disp(' Cuadro de costos [c u;v'' 0]');
[c u;v' 0]
%%%%%
set(TITULUS,'visible','on');
set(TITULVS,'visible','on');
set(vs,'visible','on');
set(us,'visible','on');
tk=v';
for j = 1:tamy
set(vs(1,j),'String',num2str(tk(1,j)));
end
for i = 1:tamx
set(us(i,1),'String',num2str(u(i,1)));
end

%PAUSE
waitfor(warndlg('Mtodo de Multiplicadores Aplicado...Precione (OK) para
continuar','Cuadro de Transporte'));
disp(' ')
disp(' Costos reducidos ')
r=(c-u*ones(size(v'))-ones(size(u))*v')*(-1);
set(nb,'visible','off');
for i = 1:tamx
for j = 1:tamy
if (r(i,j)~=0)
set(nb(i,j),'visible','on');
set(nb(i,j),'String',num2str(r(i,j)));
end
end
end
if any(any(r<0))
disp(' ')
[maxv,i,j] = maspos(r);
if(maxv==0)
break
end
else
break
end;
disp(' ')
disp(' Cuadro del transporte [x s;d'' 0]');
var_ent=sprintf('Entra X %d,%d con valor= %d',i,j,maxv);
waitfor(warndlg(var_ent,'Variable ms positiva que Entra'));
[x,b]=ciclo(x,i,j,b);
[x s;d' 0]
for i = 1:tamx
for j = 1:tamy
if (b(i,j)==1)
set(cuadro(i,j),'String',num2str(x(i,j)));
else
set(cuadro(i,j),'String','');
end
end
end

disp(' ')

%PAUSE
waitfor(warndlg('Construccin de Ciclo Aplicado...Precione (OK) para continuar','Cuadro de
Transporte'));
cost=[cost ; sum(sum(c.*x))];
fprintf('Costo de transporte = %g\n\n',cost(length(cost)));
etiq=sprintf('Costo de Transporte = %g para la Iteracin N %d',cost(length(cost)),iter+1);
waitfor(warndlg(etiq,'Costo de Transporte'));
cost_iter{iter+1}=sprintf('\n%d )- %d',iter+1,cost(length(cost)));
iter=iter+1;
end
for i = 1:tamx
for j = 1:tamy
if (~isempty(get(cuadro(i,j),'String')))
valsb1=sprintf('%d',x(i,j));
valsb2=sprintf('%d',c(i,j));
vbasc{j,i}=sprintf('X %d,%d = %s',i,j,valsb1);
multb=sprintf('%d',x(i,j)*c(i,j));
costbas{j,i}=sprintf('%s x %s = %s',valsb1,valsb2,multb);
end
end
end

disp(' ')

%PAUSE
waitfor(warndlg('Clculo Terminado...Precione (OK) para continuar','Cuadro de Transporte'));
fprintf('Costos de transporte para todas las iteraciones:\n');
cost
if(isempty(cost))
else
solcosto(cost_iter,cost(length(cost)),vbasc,costbas);
end

set(Calcular,'enable','on');

RESULTADO
oferta=n_ofe;
demanda=n_dem;

arr_size = [oferta,demanda];

rz=zeros(oferta,demanda);
bz=zeros(1,demanda);
cz=zeros(oferta,1);

a=zeros(oferta,demanda);
b=zeros(1,demanda);
c=zeros(oferta,1);

if arr_size(2) < 2
fig_dim = [arr_size(1)*25+400, 650];
else
fig_dim = [arr_size(1)*25+400, arr_size(2)*60+360];
end

% DISEO DE LA INTERFACE

t2=figure;
whitebg([1 1 1]); % Coloca las letras en negro
set(gcf,'Name' ,'Resultado:.');
set(gcf,'MenuBar','none');
set(gcf,'Resize','off');
set(gcf,'NumberTitle','off');
set(gcf,'Units', 'pixels');
set(gcf,'position',[2 2 fig_dim(2) fig_dim(1)]);
set(gcf,'Color',[0 0.50 0.50]);

% RENGLON DE VS
bd_size = 5; %borde size
posx_b = bd_size+100; %posicion horizontal
posxb_b = posx_b;
posy_b = fig_dim(1)-80-bd_size;

[xt_b,yt_b] = size(bz);
ren_dem_size = [1,yt_b];

for j = 1:ren_dem_size(2)
vs(1,j)=uicontrol('Style','edit','BackgroundColor',[1 1 1],'String','','unit','pixels','position',
[posx_b posy_b 80 30]);
tol_b=sprintf('V%d:',j);
set(vs(1,j),'TooltipString',tol_b);
TITULVS(1,j) = uicontrol(gcf,'Style','text','BackgroundColor',[0.3 0.7
0.3],'FontSize',10,'FontName','ARIAL','FontWeight','bold','ForegroundColor', [1 1 1],...
'String',tol_b,'Units', 'pixels','Position',[posx_b posy_b+30 80 15]);
posx_b = posx_b+70+bd_size;
end

% COLUMNA DE US
bd_size = 5; %borde size
posx_c = bd_size+500;
posxb_c = posx_c;
posy_c = fig_dim(1)-150-bd_size;

[xt_c,yt_c] = size(cz);
col_ofer_size = [xt_c,1];
for i = 1:col_ofer_size(1)
us(i,1)=uicontrol('Style','edit','BackgroundColor',[1 1 1],'String','','unit','pixels','position',
[posx_c-475 posy_c 70 30]);
tol_c=sprintf('U%d:',i);
set(us(i,1),'TooltipString',tol_c);
TITULUS(i,1) = uicontrol(gcf,'Style','text','BackgroundColor',[0.3 0.7
0.3],'FontSize',10,'FontName','ARIAL','FontWeight','bold','ForegroundColor', [1 1 1],...
'String',tol_c,'Units', 'pixels','Position',[posx_c-475 posy_c+30 70 15]);
posx_c = posxb_c;
posy_c = posy_c-45-bd_size;
end

% MATRIZ DE ASIGNACION
bd_size = 5; %borde size
posx = bd_size+100; %posicion horizontal
posxb = posx;
posy = fig_dim(1)-150-bd_size;

for i = 1:arr_size(1)
for j = 1:arr_size(2)
cuadro(i,j)=uicontrol('Style','edit','BackgroundColor',[0.75 0.75
0.75],'String','','unit','pixels','ForegroundColor',[0.25 0.25 1]
,'HorizontalAlignment','center','position', [posx posy 80 50]);
tol_a=sprintf(' X %d,%d ',i,j);
set(cuadro(i,j),'TooltipString',tol_a);
posx = posx+70+bd_size;
end
posx = posxb;
posy = posy-45-bd_size;
end

% MATRIZ DE VARIABLES NO BASICAS


bd_size = 5; %borde size
posx = bd_size+100; %posicion horizontal
posxb = posx;
posy = fig_dim(1)-150-bd_size;

for i = 1:arr_size(1)
for j = 1:arr_size(2)
nb(i,j)=uicontrol('Style','edit','BackgroundColor',[1 1
1],'String','','unit','pixels','ForegroundColor',[1 0.25 0.25]
,'HorizontalAlignment','center','position', [posx posy 55 15]);
tol_a=sprintf(' X %d,%d ',i,j);
set(nb(i,j),'TooltipString',tol_a);
posx = posx+70+bd_size;
end
posx = posxb;
posy = posy-45-bd_size;
end

% MATRIZ DE COSTOS
bd_size = 5; %borde size
posxc = bd_size+100; %posicion horizontal
posxbc = posxc;
posyc = fig_dim(1)-150-bd_size;

for i = 1:arr_size(1)
for j = 1:arr_size(2)
costo(i,j)=uicontrol('Style','edit','BackgroundColor',[1 1
0],'String','','unit','pixels','ForegroundColor',[0 0 0] ,'HorizontalAlignment','center','position',
[posxc+23 posyc+34 55 15]);
tol_a=sprintf(' X %d,%d ',i,j);
set(costo(i,j),'TooltipString',tol_a);
posxc = posxc+70+bd_size;
end
posxc = posxbc;
posyc = posyc-45-bd_size;
end

% RENGLON DE DEMANDAS
bd_size = 5; %borde size
posx_b = bd_size+100; %posicion horizontal
posxb_b = posx_b;
posy_b = posy-10-bd_size;

%TITULO DEL RENGLON DEMANDA


TITULO2 = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...ojo
'FontSize',8,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...ojo
'String','Demandas:',...
'Units', 'pixels',...
'Position',[posx_b-65 posy_b 65 25]);

[xt_b,yt_b] = size(bz);
ren_dem_size = [1,yt_b];
for i = 1:ren_dem_size(1)
for j = 1:ren_dem_size(2)
b2(i,j)=uicontrol('Style','edit','BackgroundColor',[1 1
1],'String',num2str(bz(i,j)),'unit','pixels','position', [posx_b posy_b 80 30]);
tol_b=sprintf('Demanda n: %d',j);
set(b2(i,j),'TooltipString',tol_b);
posx_b = posx_b+70+bd_size;
end
posx_b = posxb_b;
posy_b = posy_b-25-bd_size;
end

% COLUMNA DE OFERTAS
bd_size = 5; %borde size
posx_c = posx+75*demanda+bd_size*demanda;
posxb_c = posx_c;
posy_c = fig_dim(1)-150-bd_size;

%TITULO DE LA COLUMNA DE OFERTAS


TITULO3 = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',8,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','Ofertas:',...
'Units', 'pixels',...
'Position',[posx_c posy_c+50 80 15]);

[xt_c,yt_c] = size(cz);
col_ofer_size = [xt_c,1];
for i = 1:col_ofer_size(1)
for j = 1:col_ofer_size(2)
c2(i,j)=uicontrol('Style','edit','BackgroundColor',[1 1
1],'String',num2str(cz(i,j)),'unit','pixels','position', [posx_c posy_c 80 50]);
tol_c=sprintf('Oferta n: %d',i);
set(c2(i,j),'TooltipString',tol_c);
posx_c = posx_c+70+bd_size;
end
posx_c = posxb_c;
posy_c = posy_c-45-bd_size;
end

% BOTON DE SALIR
Salir = uicontrol(gcf,...
'Style','pushbutton',...
'FontSize',8,'FontName','Arial',...
'Units', 'pixels',...
'Position',[posx_c posy_c-17 80 30],...
'String','< Salir >..',...
'CallBack', 'close;');

SOLBASICA
% DISEO DE LA INTERFACE
t3=figure;
whitebg([1 1 1]); % Coloca las letras en negro
set(gcf,'Name' ,'Solucin Basica Inicial');
set(gcf,'MenuBar','none');
set(gcf,'Resize','off');
set(gcf,'NumberTitle','off');
set(gcf,'Units', 'pixels');
set(gcf,'position',[200 200 450 300]);
set(gcf,'Color',[0 0.50 0.50]);

%TITULO
TITULOA = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','Variables Bsicas:',...
'Units', 'pixels',...
'Position',[10 270 215 20]);
%TITULO
TITULOB = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','Costo:',...
'Units', 'pixels',...
'Position',[230 270 215 20]);

%V. BSICAS
RESULT_A= uicontrol(gcf,...
'Style','edit',...
'BackgroundColor',[0 0.50 0.50],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'HorizontalAlignment','left',...
'String',vbas,...
'Units', 'pixels',...
'Max',100,...
'Position',[10 115 215 150]);

%COSTO
RESULT_B= uicontrol(gcf,...
'Style','edit',...
'BackgroundColor',[0 0.50 0.50],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 0 0],...
'HorizontalAlignment','left',...
'String',cosbas,...
'Units', 'pixels',...
'Max',100,...
'Position',[230 115 215 150]);

%COSTO TOTAL
TITULOC = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','COSTO TOTAL =',...
'Units', 'pixels',...
'Position',[10 80 215 20]);

%COSTO TOTAL
TITULOD = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 0 0],...
'String',costo_total,...
'Units', 'pixels',...
'Position',[230 80 215 20]);

%CERRAR
cerrasol=uicontrol(gcf,...
'Style','pushbutton',...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [0 0.50 0.50],...
'String','< Cerrar >',...
'Units', 'pixels',...
'Position',[180 10 100 20],...
'callback','close;');

SOLCOSTO

% DISEO DE LA INTERFACE
t4=figure;
whitebg([1 1 1]); % Coloca las letras en negro
set(gcf,'Name' ,'Costo Total de Transporte');
set(gcf,'MenuBar','none');
set(gcf,'Resize','off');
set(gcf,'NumberTitle','off');
set(gcf,'Units', 'pixels');
set(gcf,'position',[50 200 680 300]);
set(gcf,'Color',[0 0.50 0.50]);

%TITULO
TITULOA = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','Variables Bsicas:',...
'Units', 'pixels',...
'Position',[10 270 215 20]);

%TITULO
TITULOB = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','Costo:',...
'Units', 'pixels',...
'Position',[230 270 215 20]);

%TITULO
TITULOC = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','Costos para toda las Iteraciones:',...
'Units', 'pixels',...
'Position',[450 270 215 20]);

%V. BSICAS
RESULT_A= uicontrol(gcf,...
'Style','edit',...
'BackgroundColor',[1 1 1],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [0 0 1],...
'HorizontalAlignment','left',...
'String',vbasc,...
'Units', 'pixels',...
'Max',100,...
'Position',[10 85 215 180]);

%COSTO
RESULT_B= uicontrol(gcf,...
'Style','edit',...
'BackgroundColor',[1 1 1],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [0 0 1],...
'HorizontalAlignment','left',...
'String',costos_f,...
'Units', 'pixels',...
'Max',100,...
'Position',[230 85 215 180]);

%SOLUCIONES ITERACIONES
RESULT_C= uicontrol(gcf,...
'Style','edit',...
'BackgroundColor',[1 1 1],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 0 0],...
'HorizontalAlignment','center',...
'String',costo_i,...
'Units', 'pixels',...
'Max',100,...
'Position',[450 85 215 180]);

%COSTO TOTAL
TITULOC = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 1 1],...
'String','COSTO TOTAL =',...
'Units', 'pixels',...
'Position',[10 58 215 20]);

%COSTO TOTAL
TITULOD = uicontrol(gcf,...
'Style','text',...
'BackgroundColor',[0.3 0.7 0.3],...
'FontSize',10,'FontName','ARIAL',...
'FontWeight','bold',...
'ForegroundColor', [1 0 0],...
'String',costo_total,...
'Units', 'pixels',...
'Position',[230 58 215 20]);
CONCLUSIONES

El mtodo de transporte es muy til para el tipo de resoluciones de estos


problemas como fue identificado en el informe

Alcanzamos concluir que este mtodo no nos da la mejor solucin pero


la solucin que presenta este trabajo cumple con todas las
restricciones presentadas por el problema.

Este mtodo comienza asignando la cantidad mxima permisible para la


oferta y la demanda.

Mediante la aplicacin de este mtodo podemos hallar directamente el


costo total unitario de transporte para cada posible solucin

La ventaja de este mtodo es la rapidez de su ejecucin y es usado en


numerosos ejercicios por su facilidad para obtener resultados.

El mtodo de esquina noroeste no tiene en cuenta los costos para


hacer las asignaciones.

El software diseado usa como base un modelo tarifario de transporte


lineal en base a rutas especficas. El objetivo principal del software es el
determinar la tarifa de transporte para un numero especifico de
vehculos en una ruta especfica, comparar las tarifas y seleccionar la de
menor costo.

Habitualmente el resultado obtenido mediante este mtodo nos deja


lejos del valor ptimo.

Você também pode gostar