def get_type_s1(self, curr: Cut) -> Cut: if len(curr.cl) == 0: return Cut() final_cut = Cut() final_cut.cl = curr.cl.copy() self.random_one_less_edge(final_cut) count = 0 while self.support_el(final_cut.pl) >= self.support_count and \ count <= self.G[self.mini_idx].number_of_edges(): count += 1 final_cut.cl = curr.cl.copy() self.random_one_less_edge(final_cut) if count > self.G[self.mini_idx].number_of_edges(): return Cut() final_cut.cl = final_cut.pl.copy() grand_parents = self.one_less_edge(final_cut.cl) for gp in grand_parents: if self.support_el(gp) >= self.support_count: final_cut.pl = gp break if len(final_cut.pl) == 0: return Cut() return final_cut
def random_one_more_edge(self, cut: Cut) -> None: list_cand_edge = list(set(self.G[self.mini_idx].edges) - set(cut.pl)) while True: chose_edge = random.choice(list_cand_edge) cut.cl = cut.pl.copy() + [chose_edge] cut.cl = list(sorted(cut.cl)) p_graph = self.edgelist_to_graph(cut.cl) if not nx.classes.function.is_empty(p_graph) and nx.is_connected( p_graph): break
def get_type_m(self, curr: Cut) -> Cut: pall = self.get_type_pall(curr) if len(pall.pl) == 0: return Cut() final_cut = Cut() final_cut.pl = pall.pl.copy() self.random_one_more_edge(final_cut) count = 0 while self.support_el(final_cut.cl) < self.support_count and \ count <= self.G[self.mini_idx].number_of_edges(): count += 1 final_cut.pl = pall.pl.copy() self.random_one_more_edge(final_cut) if count > self.G[self.mini_idx].number_of_edges(): return Cut() cm_child = self.find_common_child(final_cut.cl, curr.cl) final_cut.pl = final_cut.cl final_cut.cl = cm_child return final_cut
def random_replace_edge(self, cut: Cut, change_time: int) -> None: final_cut = Cut() final_cut.pl = cut.pl.copy() list_cand_edge = list(set(self.G[self.mini_idx].edges) - set(cut.pl)) for _ in range(change_time): step_cut = final_cut.copy() chose_edge = None p_graph = nx.Graph() while len(list_cand_edge) > 0: chose_edge = random.choice(list_cand_edge) final_cut.pl = step_cut.pl.copy() + [chose_edge] final_cut.pl = list(sorted(final_cut.pl)) p_graph = self.edgelist_to_graph(final_cut.pl) if nx.is_connected(p_graph): break if not nx.classes.function.is_empty( p_graph) and self.support_graph( p_graph) >= self.support_count: list_cand_edge.remove(chose_edge) else: final_cut.pl = step_cut.pl.copy() break final_cut.cl = final_cut.pl step_cl = final_cut.cl.copy() while len(list_cand_edge) > 0: chose_edge = random.choice(list_cand_edge) final_cut.cl = step_cl + [chose_edge] final_cut.cl = list(sorted(final_cut.cl)) p_graph = self.edgelist_to_graph(final_cut.cl) if nx.is_connected(p_graph): list_cand_edge.remove(chose_edge) step_cl = final_cut.cl.copy() if self.support_graph(p_graph) < self.support_count: break cut.cl = final_cut.cl cut.pl = final_cut.pl
def get_type_pall(self, curr: Cut) -> Cut: if len(curr.cl) == 0: return Cut() final_cut = Cut() final_cut.cl = curr.cl.copy() self.random_one_less_edge(final_cut) count = 0 while self.support_el(final_cut.pl) < self.support_count and \ count <= self.G[self.mini_idx].number_of_edges(): count += 1 final_cut.cl = curr.cl.copy() self.random_one_less_edge(final_cut) if count > self.G[self.mini_idx].number_of_edges(): return Cut() return final_cut