예제 #1
0
class GraphPartitioningSet(object):
    def __init__(self, p_graph):
        self.p_graph = p_graph
        self.roots = p_graph.get_roots()
        self.subgraph_dict = {root: self.p_graph.get_subgraph_from_root(root) for root in self.roots}
        self.complex_subgraph_dict = {}

        self.all_partitions = Partition(self.roots)
        self.m = self.all_partitions.__len__()

        self.graph_partitionings = {}

    def get_graph_partition(self, k):
        if k in self.graph_partitionings:
            return self.graph_partitionings[k]
        else:
            root_partitioning = set([frozenset(roots) for roots in self.all_partitions[k]])
            graph_partitioning = GraphPartitioning(self.p_graph, root_partitioning, self.subgraph_dict, self.complex_subgraph_dict)
            self.graph_partitionings[k] = graph_partitioning
            return self.graph_partitionings[k]

    def sample_graph_partitionings(self):
        i = random.randint(0, self.m-1)
        return self.get_graph_partition(i)