Help with how to interpret Code given in a paper

9 visualizaciones (últimos 30 días)
Garrett
Garrett el 29 de Jul. de 2017
Comentada: Garrett el 31 de Jul. de 2017

I am reading this paper SOLVING TRANSPORTATION PROBLEM BY USING MATLAB and I am having trouble with the 4th code down "The MODI MEthod" the code that is given in the paper is a mess of misplaced 'end's and other such issues. Below I have given my attempt at pasting it but still crops up with errors such as 'function not permitted in this context' is there a technique for deciphering this?

clc;
clear all;
close all;
function [ibfs,objCost] = modi method(data)
x=input('enter the transportation matrix');
x=sd('supply; demand');
val = -1;
while val< 0[prow,pcol]=find(ibfs> 0);
    occupiedCells=[prow,pcol];
    [prow,pcol]=find(ibfs==0);
    unoccupiedCells = [prow,pcol];
    r = 0;
    k = [column occupied];
    for i = 1:length(occupiedCells(1,:)) 
        ri = occupiedCells(1,i);
        kj = occupiedCells(2,i);
        [r,k] = occupiedSystemSolve(r,k,ri,kj,cost);
    end
    improvementIndex = zeros(length(unoccupiedCells(1,:)),3);
    for i = 1:length(unoccupiedCells(1,:)) 
        ri = unoccupiedCells(1,i);
        kj = unoccupiedCells(2,i);
        e = cost(ri,kj) - r(ri) - k(kj);
        improvementIndex(i,:) = [ri,kj,e];
    end
    [val,ind] = min(improvementIndex(:,end));
    if val< 0 %check whether improvement is required ri = improvementIndex(ind,1);
        kj = improvementIndex(ind,2);
        disp(['Create a circuit around cell (' num2str(ri) ',' num2str(kj) ')' ]);
        circuitImproved = [ri,kj,0];
        n = input('Enter number of element that forms the circuit: ');
    for i = 1:n 
        nCells = input(['Enter the index of cell ' num2str(i) ' that forms the circuit: ']);
        if mod(i,2) == 0 circuitImproved(i+1,:) = [nCells, ibfs(nCells(1),nCells(2))];
        else circuitImproved(i+1,:) = [nCells, -ibfs(nCells(1),nCells(2))];
        end
    end
    ibfs = reallocateDemand(ibfs,circuitImproved);
    disp(ibfs) 
    objCost = sum(sum(ibfs.*cost));
    end
end
    function [r,k] = occupiedSystemSolve(r,k,ri,kj,cost)
    if length(r)>=rik(kj)== cost(ri,kj)-r(ri);
    elser(ri) = cost(ri,kj)-k(kj);
    end
    function [y,demand,supply,ctemp] = chkdemandsupply(demand,supply,ded,sud,ctem)
    tempd= demand;
    temps = supply;
    if tempd(ded) > temps(sud) 
        temps(sud) = 0;
        tempd(ded) = demand(ded) - supply(sud);
        y = supply(sud);ctem(sud,:) = inf;
    elseif tempd(ded) < temps(sud) 
        tempd(ded) = 0;
        temps(sud) = supply(sud) - demand(ded);
        y = demand(ded);
        ctem(:,ded) = inf;
    end
    elseif  tempd(ded) == temps(sud) 
        tempd(ded) = 0;
        temps(sud) = 0;
        y = demand(ded);
        ctem(:,ded) = inf;
        ctem(sud,:) = inf;
    end
demand =tempd;
supply = temps;
ctemp = ctem;
disp(['the transportation cost is ', sum(sum(ibfs.*cost))]);
  3 comentarios
Garrett
Garrett el 31 de Jul. de 2017
okay the if true thing is just the comment box auto addition thing that idk how to get rid of, but i will try fixing the functions
Walter Roberson
Walter Roberson el 31 de Jul. de 2017
The code is broken. I posted a less-broken version.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 30 de Jul. de 2017
Yep, that code is a mess.
Some of the parts you are looking at appear to be the same as in the earlier https://www.researchgate.net/publication/281409940_MATLAB_Implementation_of_Vogel%27s_Approximation_and_the_Modified_Distribution_Methods which has the same typos.
I have done some cleaning up of the code, and have attached that.
However, the code is still not usable. It uses the undefined function sd(). It is not clear why it uses that. It is not clear why it bothers with data or x or sd as it does not use any of those. But it does have an internal prompt about circuits, and it is not clear from the paper what values should be input there.
Some of the other code in that paper has completely bogus function names. And the sd() part just doesn't make sense.
  1 comentario
Garrett
Garrett el 31 de Jul. de 2017
Thank you, it is a shame it doesn't work. I have had no luck doing it from scratch either.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by