def compare_vertices(v1: Vertex, v2: Vertex): v1d = v1.degree() v2d = v2.degree() if v1d < v2d: return v1 elif v1d > v2d: return v2 else: n: Vertex sum_neighbours_degree_v1 = sum([n.degree() for n in v1.neighbors()]) sum_neighbours_degree_v2 = sum([n.degree() for n in v2.neighbors()]) if sum_neighbours_degree_v1 > sum_neighbours_degree_v2: return v1 elif sum_neighbours_degree_v1 < sum_neighbours_degree_v2: return v2 else: random_number = random.randint(0, 1) return v1 if random_number == 0 else v2
def compute_g_of_v_for_testing(v: Vertex): degree = v.degree() if degree == 0: return 0, degree, (0 * degree) g_minus = 1 / (degree + 1) g_plus = np.array( [1 / (n.degree() * (n.degree() + 1)) for n in v.neighbors()]).sum() g = g_plus - g_minus return g, degree, g * degree
def compute_g_of_v(v: Vertex): degree = v.degree() if degree == 0: return 0 g_minus = 1 / (degree + 1) g_plus = np.array( [1 / (n.degree() * (n.degree() + 1)) for n in v.neighbors()]).sum() g = g_plus - g_minus return g
def helper(v: Vertex): dv = v.degree() dv_1_squared = (dv + 1)**2 return dv / dv_1_squared
def compute_x_minus_1(v: Vertex): deg = v.degree() return (deg - 1) / deg
def compute_x(v: Vertex): deg = v.degree() return deg / (deg + 1)
def compute_t(orig: Graph, vertex: Vertex): graph: Graph = orig.copy() how_many_neighbors = vertex.degree() remove_vertex_and_neighbors(graph, vertex) dv_dv_plus_1 = [(v.degree() / (v.degree() + 1)) for v in graph.vs] return sum(dv_dv_plus_1) + how_many_neighbors
def b_v(v: Vertex): degree = v.degree() neighbors_with_lower_degree = [ n for n in v.neighbors() if n.degree() == degree ] return len(neighbors_with_lower_degree)
def isInA(v: Vertex): degree = v.degree() neighbors_with_lower_degree = [ n for n in v.neighbors() if n.degree() < degree ] return len(neighbors_with_lower_degree) > 0