function plotgraph(A,xy,weights)
[n,m]= size(A);
R = max(max(abs(xy)));
x = xy(:,1)/R; y = xy(:,2)/R;
weights = weights/max(abs(weights));
rNode = 0;
wNode = 2;
PWColor = [0 0 1];
NWColor = [1 0 0];
Wmin = 0.0001;
max_width = 0.05;
for i=1:m
if ( abs(weights(i)) > Wmin )
Isrc = find( sign(weights(i))*A(:,i)>0 );
Idst = find( sign(weights(i))*A(:,i)<0 );
else
Isrc = find( A(:,i)>0 );
Idst = find( A(:,i)<0 );
end
xdelta = x(Idst) - x(Isrc); ydelta = y(Idst) - y(Isrc);
RotAgl = atan2( ydelta, xdelta );
xstart = x(Isrc) + rNode*cos(RotAgl); ystart = y(Isrc) + rNode*sin(RotAgl);
xend = x(Idst) - rNode*cos(RotAgl); yend = y(Idst) - rNode*sin(RotAgl);
L = sqrt( xdelta^2 + ydelta^2 ) - 2*rNode;
if ( weights(i) > Wmin )
W = abs(weights(i))*max_width;
drawedge(xstart, ystart, RotAgl, L, W, PWColor);
hold on;
elseif ( weights(i) < -Wmin )
W = abs(weights(i))*max_width;
drawedge(xstart, ystart, RotAgl, L, W, NWColor);
hold on;
else
plot([xstart xend],[ystart yend],'k:','LineWidth',2.5);
end
end
angle = linspace(0,2*pi,100);
xbd = rNode*cos(angle);
ybd = rNode*sin(angle);
for i=1:n
plot( x(i)+xbd, y(i)+ybd, 'k', 'LineWidth', wNode );
end;
axis equal;
set(gca,'Visible','off');
hold off;
function drawedge( x0, y0, RotAngle, L, W, color )
xp = [ 0 L L L L L 0 0 ];
yp = [-0.5*W -0.5*W -0.5*W 0 0.5*W 0.5*W 0.5*W -0.5*W];
RotMat = [cos(RotAngle) -sin(RotAngle); sin(RotAngle) cos(RotAngle)];
DrawCoordinates = RotMat*[ xp; yp ];
xd = x0 + DrawCoordinates(1,:);
yd = y0 + DrawCoordinates(2,:);
patch( xd, yd, color );