def find_clique_aux(self, father, clique): adjacent = self.graph.get_node(father).neighbors_indices.copy() while len(adjacent) != 0: candidate = self.find_better(adjacent) if GraphUtils.become_clique(self.graph, clique, candidate): adjacent = GraphUtils.discard_adjacent(self.graph, adjacent, candidate) clique.append(candidate) else: adjacent.remove(candidate)
def find_clique_aux(self, graph, father, old_clique): clique = old_clique.copy() adjacent = graph.get_node(father).neighbors_indices.copy() while len(adjacent) != 0: candidate = self.find_better(graph, adjacent) if GraphUtils.become_clique(graph, clique, candidate): adjacent = GraphUtils.discard_adjacent(graph, adjacent, candidate) clique.update({candidate}) else: adjacent.discard(candidate) return clique, GraphUtils.calculate_clique_ratio(graph, clique)
def find_grasp_solution(self, graph, name, solution_type, fixed_seed, alpha): """ Find solution on graph with a GRASP algorithm. """ random.seed(fixed_seed) total_keys = sorted(list(graph.nodes.keys())) vertex = random.randint(total_keys[0], total_keys[-1]) solution = {vertex} cl = graph.nodes[vertex].neighbors_indices.copy() while len(cl) != 0: g_min, g_max, gc = self.get_g(cl, solution_type, graph, name) mu = g_max - alpha * (g_max - g_min) rcl = self.get_rcl(mu, gc) random.seed(fixed_seed) random_position = random.randint(0, len(rcl) - 1) u = rcl[random_position][0] if GraphUtils.become_clique(graph, solution, u): solution = solution.union({u}) cl -= {u} cl.intersection_update(graph.get_node(u).neighbors_indices) return solution