% matlab code to plot minimum-cost network; % loads the data file mincost.dat into a matrix ex2. load mincost.dat % move it to A A = mincost; % figure number of arcs to plot N = size(A,1); % figure number of nodes (assumed numbered as integers, starting at zero) nodes = max(max(A(:,1:2))) + 1; % pi = 4*atan(1.0); % what's the biggest flow? maxflow = max(A(:,3)); clf; figure(1); inx=0:nodes-1; x = cos(inx*2*pi/nodes); y = sin(inx*2*pi/nodes); scatter(x,y,100,[0 0 1]); xt=1.1*x; yt=1.1*y; for i=1:nodes text(xt(i),yt(i),num2str(inx(i))); end % draw the flow lines: gray for arcs with no flow, shades of blue % for arcs with flow (closer to dark blue for heavy flow) for i=1:N, x = [cos(A(i,1)*2*pi/nodes), cos(A(i,2)*2*pi/nodes)]; y = [sin(A(i,1)*2*pi/nodes), sin(A(i,2)*2*pi/nodes)]; if A(i,3)==0 colorarr = .9 * [1 1 1]; else colorarr = [1-(A(i,3)/maxflow) 1-(A(i,3)/maxflow) 1]; end line(x,y,'LineWidth',2,'Color',colorarr); if A(i,3) > 0 xt = (x(1)+x(2))/2; yt = (y(1)+y(2))/2; text(xt,yt,num2str(A(i,3))); end end axis([-1.1 1.1 -1.1 1.1]); axis square; title('solution to mincost flow problem');