# SageMathCell online https://sagecell.sagemath.org/?q=hobyjo # P'_11 Graph with 133 vertices and 792 edges, 12 vertices have degree 11 and 121 degree 12 # deg. distrib.: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 121] # diameter: 2 avg. dist.: 1.90977 # Girth: 3 # import networkx as nx P11=Graph(r":~?AD_C?_C??S?_C??s??K?_?H_?D_?B_[A@k@@gM_wL`GL`OL__LACJ@kD@gP_oLASG@gS_WL`GM_wM_oM`_MBKD@sJ@oY`OMB[G@o\_OM_GN_OWCSDAW\CSEAgZCSKAoYCSHA?_COb_wVBGa__PBwa`OQBoaCcJA_[COd_W`COg__N_oNDkHB?XCgl_wTBwbDkCAo\DWl`WOBofDkKAwZD?lESGAG[C_l_gQBOkDgn`OSCGeDgs_W_DOlECH@{D@ww_wWBOcE_w_oRBobEow_OTDOrFCJAo_D?vFCKA?[DGtF?|`GVBgeE?w`?QCGdEOw__SBWkF?y_W^DWpF?z_wN`WNG[GB?ZDOpFpB__RBGeG@B`OTB_kEP@G[AAocDw|GXF_gVBwfEhAGXE`GPCGjExB`_QBgbEWzGXI_wSC?hEo{G[BBodE_~G[DB?[CWmG@K`ORBwgDo|HhM`?TC?eDpAG{AA?jDo~HCEAw`C_mFpI`_PBoiDp@HHP`WQBGhDoyHXO`GSBOfDpD_W\D_mF`EIkK@{I@xV_oWBghEO~GxV`?RBOjEg{HPNIxX_gTBGgEozGhPI{HAo]D_pH`MI{FA?`DOnGPOI{AAwdEwyHHSIx[`WPBWbE_|GpUIx\__QC?fGHLIPVJ[KA_^C_oG@GIhV__WBogFHII@``_RC?dDwxH`R_gUCGhEWxHhTJkGA?^D_sFHJIH[`OVBObEGxGxQJxb_OPCoqFHDHx]_wQB_jE?xIp_K{EA_XDOvFHEJHd_WZCwuFHGI`Y`WWBweDw{G`QK@d`GRBWcEXCI@[LCKAg`CwpFPCHxh`?UBGbE@@G`RJPc`OOBgdEo}G`UJpaLsCAw[DO~G`MJhi_oPC?kEgzG``Kxo_OQD?sGPCIhXK[BBOhEx?G`PJXeLcIB?_DWrFPEIHWK`p`WRCGkE?~GhSJ@b__TBOdFhJIhWKho_oUB_fE_{HHWKPrMkDA?ZCovGHIHpWMSGAw]DGnFXGIpWL@lNCFAG\D?pG@RJ@iL[AA_bEg}HhOJ@hL`y_WXC_qGPKIPWKxmMs@B?`Eo|HHRJHgL`u_GRB_vFXFIh]K`jNS@Ag]E?}GpQJ`iMPs_GUBwqFPIIpZKXoN[@A?XEG{HhSKHeMHwNk@AGYEXAH@MK@hLxt_GQBWtFxKIH^KPlN`}_GSBgnGHJHx\KxrMx~") P11nx = P11.networkx_graph() # List of graphs to process graphs = [('P11 ', P11 )] def count_k_cycles(G, k): count = 0 visited = set() def dfs(path, start, depth): nonlocal count current = path[-1] # Early exit if we?re going too deep if depth == k: if start in G.neighbors(current): # Normalize to avoid duplicates cycle = tuple(sorted(path)) if cycle not in visited: visited.add(cycle) count += 1 return for neighbor in G.neighbors(current): if neighbor not in path and neighbor >= start: dfs(path + [neighbor], start, depth + 1) for v in G.vertices(): dfs([v], v, 1) return count # each cycle counted twice (once forward, once reverse) def algebraic_connectivity(G): """ Compute the algebraic connectivity (Fiedler value) of a graph G. INPUT: - G: a SageMath Graph OUTPUT: - The second-smallest eigenvalue of the Laplacian matrix of G """ L = G.laplacian_matrix() eigenvalues = L.eigenvalues() eigenvalues.sort() if len(eigenvalues) < 2: return 0 # Trivial case: empty or isolated vertex graph return eigenvalues[1] def domination_number(G): """ Compute the domination number of a graph G using MILP. INPUT: - G: a SageMath Graph OUTPUT: - The domination number (integer) """ p = MixedIntegerLinearProgram(maximization=False) x = p.new_variable(binary=True) # Objective: minimize the number of chosen vertices p.set_objective(sum(x[v] for v in G.vertices())) # Constraint: each vertex is dominated for v in G.vertices(): p.add_constraint(x[v] + sum(x[u] for u in G.neighbors(v)) >= 1) return p.solve() # Print properties for each graph in the list print("\n Main properties of the graph\n") for label, graph in graphs: print(f"{label} | Ord.: {graph.order()} / Size: {graph.size()} " f" / Diam.: {graph.diameter()} / Avg.dist: {graph.average_distance().n(digits=6)} \n" f" / 10-reg.? {graph.is_regular(k=10)} / Degree histogram: {nx.degree_histogram(P11nx)} / Girth: {graph.girth()}\n " f" / Alg.conn. {algebraic_connectivity(graph).n(digits=6)} / Domin. number: {domination_number(graph)} ") print("\n Symmetry properties of the graph\n") for label, graph in graphs: print(f"{label} | Aut.group.ord.: {graph.automorphism_group().order()} / Cayley ? {graph.is_cayley()} --- vtx.trans. ? {graph.is_vertex_transitive()} -- edge.trans. ? {graph.is_edge_transitive()}" ) # Compute the distance distribution from a given vertex v in graph G # Returns a list where the i-th element is the number of vertices at distance i from v def distance_distribution(G, v): from collections import Counter distances = G.shortest_path_lengths(v) distribution = Counter(distances.values()) result = [distribution[d] for d in sorted(distribution)] return result print("\n") for label, graph in graphs: print(f"{label} distance distrib from vtx. 0: {distance_distribution(graph, 0)}") # Counting k-cycles for each graph print("\nNumber of k-cycles for k=3 up to 5") for label, graph in graphs: print(f"{label} ", " ".join(str(count_k_cycles(graph, k)) for k in range(3, 6))) print("\n") ##