public static void main(String[] args) throws Exception { final NetPlan np = new NetPlan (); final Node n1 = np.addNode(0 , 0 , "name1" , null); final Node n2 = np.addNode(0 , 0 , "name2" , null); final Node n3 = np.addNode(0 , 0 , "name3" , null); final Link e12 = np.addLink(n1,n2,3,100,200000,null); final Link e23 = np.addLink(n2,n3,3,100,200000,null); final Resource r1 = np.addResource("CPU" , "nameRes1" , Optional.of(n1) , 10 , "Mbps" , null , 5 , null); final Resource r2 = np.addResource("RAM" , "nameRes2" , Optional.of(n2) , 10 , "Mbps" , null , 5 , null); final Demand d = np.addDemand(n1 , n3 , 0 , RoutingType.SOURCE_ROUTING , null); d.setServiceChainSequenceOfTraversedResourceTypes(Arrays.asList("CPU" , "RAM")); final Route r = np.addServiceChain(d , 2.0 , Arrays.asList(1.0,2.0,3.0,4.0) , Arrays.asList(r1,e12,r2,e23) , null); final NetworkLayer layer = np.getNetworkLayerDefault(); layer.setName("WDM"); JFrame frame = new JFrame("Example"); frame.getContentPane().setLayout(new FlowLayout()); frame.setPreferredSize(new Dimension (600,600)); //frame.add(new FigureLinkSequencePanel(r.getPath() , layer , r.getSeqOccupiedCapacitiesIfNotFailing() , "Route " + r.getIndex() , r.getCarriedTraffic())); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
/** * <p>Adds traffic routes (or forwarding rules, depending on the routing type) from destination-link routing at the given layer. * If no layer is provided, default layer is assumed. If the routing is SOURCE-ROUTING, the new routing will have no closed nor open loops. If the routing is * HOP-BY-HOP routing, the new routing can have open loops. However, if the routing has closed loops (which were not removed), a {@code ClosedCycleRoutingException} * will be thrown </p> * * @param x_te For each destination node <i>t</i> (rows), and each link <i>e</i> (columns), {@code f_te[t][e]} represents the traffic targeted to node <i>t</i> that arrives (or is generated * in) node a(e) (the origin node of link e), that is forwarded through link e * @param removeCycles If true, the open and closed loops are eliminated from the routing before any processing is done. The form in which this is done guarantees that the resulting * routing uses the same or less traffic in the links for each destination than the original routing. For removing the cycles, * the method calls to {@code removeCyclesFrom_xte} using the default ILP solver defined in Net2Plan, and no limit in the maximum solver running time. * @param optionalLayerParameter Network layer (optional) */ public void setRoutingFromDestinationLinkCarriedTraffic(DoubleMatrix2D x_te, boolean removeCycles, NetworkLayer... optionalLayerParameter) { checkIsModifiable(); final NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter); checkMatrixDestinationLinkCarriedTrafficFlowConservationConstraints(x_te, layer); if (removeCycles) x_te = GraphUtils.removeCyclesFrom_xte(nodes, layer.links, getMatrixNode2NodeOfferedTraffic(layer), x_te, Configuration.getOption("defaultILPSolver"), null, -1); final DoubleMatrix2D f_te = GraphUtils.convert_xte2fte(nodes, layer.links, x_te); final Quadruple<DoubleMatrix2D, DoubleMatrix1D, DoubleMatrix1D, List<RoutingCycleType>> xdeInfo = GraphUtils.convert_fte2xde(nodes.size(), layer.demands.size() , layer.links, new TreeSet<> (layer.demands) , f_te); final DoubleMatrix2D x_de = xdeInfo.getFirst(); setRoutingFromDemandLinkCarriedTraffic(x_de, false , false , new TreeSet<> (layer.demands) , layer); if (ErrorHandling.isDebugEnabled()) this.checkCachesConsistency(); }
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); } } }
@Override public void saveDemandSetToFile(NetPlan netPlan, File file) { for (NetworkLayer layer : netPlan.getNetworkLayers ()) if (!layer.equals(netPlan.getNetworkLayerDefault())) netPlan.removeNetworkLayer (layer); netPlan.removeAllLinks(); netPlan.removeAllUnicastRoutingInformation(); netPlan.removeAllSRGs(); netPlan.saveToFile(file); }
/** * <p>Resets the state of the network to an empty {@code NetPlan}.</p> */ public void reset() { checkIsModifiable(); assignFrom(new NetPlan()); if (ErrorHandling.isDebugEnabled()) this.checkCachesConsistency(); }
private NetworkElement getInThisNetPlan (NetworkElement e) { NetworkElement res = null; if (e instanceof Link) res = this.netPlan.getLinkFromId(e.id); else if (e instanceof Resource) res = this.netPlan.getResourceFromId(e.id); else if (e instanceof Node) res = this.netPlan.getNodeFromId(e.id); else throw new RuntimeException ("Bad"); if (res == null) throw new RuntimeException ("Element of id: " + e.id + ", of class: " + e.getClass().getName() + ", does not exsit in current NetPlan"); return res; }
final int N = netPlan.getNumberOfNodes (); final int E = netPlan.getNumberOfLinks (); final double PRECISION_FACTOR = Double.parseDouble(net2planParameters.get("precisionFactor")); if (E == 0) throw new Net2PlanException("This algorithm requires a topology with links"); netPlan.removeAllUnicastRoutingInformation(); netPlan.setRoutingTypeAllDemands(RoutingType.SOURCE_ROUTING); netPlan.setTrafficMatrix(DoubleFactory2D.dense.make (N,N,1.0) , RoutingType.SOURCE_ROUTING); // just to create the demands final DoubleMatrix1D linkCostVector = shortestPathType.getString().equalsIgnoreCase("hops")? DoubleFactory1D.dense.make (E , 1.0) : netPlan.getVectorLinkLengthInKm(); netPlan.addRoutesFromCandidatePathList(netPlan.computeUnicastCandidatePathList(linkCostVector , k.getInt(), maxLengthInKm.getDouble(), -1, -1, -1, -1, -1 , null)); final int P = netPlan.getNumberOfRoutes(); DoubleMatrix2D thisIntervalTrafficMatrix = new NetPlan(new File (rootOfNameOfInputTrafficFiles.getString() + "_tm" + netPlanFiles.size () + ".n2p")).getMatrixNode2NodeOfferedTraffic(); NetPlan netPlanToAdd = netPlan.copy (); for (Demand d : netPlanToAdd.getDemands()) d.setOfferedTraffic(thisIntervalTrafficMatrix.get (d.getIngressNode().getIndex() , d.getEgressNode().getIndex())); netPlanFiles.add (netPlanToAdd); } catch (Exception e) { break; } op.setInputParameter("u_e", netPlan.getVectorLinkSpareCapacity(), "row"); /* for each link, its unused capacity (the one not used by any mulitcast trees) */ op.setInputParameter("A_dp", netPlan.getMatrixDemand2RouteAssignment()); /* 1 in position (d,p) if demand d is served by path p, 0 otherwise */ op.setInputParameter("A_ep", netPlan.getMatrixLink2RouteAssignment()); /* 1 in position (e,p) if link e is traversed by path p, 0 otherwise */ DoubleMatrix2D h_dt = DoubleFactory2D.dense.make (N*(N-1),T); DoubleMatrix2D h_pt = DoubleFactory2D.dense.make (P,T); for (int t = 0; t < T ; t ++) h_dt.viewColumn(t).assign (netPlanFiles.get(t).getVectorDemandOfferedTraffic()); h_pt.viewColumn(t).assign (netPlanFiles.get(t).getVectorRouteOfferedTrafficOfAssociatedDemand());
if (netPlan.getNumberOfNodes() == 0) throw new Net2PlanException ("The input design has no nodes"); netPlan.removeAllLinks(); netPlan.setRoutingTypeAllDemands(RoutingType.SOURCE_ROUTING); this.N = netPlan.getNumberOfNodes(); this.rng = new Random (algorithm_randomSeed.getLong ()); for (Node n1 : netPlan.getNodes()) for (Node n2 : netPlan.getNodes()) if (n1 != n2) netPlan.addLink(n1, n2, 0.01, netPlan.getNodePairEuclideanDistance(n1, n2), 200000 , null); final double linkLengthKmFromEuclideanDistanceFactor = tcfa_networkDiameterKmToNormalize.getDouble() / netPlan.getVectorLinkLengthInKm().getMaxLocation() [0]; for (Link e : netPlan.getLinks()) e.setLengthInKm(e.getLengthInKm() * linkLengthKmFromEuclideanDistanceFactor); this.Efm = netPlan.getNumberOfLinks(); if (Efm != N*(N-1)) throw new RuntimeException ("Bad, Efm" + Efm + ", N: " + N); this.linkCost_e = DoubleFactory1D.dense.make(Efm); for (Link e : netPlan.getLinks ()) linkCost_e.set(e.getIndex () , tcfa_linkCostPerKm.getDouble() * e.getLengthInKm()); if (netPlan.getNumberOfDemands() == 0) for (Node n1 : netPlan.getNodes()) for (Node n2 : netPlan.getNodes()) if (n1 != n2) netPlan.addDemand(n1, n2, tcfa_circuitCapacity_Gbps.getDouble(), RoutingType.SOURCE_ROUTING , null); DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic(); netPlan.removeAllDemands(); for (Node n1 : netPlan.getNodes()) for (Node n2 : netPlan.getNodes()) if (n1.getIndex () > n2.getIndex ()) netPlan.addDemand(n1, n2, tcfa_circuitCapacity_Gbps.getDouble() * Math.ceil(maxTrafficBidir / tcfa_circuitCapacity_Gbps.getDouble()) , RoutingType.SOURCE_ROUTING , null); netPlan.addDemand(n2, n1, tcfa_circuitCapacity_Gbps.getDouble() * Math.ceil(maxTrafficBidir / tcfa_circuitCapacity_Gbps.getDouble()) , RoutingType.SOURCE_ROUTING , null); NetPlan npcopy = netPlan.copy(); netPlan.removeAllDemands(); for (Demand d : npcopy.getDemands()) for (int cont = 0 ; cont < numChannels ; cont ++) netPlan.addDemand(netPlan.getNodeFromId (d.getIngressNode().getId ()), netPlan.getNodeFromId (d.getEgressNode().getId ()), tcfa_circuitCapacity_Gbps.getDouble () , RoutingType.SOURCE_ROUTING , d.getAttributes()); this.D = netPlan.getNumberOfDemands();
if (netPlan.getNumberOfLayers() > 2) throw new Net2PlanException ("The design must have one or two layers"); if (netPlan.isSingleLayer()) this.lowerLayer = netPlan.getNetworkLayerDefault(); this.upperLayer = netPlan.addLayer("UP LAYER" , "Upper layer of the design" , "Gbps" , "Gbps" , null , null); for (Demand d : netPlan.getDemands (lowerLayer)) netPlan.addDemand(d.getIngressNode() , d.getEgressNode() , d.getOfferedTraffic() , RoutingType.HOP_BY_HOP_ROUTING , null , upperLayer); this.lowerLayer = netPlan.getNetworkLayer(0); this.upperLayer = netPlan.getNetworkLayer(1); netPlan.setRoutingTypeAllDemands(RoutingType.HOP_BY_HOP_ROUTING, upperLayer); netPlan.setRoutingTypeAllDemands (RoutingType.SOURCE_ROUTING, lowerLayer); final int N = netPlan.getNumberOfNodes(); final int D_up = netPlan.getNumberOfDemands (upperLayer); final int E_lo = netPlan.getNumberOfLinks (lowerLayer); if (N == 0 || D_up == 0) throw new Net2PlanException("This algorithm requires a topology and a demand set"); netPlan.removeAllLinks(upperLayer); netPlan.removeAllDemands(lowerLayer); netPlan.setLinkCapacityUnitsName("Gbps" , lowerLayer); netPlan.setLinkCapacityUnitsName("Gbps" , upperLayer); netPlan.setDemandTrafficUnitsName("Gbps" , lowerLayer); netPlan.setDemandTrafficUnitsName("Gbps" , upperLayer); netPlan.setVectorLinkCapacity(DoubleFactory1D.dense.make (E_lo , capLowLayerLinksInNumCircuits.getInt() * ciurcuitCapacityGbps.getDouble()) , lowerLayer); for (Node i : netPlan.getNodes ()) for (Node j : netPlan.getNodes ()) if (i != j)
if (currentNetPlan.getNumberOfLayers() != 1) throw new Net2PlanException("This algorithm works in single layer networks"); this.currentNetPlan.removeAllUnicastRoutingInformation(); this.currentNetPlan.setRoutingTypeAllDemands(RoutingType.HOP_BY_HOP_ROUTING); this.N = this.currentNetPlan.getNumberOfNodes(); // total number of nodes in the network this.E = this.currentNetPlan.getNumberOfLinks(); // total number of nodes in the network this.D = this.currentNetPlan.getNumberOfDemands(); // total number of nodes in the network if ((E == 0) || (D == 0)) throw new Net2PlanException ("The input design should have links and demands"); this.allT = new int[N]; this.frontierGlobalLinkIndexes_c = new HashMap<String, int[]>(); this.internalAndFrontierGlobalLinkIndexes_c = new HashMap<String, int[]>(); for (Node n : this.currentNetPlan.getNodes()) for (Link e : this.currentNetPlan.getLinks()) for (Link e : this.currentNetPlan.getLinks()) for (String cId : clusterIds) mostUpdated_vte_fromC.put(cId, null); this.global_A_ne = this.currentNetPlan.getMatrixNodeLinkIncidence(); this.global_u_e = this.currentNetPlan.getVectorLinkCapacity(); this.global_h_nt = this.currentNetPlan.getMatrixNode2NodeOfferedTraffic(); for (int t = 0; t < N; t++) for (Node t : this.currentNetPlan.getNodes()) for (Node n : this.currentNetPlan.getNodes())
netPlan = new NetPlan(); for (int n = 0; n < numNodes; n++) netPlan.addNode(0, 0, null, null); } else { netPlan = new NetPlan((File) cli.getParsedOptionValue("input-file")); numNodes = netPlan.getNumberOfNodes(); DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic(); List<DoubleMatrix2D> newMatrices; String variationPattern = (String) cli.getParsedOptionValue("variation-pattern"); DoubleMatrix2D distanceMatrix = netPlan.getMatrixNode2NodeEuclideanDistance(); double[] populationVector = netPlan.getVectorNodePopulation().toArray(); int[] levelVector = StringUtils.toIntArray(NetPlan.getAttributes(netPlan.getNodes(), "level").values(), 1); trafficMatrices[0] = netPlan.getMatrixNode2NodeOfferedTraffic(); netPlan.setTrafficMatrix(trafficMatrices[tmId] , RoutingType.SOURCE_ROUTING); netPlan.setVectorDemandOfferedTraffic(TrafficMatrixGenerationModels.normalizeTraffic_networkCapacity(netPlan)); trafficMatrices[tmId] = netPlan.getMatrixNode2NodeOfferedTraffic(); netPlan.setTrafficMatrix(trafficMatrices[tmId] , RoutingType.SOURCE_ROUTING); netPlan.setVectorDemandOfferedTraffic(TrafficMatrixGenerationModels.normalizeTraffic_linkCapacity_xde(netPlan, solverName, solverLibraryName)); trafficMatrices[tmId] = netPlan.getMatrixNode2NodeOfferedTraffic(); NetPlan aux = new NetPlan(); aux.setTrafficMatrix(trafficMatrices[tmId] , RoutingType.SOURCE_ROUTING); outputDemandSets.add(aux);
if (currentNetPlan.getNumberOfLayers() != 1) throw new Net2PlanException ("This algorithm works in single layer networks"); currentNetPlan.removeAllUnicastRoutingInformation(); currentNetPlan.setRoutingTypeAllDemands(RoutingType.SOURCE_ROUTING); this.currentNetPlan.addRoutesFromCandidatePathList(currentNetPlan.computeUnicastCandidatePathList(currentNetPlan.getVectorLinkLengthInKm() , 1, -1, -1, -1, -1, -1, -1 , null)); this.control_epsilonOrMuFactor = control_isBarrierMethod? gradient_interiorPenaltyEpsilonFactor.getDouble() : gradient_exteriorPenaltyMuFactor.getDouble(); this.rng = new Random (simulation_randomSeed.getLong()); this.D = currentNetPlan.getNumberOfDemands (); this.E = currentNetPlan.getNumberOfLinks (); if ((E == 0) || (D == 0)) throw new Net2PlanException ("The input design should have links and demands"); currentNetPlan.setVectorDemandOfferedTraffic(control_previous_h_d); for (Demand d : currentNetPlan.getDemands()) // carry the demand traffic this.control_priceFirstOrder_e = DoubleFactory1D.dense.make (E); for (Link e : this.currentNetPlan.getLinks ()) control_priceFirstOrder_e.set (e.getIndex () , computeFirstOrderPriceFromNetPlan(e)); this.control_priceSecondOrder_e = DoubleFactory1D.dense.make (E); for (Link e : this.currentNetPlan.getLinks ()) control_priceSecondOrder_e.set (e.getIndex () , computeSecondOrderPriceFromNetPlan(e)); for (Demand d : currentNetPlan.getDemands ()) for (Link e : currentNetPlan.getLinks()) for (Demand d : currentNetPlan.getDemands()) this.stat_traceOf_objFunction = new TimeTrace (); this.stat_traceOf_maxLinkTraffic = new TimeTrace (); this.stat_traceOf_hd.add(0 , this.currentNetPlan.getVectorDemandOfferedTraffic()); this.stat_traceOf_objFunction.add(0 , NetworkPerformanceMetrics.alphaUtility(currentNetPlan.getVectorDemandOfferedTraffic() , control_fairnessFactor.getDouble())); this.stat_traceOf_maxLinkTraffic.add(0.0, this.currentNetPlan.getVectorLinkCarriedTraffic().getMaxLocation() [0]);
private Pair<NetPlan,double[][]> computeOptimumSolution () final int D = this.currentNetPlan.getNumberOfDemands(); final int E = this.currentNetPlan.getNumberOfLinks(); final DoubleMatrix1D u_e = this.currentNetPlan.getVectorLinkCapacity(); op.setObjectiveFunction("maximize", "(1-alpha) * sum(h_d ^ (1-alpha))"); op.setInputParameter("A_ne", currentNetPlan.getMatrixNodeLinkIncidence()); op.setInputParameter("A_nd", currentNetPlan.getMatrixNodeDemandIncidence()); op.addConstraint("A_ne * (x_de') >= A_nd * diag(h_d)" , "flowConservationConstraints"); // the flow-conservation constraints (NxD constraints) op.addConstraint("sum(x_de,1) <= u_e"); // the capacity constraints (E constraints) NetPlan np = this.currentNetPlan.copy(); np.removeAllUnicastRoutingInformation(); np.setVectorDemandOfferedTraffic(h_d_array); np.setRoutingFromDemandLinkCarriedTraffic(x_de_array , false , false , null); for (Demand d : np.getDemands()) if (thisDemand_hd > cc_control_maxHd.getDouble() + 1E-3) throw new RuntimeException ("Bad"); if (np.getVectorLinkUtilization().getMaxLocation() [0] > 1.001) throw new RuntimeException ("Bad");
final int N = netPlan.getNumberOfNodes (); final int E = netPlan.getNumberOfLinks(); final int D = netPlan.getNumberOfDemands(); if (E == 0 || D == 0) throw new Net2PlanException("This algorithm requires a topology with links and a demand set"); netPlan.removeAllUnicastRoutingInformation (); op.setInputParameter("u_e", netPlan.getVectorLinkSpareCapacity(), "row"); /* for each link, its unused capacity (the one not used by any mulitcast trees) */ op.setInputParameter("A_ne", netPlan.getMatrixNodeLinkIncidence()); /* 1 in position (n,e) if link e starts in n, -1 if it ends in n, 0 otherwise */ final DoubleMatrix1D egressTraffic_t = netPlan.getVectorNodeEgressUnicastTraffic(); final DoubleMatrix2D trafficMatrixDiagonalNegative = netPlan.getMatrixNode2NodeOfferedTraffic(); trafficMatrixDiagonalNegative.assign (DoubleFactory2D.sparse.diagonal(egressTraffic_t) , DoubleFunctions.minus); op.setInputParameter("TM", trafficMatrixDiagonalNegative); op.setInputParameter("d_e_secs", netPlan.getVectorLinkPropagationDelayInMiliseconds().assign (DoubleFunctions.mult (0.001)) , "row"); op.setInputParameter("L", averagePacketLengthInBytes.getDouble() * 8); /* average packet length in bits */ op.setInputParameter("R", binaryRatePerTrafficUnit_bps.getDouble()); /* binary rate per traffic unit */ op.addDecisionVariable("x_te", false , new int[] { N, E }, 0, Double.MAX_VALUE); /* the amount of traffic targeted to node t, that is carried by link e */ op.addDecisionVariable("y_e", false, new int[] { 1, E }, DoubleUtils.zeros(E), netPlan.getVectorLinkCapacity().toArray()); /* traffic in the links (already limited to the link capacity) */ if (nonBifurcatedRouting.getBoolean()) op.addDecisionVariable("f_te", true, new int [] {N,E} , 0 , 1); op.setObjectiveFunction("minimize", "sum( y_e .* (d_e_secs + (L./R) * (1 ./ (u_e - y_e))) )"); op.addDecisionVariable("y_e", false, new int[] { 1, E }, DoubleUtils.zeros(E), netPlan.getVectorLinkCapacity().toArray()); /* traffic in the links (already limited to the link capacity) */ if (nonBifurcatedRouting.getBoolean()) op.addDecisionVariable("f_te", true, new int [] {N,E} , 0 , 1); op.setObjectiveFunction("minimize", "sum(y_e .* erlangB(y_e, u_e))"); op.setInputParameter("U", netPlan.getVectorLinkCapacity().getMaxLocation() [0]); op.setInputParameter("Aout_ne", netPlan.getMatrixNodeLinkOutgoingIncidence()); op.setInputParameter("outMax_nt", maxNumOutLinksCarryingTraffic_nt);
final List<Link> links = np.getLinks (layer); final List<Demand> demands = np.getDemands(layer); final List<MulticastDemand> mdemands = np.getMulticastDemands(layer); final int E = links.size(); final int D = demands.size(); final DoubleMatrix1D originalDemandOffered_d = np.getVectorDemandOfferedTraffic(layer); final DoubleMatrix1D originalDemandOffered_md = np.getVectorMulticastDemandOfferedTraffic(layer); if (D>0) np.getDemand(dIndex, layer).setOfferedTraffic(h_d [dIndex]); np.getMulticastDemand(dIndex, layer).setOfferedTraffic(h_md [dIndex]); np.setVectorDemandOfferedTraffic(originalDemandOffered_d, layer); np.setVectorMulticastDemandOfferedTraffic(originalDemandOffered_md, layer);
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); }
if (netPlan.getNumberOfLayers() != 1) throw new Net2PlanException ("This algorithm works in single layer networks"); this.N = netPlan.getNumberOfNodes(); this.E = netPlan.getNumberOfLinks(); this.PRECISIONFACTOR = Double.parseDouble(net2planParameters.get("precisionFactor")); this.stat_pie = new TimeTrace (); netPlan.removeAllUnicastRoutingInformation(); netPlan.setRoutingTypeAllDemands(RoutingType.HOP_BY_HOP_ROUTING); double [][] trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic().toArray(); for (int n1 = 0 ; n1 < N ; n1 ++) for (int n2 = 0 ; n2 < N ; n2 ++) if (n1 == n2) continue; else trafficMatrix [n2][n2] -= trafficMatrix [n1][n2]; this.tmColumnSumZero= DoubleFactory2D.dense.make(trafficMatrix); System.out.println(netPlan.getMatrixNode2NodeOfferedTraffic()); this.numModulesUpperBound = Math.ceil(netPlan.getVectorDemandOfferedTraffic().zSum() / moduleCapacity.getDouble()); this.A_ne = netPlan.getMatrixNodeLinkIncidence();
/** Creates an empty design with no nodes, links etc. * @return see above */ public static WNet createEmptyDesign () { final NetPlan np = new NetPlan (); np.getNetworkLayerDefault().setName("WDM"); np.addLayer("IP", "IP Layer", "", "", null, null); np.addNode(0, 0, WNetConstants.WNODE_NAMEOFANYCASTORIGINNODE , null); np.addNode(0, 0, WNetConstants.WNODE_NAMEOFANYCASTDESTINATION, null); final WNet res = new WNet (np); 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; }
/** * <p>Adds two demands, one in each direction,.</p> * <p><b>Important</b>: Self-demands are not allowed.</p> * * @param ingressNode Identifier of the ingress node * @param egressNode Identifier of the egress node * @param offeredTraffic Offered traffic by this demand. It must be greater or equal than zero * @param attributes SortedMap for user-defined attributes ({@code null} means 'no attribute'). Each key represents the attribute name, whereas value represents the attribute value * @param optionalLayerParameter Network layer to which add the demand (optional) * @param routingType Routing type * @return A pair object with the two newly created demands * @see com.net2plan.interfaces.networkDesign.Demand * @see com.net2plan.utils.Pair */ public Pair<Demand, Demand> addDemandBidirectional(Node ingressNode, Node egressNode, double offeredTraffic, RoutingType routingType , Map<String, String> attributes, NetworkLayer... optionalLayerParameter) { offeredTraffic = NetPlan.adjustToTolerance(offeredTraffic); checkIsModifiable(); NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter); checkInThisNetPlan(ingressNode); checkInThisNetPlan(egressNode); if (ingressNode.equals(egressNode)) throw new Net2PlanException("Self-demands are not allowed"); if (offeredTraffic < 0) throw new Net2PlanException("Offered traffic must be non-negative"); Demand d1 = addDemand(ingressNode, egressNode, offeredTraffic, routingType , attributes, layer); Demand d2 = addDemand(egressNode, ingressNode, offeredTraffic, routingType , attributes, layer); d1.bidirectionalPair = d2; d2.bidirectionalPair = d1; if (ErrorHandling.isDebugEnabled()) this.checkCachesConsistency(); return Pair.of(d1, d2); }