Help with how to interpret Code given in a paper

9 次查看(过去 30 天)

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 个评论
Garrett
Garrett 2017-7-31
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

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2017-7-30
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 个评论
Garrett
Garrett 2017-7-31
Thank you, it is a shame it doesn't work. I have had no luck doing it from scratch either.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by