/** Returns the list of lightpath requests, in increasing order according to its id * @return see above */ public List<WLightpathRequest> getLightpathRequests () { return np.getDemands(getWdmLayer().getNe()).stream().map(n->new WLightpathRequest(n)).collect(Collectors.toCollection(ArrayList::new)); } /** Returns the list of lightpaths, in increasing order according to its id
private static void checkSolution(NetPlan netPlan, DoubleMatrix2D xx_de , DoubleMatrix3D xx_des) { if (!netPlan.getLinksOversubscribed().isEmpty()) throw new Net2PlanException("Bad - Some link is oversubscribed (constraint violated)"); if (!netPlan.getDemandsBlocked().isEmpty()) throw new Net2PlanException("Bad - Some demand is blocked (constraint violated)"); for (SharedRiskGroup srg : netPlan.getSRGs()) { NetPlan npThis = netPlan.copy (); npThis.removeAllUnicastRoutingInformation(); DoubleMatrix2D this_xxde = xx_des.viewColumn (srg.getIndex ()).copy (); for (Link e : srg.getAffectedLinksAllLayers()) if (this_xxde.viewColumn(e.getIndex ()).zSum () != 0) throw new Net2PlanException("Bad - some failing links carry traffic"); npThis.setRoutingFromDemandLinkCarriedTraffic(this_xxde , true , false , null); if (!npThis.getLinksOversubscribed().isEmpty()) throw new Net2PlanException("Bad - Some link is oversubscribed (constraint violated) in a failure"); if (!npThis.getDemandsBlocked().isEmpty()) throw new Net2PlanException("Bad - Some demand is blocked (constraint violated) in a failure"); for (Demand d : netPlan.getDemands ()) { IntArrayList es_noFailure = new IntArrayList (); xx_de.viewRow (d.getIndex ()).getNonZeros(es_noFailure , new DoubleArrayList ()); boolean affectedByThisFailure = false; for (Link e : srg.getAffectedLinksAllLayers()) if (xx_de.get(d.getIndex() , e.getIndex ()) != 0) { affectedByThisFailure = true; break; } if (!affectedByThisFailure) { IntArrayList es_thisFailure = new IntArrayList (); this_xxde.viewRow (d.getIndex ()).getNonZeros(es_thisFailure , new DoubleArrayList ()); if (!es_noFailure.equals(es_thisFailure)) throw new Net2PlanException("Routing cannot change when a demand is not affected by the failure"); } } } } }
public void setOfferedTrafficsToTheOnesEstimated () { final NetPlan np = input_layer.getNetPlan(); if (!new HashSet<> (np.getDemands(input_layer)).equals(output_estimTraffic_d.keySet()))throw new Net2PlanException ("The set of demands is different"); if (!new HashSet<> (np.getMulticastDemands(input_layer)).equals(output_estimTraffic_md.keySet()))throw new Net2PlanException ("The set of multicast demands is different"); for (Entry<Demand,Double> val : output_estimTraffic_d.entrySet()) val.getKey().setOfferedTraffic(val.getValue()); for (Entry<MulticastDemand,Double> val : output_estimTraffic_md.entrySet()) val.getKey().setOfferedTraffic(val.getValue()); }
/** * <p>Returns the forwarding rules for the given layer. If no layer is provided, the default layer is assumed.</p> * <p><b>Important</b>: Routing type must be {@link com.net2plan.utils.Constants.RoutingType#HOP_BY_HOP_ROUTING HOP_BY_HOP_ROUTING}.</p> * * @param optionalLayerParameter Network layer (optional) * @return The forwarding rules as a map of splitting factor (value) per demand and link (key) * @see com.net2plan.utils.Pair */ public SortedMap<Pair<Demand, Link>, Double> getForwardingRules(NetworkLayer... optionalLayerParameter) { final NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter); SortedMap<Pair<Demand, Link>, Double> res = new TreeMap<Pair<Demand, Link>, Double>(); for (Demand d : netPlan.getDemands(layer)) for (Entry<Link,Double> fr : d.cacheHbH_frs.entrySet()) res.put(Pair.of(d, fr.getKey()), fr.getValue()); return res; }
/** Returns the list of service chain requests, in increasing order according to its id * @return see above */ public List<WServiceChainRequest> getServiceChainRequests () { return np.getDemands(getIpLayer().getNe()).stream().map(n->new WServiceChainRequest(n)).collect(Collectors.toCollection(ArrayList::new)); }
private static TmEstimationResults createTakingEstimatedValuesFromCurrentNp (NetworkLayer layer , Map<Link,Double> monitOfSomeLinkTraffics , Map<Demand,Double> monitOfSomeDemands , Map<MulticastDemand,Double> monitOfSomeMDemands) { final NetPlan np = layer.getNetPlan(); final double output_averageDeviation_d = Math.sqrt(monitOfSomeDemands.entrySet().stream().mapToDouble(e-> { Demand d = e.getKey(); double est = e.getValue(); double val = d.getOfferedTraffic(); return Math.pow (est - val , 2); }).sum ()); final double output_averageDeviation_md = Math.sqrt(monitOfSomeMDemands.entrySet().stream().mapToDouble(e-> { MulticastDemand d = e.getKey(); double est = e.getValue(); double val = d.getOfferedTraffic(); return Math.pow (est - val , 2); }).sum ()); final double output_averageDeviation_e = Math.sqrt(monitOfSomeLinkTraffics.entrySet().stream().mapToDouble(e-> { Link d = e.getKey(); double est = e.getValue(); double val = d.getCarriedTraffic(); return Math.pow (est - val , 2); }).sum ()); final Map<Demand,Double> sol_offered_d = np.getDemands(layer).stream().collect(Collectors.toMap(d->d , d->d.getOfferedTraffic ())); final Map<MulticastDemand,Double> sol_offered_md = np.getMulticastDemands(layer).stream().collect(Collectors.toMap(d->d , d->d.getOfferedTraffic ())); final TmEstimationResults tm = new TmEstimationResults(layer, output_averageDeviation_d, output_averageDeviation_md, output_averageDeviation_e, sol_offered_d, sol_offered_md); return tm; } public String toStringQualityMerits ()
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); }
public static SortedSet<Date> getDatesWithAtLeastOneUnicastDemandMonitorInfo (NetworkLayer layer) { return layer.getNetPlan().getDemands(layer).stream().map(e->e.getMonitoredOrForecastedOfferedTraffic().getDatesWithValue()).flatMap(e->e.stream()).collect(Collectors.toCollection(TreeSet::new)); } public static SortedSet<Date> getDatesWithAtLeastOneMulticastDemandMonitorInfo (NetworkLayer layer)
private double computeObjectiveFunctionFromNetPlan (NetPlan np) { double objFunc = 0; for (Demand d : np.getDemands()) { final double h_d = d.getOfferedTraffic(); objFunc += (this.cc_control_fairnessFactor.getDouble() == 1)? Math.log(h_d) : Math.pow(h_d, 1-this.cc_control_fairnessFactor.getDouble()) / (1-this.cc_control_fairnessFactor.getDouble()); } return objFunc; }
public static boolean isGravityModelApplicableWithLinkMonitoringInfo (NetworkLayer layer , Date date) { final NetPlan np = layer.getNetPlan(); final List<Link> links = np.getLinks(layer); final List<Demand> demands = np.getDemands(layer); if (links.isEmpty()) return false; if (np.hasMulticastDemands(layer)) return false; final SortedSet<Node> demandEndNodes = demands.stream().map(d->d.getEndNodes()).flatMap(d->d.stream()).collect(Collectors.toCollection(TreeSet::new)); final SortedSet<Link> linksWeNeedToHaveFullInOutInfo = new TreeSet<> (); if (demands.stream().map(d->d.getIngressNode()).anyMatch(n->n.getOutgoingLinks(layer).isEmpty())) return false; if (demands.stream().map(d->d.getEgressNode()).anyMatch(n->n.getIncomingLinks(layer).isEmpty())) return false; demandEndNodes.forEach(n->linksWeNeedToHaveFullInOutInfo.addAll(n.getOutgoingLinks(layer))); demandEndNodes.forEach(n->linksWeNeedToHaveFullInOutInfo.addAll(n.getIncomingLinks(layer))); return linksWeNeedToHaveFullInOutInfo.stream().allMatch(ee->ee.getMonitoredOrForecastedCarriedTraffic().hasValue (date)); } public static SortedSet<Date> getDatesWhereGravityModelCanBeApplied (NetworkLayer layer)
public static SortedSet<Date> getDatesWhereGravityModelCanBeApplied (NetworkLayer layer) { final NetPlan np = layer.getNetPlan(); final List<Link> links = np.getLinks(layer); final List<Demand> demands = np.getDemands(layer); if (links.isEmpty()) return new TreeSet<> (); if (np.hasMulticastDemands(layer)) return new TreeSet<> (); final SortedSet<Node> demandEndNodes = demands.stream().map(d->d.getEndNodes()).flatMap(d->d.stream()).collect(Collectors.toCollection(TreeSet::new)); final SortedSet<Link> linksWeNeedToHaveFullInOutInfo = new TreeSet<> (); if (demands.stream().map(d->d.getIngressNode()).anyMatch(n->n.getOutgoingLinks(layer).isEmpty())) return new TreeSet<> (); if (demands.stream().map(d->d.getEgressNode()).anyMatch(n->n.getIncomingLinks(layer).isEmpty())) return new TreeSet<> (); demandEndNodes.forEach(n->linksWeNeedToHaveFullInOutInfo.addAll(n.getOutgoingLinks(layer))); demandEndNodes.forEach(n->linksWeNeedToHaveFullInOutInfo.addAll(n.getIncomingLinks(layer))); final SortedSet<Date> datesWithEnoughInformationFromGM = new TreeSet<> (); for (Date dateFirstLink : linksWeNeedToHaveFullInOutInfo.first().getMonitoredOrForecastedCarriedTraffic().getDatesWithValue()) if (linksWeNeedToHaveFullInOutInfo.stream().allMatch(ee->ee.getMonitoredOrForecastedCarriedTraffic().hasValue (dateFirstLink))) datesWithEnoughInformationFromGM.add(dateFirstLink); return datesWithEnoughInformationFromGM; } public static SortedMap<Demand,Double> getGravityModelEstimationFromMonitorTraffic (NetworkLayer layer , Date date)
private double getMinimumNonZeroTrafficOrCapacityValue (NetPlan netPlan) { double res = Double.MAX_VALUE; for (Demand d : netPlan.getDemands ()) if (d.getOfferedTraffic() > 0) res = Math.min (res , d.getOfferedTraffic()); for (Link e : netPlan.getLinks ()) if (e.getCapacity() > 0) res = Math.min (res , e.getCapacity()); if (res == Double.MAX_VALUE) throw new Net2PlanException ("Too large offered traffics and link capacities"); return res; } }
private double getMinimumNonZeroTrafficOrCapacityValue (NetPlan netPlan) { double res = Double.MAX_VALUE; for (Demand d : netPlan.getDemands ()) if (d.getOfferedTraffic() > 0) res = Math.min (res , d.getOfferedTraffic()); for (Link e : netPlan.getLinks ()) if (e.getCapacity() > 0) res = Math.min (res , e.getCapacity()); if (res == Double.MAX_VALUE) throw new Net2PlanException ("Too large offered traffics and link capacities"); return res; } }
private double getMinimumNonZeroTrafficOrCapacityValue (NetPlan netPlan) { double res = Double.MAX_VALUE; for (Demand d : netPlan.getDemands ()) if (d.getOfferedTraffic() > 0) res = Math.min (res , d.getOfferedTraffic()); for (Link e : netPlan.getLinks ()) if (e.getCapacity() > 0) res = Math.min (res , e.getCapacity()); if (res == Double.MAX_VALUE) throw new Net2PlanException ("Too large offered traffics and link capacities"); return res; } }
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(); } }
/** * <p>Adds multiples routes for each demand of the given layer, using the paths in an input Candidate Path List. * The paths should use the links of the same layer</p> * * @param cpl {@code SortedMap} where the keys are the node pairs and the values a list of sequence of links (each sequence is a route) * @param optionalLayer the layer (optional) */ public void addRoutesFromCandidatePathList(SortedMap<Pair<Node, Node>, List<List<Link>>> cpl, NetworkLayer... optionalLayer) { checkIsModifiable(); NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayer); List<Route> routes = new LinkedList<Route>(); try { for (Demand d : getDemands(layer)) for (List<Link> path : cpl.get(Pair.of(d.getIngressNode(), d.getEgressNode()))) routes.add(this.addRoute(d, 0, 0, path, null)); } catch (Exception e) { for (Route r : routes) r.remove(); throw e; } if (ErrorHandling.isDebugEnabled()) this.checkCachesConsistency(); }
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); } } } }
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 double [] getVectorIPDemandAverageAllStatesBlockedTraffic () { double [] res = new double [Dip]; for (Demand ipDemand : netPlan.getDemands(ipLayer)) { res [ipDemand.getIndex()] = ipDemand.getBlockedTraffic(); if (singleSRGToleranceNot11Type) { for (SharedRiskGroup srg : netPlan.getSRGs()) { Set<Route> affectedRoutes = srg.getAffectedRoutes(wdmLayer); double carriedTrafficThisFailure = 0; for (Route ipRoute : ipDemand.getRoutes()) { final Set<Route> wdmRoutes = ipRoute.getSeqLinks().get(0).getCoupledDemand().getRoutes(); for (Route r : wdmRoutes) if (!affectedRoutes.contains(r)) carriedTrafficThisFailure += r.getCarriedTraffic(); } res [ipDemand.getIndex()] += Math.max(0 , ipDemand.getOfferedTraffic() - carriedTrafficThisFailure); } } res [ipDemand.getIndex()] /= (singleSRGToleranceNot11Type? (netPlan.getNumberOfSRGs() + 1) : 1); } return res; }
public static SortedMap<Demand,Double> getGravityModelEstimationFromMonitorTraffic (NetworkLayer layer , Date date) { if (!isGravityModelApplicableWithLinkMonitoringInfo(layer, date)) throw new Net2PlanException ("Gravity model not applicable"); final NetPlan np = layer.getNetPlan(); final List<Link> links = np.getLinks(layer); final List<Demand> demands = np.getDemands(layer); final int N = np.getNumberOfNodes(); final double [] ingressTrafficPerNode = new double [N]; final double [] egressTrafficPerNode = new double [N]; for (Node n : np.getNodes()) { ingressTrafficPerNode [n.getIndex()] = n.getIncomingLinks(layer).stream().mapToDouble(e->e.getMonitoredOrForecastedCarriedTraffic().getValueOrNull(date)).sum(); egressTrafficPerNode [n.getIndex()] = n.getOutgoingLinks(layer).stream().mapToDouble(e->e.getMonitoredOrForecastedCarriedTraffic().getValueOrNull(date)).sum(); } final DoubleMatrix2D tm = TrafficMatrixGenerationModels.gravityModel(ingressTrafficPerNode, egressTrafficPerNode); final SortedMap<Demand,Double> res = new TreeMap<> (); for (Node n1 : np.getNodes()) for (Node n2 : np.getNodes()) { if (n1 == n2) continue; final SortedSet<Demand> nodePairDemands = np.getNodePairDemands(n1, n2, false, layer); final double traf = tm.get(n1.getIndex(), n2.getIndex()); nodePairDemands.forEach(d->res.put(d, traf / nodePairDemands.size())); } return res; }