private static SortedSet<Node> getCandidateDistributionCenters (NetPlan np) { return np.getNodes().stream().filter(n->getNodeType(n, null) == LOCATIONTYPE.CANDIDATELOCATION_DISTRIBUTIONCENTER).collect(Collectors.toCollection(TreeSet::new)); } private static SortedSet<Node> getCandidateDestinations (NetPlan np) { return np.getNodes().stream().filter(n->getNodeType(n, null) == LOCATIONTYPE.DESTINATION).collect(Collectors.toCollection(TreeSet::new)); }
private static SortedSet<Node> getCandidatePlants (NetPlan np) { return np.getNodes().stream().filter(n->getNodeType(n, null) == LOCATIONTYPE.CANDIDATELOCATION_PLANT).collect(Collectors.toCollection(TreeSet::new)); } private static SortedSet<Node> getCandidateDistributionCenters (NetPlan np) { return np.getNodes().stream().filter(n->getNodeType(n, null) == LOCATIONTYPE.CANDIDATELOCATION_DISTRIBUTIONCENTER).collect(Collectors.toCollection(TreeSet::new)); }
private static SortedSet<Node> getCandidateDestinations (NetPlan np) { return np.getNodes().stream().filter(n->getNodeType(n, null) == LOCATIONTYPE.DESTINATION).collect(Collectors.toCollection(TreeSet::new)); }
/** Returns the list of network nodes, in increasing order according to its id * @return see above */ public List<WNode> getNodes () { return np.getNodes().stream().map(n->new WNode(n)).filter(n->!n.isVirtualNode()).collect(Collectors.toCollection(ArrayList::new)); } /** Returns the list of fibers, in increasing order according to its id
private void updateComboBox() { final NetPlan np = networkViewer.getDesign(); itemListener.setEnabled(false); cmb_tagNodesSelector.removeAllItems(); cmb_tagNodesSelector.addItem(DEFAULT_TAG_FILTER); final Set<String> allTagsNodes = np.getNodes().stream().map(n -> n.getTags()).flatMap(e -> e.stream()).collect(Collectors.toSet()); final List<String> allTagsNodesOrdered = allTagsNodes.stream().sorted().collect(Collectors.toList()); for (String tag : allTagsNodesOrdered) this.cmb_tagNodesSelector.addItem(tag); cmb_tagDemandsSelector.removeAllItems(); cmb_tagDemandsSelector.addItem(DEFAULT_TAG_FILTER); final Set<String> allTagsDemands = np.getDemands(layerThisTable).stream().map(n -> n.getTags()).flatMap(e -> e.stream()).collect(Collectors.toSet()); final List<String> allTagsDemandsOrdered = allTagsDemands.stream().sorted().collect(Collectors.toList()); for (String tag : allTagsDemandsOrdered) this.cmb_tagDemandsSelector.addItem(tag); itemListener.setEnabled(true); }
@Override public void zoomAll() { zoomNodes(callback.getDesign().getNodes()); }
/** * Calculates the correct map center and zoom so that all nodes are visible. */ private void calculateMapPosition() { final NetPlan netPlan = callback.getDesign(); final double zoomRatio = 0.6; // Read xy coordinates of each node as latitude and longitude coordinates. final Map<Long, GeoPosition> nodeToGeoPositionMap = netPlan.getNodes().stream().collect(Collectors.toMap(Node::getId, node -> new GeoPosition(node.getXYPositionMap().getY(), node.getXYPositionMap().getX()))); // Calculating OSM map center and zoom. mapViewer.zoomToBestFit(nodeToGeoPositionMap.isEmpty() ? Collections.singleton(mapViewer.getDefaultPosition()) : new HashSet<>(nodeToGeoPositionMap.values()), zoomRatio); if (netPlan.getNumberOfNodes() <= 1) mapViewer.setZoom(16); // So that the map is not too close to the node. }
private void checkSolution (NetPlan netPlan) { for (Link e : netPlan.getLinks ()) { final double pThisLink = Double.parseDouble(e.getAttribute("p_e")); if (pThisLink < minLinkPersistenceProb.getDouble() - 1E-3) throw new RuntimeException ("Bad"); } for (Node n : netPlan.getNodes ()) { final double qThisNode = Double.parseDouble(n.getAttribute("q_n")); if (qThisNode < 0) throw new RuntimeException ("Bad"); if (qThisNode > maxNodePersistenceProb.getDouble() +1E-3) throw new RuntimeException ("Bad"); double peAccum = 0; for (Link e : n.getOutgoingLinks()) peAccum += Double.parseDouble(e.getAttribute("p_e")); if (Math.abs(peAccum - qThisNode) > 1E-3) throw new RuntimeException ("Bad"); } } }
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); } }
public void execute() { 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; else 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>(netPlan.getNodes()); egressNodes.remove(ingressNode); netPlan.addMulticastDemand(ingressNode, egressNodes, 0, null); } } }
public double getCanvasDefaultVerticalDistanceForInterLayers() { if (this.getNetPlan().getNumberOfNodes() == 0) return 1.0; final int numVisibleLayers = getCanvasNumberOfVisibleLayers() == 0 ? this.getNetPlan().getNumberOfLayers() : getCanvasNumberOfVisibleLayers(); double minY = Double.MAX_VALUE; double maxY = -Double.MAX_VALUE; for (Node n : this.getNetPlan().getNodes()) { final double y = n.getXYPositionMap().getY(); minY = Math.min(minY, y); maxY = Math.max(maxY, y); } if ((maxY - minY < 1e-6)) return Math.abs(maxY) / (30 * numVisibleLayers); return (maxY - minY) / (30 * numVisibleLayers); }
public WNode getNearestCoreNode(NetPlan netPlan, WNet wNet, WNode node) { int minStepsBetweenNodes = Integer.MAX_VALUE; WNode nearestCoreNode = null; for (WNode coreNode : wNet.getNodesConnectedToCore()) { int currentStepsBetweenNodes = GraphUtils .getShortestPath(netPlan.getNodes(), netPlan.getLinks(), node.getNe(), coreNode.getNe(), null) .size(); if (minStepsBetweenNodes > currentStepsBetweenNodes) { minStepsBetweenNodes = currentStepsBetweenNodes; nearestCoreNode = coreNode; } } return nearestCoreNode; }
private List<List<Link>> getAndUpdateCplWdm (Pair<Node,Node> pair , NetPlan np) { List<List<Link>> res = cplWdm.get(pair); if (res != null) return res; final Map<Link,Double> linkCostMap = new HashMap<> (); for (Link e : np.getLinks(wdmLayer)) linkCostMap.put(e, e.getLengthInKm()); res = GraphUtils.getKLooplessShortestPaths(np.getNodes(), np.getLinks(wdmLayer), pair.getFirst(), pair.getSecond(), linkCostMap, wdmK.getInt(), tpInfo.getMaxOpticalReachKm(), wdmMaxLightpathNumHops.getInt(), -1, -1, -1, -1); if (res.isEmpty()) throw new Net2PlanException ("There is no path between nodes: " + pair.getFirst() + " -> " + pair.getSecond()); cplWdm.put(pair , res); return res; } private List<Pair<List<Link>,List<Link>>> getAndUpdateCplWdm11 (Pair<Node,Node> pair , NetPlan np)
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"); }
public static List<?> getAllElements (NetPlan np , NetworkLayer layer , AJTableType tableType) { if (tableType.getNeType() == null) throw new RuntimeException(); switch (tableType.getNeType()) { case DEMAND: return np.getDemands(layer); case FORWARDING_RULE: return new ArrayList<> (np.getForwardingRules(layer).keySet()); case LAYER: return np.getNetworkLayers(); case LINK: return np.getLinks(layer); case MULTICAST_DEMAND: return np.getMulticastDemands(layer); case MULTICAST_TREE: return np.getMulticastTrees(layer); case NODE: return np.getNodes(); case RESOURCE: return np.getResources(); case ROUTE: return np.getRoutes(layer); case SRG: return np.getSRGs(); default: throw new RuntimeException(); } }
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 Pair<Map<Demand,Demand>,Map<Route,Route>> initializeNetPlanLinksBidirDemandsAndRoutes (NetPlan np) { /* Remove lower half demands from np */ np.removeAllRoutes(); for (Node n1 : np.getNodes()) for (Node n2 : np.getNodes()) if (n1.getIndex () > n2.getIndex ()) for (Demand d : np.getNodePairDemands(n1, n2,false)) d.remove (); np.addRoutesFromCandidatePathList(netPlan.computeUnicastCandidatePathList(null , tcfa_maxNumberPathsPerDemand.getInt(), tcfa_maxPathLengthInKm.getDouble(), tcfa_maxPathNumberOfHops.getInt(), -1, -1, -1, -1 , null)); /* Add symmetric demands and routes */ Map<Demand,Demand> opposite_d = new HashMap<Demand,Demand> (); Map<Route,Route> opposite_r = new HashMap<Route,Route> (); for (Demand d : new HashSet<Demand> (np.getDemands())) { final Demand opDemand = np.addDemand(d.getEgressNode(), d.getIngressNode(), d.getOfferedTraffic(), RoutingType.SOURCE_ROUTING , null); opposite_d.put(d,opDemand); opposite_d.put(opDemand,d); for (Route r : new HashSet<Route> (d.getRoutes ())) { final Route oppRoute = np.addRoute(opDemand, r.getCarriedTraffic(), r.getOccupiedCapacity() , oppositeSeqLinks (r.getSeqLinks()), null); opposite_r.put(r,oppRoute); opposite_r.put(oppRoute,r); } } return Pair.of(opposite_d,opposite_r); }
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 Quadruple<Double,Double,Double,Double> computeCost (NetPlan np) { double costLinks = 0; for (Link e : np.getLinks ()) costLinks += linkCost_e.get(e.getIndex ()) * e.getCapacity() / (tcfa_linkCapacity_numCirc.getInt () * tcfa_circuitCapacity_Gbps.getDouble ()); double costCircuits = 0; for (Route r : np.getRoutes ()) // sums both lps and 1+1 if there are any { final double lineRate = r.isBackupRoute()? r.getRoutesIAmBackup().iterator().next().getCarriedTrafficInNoFailureState() : r.getCarriedTrafficInNoFailureState(); costCircuits += tcfa_circuitCost.getDouble () * (lineRate / tcfa_circuitCapacity_Gbps.getDouble ()); } double costNodes = 0; for (Node n : np.getNodes()) { final int nodeDegree = (int) Math.max(n.getOutgoingLinks().size(), n.getIncomingLinks().size()); costNodes += (nodeDegree <= 2)? tcfa_costNodeDegree2.getDouble () : tcfa_costNodeDegreeHigherThan2.getDouble (); } final double totalCost = costLinks+ costCircuits + costNodes; System.out.println("Total cost: " + totalCost + ", links %: " + (costLinks/totalCost) + ", circ %: " + (costCircuits/totalCost) + ", nodes %: " + (costNodes/totalCost)); System.out.println("-- From np cost total :" + totalCost + ", links: " + costLinks + ", nodes: " + costNodes + ", circ: " + costCircuits); return Quadruple.of(totalCost,costLinks,costNodes,costCircuits); }
private void createCandidateRoutes (NetPlan netPlan , double [] c0) { if (useExistingRoutes.getBoolean()) { for (Demand d : netPlan.getDemands()) if (d.getRoutes().isEmpty()) throw new Net2PlanException ("There are no paths available for the demand " + d + ", from: " + d.getIngressNode() + " to " + d.getEgressNode()); } else { netPlan.removeAllRoutes(); Map<Link,Double> linkCostMap = new HashMap<Link,Double> (); for (Link e : netPlan.getLinks()) linkCostMap.put(e , c0 [e.getIndex()]); for (Demand d : netPlan.getDemands()) { List<List<Link>> shortestPaths = GraphUtils.getKLooplessShortestPaths(netPlan.getNodes (), netPlan.getLinks(), d.getIngressNode(), d.getEgressNode(), linkCostMap, numberOfRoutesPerDemand.getInt(), -1, -1, -1, -1, -1, -1); if (shortestPaths.isEmpty()) throw new Net2PlanException ("There are no paths available for the demand " + d + ", from: " + d.getIngressNode() + " to " + d.getEgressNode()); for (List<Link> path : shortestPaths) netPlan.addRoute(d, 0, 0, path, null); } } } }