def edge_coloring(self): r""" Compute a proper edge-coloring. A proper edge-coloring is an assignment of colors to the sets of the hypergraph such that two sets with non-empty intersection receive different colors. The coloring returned minimizes the number of colors. OUTPUT: A partition of the sets into color classes. EXAMPLES:: sage: H = Hypergraph([{1,2,3},{2,3,4},{3,4,5},{4,5,6}]); H Hypergraph on 6 vertices containing 4 sets sage: C = H.edge_coloring() sage: C # random [[{3, 4, 5}], [{4, 5, 6}, {1, 2, 3}], [{2, 3, 4}]] sage: Set(sum(C,[])) == Set(H._sets) True """ from sage.graphs.graph import Graph g = Graph([self._sets,lambda x,y : len(x&y)],loops = False) return g.coloring(algorithm="MILP")
def edge_coloring(self): r""" Compute a proper edge-coloring. A proper edge-coloring is an assignment of colors to the sets of the incidence structure such that two sets with non-empty intersection receive different colors. The coloring returned minimizes the number of colors. OUTPUT: A partition of the sets into color classes. EXAMPLES:: sage: H = Hypergraph([{1,2,3},{2,3,4},{3,4,5},{4,5,6}]); H Incidence structure with 6 points and 4 blocks sage: C = H.edge_coloring() sage: C # random [[[3, 4, 5]], [[2, 3, 4]], [[4, 5, 6], [1, 2, 3]]] sage: Set(map(Set,sum(C,[]))) == Set(map(Set,H.blocks())) True """ from sage.graphs.graph import Graph blocks = self.blocks() blocks_sets = map(frozenset,blocks) g = Graph([range(self.num_blocks()),lambda x,y : len(blocks_sets[x]&blocks_sets[y])],loops = False) return [[blocks[i] for i in C] for C in g.coloring(algorithm="MILP")]
def edge_coloring(self): r""" Compute a proper edge-coloring. A proper edge-coloring is an assignment of colors to the sets of the hypergraph such that two sets with non-empty intersection receive different colors. The coloring returned minimizes the number of colors. OUTPUT: A partition of the sets into color classes. EXAMPLES:: sage: H = Hypergraph([{1,2,3},{2,3,4},{3,4,5},{4,5,6}]); H Hypergraph on 6 vertices containing 4 sets sage: C = H.edge_coloring() sage: C # random [[{3, 4, 5}], [{4, 5, 6}, {1, 2, 3}], [{2, 3, 4}]] sage: Set(sum(C,[])) == Set(H._sets) True """ from sage.graphs.graph import Graph g = Graph([self._sets, lambda x, y: len(x & y)], loops=False) return g.coloring(algorithm="MILP")
def edge_coloring(self): r""" Compute a proper edge-coloring. A proper edge-coloring is an assignment of colors to the sets of the incidence structure such that two sets with non-empty intersection receive different colors. The coloring returned minimizes the number of colors. OUTPUT: A partition of the sets into color classes. EXAMPLES:: sage: H = Hypergraph([{1,2,3},{2,3,4},{3,4,5},{4,5,6}]); H Incidence structure with 6 points and 4 blocks sage: C = H.edge_coloring() sage: C # random [[[3, 4, 5]], [[2, 3, 4]], [[4, 5, 6], [1, 2, 3]]] sage: Set(map(Set,sum(C,[]))) == Set(map(Set,H.blocks())) True """ from sage.graphs.graph import Graph blocks = self.blocks() blocks_sets = map(frozenset, blocks) g = Graph([ range(self.num_blocks()), lambda x, y: len(blocks_sets[x] & blocks_sets[y]) ], loops=False) return [[blocks[i] for i in C] for C in g.coloring(algorithm="MILP")]