示例#1
0
    def subgraph(self, nodes={}, index_mapping=None):
        nodes = set(nodes)
        if index_mapping is None:
            index_mapping = {node: node for node in nodes}
        sub = DoubleWeightedDiGraph(
            magicgraph.from_adjlist([[index_mapping[node]] for node in nodes]))
        for node in nodes:
            for adj_node, weight in zip(self[node], self[node].weights):
                if adj_node in nodes:
                    sub[index_mapping[node]].append(index_mapping[adj_node],
                                                    weight)
            if len(self[node]) == 0:
                if index_mapping:
                    sub[index_mapping[node]].append(index_mapping[node], 1.)
                else:
                    sub[node].append(node, 1.)

        node_weight_map = {
            node: weight
            for node, weight in zip(self.weighted_nodes,
                                    self.weighted_nodes.weights)
        }
        for node in nodes:
            sub.weighted_nodes.weights[
                index_mapping[node]] = node_weight_map[node]
        return sub
示例#2
0
def clique(size):
    return magicgraph.from_adjlist(permutations(range(1,size+1)))