def reciprocal_complementary_w(adjmatrix, x=1): """ Parametri --------- adjmatrix : numpy.matrix Matrica susedstva grafa G. x : float Varijabilni parametar. Rezultati --------- rcw : float Reciprocal-Complementary-Wienner indeks. """ dist = distance_matrix(adjmatrix) dia = diameter(adjmatrix) rcw = 0 for i in range(len(dist) - 1): for j in range(i + 1, len(dist)): rcw += 1 / (dia + 1 - dist[i, j])**x return rcw
def n1n2(adjmatrix): """Pravi listu sa vrednostima za n1 i n2. Parametri --------- adjmatrix : numpy.matrix Matrica susedstva grafa G. Rezultati --------- n1n2 : int Proizvod broja cvorova sa jedne i druge strane zadate grane. """ dmatrix = distance_matrix(adjmatrix) n1n2 = [] for u in range(len(dmatrix) - 1): for v in range(u + 1, len(dmatrix)): if dmatrix[u, v] == 1: n1 = 0 n2 = 0 for p in range(len(dmatrix)): if dmatrix[u, p] < dmatrix[v, p]: n1 += 1 elif dmatrix[u, p] > dmatrix[v, p]: n2 += 1 n1n2.append((n1, n2)) return n1n2
def eccentricity(adjmatrix): """ :param adjmatrix: :return: """ dmatrix = gp.distance_matrix(adjmatrix).tolist() ecc = list() for row in dmatrix: ecc.append(max(row)) return ecc
def vertex_distance(adjmatrix): """ :param adjmatrix: :return: """ dmatrix = gp.distance_matrix(adjmatrix).tolist() vdist = list() for row in dmatrix: vdist.append(sum(row)) return vdist
def gutman(adjmatrix): """ :param adjmatrix: :return: """ dmatrix = gp.distance_matrix(adjmatrix) degs = gp.degree(adjmatrix) gut = 0 for i in range(len(degs) - 1): for j in range(i + 1, len(degs)): gut += degs[i] * degs[j] * dmatrix[i, j] return gut
def balaban(adjmatrix, sum_balaban=False): ''' Parametri --------- adjmatrix : numpy matrix ili list of lists Matrica susedstva grafa G. sum_balaban : bool Uslov koji ukoliko je ispunjen, funkcija racuna sum-Balabanov indeks. Ukoliko uslov nije ispunjen racuna se originalni Balabanov indeks. Rezultati --------- jj : float Balabanov ili sum-Balabanov indeks u zavisnosti od ispunjenosti uslova sum_balaban. ''' n = len(adjmatrix) m = 0 for row in adjmatrix.tolist(): m += sum(row) / 2 dm = distance_matrix(adjmatrix) c = m / (m - n + 2) jj = 0 rowsum = [] for row in dm: rowsum.append(sum(row)) for i in range(len(dm) - 1): for j in range(i + 1, len(dm)): if dm[i, j] == 1: if not sum_balaban: jj += 1 / np.sqrt(rowsum[i] * rowsum[j]) else: jj += 1 / np.sqrt(rowsum[i] + rowsum[j]) return c * jj
def distance_partition(adjmatrix): """Distance partition. Parametri --------- adjmatrix : numpy.matrix Matrica susedstva grafa G. Rezultati --------- k : int Broj javljanja rastojanja k u matrici rastojanja. """ dm = distance_matrix(adjmatrix) k = dict() for i in range(len(dm) - 1): for j in range(i + 1, len(dm)): k[int(dm[i, j])] = k.get(int(dm[i, j]), 0) + 1 return k
def estrada(M, mat='adjacency', c=0): """Some kind of the Estrada index. Parametri --------- M : numpy.matrix Matrica iz koje se racuna spektar grafa i potom energija. mat : str Nacin na koji biramo matricu. Podrazumevana vrednost je 'adjacency'. c : float Konstanta od koje se oduzima sopstvena vrednost grafa. Podrazumavana vrednost je 0. Npr. kod laplasove energije c = 2*m/n . Rezultati --------- ee : float Neki Estradin indeks. """ if mat == 'laplacian': M = gp.laplacian_matrix(M) elif mat == "distance": M = gp.distance_matrix(M) elif mat == 'randic': M = gp.randic_matrix(M) elif mat == 'xu': M = gp.degree_extended_matrix(M) elif mat == 'harary': M = gp.harary_matrix(M) else: pass ee = 0 spec = gp.matrix_spectrum(M) for l in spec: ee += np.exp(l - c) return ee
def diameter(adjmatrix): """Izracunava diametar grafa (maksimalno rastojanje). Parametri --------- adjmatrix : numpy.matrix Matrica susedstva grafa G. Rezultati --------- dia : int Maksimalno rastojanje u matrici rastojanja. """ dist = distance_matrix(adjmatrix) dia = None for row in dist: if dia is None or dia < max(row): dia = max(row) return dia
def ti(self, adjmatrix): dist = distance_matrix(adjmatrix) deg = degree(adjmatrix) y = 0 if self.choose == 't': for i in range(len(dist) - 1): for j in range(i + 1, len(dist)): if deg[i] == 1 and deg[j] == 1: y += self.func(dist[i, j], self.x) return y elif self.choose == 's': for i in range(len(dist) - 1): for j in range(i + 1, len(dist)): if deg[i] == 1 or deg[j] == 1: y += self.func(dist[i, j], self.x) return y else: for i in range(len(dist) - 1): for j in range(i + 1, len(dist)): y += self.func(dist[i, j], self.x) return y