Ejemplo n.º 1
0
def Connect(loc, m, sourcenum):
    """Connect the vertices generated in Function Nodeloc - generate the adjacent matrix
    Input: loc - vertex location geographically
           m - the most m cloest facilities to be connected
           
    Output: distmatrix - the distance matrix of the vertices
            adjmatrix - the adjacent matrix of the vertices
    """
    distmatrix = np.zeros([len(loc), len(loc)])

    for i in range(len(loc)):
        for j in range(len(loc)):
            distmatrix[i, j] = sf.dist(loc[i, 0], loc[i, 1], loc[j, 0], loc[j,
                                                                            1])

    #Calculate the adjacent matrix
    adjmatrix = np.zeros([len(loc), len(loc)])

    for i in range(len(distmatrix) - sourcenum):
        index = sorted(range(len(distmatrix[i + sourcenum, :])),
                       key=lambda k: distmatrix[i + sourcenum, :][k])
        adjmatrix[i + sourcenum, index[0:m]] = 1
        adjmatrix[index[0:m], i + sourcenum] = 1

    return distmatrix, adjmatrix
 def Distmatrix(self):
     """Calculate the distance matrix for the vertices in the network
     """
     self.Dismatrix = np.zeros((self.nodenum, self.nodenum))
     for i in range(len(self.Dismatrix)):
         for j in range(len(self.Dismatrix)):
             self.Dismatrix[i, j] = sf.dist(self.y[i], self.x[i], self.y[j],
                                            self.x[j])
             self.Dismatrix[j, i] = self.Dismatrix[i, j]
    def Distmatrix(self):
        """Define the distance matrix of this dependency
        Ex: self.distmatrix[i, j] - the distance between node i in network1 and node j in network2
        Output: 2D numpy array, the distance matrix of the dependency
        """
        self.distmatrix = np.zeros((self.nodenum1, self.nodenum2), dtype=float)

        for i in range(self.nodenum1):
            for j in range(self.nodenum2):
                self.distmatrix[i, j] = sf.dist(self.network1.y[self.network1.demandseries[i]], self.network1.x[self.network1.demandseries[i]], \
                                                self.network2.y[self.network2.supplyseries[j]], self.network2.x[self.network2.supplyseries[j]])
    def Distmatrix(self):
        """Define the distance matrix of this dependency
        Ex: self.distmatrix[i, j] - the distance between node i in network3 and middle point of link j in internet from network1 to network2
        Output: 2D numpy array, the distance matrix of the dependency
        """
        self.distmatrix = np.zeros((self.nodenum3, self.linknum), dtype=float)

        for i in range(self.nodenum3):
            for j in range(self.linknum):
                self.distmatrix[i, j] = sf.dist(self.network3.y[self.network3.demandseries[i]], self.network3.x[self.network3.demandseries[i]], \
                                                self.internet1net2.edgelist[j]["middley"], self.internet1net2.edgelist[j]["middlex"])
Ejemplo n.º 5
0
    def distmatrix(self):
        """Set up the distance matrix of the network
        """
        import numpy as np

        self.nodexnormal, self.nodeynormal = sf.FeatureScaling(
            self.nodex), sf.FeatureScaling(self.nodey)

        self.dmatrix = np.empty((self.nodenum, self.nodenum), dtype=float)
        self.dnormalmatrix = np.empty((self.nodenum, self.nodenum),
                                      dtype=float)

        for i in range(self.nodenum):
            for j in range(i, self.nodenum):
                self.dmatrix[i, j] = sf.dist(self.nodey[i], self.nodex[i],
                                             self.nodey[j], self.nodex[j])
                self.dmatrix[j, i] = self.dmatrix[i, j]

                self.dnormalmatrix[i, j] = sf.dist(self.nodeynormal[i],
                                                   self.nodexnormal[i],
                                                   self.nodeynormal[j],
                                                   self.nodexnormal[j])
                self.dnormalmatrix[j, i] = self.dnormalmatrix[i, j]
Ejemplo n.º 6
0
 def Connect(self, m):
     """Connect the vertices generated in Function Nodeloc - generate the adjacent matrix
     Input:  m - the most m cloest facilities to be connected
            
     Output: distmatrix - the distance matrix of the vertices
             adjmatrix - the adjacent matrix of the vertices
     """
     self.distmatrix = np.zeros([len(self.loc), len(self.loc)])
     
     for i in range(len(self.loc)):
         for j in range(len(self.loc)):
             self.distmatrix[i, j] = sf.dist(self.Geoloc[i, 0], self.Geoloc[i, 1], self.Geoloc[j, 0], self.Geoloc[j, 1])
     
     #Calculate the adjacent matrix
     self.adjmatrix = np.zeros([len(self.loc), len(self.loc)])
     
     for i in range(len(self.demandseries)):
         minindex = np.array(sf.minimumk(self.distmatrix[:self.demandseries[i], self.demandseries[i]], m))
         self.adjmatrix[minindex, self.demandseries[i]] = 1