here is a simple rewrite that runs well for large networks. Th costmatrix is sparse (no entries for non-existing links) and only total costs are calculated:
function [spcost] = dijkstra(costmatrix, s, d)
% uses sparse matrix and ingores paths to save time and memory for large networks
% calculates totals cost only
% This is an implementation of the dijkstra´s algorithm, wich finds the
% minimal cost path between two nodes. It´s supoussed to solve the problem on
% possitive weighted instances.
% n*n costmatrix, can be sparse for nonexisting links
% n: the number of nodes in the network;
% s: source node index;
% d: destination node index;
%For information about this algorithm visit:
%This implementatios is inspired by the Xiaodong Wang's implememtation of
%the dijkstra's algorithm, available at
%file ID 5550
%Author: Jorge Ignacio Barrera Alviar. April/2007
%Edited Dirk Stelder September/2013
S(1:n) = 0; % vector, set of visited vectors
dist(1:n) = inf; % it stores the shortest distance between the source node and any other node;
prev(1:n) = n+1; % Previous node, informs about the best previous node known to reach each network node
dist(s) = 0;
if costmatrix(u,i)>0 % ignore non-existing links (=zero in sparse matrices) to save time and memory
spcost = dist(d);
I'm having trouble using this for large datasets - it works fine for 10 start/end points, but take that up an to 1000 startpoints and endpoints, and my computer almost always runs out of memory. Any way to make it more efficient would be much appreciated.
This is a script with no comments on how to use it.
The file AS_TSP.m clears all variables (!) and then calls the file DistanceMatrix.m which contains a graph. It makes use of the function randint (from Communications Toolbox?).
I think the author should consider to rewrite it as it might be actually useful but it's not very usable in the current version.