Ejemplo n.º 1
0
 def calcMMD(self, geneSerial, data):
     customers = []
     for item in data.CUSTOMERS:
         tmp = Customer()
         tmp.x = copy.deepcopy(item.x)
         tmp.y = copy.deepcopy(item.y)
         tmp.demand = copy.deepcopy(item.demand)
         customers.append(tmp)
     providers = []
     sigmaCost = 0
     sigmaCapacity = 0
     sigmaDemand = 0
     mmd = -1000.00
     for i in range(0, len(geneSerial)):
         tmpProvider = Provider()
         tmpProvider.x = copy.deepcopy(data.PROVIDERS[i].x)
         tmpProvider.y = copy.deepcopy(data.PROVIDERS[i].y)
         tmpProvider.capacity = copy.deepcopy(
             data.PROVIDERS[i].capacity[geneSerial[i]])
         tmpProvider.cost = copy.deepcopy(
             data.PROVIDERS[i].cost[geneSerial[i]])
         sigmaCost = sigmaCost + tmpProvider.cost
         sigmaCapacity = sigmaCapacity + tmpProvider.capacity
         providers.append(tmpProvider)
     for item in customers:
         sigmaDemand = sigmaDemand + item.demand
     if sigmaCapacity >= sigmaDemand:
         swapchainsolver = SwapChainSolver(providers, customers)
         mmd = swapchainsolver.Solver()
     return mmd
Ejemplo n.º 2
0
    def calcFitness(self, geneSerial, data, D):
        """
            usage ChromosomeNumber,geneSerial,data,D
            return fitness for this1  Chromosome
        """
        alpha = self.m_Alpha
        beta = self.m_Beta
        # alpha and beta are weight factor
        customers = []
        fitness = 0
        for item in data.CUSTOMERS:
            tmp = Customer()
            tmp.x = copy.deepcopy(item.x)
            tmp.y = copy.deepcopy(item.y)
            tmp.demand = copy.deepcopy(item.demand)
            customers.append(tmp)
        providers = []
        sigmaCost = 0
        sigmaCapacity = 0
        sigmaDemand = 0
        mmd = self.m_D * 1000.0
        for i in range(0, len(geneSerial)):
            tmpProvider = Provider()
            tmpProvider.x = copy.deepcopy(data.PROVIDERS[i].x)
            tmpProvider.y = copy.deepcopy(data.PROVIDERS[i].y)
            tmpProvider.capacity = copy.deepcopy(
                data.PROVIDERS[i].capacity[geneSerial[i]])
            tmpProvider.cost = copy.deepcopy(
                data.PROVIDERS[i].cost[geneSerial[i]])
            sigmaCost = sigmaCost + tmpProvider.cost
            sigmaCapacity = sigmaCapacity + tmpProvider.capacity
            providers.append(tmpProvider)
        for item in customers:
            sigmaDemand = sigmaDemand + item.demand

        if sigmaCapacity >= sigmaDemand:
            swapchainsolver = SwapChainSolver(providers, customers)
            mmd = swapchainsolver.Solver()
            if mmd > D:
                fitness = -4.0
            else:
                if sigmaCost != 0:
                    fitness = float(4.0 / sigmaCost)
                else:
                    fitness = 8.0
        else:
            fitness = -8.0
        # print("fitness,mmd,sigmaCapacity,sigmaCost,sigmaDemand:",fitness,mmd,sigmaCapacity,sigmaCost,sigmaDemand)
        return math.exp(fitness), mmd, sigmaCapacity, sigmaCost, sigmaDemand