boolean isVirtualNode () { return n.getIndex() <= 1; }
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(); }
/** * Returns the node label. * * @return Node label * @since 0.2.0 */ public String getLabel() { return npNode.getName().equals("") ? "Node " + npNode.getIndex() : npNode.getName(); // return npNode.getName() + " - L" + layer.getIndex() + ", VL" + getVisualizationOrderRemovingNonVisibleLayers(); }
private static String getNodeName(Node n) { return n.getName().equals("") ? "Node " + n.getIndex() : n.getName(); }
private String getNodeName (Node n) { return "Node " + n.getIndex() + " (" + (n.getName().length() == 0? "No name" : n.getName()) + ")"; } private String getResourceName (Resource e) { return "Resource " + e.getIndex() + " (" + (e.getName().length() == 0? "No name" : e.getName()) + "). Type: " + e.getType(); }
private String getNodeName (Node n) { return "Node " + n.getIndex() + " (" + (n.getName().length() == 0? "No name" : n.getName()) + ")"; } private String getResourceName (Resource e) { return "Resource " + e.getIndex() + " (" + (e.getName().length() == 0? "No name" : e.getName()) + "). Type: " + e.getType(); }
DrawNode (Node n , NetworkLayer layer , int maxHeightOrSizeIcon) { Pair<ImageIcon,Shape> getIconAndShape = getNodeIcon(n , layer , maxHeightOrSizeIcon); this.associatedElement = n; this.icon = getIconAndShape.getFirst().getImage(); this.shapeIconToSetByPainter = getIconAndShape.getSecond(); this.labels = Arrays.asList(n.getName().equals("")? "Node " + n.getIndex() : n.getName()); this.urlsLabels = Arrays.asList("node" + n.getId()); } DrawNode (Resource r , int maxHeightOrSizeIcon , double occupiedCapacity)
private double computeGradient (Link thisLink , double fairnessFactor , double thisLink_pe , DoubleMatrix1D infoIKnow_p_n , DoubleMatrix1D infoIKnow_ue) { final Node a_e = thisLink.getOriginNode(); if (thisLink_pe == 0) throw new RuntimeException ("Link " + thisLink + " has zero p_e"); double gradient = Math.pow(infoIKnow_ue.get(thisLink.getIndex ()) , 1 - fairnessFactor) / thisLink_pe; for (Link e : this.control_linksInterfFrom_n.get(a_e)) { if (e.getOriginNode() == thisLink.getOriginNode()) throw new RuntimeException ("Bad"); gradient -= Math.pow(infoIKnow_ue.get(e.getIndex ()),1-fairnessFactor) / (1 - infoIKnow_p_n.get(e.getOriginNode().getIndex ())); } if (Double.isNaN(gradient)) throw new RuntimeException ("Link " + thisLink + " gradient is Nan"); if (Double.isInfinite(gradient)) throw new RuntimeException ("Link " + thisLink + " gradient is inifinte"); return gradient; }
private void checkCapacitiesNetPlan () { double [] p_e = new double [E]; for (Link e : currentNetPlan.getLinks ()) { p_e [e.getIndex ()] = Double.parseDouble (e.getAttribute("p_e")); if ((p_e [e.getIndex ()] < control_minLinkPersistenceProb.getDouble() - 1E-3) ||(p_e [e.getIndex ()] > 1E-3 + control_maxNodePersistenceProb.getDouble())) throw new RuntimeException ("Bad"); } double [] q_n = new double [N]; for (Node n : currentNetPlan.getNodes ()) { for (Link e : n.getOutgoingLinks()) q_n [n.getIndex ()] += p_e [e.getIndex ()]; if (Math.abs (q_n [n.getIndex ()] - Double.parseDouble (n.getAttribute("q_n"))) > 1E-3) throw new RuntimeException ("Bad"); if (q_n [n.getIndex ()] > control_maxNodePersistenceProb.getDouble() + 1E-3) throw new RuntimeException ("Bad"); } for (Link e : currentNetPlan.getLinks ()) { final double u_e = e.getCapacity(); double supposedCapacity = control_linkNominalCapacities.get(e.getIndex ()) * control_p_e.get (e.getIndex ()); for (Node n : control_nodesInterfTo_e.get(e)) supposedCapacity *= 1 - q_n [n.getIndex ()]; if (Math.abs (u_e - supposedCapacity) > 1e-3) throw new RuntimeException ("Bad"); } }
private double computeHdFromPrices (Demand d) { /* compute the demand price as weighted sum in the routes of route prices */ final int index_ad = d.getIngressNode().getIndex (); final int index_d = d.getIndex (); final double demandInitialNodeQueueSize = this.routing_numTrafficUnitsOfOnePacket.getDouble() * ((double) this.ctlNumPacketsQueue_nd [index_ad][index_d]) * this.routing_gradient_gammaStep.getDouble(); /* compute the new h_d */ final double new_hd = Math.max(this.cc_control_minHd.getDouble() , Math.min(this.cc_control_maxHd.getDouble(), Math.pow(demandInitialNodeQueueSize, -1/this.cc_control_fairnessFactor.getDouble()))); return new_hd; }
public void execute() { Random rng = new Random(); NetPlan netPlan = callback.getDesign(); if (netPlan.hasMulticastDemands(getTableNetworkLayer())) { int result = JOptionPane.showConfirmDialog(null, "Remove all existing multicast demands before?", "", JOptionPane.YES_NO_CANCEL_OPTION); if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) return; if (result == JOptionPane.YES_OPTION) netPlan.removeAllMulticastDemands(); } if (netPlan.getNumberOfNodes() < 2) throw new Net2PlanException("At least two nodes are needed"); for (Node ingressNode : netPlan.getNodes()) { Set<Node> egressNodes = new HashSet<Node>(); for (Node n : netPlan.getNodes()) if ((n != ingressNode) && rng.nextBoolean()) egressNodes.add(n); if (egressNodes.isEmpty()) egressNodes.add(netPlan.getNode(ingressNode.getIndex() == 0 ? 1 : 0)); netPlan.addMulticastDemand(ingressNode, egressNodes, 0, null); } }
private void rcMenuFullMeshTraffic(boolean isSourceRouting) { final NetPlan np = callback.getDesign(); final Collection<Node> nodes; nodes = (callback.getSelectedElements(AJTableType.NODES , getTableNetworkLayer()).isEmpty()? np.getNodes() : (Set<Node>) callback.getSelectedElements(AJTableType.NODES , getTableNetworkLayer())); if (nodes.isEmpty()) throw new Net2PlanException("There are no nodes"); for (Node n1 : nodes) for (Node n2 : nodes) if (n1.getIndex() < n2.getIndex()) np.addDemandBidirectional(n1, n2, 0 , isSourceRouting? RoutingType.SOURCE_ROUTING : RoutingType.HOP_BY_HOP_ROUTING , null , getTableNetworkLayer()); callback.getPickManager().reset(); }
private void initializeSRGs (NetPlan np) { np.removeAllSRGs(); if (tcfa_srgType.getString ().equals("perBidirectionalLinkBundle")) { for (Node n1 : np.getNodes()) for (Node n2 : np.getNodes()) if (n1.getIndex () < n2.getIndex()) { final double linkLengthKm = np.getNodePairLinks(n1, n2,false).iterator().next().getLengthInKm(); final SharedRiskGroup srg = np.addSRG(tcfa_srgMttfPer1000Km_hrs.getDouble () * linkLengthKm / 1000, tcfa_srgMttr_hrs.getDouble (), null); for (Link e : np.getNodePairLinks(n1, n2,true)) srg.addLink(e); } } else if (tcfa_srgType.getString ().equals("noFailure")) { } else throw new Net2PlanException ("Wrong SRG type"); }
@Override public List<AjtColumnInfo<MulticastTree>> getNonBasicUserDefinedColumnsVisibleOrNot() { final List<AjtColumnInfo<MulticastTree>> res = new LinkedList<> (); res.add(new AjtColumnInfo<MulticastTree>(this , Node.class, null , "A", "Ingress node", null , d->d.getIngressNode() , AGTYPE.NOAGGREGATION , null)); res.add(new AjtColumnInfo<MulticastTree>(this , String.class, null , "Bs", "Egress nodes", null , d->d.getMulticastDemand().getEgressNodes().stream().map(n->n.getName().equals("")? "Node " + n.getIndex() : n.getName()).collect(Collectors.joining(",")) , AGTYPE.NOAGGREGATION , null)); res.add(new AjtColumnInfo<MulticastTree>(this , String.class, null , "Bs (reached)", "Reached egress nodes", null , d->d.getEgressNodesReached().stream().map(n->n.getName().equals("")? "Node " + n.getIndex() : n.getName()).collect(Collectors.joining(",")) , AGTYPE.NOAGGREGATION , null)); res.add(new AjtColumnInfo<MulticastTree>(this , Integer.class, null , "# Bs not reached", "Number of non-reached egress nodes", null , d->d.getMulticastDemand().getEgressNodes().size() - d.getEgressNodesReached().size() , AGTYPE.SUMINT , d-> d.getMulticastDemand().getEgressNodes().size() - d.getEgressNodesReached().size() > 0? Color.RED : null)); res.add(new AjtColumnInfo<MulticastTree>(this , MulticastDemand.class, null , "Demand", "Associated multicast demand", null , d->d.getMulticastDemand() , AGTYPE.NOAGGREGATION , null)); res.add(new AjtColumnInfo<MulticastTree>(this , Double.class, null , "Carried traffic (" + getTableNetworkLayer().getDemandTrafficUnits() + ")", "Carried traffic by the multicast tree", null , d->d.getCarriedTraffic() , AGTYPE.SUMDOUBLE , null)); res.add(new AjtColumnInfo<MulticastTree>(this , Double.class, null , "Occupied capacity (" + getTableNetworkLayer().getLinkCapacityUnits() + ")", "Occupied capacity in the traversed links", null, d->d.getOccupiedLinkCapacity() , AGTYPE.NOAGGREGATION , null)); res.add(new AjtColumnInfo<MulticastTree>(this , Collection.class, null , "Traversed links", "Traversed links in the non-failure state", null, d->d.getLinkSet() , AGTYPE.NOAGGREGATION , null)); res.add(new AjtColumnInfo<MulticastTree>(this , Double.class, null , "Total tree length (km)", "Sum of the lengths of all the tree links (accumulating any lower layer propagation lengths if any)", null, d->d.getTreeTotalLengthInKm() , AGTYPE.NOAGGREGATION , null)); res.add(new AjtColumnInfo<MulticastTree>(this , Double.class, null , "Worst e2e lat (ms)", "Current worst case end-to-end propagation time in miliseconds (accumulating any lower layer propagation times if any), from the origin node, to destination nodes reached", null, d->d.getTreeMaximumPropagationDelayInMs() , AGTYPE.NOAGGREGATION , d->{ final double m = d.getMulticastDemand().getMaximumAcceptableE2EWorstCaseLatencyInMs(); if (m >= 0) return null; return d.getTreeMaximumPropagationDelayInMs () > m? Color.RED : null; })); res.add(new AjtColumnInfo<MulticastTree>(this , Double.class, null , "Worst e2e length (km)", "Current worst case end-to-end propagation length in km (accumulating any lower layer propagation lengths if any)", null, d->d.getTreeMaximumPathLengthInKm() , AGTYPE.NOAGGREGATION , null)); res.add(new AjtColumnInfo<MulticastTree>(this , Double.class, null , "Worst e2e length (hops)", "Current worst case end-to-end propagation length in number of traversed links", null, d->d.getTreeMaximumPathLengthInHops() , AGTYPE.NOAGGREGATION , null)); return res; }
/** * Returns the number of outgoing links for each node. * * @return Number of outgoing links per node */ public DoubleMatrix1D getOutNodeDegree() { if (outNodeDegree == null) { Graph<Node, Link> aux_graph = getGraph_JUNG(); outNodeDegree = DoubleFactory1D.dense.make (N); for (Node node : nodes) { outNodeDegree.set(node.getIndex (), aux_graph.outDegree(node)); } } return outNodeDegree; }
/** Given a destination-based routing in the form f_te (fractions of traffic in a node, that is forwarded through each of its output links), it generates the resulting demand-link routing in the form f_de (fractions of traffic in a node from demand d, transmitted through link e). * * @param numDemandsInLayer Number of demands in the layer. * @param demandsToConvert List of demands in the layer to apply conversion, the rest are untouched * @param f_te For each destination node <i>t</i> (<i>t = 0</i> refers to the first node index, <i>t = 1</i> refers to the second one, and so on), and each link <i>e</i> (<i>e = 0</i> refers to the first link index, <i>e = 1</i> refers to the second one, and so on), {@code f_te[t][e]} sets the fraction of the traffic targeted to node <i>t</i> that arrives (or is generated in) node <i>a(e)</i> (the origin node of link <i>e</i>), that is forwarded through link <i>e</i>. It must hold that for every node <i>n</i> different of <i>t</i>, the sum of the fractions <i>f<sub>te</sub></i> along its outgoing links must be lower or equal than 1 (unchecked) * @return Demand-link routing in the form f_de (fractions of traffic in a node from demand d, transmitted through link e) */ public static DoubleMatrix2D convert_fte2fde(int numDemandsInLayer , SortedSet<Demand> demandsToConvert, DoubleMatrix2D f_te) { int E = f_te.columns(); int D = numDemandsInLayer; DoubleMatrix2D f_de = DoubleFactory2D.sparse.make(D, E); for (Demand d : demandsToConvert) f_de.viewRow(d.getIndex()).assign(f_te.viewRow(d.getEgressNode().getIndex())); return f_de; }
/** Given a demand-link routing in the form x_de (amount of traffic from demand d, transmitted through link e), returns the equivalent forwarding rule mapping (fractions of traffic entering a node from demand 'd', leaving that node through link 'e'). * @param numNodes Number of nodes * @param demandsToConsider List of demands * @param x_de Demand-link routing in the form x_de (amount of traffic from demand d, transmitted through link e) * @return Forwarding rule matrix (a <i>N</i>x<i>E</i> matrix where each element <i>δ<sub>ne</sub></i> equals the fraction of traffic entering a node 'n' from demand 'd', leaving that node through link 'e') */ public static DoubleMatrix2D convert_xde2xte(int numNodes, SortedSet<Demand> demandsToConsider, DoubleMatrix2D x_de) { final int E = x_de.columns(); DoubleMatrix2D x_te = DoubleFactory2D.sparse.make(numNodes, E); for (Demand demand : demandsToConsider) { final int t = demand.getEgressNode().getIndex(); final int d = demand.getIndex(); DoubleMatrix1D x_e_thisDemand = x_de.viewRow(d); x_te.viewRow(t).assign(x_e_thisDemand, DoublePlusMultFirst.plusMult(1)); } return x_te; }
private void computeBetweenessCentrality() { Graph<Node, Link> aux_graph = getGraph_JUNG(); BetweennessCentrality bc = new BetweennessCentrality(aux_graph, getCostTransformer()); nodeBetweenessCentrality = DoubleFactory1D.dense.make (N); for (Node node : this.nodes) nodeBetweenessCentrality.set(node.getIndex () , bc.getVertexScore(node)); linkBetweenessCentrality = DoubleFactory1D.dense.make (E); for (Link link : linkMap) linkBetweenessCentrality.set(link.getIndex (), bc.getEdgeScore(link)); }
private void updateDemandRoutingFromWeightsKnown (Demand d) { final Node a_d = d.getIngressNode(); final double h_d = d.getOfferedTraffic(); final DoubleMatrix1D weightsKnown_e = this.routing_mostUpdatedLinkPriceKnownByNode_ne.viewRow(a_d.getIndex ()); DoubleMatrix1D a_k = DoubleFactory1D.dense.make (R); for (Route r : d.getRoutes()) { double val = 0; for (Link e : r.getSeqLinks()) val += weightsKnown_e.get(e.getIndex()) + 1; a_k.set(r.getIndex (), val); } DoubleMatrix1D x_r = GradientProjectionUtils.regularizedProjection_sumEquality (a_k , control_routeIndexes_d [d.getIndex ()] , null , h_d , this.gradient_regularizationEpsilon.getDouble()); for (Route r : d.getRoutes ()) r.setCarriedTraffic(x_r.get(r.getIndex ()) , x_r.get(r.getIndex ())); }