No BSD License  

Highlights from
MatPlanWDM v0.5

image thumbnail
from MatPlanWDM v0.5 by Pablo Pavon MariƱo
Educational network planning tool for the RWA problem in WDM networks (MILP and heuristic based)

plotTrafficFlow (nodesPlaceMatrix, edgeTable, flowID, flowTable, flowRoutingMatrix, topologyTitle)
% plotTrafficFlow
% 
%>> Usage:      plotTrafficFlow (nodesPlaceMatrix, edgeTable, flowID,
%flowTable, flowRoutingMatrix, topologyTitle)
%
%>> Abstract:   This function draws the component of traffic in an edge due to the pair of nodes <flowOrigin, flowDestination> 
%               over the network topology. We call partial flow to this component of traffic. The network topology of nodes and 
%               edges is done by mean of the positions of nodes and the matrix of edges information. In this representation it is   
%               not assumed bidirectional edges between each node pair and the edges are represented by means of arrows.
%              
%>> Arguments:
%   o In: 
%     nodesPlaceMatrix(Nx2): XY coordinates of nodes, where N is the number of nodes. 
%      They are contained in the first and second column respectively.
%
%    . edgeTable(M,2): M-by-2 integer matrix. Each row is an edge (physical link 
%      or lightpath) 'm', where the first and second columns of each row are the 
%      origin node 'x' and destination node 'y' of this edge 'm' respectively and
%      M is the number of physical links or lightpaths if the network topology
%      is physical or virtual respectively.
%
%     flowID(1x1): Identifier of the flow to plot
%
%   . flowTable(F,6): F-by-6 integer matrix where F is the number of flows.
%     Each row is a flow 'f', where the first column is the serial number of the
%     flow, the second column is the source node 's', the third column is the 
%     destination node 'd', the fourth column is the  traffic flow from 
%     node 's' to node 'd', the fifth column is the initial time of the flow, and the 
%     sixth column is the total duration of the flow. 
%
%   . flowRoutingMatrix (F,L): F-by-L integer matrix where F is the number of 
%     flows and L is the number of lightpaths. Each row is a flow 'f' and each 
%     column is a lightpath 'l'. If a flow 'f' uses a lightpath 'l', the entry
%     (f,l) is equal to the value of the flow 'f' carried by the lightpath 'l'. If no 
%     lightpath is used by the flow 'f', the entry is equal to '0'. 
%
%     topologyTitle:  Title of the plot.
%
function plotTrafficFlow (nodesPlaceMatrix, edgeTable, flowID, flowTable, flowRoutingMatrix, topologyTitle)

if (nargin==0),  help plotTrafficFlow;return, end %help calling
if (nargin~=6),  error('1: Incorrect number of arguments.'),end %Number of input arguments different of 6
if(size(nodesPlaceMatrix,2)~=2), error('2: Argument "nodePlaceMatrix" must have two columns'), end

backgroundScaleX = abs(max(nodesPlaceMatrix(:,1)) - min(nodesPlaceMatrix(:,1)));
backgroundScaleY = abs(max(nodesPlaceMatrix(:,2)) - min(nodesPlaceMatrix(:,2)));
textOffset = 0.03;

%All nodes are drawn 
plot(nodesPlaceMatrix(:,1),nodesPlaceMatrix(:,2),'bo','MarkerSize',10,'Color',[1 0.41 0],'LineWidth',2.0,'MarkerFaceColor',[1 0.41 0]);
%The axis are fixed in both dimensions according to minimum and maximum values of nodesPlaceMatrix
axis([min(min(nodesPlaceMatrix(:,1)))-backgroundScaleX*0.01 max(max(nodesPlaceMatrix(:,1)))+backgroundScaleX*0.01 min(min(nodesPlaceMatrix(:,2)))-backgroundScaleY*0.01 max(max(nodesPlaceMatrix(:,2)))+backgroundScaleY*0.1],'manual','off');

%We draw the virtual topology .With a virtual topology, we are drawing an arrow diagram (lightpath network)
H=title(topologyTitle,'FontSize',8,'Fontweight','light','FontName','Verdana','HorizontalAlignment','Center','VerticalAlignment','Baseline');
aux=get(H,'Position');
for m=1:size(edgeTable,1),
%     line([nodesPlaceMatrix(edgeTable(m,1),1) nodesPlaceMatrix(edgeTable(m,2),1)],[nodesPlaceMatrix(edgeTable(m,1),2) nodesPlaceMatrix(edgeTable(m,2),2)],'color',[1 0.4 0],'lineWidth',1);
      arrow(line([nodesPlaceMatrix(edgeTable(m,1),1) nodesPlaceMatrix(edgeTable(m,2),1)],[nodesPlaceMatrix(edgeTable(m,1),2) nodesPlaceMatrix(edgeTable(m,2),2)],'color',[0 0 0.52],'lineWidth',1),'Length',19,'BaseAngle',90,'TipAngle',5,'Width',0,'FaceColor',[0 0 0.52]);
end

%We draw the traffic flow with identifier "flowID". We are drawing an arrow diagram.
flowEdges=find(flowRoutingMatrix(flowID,:)>0);

for i=1:length(flowEdges),
    arrow(line([nodesPlaceMatrix(edgeTable(flowEdges(i),1),1) nodesPlaceMatrix(edgeTable(flowEdges(i),2),1)],[nodesPlaceMatrix(edgeTable(flowEdges(i),1),2) nodesPlaceMatrix(edgeTable(flowEdges(i),2),2)],'color',[0 0.6 0.2],'lineWidth',2),'Length',19,'BaseAngle',90,'TipAngle',10,'Width',0,'FaceColor',[0 0.6 0.2]);
    
    %The distances between source and destination node pair in
    %both dimensions are necessary
    distanceX=nodesPlaceMatrix(edgeTable(flowEdges(i),2),1) - nodesPlaceMatrix(edgeTable(flowEdges(i),1),1);
    distanceY=nodesPlaceMatrix(edgeTable(flowEdges(i),2),2) - nodesPlaceMatrix(edgeTable(flowEdges(i),1),2);
       
    colour=[0 0 0];
    textLabel={[num2str( flowRoutingMatrix(flowID,flowEdges(i))  )],['%F:',num2str( 100* flowRoutingMatrix(flowID,flowEdges(i))./ flowTable(flowID,4))],...
   ['%U:',num2str( 100* flowRoutingMatrix(flowID,flowEdges(i))./ sum(flowRoutingMatrix(:,flowEdges(i))) )]};

    %Text labels are set according to the relative node pairs position
    distanceVector = [distanceX distanceY 0];
    normalVectorToDistanceVector = cross(distanceVector/norm(distanceVector) , [0 0 1]);
    text(nodesPlaceMatrix(edgeTable(flowEdges(i),2),1)-distanceX/3+textOffset*backgroundScaleX*normalVectorToDistanceVector(1), nodesPlaceMatrix(edgeTable(flowEdges(i),2),2)-distanceY/3+textOffset*backgroundScaleY*normalVectorToDistanceVector(2) , textLabel,'color',colour,'FontSize',8,'FontWeight','bold');
end
                       
%At the end, text label of each node is set
for i=1:length(nodesPlaceMatrix)
    text(nodesPlaceMatrix(i,1),nodesPlaceMatrix(i,2),{int2str(i)},'FontSize',6,'Color',[1 1 1],'HorizontalAlignment','Center');
end






Contact us at files@mathworks.com