def cost(Network, Tract_pop, Tractx, Tracty, Geox, Geoy, cnum):
    """Calculate the overall cost all a new solution: two type: demand-population, supply-transmission(transmission-demand)
    """
    x = sf.FeatureScaling2(Network.demandx, np.min(Geox),
                           np.max(Geox) - np.min(Geox))
    y = sf.FeatureScaling2(Network.demandy, np.min(Geoy),
                           np.max(Geoy) - np.min(Geoy))
    Tract_pop1 = sf.FeatureScaling(Tract_pop)
    Tractx1 = sf.FeatureScaling(Tractx)
    Tracty1 = sf.FeatureScaling(Tracty)

    Sum_Cost = 0
    Popu_assign2 = np.zeros(len(x))

    for i in range(len(Tractx1)):
        Dist = np.empty(len(x), dtype=float)
        for k in range(len(x)):
            Dist[k] = math.sqrt((Tracty1[i] - y[k])**2 +
                                (Tractx1[i] - x[k])**2)

        index = sf.minimumk(Dist, min(cnum, len(x)))
        ratio = sf.FeatureScaling3(
            np.sum(np.exp(Dist[index])) / np.exp(Dist[index]))

        for k in range(len(index)):
            Popu_assign2[index[k]] += Tract_pop1[i] * ratio[k]
            Sum_Cost += Popu_assign2[index[k]] * Dist[index[k]]

    Network.cost = Sum_Cost
Esempio n. 2
0
def cost(sol, Geox, Geoy, PD, Type, Tractx, Tracty, PD_beforenormalize, cnum):
    """Calculate the overall cost of a new solution: two type: demand-population, supply-transmission(transmission-demand)
    Input: sol - new solution: location in the form of the index
           Geox -
           Geoy -
           PD -
           Type -
           Tractx -
           Tracty -
    Output: cost of the new solution and the population assignment for the demand nodes of the new solution
    """
    Popu_assign, Popu_assign2 = np.zeros(len(sol)), np.zeros(len(sol))
    Sum_Cost = 0

    for i in range(len(Tractx)):
        Dist = np.empty(len(sol), dtype=float)
        for k in range(len(sol)):
            Dist[k] = math.sqrt((Tracty[i] - Geoy[sol[k][0]])**2 +
                                (Tractx[i] - Geox[sol[k][1]])**2)

        index = sf.minimumk(Dist, min(cnum, len(sol)))
        ratio = sf.FeatureScaling3(
            np.sum(np.exp(Dist[index])) / np.exp(Dist[index]))

        for k in range(len(index)):
            Popu_assign[index[k]] += PD_beforenormalize[i] * ratio[k]
            Popu_assign2[index[k]] += PD[i] * ratio[k]

            if (Type == 'Population'):
                Sum_Cost += Popu_assign2[index[k]] * Dist[index[k]]
            else:
                Sum_Cost += Dist[index[k]]

    return Sum_Cost, Popu_assign
Esempio n. 3
0
    def assignprob(self, density):
        """Calculate the assignment probability based on population density
        Input:
            density - the density of the population distribution

        Output: the cumu_prob along with the index transformatino metric
        """
        prob = sf.FeatureScaling3(density**self.gamma)
        temp1 = len(prob[0])

        probflatten = prob.flatten()
        cumu_prob = []
        cumu_prob_index = []

        for i in range(len(probflatten)):
            cumu_prob_index.append([i % temp1, int(i / temp1)])

            if (i == 0):
                cumu_prob.append(probflatten[i])
            else:
                cumu_prob.append(probflatten[i] + cumu_prob[-1])

        return cumu_prob, cumu_prob_index