private static List<Node> listTraversedNodes (List<Link> path) { List<Node> res = new ArrayList<> (); res.add (path.get(0).originNode); for (Link e : path) res.add (e.getDestinationNode()); return res; }
/** Returns the IP link destination node * @return see above */ public WNode getB() { return new WNode (npLink.getDestinationNode()); } /** Returns true if the IP link is part of a pair of IP bidirectional links
/** Returns the destination node of the link * @return see above */ public WNode getB () { return new WNode (e.getDestinationNode()); }
/** Creates a RSA object from the provided information * @param seqLinks sequence of traversed fibers (a copy is made internally) * @param seqFrequencySlots_se 2D array with the sequence of frequency slots information. * @param seqRegenerators_e vector with the sequence of traversed regenerators information (if {@code null}, no regenerators are placed) */ public RSA (List<Link> seqLinks , IntMatrix2D seqFrequencySlots_se, int [] seqRegenerators_e) { this.seqLinks = new ArrayList<Link> (seqLinks); for (Link e : seqLinks) { if (e == null) throw new WDMException ("The sequence of links cannot contain a null"); } this.seqFrequencySlots_se = seqFrequencySlots_se; this.ingressNode = seqLinks.get(0).getOriginNode(); this.egressNode = seqLinks.get(seqLinks.size()-1).getDestinationNode(); this.seqRegeneratorsOccupancy_e = seqRegenerators_e == null? new int [seqLinks.size()] : Arrays.copyOf(seqRegenerators_e , seqRegenerators_e.length); checkValidity (); }
private String seqNodesString(List<Link> seqLinks) { if (seqLinks.isEmpty()) return ""; String st = "[ " + printNode(seqLinks.get(0).getOriginNode()); for (Link e : seqLinks) st += " -> " + printNode(e.getDestinationNode()); return st + " ]"; }
private static String getSequenceNodeIndexesWithResourceInfo(Route r) { StringBuffer buf = new StringBuffer(); buf.append("N" + r.getIngressNode().getIndex()); for (NetworkElement e : r.getPath()) if (e instanceof Link) buf.append(",N" + ((Link) e).getDestinationNode().getIndex()); else if (e instanceof Resource) buf.append(",(R" + e.getIndex() + ")"); return buf.toString(); }
/** Converts a given sequence of links to the corresponding sequence of nodes. * * @param seqLinks Sequence of traversed links * @return Sequence of nodes */ public static List<Node> convertSequenceOfLinksToSequenceOfNodes(List<Link> seqLinks) { if (seqLinks.isEmpty()) throw new Net2PlanException("No path"); List<Node> sequenceOfNodes = new LinkedList<Node>(); Node lastVisitedNode = seqLinks.iterator().next().getOriginNode(); sequenceOfNodes.add(lastVisitedNode); for (Link e : seqLinks) { if (!e.getOriginNode().equals(lastVisitedNode)) throw new Net2PlanException("Invalid sequence of links"); sequenceOfNodes.add(e.getDestinationNode()); lastVisitedNode = e.getDestinationNode(); } return sequenceOfNodes; }
/** * Returns a set of SRGs that are affecting the given links. * @param links Collection of links * @return SRGs affecting the links */ public static SortedSet<SharedRiskGroup> getAffectingSRGs (Collection<Link> links) { if (links == null) return new TreeSet<SharedRiskGroup> (); if (links.isEmpty()) return new TreeSet<SharedRiskGroup> (); final NetPlan np = links.iterator().next().getNetPlan(); SortedSet<SharedRiskGroup> res = new TreeSet<SharedRiskGroup> (); res.addAll (links.iterator().next().getOriginNode().getSRGs()); for (Link e : links) { res.addAll (e.getSRGs()); res.addAll (e.getDestinationNode().getSRGs()); } return res; }
/** Creates a RSA with the same set of contigous slots occupied in all the traversed fibers * @param seqLinks Sequence of traversed fiber * @param initialSlot id of the initial frequency slot occupied * @param numSlots number of contiguous slots of the RSA */ public RSA (List<Link> seqLinks , int initialSlot , int numSlots) { this.seqLinks = new ArrayList<Link>(seqLinks); for (Link e : seqLinks) { if (e == null) throw new WDMException ("The sequence of links cannot contain a null"); } this.seqFrequencySlots_se = IntFactory2D.dense.make(numSlots , seqLinks.size()); for (int e = 0; e < seqLinks.size() ; e ++) for (int s = 0 ; s < numSlots ; s ++) seqFrequencySlots_se.set(s,e,s+initialSlot); this.ingressNode = seqLinks.get(0).getOriginNode(); this.egressNode = seqLinks.get(seqLinks.size()-1).getDestinationNode(); this.seqRegeneratorsOccupancy_e = new int [seqLinks.size()]; checkValidity (); }
/** Creates a RSA with the same set of contigous slots occupied in all the traversed fibers * @param seqLinks Sequence of traversed fiber * @param initialSlot id of the initial frequency slot occupied * @param numSlots number of contiguous slots of the RSA * @param seqRegenerators_e vector with the sequence of traversed regenerators information (if {@code null}, no regenerators are placed) */ public RSA (List<Link> seqLinks , int initialSlot , int numSlots , int [] seqRegenerators_e) { this.seqLinks = new ArrayList<Link>(seqLinks); for (Link e : seqLinks) { if (e == null) throw new WDMException ("The sequence of links cannot contain a null"); } this.seqFrequencySlots_se = IntFactory2D.dense.make(numSlots , seqLinks.size()); for (int e = 0; e < seqLinks.size() ; e ++) for (int s = 0 ; s < numSlots ; s ++) seqFrequencySlots_se.set(s,e,s+initialSlot); this.ingressNode = seqLinks.get(0).getOriginNode(); this.egressNode = seqLinks.get(seqLinks.size()-1).getDestinationNode(); this.seqRegeneratorsOccupancy_e = seqRegenerators_e == null? new int [seqLinks.size()] : Arrays.copyOf(seqRegenerators_e , seqRegenerators_e.length); checkValidity (); }
private static Link oppositeLink (Link e) { return e.getNetPlan ().getNodePairLinks(e.getDestinationNode(), e.getOriginNode() , false).iterator().next(); }
static Pair<SortedSet<Demand>, SortedSet<Pair<MulticastDemand, Node>>> getDownCoupling(Collection<Link> links) { final SortedSet<Demand> res_1 = new TreeSet<>(); final SortedSet<Pair<MulticastDemand, Node>> res_2 = new TreeSet<>(); for (Link link : links) { if (link.getCoupledDemand() != null) res_1.add(link.getCoupledDemand()); else if (link.getCoupledMulticastDemand() != null) res_2.add(Pair.of(link.getCoupledMulticastDemand(), link.getDestinationNode())); } return Pair.of(res_1, res_2); }
private boolean isLooplessPath (NetPlan netPlan , NetworkLayer layer , List<Link> seqLinks) { if (seqLinks == null) return false; if (seqLinks.isEmpty()) return false; final Link firstLink = seqLinks.iterator().next(); final Node pathInitialNode = firstLink.getOriginNode(); Set<Node> traversedNodes = new TreeSet<Node> (); traversedNodes.add(pathInitialNode); Node previousLinkOutNode = pathInitialNode; for (Link e : seqLinks) { e.checkAttachedToNetPlanObject(netPlan); if (!e.layer.equals(layer)) throw new Net2PlanException ("The link " + e + " does not belong to the multicast tree layer"); final Node linkInitialNode = e.getOriginNode(); final Node linkEndNode = e.getDestinationNode(); if (previousLinkOutNode != linkInitialNode) return false; if (traversedNodes.contains(linkEndNode)) return false; // loop traversedNodes.add(linkEndNode); previousLinkOutNode = linkEndNode; } return true; }
private static Pair<SortedSet<Demand>, SortedSet<Pair<MulticastDemand, Node>>> getDownCoupling(Collection<Link> links) { final SortedSet<Demand> res_1 = new TreeSet<>(); final SortedSet<Pair<MulticastDemand, Node>> res_2 = new TreeSet<>(); for (Link link : links) { if (link.getCoupledDemand() != null) res_1.add(link.getCoupledDemand()); else if (link.getCoupledMulticastDemand() != null) res_2.add(Pair.of(link.getCoupledMulticastDemand(), link.getDestinationNode())); } return Pair.of(res_1, res_2); }
private static SortedSet<Link> getUpCoupling(Collection<Demand> demands, Collection<Pair<MulticastDemand, Node>> mDemands) { final SortedSet<Link> res = new TreeSet<>(); if (demands != null) for (Demand d : demands) if (d.isCoupled()) res.add(d.getCoupledLink()); if (mDemands != null) for (Pair<MulticastDemand, Node> md : mDemands) { if (md.getFirst().isCoupled()) res.add(md.getFirst().getCoupledLinks().stream().filter(e -> e.getDestinationNode() == md.getSecond()).findFirst().get()); } return res; }
/** <p>Obtains a {@code JUNG} graph from a given set of links.</p> * * @param nodes Collection of nodes * @param links Collection of links * @return {@code JUNG} graph */ public static Graph<Node, Link> getGraphFromLinkMap(Collection<Node> nodes, Collection<Link> links) { Graph<Node, Link> graph = new DirectedOrderedSparseMultigraph<Node, Link>(); for (Node node : nodes) graph.addVertex(node); if (links != null) { for (Link e : links) { if (!graph.containsVertex(e.getOriginNode())) throw new RuntimeException("Bad"); //graph.addVertex(e.getOriginNode()); if (!graph.containsVertex(e.getDestinationNode())) throw new RuntimeException("Bad"); //graph.addVertex(e.getDestinationNode()); graph.addEdge(e, e.getOriginNode(), e.getDestinationNode()); } } return graph; }
private static Pair<Boolean,Double> isValidPath (List<Link> seqLinks , double routeOccupiedCapacity) { final double minimumCapacityNeeded = routeOccupiedCapacity; boolean validPath = true; double thisPathIdleCapacity = Double.MAX_VALUE; for (Link e : seqLinks) { final double thisLinkIdleCapacity = e.getCapacity() - e.getCarriedTraffic(); thisPathIdleCapacity = Math.min(thisPathIdleCapacity, thisLinkIdleCapacity); if (e.isDown() || e.getOriginNode().isDown() || e.getDestinationNode().isDown() || (thisLinkIdleCapacity <= minimumCapacityNeeded)) { validPath = false; break; } } return Pair.of(validPath, thisPathIdleCapacity); } }
private Triple<Boolean,Integer,Double> computeValidWAFirstFit_path (List<Link> seqLinks , int numContiguousSlots , double maxOpticalReachKm) { if (seqLinks.isEmpty()) throw new RuntimeException ("Bad"); if (seqLinks.get(0).getOriginNode().isDown()) return Triple.of(false,-1,-1.0); if (getLengthInKm(seqLinks) > maxOpticalReachKm) return Triple.of(false,-1,-1.0); double worseCaseSpareCapacity = Double.MAX_VALUE; for (Link e : seqLinks) { worseCaseSpareCapacity = Math.min(worseCaseSpareCapacity, e.getCapacity() - e.getOccupiedCapacity()); if (e.getDestinationNode().isDown() || e.isDown()) return Triple.of(false,-1,-1.0); } int wavelength = WDMUtils.spectrumAssignment_firstFit(seqLinks, wavelengthFiberOccupancy , numContiguousSlots); if (wavelength != -1) return Triple.of(true , wavelength , worseCaseSpareCapacity); else return Triple.of(false,-1,-1.0); }
public Paint getEdgeDrawPaint() { if (npLink == null) return edgeDrawPaint; if (!npLink.isUp()) return Color.RED; /* Consider worst case color if not separated links */ final Set<Link> overlappingLinksToConsider = shownSeparated ? Sets.newHashSet(npLink) : npLink.getNetPlan().getNodePairLinks(npLink.getOriginNode(), npLink.getDestinationNode(), true); /* In red if any overlapping link is down */ if (overlappingLinksToConsider.stream().anyMatch(ee->ee.isDown())) return Color.RED; if (vs.getIsActiveLinkUtilizationColorThresholdList()) { if(!npLink.getLayer().isDefaultLayer()) return edgeDrawPaint; final double worstUtilization = overlappingLinksToConsider.stream().mapToDouble(e->e.getUtilization()).max().orElse(0); return vs.getLinkColorAccordingToUtilization(worstUtilization); } else if (vs.getIsActiveLinkRunoutTimeColorThresholdList()) { return edgeDrawPaint; } else return edgeDrawPaint; }
/** * Returns the adjacency matrix of the network. The adjacency matrix is a * <i>NxN</i> matrix (where <i>N</i> is the number of nodes in the network), * where each position (<i>i</i>,<i>j</i>) represents the number of directed * links from <i>i</i> to <i>j</i>. * * @return Adjacency matrix */ private DoubleMatrix2D getAdjacencyMatrix() { if (adjacencyMatrix == null) { adjacencyMatrix = DoubleFactory2D.sparse.make(N, N); for (Link link : linkMap) { int a_e = link.getOriginNode().getIndex (); int b_e = link.getDestinationNode().getIndex(); adjacencyMatrix.setQuick(a_e, b_e, adjacencyMatrix.get(a_e, b_e) + 1); } } return adjacencyMatrix; }