@Override public void saveDemandSetToFile(NetPlan netPlan, File file) { DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic(); int N = trafficMatrix.rows(); PrintStream out; try { out = new PrintStream(new FileOutputStream(file), true, StandardCharsets.UTF_8.name()); for(int ingressNodeId = 0; ingressNodeId < N; ingressNodeId++) { for(int egressNodeId = 0; egressNodeId < N; egressNodeId++) out.print(trafficMatrix.getQuick(ingressNodeId, egressNodeId) + " "); out.println(); } out.flush(); out.close(); } catch(FileNotFoundException | UnsupportedEncodingException e) { throw new RuntimeException(e); } } }
private void loadTrafficMatrices(File[] files, Collection<NetPlan> netPlans) { List<DoubleMatrix2D> trafficMatrices_theseFiles = new LinkedList<DoubleMatrix2D>(); int i = 0; for (NetPlan netPlan : netPlans) { int D = netPlan.getNumberOfDemands(); if (D == 0) throw new Net2PlanException("File " + files[i] + " does not contain any demand"); DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic(); trafficMatrices_theseFiles.add(trafficMatrix); i++; } int removeExistingMatrices = askForRemovingExistingMatrices(); if (removeExistingMatrices == JOptionPane.CLOSED_OPTION) return; else if (removeExistingMatrices == JOptionPane.YES_OPTION) removeAllMatrices(); int firstMatrixId = -1; i = 0; for (DoubleMatrix2D trafficMatrix : trafficMatrices_theseFiles) { int N = trafficMatrix.rows(); int matrixId = addTrafficMatrix(N); if (i == 0) firstMatrixId = matrixId; setTrafficMatrix(trafficMatrix, getNumberOfTrafficMatrices() - 1); i++; } tabbedPane.setSelectedIndex(firstMatrixId); }
/** * <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(); }
return netPlan.getMatrixNode2NodeOfferedTraffic();
setTrafficMatrix(aux.getMatrixNode2NodeOfferedTraffic(), matrixId);
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++)
if (numMatrices < 1) throw new Net2PlanException("Number of traffic matrices must be positive"); DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic(); List<DoubleMatrix2D> newMatrices; String variationPattern = (String) cli.getParsedOptionValue("variation-pattern"); 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();
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());
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()));
DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic(); netPlan.removeAllDemands(); for (Node n1 : netPlan.getNodes()) for (Node n2 : netPlan.getNodes()) if (n1.getIndex () > n2.getIndex ())
DoubleMatrix2D thisIntervalTrafficMatrix = new NetPlan(new File (rootOfNameOfInputTrafficFiles.getString() + "_tm" + netPlanFiles.size () + ".n2p")).getMatrixNode2NodeOfferedTraffic(); if (thisIntervalTrafficMatrix.rows () != N) throw new Net2PlanException ("The number of nodes in traffic matrix: " + rootOfNameOfInputTrafficFiles.getString() + "_tm" + netPlanFiles.size () + ".n2p (" + thisIntervalTrafficMatrix.rows() + ") is not correct (" + N + ")"); NetPlan netPlanToAdd = netPlan.copy ();
DoubleMatrix2D thisIntervalTrafficMatrix = new NetPlan(new File (rootOfNameOfInputTrafficFiles.getString() + "_tm" + netPlanFiles.size () + ".n2p")).getMatrixNode2NodeOfferedTraffic(); if (thisIntervalTrafficMatrix.rows () != N) throw new Net2PlanException ("The number of nodes in traffic matrix: " + rootOfNameOfInputTrafficFiles.getString() + "_tm" + netPlanFiles.size () + ".n2p (" + thisIntervalTrafficMatrix.rows() + ") is not correct (" + N + ")"); NetPlan netPlanToAdd = netPlan.copy ();
final DoubleMatrix2D trafficMatrixDiagonalNegative = netPlan.getMatrixNode2NodeOfferedTraffic(upperLayer); trafficMatrixDiagonalNegative.assign (DoubleFactory2D.sparse.diagonal(egressTraffic_t) , DoubleFunctions.minus); op.setInputParameter("TM", trafficMatrixDiagonalNegative);
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);