def makeState(self): #Version 1 if self.stateVersion == 1: bwUsed = Util.bandwithUsed(self.allocateur.listSlicesCurrentlyAllocated, self.allocateur.currentAlloc) return [self.nbSlicesAddSinceLastReconf, self.nbSlicesRejectSinceLastReconf, self.nbSlicesRemoveSinceLastReconf, self.nbMinutesSinceLastReconf, float(bwUsed)/self.topology.linksCapacity, float(self.timeStep)/len(self.scenario.listOfArrival)] #Version 2 elif self.stateVersion == 2: print("Version make state NOOOO") exit() bwUsed, nbVnfUsed = Util.bandwithAndVnfUsed(self.allocateur.listSlicesCurrentlyAllocated, self.allocateur.currentAlloc) maxBwServed = self.topology.numberLinksToBaseStations * self.topology.capacityEdgeLinks bwServed = 0 for s in self.allocateur.listSlicesCurrentlyAllocated: bwServed += s.bd return [ float(bwServed)/maxBwServed, float(nbVnfUsed)/self.nbVnf, float(bwUsed)/self.topology.linksCapacity, float(self.timeStep)/len(self.scenario.listOfArrival)] #Version 3 elif self.stateVersion == 3: return [float(self.nbMinutesSinceLastReconf)/len(self.scenario.listOfArrival), float(self.timeStep)/len(self.scenario.listOfArrival)] #Version 4 elif self.stateVersion == 4: return [float(self.nbSlicesAddSinceLastReconf)/len(self.scenario.listOfArrival), float(self.nbSlicesRemoveSinceLastReconf)/len(self.scenario.listOfArrival), float(self.nbMinutesSinceLastReconf)/len(self.scenario.listOfArrival), float(self.timeStep)/len(self.scenario.listOfArrival)] #Version 5 elif self.stateVersion == 5: linksUsage, nodesUsage, nodeFunction = Util.utilisationAndVnfUsed(self.functions, self.allocateur.listSlicesCurrentlyAllocated, self.allocateur.currentAlloc, roundNumber = 8) newCostVnfsUsed = 0 for u in nodesUsage: for f in nodeFunction[u]: newCostVnfsUsed += self.functions[f][1] return [float(self.nbSlicesAddSinceLastReconf)/len(self.scenario.listOfArrival), float(self.nbSlicesRemoveSinceLastReconf)/len(self.scenario.listOfArrival), float(self.nbMinutesSinceLastReconf)/len(self.scenario.listOfArrival), float(self.timeStep)/len(self.scenario.listOfArrival), newCostVnfsUsed] #Version 6 elif self.stateVersion == 6: return [float(self.nbSlicesAddSinceLastReconf)/len(self.scenario.listOfArrival), float(self.nbSlicesRemoveSinceLastReconf)/len(self.scenario.listOfArrival), float(self.nbMinutesSinceLastReconf)/len(self.scenario.listOfArrival)]
def _reset(self): if not self.doStillRunning(): print("ReconfigurationEnvironement : I can't reset, there is no more instances, I'm empty :'(") return False self.instanceNum = self.listInstanceFiles[0].split("-")[-1:][0] self.instanceName = "{}-S{}".format(self.listInstanceFiles[0][:-(1+len(self.instanceNum))], self.TopologySettings) if True : self.costReconf = 1 self.listProfitNoReconf =[0 for _ in range(2000)] self.maxProfitReconf = 0 else: self.costReconf, self.listProfitNoReconf, self.maxProfitReconf = self.loadSolutionCompare() #self.costReconf = 1 self.costReconf = self.ratioPriceSeuilReconf*self.costReconf self.rewardTotal = 0 #print("Debug Env : Reset Start") self._episode_ended = False if self.newTopo: listOfArrival = scenarioManager.loadInstance("..",self.topoName, self.listInstanceFiles[0]) else: param.startDynamic = param.startDynamicOld param.timePeriodeDynamic = param.timePeriodeDynamicOld listOfArrival = scenarioManager.loadInstanceOld("..",self.topoName, self.listInstanceFiles[0]) links, nodes, DC, capaLink, capaNode, nbVnf = initializeNetworkDynamic.avgCapa(self.topoName, self.functions, listOfArrival, 3) self.topology = TopologyManager.Topology(nodes, links) self.nbVnf = (len(self.topology.listDCCore) + len(self.topology.listDCEdge)) * len(self.functions) capaLink = self.topology.linksCapacity self.costMaxVnf = 0 for f in self.functions: self.costMaxVnf += self.functions[f][1] self.costMaxVnf = self.costMaxVnf * (len(self.topology.listDCCore) + len(self.topology.listDCEdge)) self.ratioBeta = (capaLink/float(self.costMaxVnf)) """ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ******************************************************************* """ #listOfArrival = listOfArrival[:250] """ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ******************************************************************* """ self.scenario = scenarioManager.Scenario(self.topoName, self.topology, self.listInstanceFiles[0], listOfArrival, self.functions) listSlicesAccepted = [] listSlicesCurrentlyAllocated = [] currentAlloc = {} currentPaths = {} self.doIReconfigureNow = False if self.evaluation: self.listTimeStepReconf = [] self.listPeriodeReconf = [] self.listReward = [] self.listImprovVnf = [] self.listImprovCostMb = [] self.listImprovVnfVsFake = [] self.listImprovCostMbVsFake = [] self.listNbSlicesAddSinceLastReconf = [] self.listNbSlicesRemoveSinceLastReconf = [] self.listNbMinutesSinceLastReconf = [] self.listPercBandwidthUsed = [] self.listPercVnfUsed = [] self.listPercBandwidthAllocated = [] self.listNbSlicesAllocated = [] self.nbSlicesAddSinceLastReconf = 0 self.nbSlicesRemoveSinceLastReconf = 0 self.nbSlicesRejectSinceLastReconf = 0 self.nbMinutesSinceLastReconf = 0 self.timeStep = 0 self.reconfsDone = [] """ ################################################################################################################# """ """ Initialising the Network """ """ ################################################################################################################# """ for i in range(param.startDynamic): nodeFunction = {} linksUsage, nodesUsage, nodeFunction = Util.utilisationAndVnfUsed(self.functions, listSlicesCurrentlyAllocated, currentAlloc, roundNumber = 8) #We allocate a new one slices = self.scenario.getNewSlices() for s in slices: allocPossible, dictPathTMP, currentAllocTMP = allocILP.findAllocation(self.topology, nodesUsage, linksUsage, [s], self.functions, nodeFunction, self.ratioBeta*self.betaInit) if allocPossible : listSlicesAccepted.append(s) listSlicesCurrentlyAllocated.append(s) currentAlloc[s.id] = currentAllocTMP[s.id] currentPaths[s.id] = dictPathTMP[s.id] linksUsage, nodesUsage, nodeFunction = Util.utilisationAndVnfUsed(self.functions, listSlicesCurrentlyAllocated, currentAlloc, roundNumber = 8) self.nbSlicesAddSinceLastReconf += 1 else: self.nbSlicesRejectSinceLastReconf += 1 self.nbMinutesSinceLastReconf += 1 #We remove the dead sfc j = 0 while j < len(listSlicesCurrentlyAllocated): if listSlicesCurrentlyAllocated[j].timeOfDeath == i: del(currentPaths[listSlicesCurrentlyAllocated[j].id]) del(currentAlloc[listSlicesCurrentlyAllocated[j].id]) del(listSlicesCurrentlyAllocated[j]) self.nbSlicesRemoveSinceLastReconf += 1 continue else: j += 1 bwUsed = Util.bandwithUsed(listSlicesCurrentlyAllocated, currentAlloc) capaLink = self.topology.linksCapacity capaDC = self.topology.DCCapacity name = "Reconf_Beta-1_Freq-LR" objectifChooser = ObjectifChooser.ObjectifChooser([1]) reconfChooser = self self.allocateur = AllocateurDynamic.AllocateurDynamic(name, self.topology, self.nbVnf, self.costMaxVnf, capaDC, capaLink, self.functions, currentAlloc, currentPaths, listSlicesCurrentlyAllocated, objectifChooser, reconfChooser, True, self.nbSteps) if self.rewardVersion == 4: name = "NoReconf_Beta-1" objectifChooser = ObjectifChooser.ObjectifChooser([1]) reconfChooser = ReconfigurationChooser.ReconfigurationChooser(param.startDynamic) self.allocateurNoReconf = AllocateurDynamic.AllocateurDynamic(name, self.topology, self.nbVnf, self.costMaxVnf, capaDC, capaLink, self.functions, currentAlloc, currentPaths, listSlicesCurrentlyAllocated, objectifChooser, reconfChooser, None, self.nbSteps) #self.nbSlicesAddSinceLastReconf = len(listSlicesAccepted) #self.nbSlicesDeadSinceReconf = len(listSlicesCurrentlyAllocated) self.timeStep = param.startDynamic self.nbMinutesSinceLastReconf = param.startDynamic """ ################################################################################################################# """ """ We add one slice, because each step start with a reconf in the environement """ """ ################################################################################################################# """ slices = self.scenario.getNewSlices() for s in slices: self.allocateur.addSlice(s, self.timeStep) if self.rewardVersion == 4: self.allocateurNoReconf.addSlice(s, self.timeStep) if len(self.allocateur.listSlicesAccepted)>0: if self.allocateur.listSlicesAccepted[-1].id == s.id: self.nbSlicesAddSinceLastReconf+=1 else: self.nbSlicesRejectSinceLastReconf else: self.nbSlicesRejectSinceLastReconf #self.nbMinutesSinceLastReconf +=1 nbSlices = len(self.allocateur.listSlicesCurrentlyAllocated) self.allocateur.removeSlices(self.timeStep) self.nbSlicesRemoveSinceLastReconf += nbSlices-len(self.allocateur.listSlicesCurrentlyAllocated) if self.rewardVersion == 4: self.allocateurNoReconf.removeSlices(self.timeStep) self._state = self.makeState() #print("Debug Env : Reset Stop") return ts.restart(np.array([self._state], dtype=np.float32))