if new_x < curr_x - 1: not_in_inertia.update([(i, curr_y) for i in range(new_x + 1, curr_x)]) not_in_inertia.update([(curr_y, i) for i in range(new_x + 1, curr_x)]) curr_x, curr_y = new_x, new_y return not_in_inertia def Zplus(G): return Z_pythonBitset(G, q=0) from sage.all import Graph, graphs G = Graph() G.add_edges([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [1, 4], [2, 5], [3, 6], [7, 1], [7, 2], [7, 3]]) G2 = graphs.CompleteGraph(4) G2.subdivide_edges(G2.edges(), 1) from sage.all import points def plot_inertia_lower_bound(g): return points(list(Zq_inertia_lower_bound(g)), pointsize=40, gridlines=True, ticks=[range(g.order()), range(g.order())], aspect_ratio=1)
def edge_graph(self): G = Graph() G.add_edges([[v.index for v in e.vertices] for e in self.edges]) return G
def XXXrunTest(self): g = Graph() g.add_edges([(1, 3), (5, 6), (3, 5), (1, 6), (1, 5), (3, 6)]) l = OrientedRotationSystem.from_graph(g) self.assertItemsEqual(l[0].vertices(), [1, 3, 5, 6])
Zqhat_recurse(G, q, FrozenBitset([], capacity=n), FrozenBitset([], capacity=n), BEST_LOWER_BOUND=BEST_LOWER_BOUND, BEST_LOOPS=BEST_LOOPS, CACHE=set(), G_info=G_info) if return_loops: return BEST_LOWER_BOUND[0], BEST_LOOPS else: return BEST_LOWER_BOUND[0] def Zq_compute(G,q): return Zq_bitset(G,q,push_zeros=push_zeros) def Zplus(G): return Zq_compute(G,0) from sage.all import Graph, graphs G=Graph() G.add_edges([[1,2],[2,3],[3,4],[4,5],[5,6],[6,1],[1,4],[2,5],[3,6],[7,1],[7,2],[7,3]]) G2=graphs.CompleteGraph(4) G2.subdivide_edges(G2.edges(),1) def check_trees(start,end): for i in range(start,end): print "working on %s vertices"%i list(check_tree(list(graphs.trees(i)))) @parallel def check_tree(g): if not inertia_set(g,f)==Zq_inertia_lower_bound(g): if not inertia_set(g,f)==Zq_inertia_lower_bound(g, zero_forcing_function=Zqhat): print '\n%s'%g.graph6_string()
def height_function(self, vertex_edge_collisions, extra_layers=0, edge_edge_collisions=[]): r""" Return a height function of edges if possible for given vertex-edge collisions. WARNING: Costly, since it runs through all edge-colorings. """ def e2s(e): return Set(e) for v in vertex_edge_collisions: vertex_edge_collisions[v] = Set([e2s(e) for e in vertex_edge_collisions[v]]) collision_graph = Graph([[e2s(e) for e in self._graph.edges(labels=False)],[]],format='vertices_and_edges') for u in self._graph.vertices(): collision_graph.add_edges([[e2s([u,v]),e2s([u,w]),''] for v,w in Subsets(self._graph.neighbors(u),2)]) for e in collision_graph.vertices(): for v in vertex_edge_collisions: if v in e: for f in vertex_edge_collisions[v]: collision_graph.add_edge([e2s(f), e2s(e), 'col']) for e, f in edge_edge_collisions: collision_graph.add_edge([e2s(f), e2s(e), 'e-e_col']) from sage.graphs.graph_coloring import all_graph_colorings optimal = False chrom_number = collision_graph.chromatic_number() for j in range(0, extra_layers + 1): i = 1 res = [] num_layers = chrom_number + j min_s = len(self._graph.vertices())*num_layers for col in all_graph_colorings(collision_graph,num_layers): if len(Set(col.keys()))<num_layers: continue layers = {} for h in col: layers[h] = [u for e in col[h] for u in e] col_free = True A = [] for v in vertex_edge_collisions: A_min_v = min([h for h in layers if v in layers[h]]) A_max_v = max([h for h in layers if v in layers[h]]) A.append([A_min_v, A_max_v]) for h in range(A_min_v+1,A_max_v): if v not in layers[h]: if len(Set(col[h]).intersection(vertex_edge_collisions[v]))>0: col_free = False break if not col_free: break if col_free: s = 0 for v in self._graph.vertices(): A_min_v = min([h for h in layers if v in layers[h]]) A_max_v = max([h for h in layers if v in layers[h]]) s += A_max_v - A_min_v if s<min_s: min_s = s res.append((col, s, A)) i += 1 if s==2*len(self._graph.edges())-len(self._graph.vertices()): optimal = True break if optimal: break if not res: return None vertex_coloring = min(res, key = lambda t: t[1])[0] h = {} for layer in vertex_coloring: for e in vertex_coloring[layer]: h[e] = layer return h