Ticket #12945: trac_12945-balaban-11-cage.2.patch
File trac_12945-balaban-11-cage.2.patch, 6.4 KB (added by , 9 years ago) |
---|
-
sage/graphs/graph_generators.py
# HG changeset patch # User Keshav Kini <keshav.kini@gmail.com> # Date 1336988063 -28800 # Node ID ab2253063e2cd8af58fb3f7f535fc60b617bca1c # Parent 267492bb09f3afab1a62479bb5a15874a5287eca Add some doctests, minor fixes diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
a b 2333 2333 # Named Graphs 2334 2334 ####################################################################### 2335 2335 2336 def Balaban10Cage(self, embedding =1):2336 def Balaban10Cage(self, embedding=1): 2337 2337 r""" 2338 2338 Returns the Balaban 10-cage. 2339 2339 … … 2344 2344 The default embedding gives a deeper understanding of the 2345 2345 graph's automorphism group. It is divided into 4 layers (each 2346 2346 layer being a set of points at equal distance from the drawing's 2347 center). From outside to inside 2348 2349 - L1 2347 center). From outside to inside: 2348 2349 - L1: The outer layer (vertices which are the furthest from the 2350 2350 origin) is actually the disjoint union of two cycles of length 2351 2351 10. 2352 2352 2353 - L2 2354 2355 - L3 2356 2357 - L4 2353 - L2: The second layer is an independent set of 20 vertices. 2354 2355 - L3: The third layer is a matching on 10 vertices. 2356 2357 - L4: The inner layer (vertices which are the closest from the 2358 2358 origin) is also the disjoint union of two cycles of length 10. 2359 2359 2360 2360 This graph is not vertex-transitive, and its vertices are 2361 partitioned into 3 orbits 2361 partitioned into 3 orbits: L2, L3, and the union of L1 of L4 2362 2362 whose elements are equivalent. 2363 2363 2364 2364 INPUT: … … 2366 2366 - ``embedding`` -- two embeddings are available, and can be 2367 2367 selected by setting ``embedding`` to be either 1 or 2. 2368 2368 2369 EXAMPLE:: 2370 2371 sage: g = graphs.Balaban10Cage() 2372 sage: g.girth() 2373 10 2374 sage: g.chromatic_number() 2375 2 2376 sage: g.diameter() 2377 6 2378 sage: g.is_hamiltonian() 2379 True 2380 sage: g.show(figsize=[10,10]) 2369 EXAMPLES:: 2370 2371 sage: g = graphs.Balaban10Cage() 2372 sage: g.girth() 2373 10 2374 sage: g.chromatic_number() 2375 2 2376 sage: g.diameter() 2377 6 2378 sage: g.is_hamiltonian() 2379 True 2380 sage: g.show(figsize=[10,10]) 2381 2382 TESTS:: 2383 2384 sage: graphs.Balaban10Cage(embedding='foo') 2385 Traceback (most recent call last): 2386 ... 2387 ValueError: The value of embedding must be 1 or 2. 2381 2388 """ 2382 2389 2383 2390 L = [-9, -25, -19, 29, 13, 35, -13, -29, 19, 25, 9, -29, 29, 17, 33, … … 2392 2399 if embedding == 2: 2393 2400 return g 2394 2401 elif embedding != 1: 2395 raise ValueError("The value of embedding must be either 1 or 2")2402 raise ValueError("The value of embedding must be 1 or 2.") 2396 2403 2397 2404 L3 = [5, 24, 35, 46, 29, 40, 51, 34, 45, 56] 2398 2405 _circle_embedding(g, L3, center=(0,0), radius = 4.3) … … 2428 2435 selected by setting ``embedding`` to be 1, 2, or 3. 2429 2436 2430 2437 - The first embedding is the one appearing on page 9 of the 2431 Fifth Annual Graph Drawing Contest report [FAGDC]_. 2438 Fifth Annual Graph Drawing Contest report [FAGDC]_. It 2439 separates vertices based on their eccentricity (see 2440 :meth:`eccentricity() 2441 <sage.graphs.generic_graph.GenericGraph.eccentricity>`). 2432 2442 2433 2443 - The second embedding has been produced just for Sage and is 2434 2444 meant to emphasize the automorphism group's 6 orbits. … … 2459 2469 2460 2470 Our many embeddings:: 2461 2471 2462 sage: graphs.Balaban11Cage(embedding=1).show(figsize=[10,10]) 2463 sage: graphs.Balaban11Cage(embedding=2).show(figsize=[10,10]) 2464 sage: graphs.Balaban11Cage(embedding=3).show(figsize=[10,10]) 2472 sage: g1 = graphs.Balaban11Cage(embedding=1) 2473 sage: g2 = graphs.Balaban11Cage(embedding=2) 2474 sage: g3 = graphs.Balaban11Cage(embedding=3) 2475 sage: g1.show(figsize=[10,10]) 2476 sage: g2.show(figsize=[10,10]) 2477 sage: g3.show(figsize=[10,10]) 2478 2479 Proof that the embeddings are the same graph:: 2480 2481 sage: g1.is_isomorphic(g2) # g2 and g3 are obviously isomorphic 2482 True 2483 2484 TESTS:: 2485 2486 sage: graphs.Balaban11Cage(embedding='xyzzy') 2487 Traceback (most recent call last): 2488 ... 2489 ValueError: The value of embedding must be 1, 2, or 3. 2465 2490 2466 2491 REFERENCES: 2467 2492 2468 2493 .. [FAGDC] Fifth Annual Graph Drawing Contest 2469 P. Eaded, J. Marks, P.Mutzel, S. North2470 http://www.merl.com/papers/docs/TR98-16.pdf2494 P. Eaded, J. Marks, P.Mutzel, S. North 2495 http://www.merl.com/papers/docs/TR98-16.pdf 2471 2496 """ 2472 2497 if embedding == 1: 2473 2498 pos_dict = {} … … 2565 2590 v2 = [88, 3, 19, 55, 67, 42, 101, 33, 77, 5, 17, 57, 69, 71, 73, 2566 2591 75, 11, 61, 28, 9, 37, 26, 46, 95, 13, 63, 81, 83, 108, 106, 2567 2592 48, 97] 2568 l1 = [35, 93, 1, 24, 53, 7, 44, 59, 15, 65, 79, 21, 110, 90, 50, 99] 2569 l2 = [87, 4, 18, 56, 68, 41, 102, 32, 12, 62, 29, 84, 38, 105, 47, 96] 2593 l1 = [35, 93, 1, 24, 53, 7, 44, 59, 15, 65, 79, 21, 110, 90, 50, 2594 99] 2595 l2 = [87, 4, 18, 56, 68, 41, 102, 32, 12, 62, 29, 84, 38, 105, 47, 2596 96] 2570 2597 2571 2598 d = g.get_pos() 2572 2599 for i,v in enumerate(v1): … … 2590 2617 return g 2591 2618 2592 2619 else: 2593 raise ValueError("The value of embedding must be either 1 or 2")2620 raise ValueError("The value of embedding must be 1, 2, or 3.") 2594 2621 2595 2622 def BidiakisCube(self): 2596 2623 r""" … … 7649 7676 # Helper functions # 7650 7677 #################### 7651 7678 7652 def _circle_embedding(g, vertices, center = (0,0), radius = 1, shift =0):7679 def _circle_embedding(g, vertices, center=(0, 0), radius=1, shift=0): 7653 7680 r""" 7654 7681 Set some vertices on a circle in the embedding of a graph G. 7655 7682