Offline_ipOverWdm_routingSpectrumAndModulationAssignmentHeuristicNotGrooming implements IAlgorithm { @Override public String executeAlgorithm(NetPlan netPlan, Map<String, String> algorithmParameters, Map<String, String> net2planParameters) { InputParameter.initializeAllInputParameterFieldsOfObject(this, algorithmParameters); this.netPlan = netPlan; if (netPlan.getNumberOfLayers() == 1) { this.wdmLayer = netPlan.getNetworkLayerDefault(); this.netPlan.setDemandTrafficUnitsName("Gbps"); this.netPlan.setLinkCapacityUnitsName("Frequency slots"); this.ipLayer = netPlan.addLayer("IP" , "IP layer" , "Gbps" , "Gbps" , null , null); for (Demand wdmDemand : netPlan.getDemands(wdmLayer)) netPlan.addDemand(wdmDemand.getIngressNode(), wdmDemand.getEgressNode() , wdmDemand.getOfferedTraffic() , RoutingType.HOP_BY_HOP_ROUTING , wdmDemand.getAttributes() , ipLayer); } else { this.wdmLayer = wdmLayerIndex.getInt () == -1? netPlan.getNetworkLayerDefault() : netPlan.getNetworkLayer(wdmLayerIndex.getInt ()); this.ipLayer = ipLayerIndex.getInt () == -1? netPlan.getNetworkLayerDefault() : netPlan.getNetworkLayer(ipLayerIndex.getInt ()); } this.N = netPlan.getNumberOfNodes(); this.Ewdm = netPlan.getNumberOfLinks(wdmLayer); this.Dip = netPlan.getNumberOfDemands(ipLayer); this.S = numFrequencySlotsPerFiber.getInt(); if (N == 0 || Ewdm == 0 || Dip == 0) throw new Net2PlanException("This algorithm requires a topology with links and a demand set"); this.singleSRGToleranceNot11Type = networkRecoveryType.getString().equals("single-srg-tolerant-static-lp"); if (singleSRGToleranceNot11Type && (netPlan.getNumberOfSRGs() == 0)) throw new Net2PlanException ("No SRGs are defined, so there is no reason to use the single-SRG failure-tolerant design option"); if (networkRecoveryType.getString().equals("not-fault-tolerant") || networkRecoveryType.getString().equals("single-srg-tolerant-static-lp")) recoveryTypeNewLps = Demand.IntendedRecoveryType.NONE; else if (networkRecoveryType.getString().equals("1+1-srg-disjoint-lps")) recoveryTypeNewLps = Demand.IntendedRecoveryType.PROTECTION_REVERT; else throw new Net2PlanException ("Wrong input parameters"); WDMUtils.setFibersNumFrequencySlots(netPlan, S, wdmLayer); this.tpInfo = new WDMUtils.TransponderTypesInfo(transponderTypesInfo.getString()); this.T = tpInfo.getNumTypes(); netPlan.removeAllLinks (ipLayer); netPlan.removeAllDemands (wdmLayer); netPlan.removeAllMulticastDemands(wdmLayer); this.frequencySlot2FiberOccupancy_se = DoubleFactory2D.dense.make(S , Ewdm); this.cpl = netPlan.computeUnicastCandidatePathList(netPlan.getVectorLinkLengthInKm(wdmLayer) , k.getInt(), tpInfo.getMaxOpticalReachKm() , -1, maxPropagationDelayMs.getDouble(), -1, -1, -1 , null , wdmLayer); this.cpl11 = networkRecoveryType.getString().equals("1+1-srg-disjoint-lps")? NetPlan.computeUnicastCandidate11PathList(cpl,0) : null; Map<Link,Double> linkLengthMap = new HashMap<Link,Double> (); for (Link e : netPlan.getLinks(wdmLayer)) linkLengthMap.put(e , e.getLengthInKm()); final int maximumNumberOfPaths = T*k.getInt()*Dip; List<Integer> transponderType_p = new ArrayList<Integer> (maximumNumberOfPaths); List<Double> cost_p = new ArrayList<Double> (maximumNumberOfPaths); List<Double> lineRate_p = new ArrayList<Double> (maximumNumberOfPaths); List<Integer> numSlots_p = new ArrayList<Integer> (maximumNumberOfPaths); List<List<Link>> seqLinks_p = new ArrayList<List<Link>> (maximumNumberOfPaths); List<List<Link>> seqLinks2_p = cpl11 == null? null : new ArrayList<List<Link>> (maximumNumberOfPaths); List<int []> regPositions_p = new ArrayList<int []> (maximumNumberOfPaths); List<int []> regPositions2_p = new ArrayList<int []> (maximumNumberOfPaths); List<Demand> ipDemand_p = new ArrayList<Demand> (maximumNumberOfPaths); Map<Demand,List<Integer>> ipDemand2WDMPathListMap = new HashMap<Demand,List<Integer>> (); for (Demand ipDemand : netPlan.getDemands(ipLayer)) { final Pair<Node,Node> nodePair = Pair.of(ipDemand.getIngressNode() , ipDemand.getEgressNode()); boolean atLeastOnePathOrPathPair = false; List<Integer> pathListThisDemand = new LinkedList<Integer> (); ipDemand2WDMPathListMap.put(ipDemand , pathListThisDemand); for (int t = 0 ; t < T ; t ++) { final boolean isRegenerable = tpInfo.isOpticalRegenerationPossible(t); for (Object sp : cpl11 != null? cpl11.get(nodePair) : cpl.get(nodePair)) { List<Link> firstPath = (cpl11 == null)? ((List<Link>) sp) : ((Pair<List<Link>,List<Link>>) sp).getFirst(); List<Link> secondPath = (cpl11 == null)? null : ((Pair<List<Link>,List<Link>>) sp).getSecond (); if (!isRegenerable && (getLengthInKm(firstPath) > tpInfo.getOpticalReachKm(t))) break; if (secondPath != null) if (!isRegenerable && (getLengthInKm(secondPath) > tpInfo.getOpticalReachKm(t))) break; final int [] regPositions1 = isRegenerable? WDMUtils.computeRegeneratorPositions(firstPath , tpInfo.getOpticalReachKm(t)) : new int [firstPath.size()]; final int [] regPositions2 = cpl11 == null? null : isRegenerable? WDMUtils.computeRegeneratorPositions(secondPath , tpInfo.getOpticalReachKm(t)) : new int [secondPath.size()]; final int numRegeneratorsNeeded = !isRegenerable? 0 : (int) IntUtils.sum(regPositions1) + (secondPath == null? 0 : (int) IntUtils.sum(regPositions2)) ; final double costOfLightpathOr11Pair = tpInfo.getCost(t) * (cpl11 != null? 2 : 1) + (tpInfo.getRegeneratorCost(t) * numRegeneratorsNeeded); final int pathIndex = cost_p.size(); cost_p.add (costOfLightpathOr11Pair); transponderType_p.add (t); lineRate_p.add(tpInfo.getLineRateGbps(t)); numSlots_p.add(tpInfo.getNumSlots(t)); ipDemand_p.add(ipDemand); seqLinks_p.add(firstPath); regPositions_p.add(regPositions1); pathListThisDemand.add(pathIndex); if (cpl11 != null) { seqLinks2_p.add(secondPath); regPositions2_p.add(regPositions2); } atLeastOnePathOrPathPair = true; } } if (!atLeastOnePathOrPathPair) throw new Net2PlanException ("There are no possible routes (or 1+1 pairs) for a demand (" + ipDemand + "). The topology may be not connected enough, or the optical reach may be too small"); } final int P = transponderType_p.size(); boolean atLeastOneLpAdded = false; Set<Integer> ipDemandIndexesNotToTry = new HashSet<Integer> (); double totalCost = 0; do { double [] b_d = getVectorIPDemandAverageAllStatesBlockedTraffic (); int [] ipDemandIndexes = DoubleUtils.sortIndexes(b_d , OrderingType.DESCENDING); atLeastOneLpAdded = false; for (int ipDemandIndex : ipDemandIndexes) { if (ipDemandIndexesNotToTry.contains(ipDemandIndex)) continue; final Demand ipDemand = netPlan.getDemand(ipDemandIndex , ipLayer); ipDemand.setRoutingType(RoutingType.SOURCE_ROUTING); if (isIpDemandFullySatisfied(ipDemand)) { ipDemandIndexesNotToTry.add(ipDemandIndex); continue; } WDMUtils.RSA best_rsa = null; WDMUtils.RSA best_rsa2 = null; double best_performanceMetric = 0; int best_pathIndex = -1; for (int pathIndex : ipDemand2WDMPathListMap.get (ipDemand)) { List<Link> firstPath = seqLinks_p.get(pathIndex); List<Link> secondPath = cpl11 == null? null : seqLinks2_p.get(pathIndex); Pair<Integer,Integer> slotIds = null; int slotId = -1; if (cpl11 == null) slotId = WDMUtils.spectrumAssignment_firstFit(firstPath , frequencySlot2FiberOccupancy_se , numSlots_p.get(pathIndex)); else slotIds = WDMUtils.spectrumAssignment_firstFitTwoRoutes(firstPath, secondPath, frequencySlot2FiberOccupancy_se , numSlots_p.get(pathIndex)); if (cpl11 == null) if (slotId == -1) continue; if (cpl11 != null) if (slotIds == null) continue; final double extraCarriedTraffic = getAverageAllStatesExtraCarriedTrafficAfterPotentialAllocation (ipDemand , lineRate_p.get(pathIndex) , seqLinks_p.get(pathIndex)); final double performanceIndicator = extraCarriedTraffic / cost_p.get(pathIndex); if (performanceIndicator > best_performanceMetric) { best_performanceMetric = performanceIndicator; best_rsa = new WDMUtils.RSA(firstPath , cpl11 != null? slotIds.getFirst() : slotId , numSlots_p.get(pathIndex) , regPositions_p.get(pathIndex)); best_rsa2 = cpl11 == null? null : new WDMUtils.RSA(secondPath , slotIds.getSecond() , numSlots_p.get(pathIndex) , regPositions2_p.get(pathIndex)); best_pathIndex = pathIndex; } } if (best_pathIndex == -1) { ipDemandIndexesNotToTry.add(ipDemand.getIndex()); continue; } atLeastOneLpAdded = true; totalCost += cost_p.get(best_pathIndex); final Demand newWDMDemand = netPlan.addDemand(best_rsa.ingressNode , best_rsa.egressNode , lineRate_p.get(best_pathIndex) , RoutingType.SOURCE_ROUTING , null , wdmLayer); newWDMDemand.setIntendedRecoveryType(recoveryTypeNewLps); final Route lp = WDMUtils.addLightpath(newWDMDemand , best_rsa , lineRate_p.get(best_pathIndex)); final Link ipLink = newWDMDemand.coupleToNewLinkCreated(ipLayer); final double ipTrafficToCarry = Math.min(lineRate_p.get(best_pathIndex) , ipDemand.getBlockedTraffic()); netPlan.addRoute(ipDemand , ipTrafficToCarry , ipTrafficToCarry , Arrays.asList(ipLink), null); WDMUtils.allocateResources(best_rsa , frequencySlot2FiberOccupancy_se , null); if (cpl11 != null) { final Route lpBackup = WDMUtils.addLightpath(newWDMDemand , best_rsa2 , 0); WDMUtils.allocateResources(best_rsa2 , frequencySlot2FiberOccupancy_se , null); lp.addBackupRoute(lpBackup); } break; } } while (atLeastOneLpAdded); WDMUtils.checkResourceAllocationClashing(netPlan,true,true,wdmLayer); String outMessage = "Total cost: " + totalCost + ". Num lps (not including 1+1 backup if any) " + netPlan.getNumberOfRoutes(wdmLayer); return "Ok! " + outMessage; }  @Override String executeAlgorithm(NetPlan netPlan, Map<String, String> algorithmParameters, Map<String, String> net2planParameters); @Override String getDescription(); @Override List<Triple<String, String, String>> getParameters();  }
@Test public void testExecuteAlgorithm() { Map<String,List<String>> testingParameters = new HashMap<> (); testingParameters.put("k" , Arrays.asList("5")); testingParameters.put("numFrequencySlotsPerFiber" , Arrays.asList("30")); testingParameters.put("transponderTypesInfo" , Arrays.asList("2000.0 1.0 1 9600.0 1.0 ; 4000.0 1.5 2 5000.0 1.5")); testingParameters.put("wdmLayerIndex" , Arrays.asList("0")); testingParameters.put("ipLayerIndex" , Arrays.asList("1")); testingParameters.put("networkRecoveryType" , Arrays.asList("not-fault-tolerant", "single-srg-tolerant-static-lp" , "1+1-srg-disjoint-lps")); testingParameters.put("maxPropagationDelayMs" , Arrays.asList("-1")); List<Map<String,String>> testsParam = InputParameter.getCartesianProductOfParameters (testingParameters); for (Map<String,String> params : testsParam) { System.out.println(params); final NetPlan npInput = np.copy (); new Offline_ipOverWdm_routingSpectrumAndModulationAssignmentHeuristicNotGrooming ().executeAlgorithm(np , params , null); checkValidity (npInput , np , params); } }