% Usage: [exitFlag sequenceOfSPFLinkIds sequenceOfSPFNodeIds sequenceOfWavelengths occupiedTWCsPerNode newLightpathRoutingEntry ] = ...
% libraryRWA_kShortestRWA(k, ingressNode, egressNode, phys, netState)
% Abstract: %This function makes a routing and wavelength assignment (RWA)
% to a given pair of nodes (ingressNode, egressNode) to try to establish a
% lightpath between them; first selecting the 'k' shortest routes, and
% later, trying to assign the wavelenghts to the shortest route with minimum
% number of used Tunable Wavelength Converters (TWCs). If that is not
% possible, we try with the second shortest route, and if it is not possible
% either, with the following shortest route, and so on.
% o In:
% k: Integer number. Demanded number of shortest paths between ingress
% node and egress node.
% ingressNode: Origin Node of the possible lightpath.
% . egressNode: Destination Node of the possible lightpath.
% . netState: NetState Structure. More information about netState in
% section "Structure of netState variable" from Help.
% . phys: Phys Structure. More information about netState in section
% "Structure of phys variable" from Help.
% o Out:
% exitFlag: If it is possible to make the routing and wavelength
% assignament, exitFlag = 0; otherwise exitFlag = 1.
% sequenceOfSPFLinkIds: Row vector with the sorted sequence of IDs of
% the links which the possible lightpath consist of, if the RWA was
% possible. The links IDs are sorted from the ingress node to the
% egress node of the path.
% . sequenceOfSPFNodeIds: Row vector with the sorted sequence of IDs of
% the nodes which the possible lightpath consist of, if the RWA was
% possible. The nodes IDs are sorted from the ingress node to the
% egress node of the path.
% . sequenceOfWavelengths: Vector with as many elemants as number of links
% of the possible lightpath between ingree and egress, if the RWA was
% possible. Each element is the wavelegth assigned to corresponding
% . occupiedTWCsPerNode(N): vector with N positions where N is the number
% of nodes. Each position 'i' is the number of occupied TWCs in the
% node with ID 'i' for creating this lightpath.
% newLightpathRoutingEntry(1,L): 1-by-L vector where L is the number of
% physical links. This output parameter defines the wavelenght
% assignment over the path, if was possible to make it. Each one of the
% L columns is a physical link 'l'. If the path uses a physical link
% 'l' with an assigned wavelength 'w'; then, the element (l) is equal
% to 'w'. If no physical link is used by the path, the element for that
% link is equal to '0'. It is equivalent a new entry to the field
% "lightpathRoutingMatrix" of a structure netState.
function [exitFlag sequenceOfSPFLinkIds sequenceOfSPFNodeIds sequenceOfWavelengths occupiedTWCsPerNode newLightpathRoutingEntry ] = ...
libraryRWA_kShortestRWA(k, ingressNode, egressNode, phys, netState)
weightedLinkTable=[phys.linkTable ones(size(phys.linkTable,1),1)] ;
occupiedTWCsPerNode = zeros (1,length (phys.numberTxPerNode));
[cellOfKPaths] = libraryGraph_kshortestPath (k,weightedLinkTable,ingressNode,egressNode);
exitFlag = 1;
if length(sequenceOfSPFLinkIds) == 0
[exitFlagOfWA sequenceOfWavelengths occupiedTWCsPerNode newLightpathRoutingEntry] = ...
libraryWA_minConv(sequenceOfSPFLinkIds, sequenceOfSPFNodeIds , phys, netState);