PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/ComputerAlgebra/Graphs/Lisp/docus/Tutorial.hpp

https://github.com/RWang/oklibrary
C++ Header | 84 lines | 0 code | 2 blank | 82 comment | 0 complexity | 9118d0ece3500c5728a493236c52e563 MD5 | raw file
  1. // Oliver Kullmann, 23.1.2008 (Swansea)
  2. /* Copyright 2008 Oliver Kullmann
  3. This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
  4. it and/or modify it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation and included in this library; either version 3 of the
  6. License, or any later version. */
  7. /*!
  8. \file ComputerAlgebra/Graphs/Lisp/docus/Tutorial.hpp
  9. \brief Tutorial on graphs in Maxima/Lisp by MH
  10. <h1> %Graphs via Maxima in the OKlibrary </h1>
  11. <ol>
  12. <li> For the OKlibrary, a graph is a simply a 2-element list. The first
  13. element is a set of vertices and the second is a set of 2-element vertex
  14. sets.
  15. \verbatim
  16. (%i3) g:[{1,2,3},{{1,2},{1,3}}];
  17. (%o3) [{1, 2, 3}, {{1, 2}, {1, 3}}]
  18. \endverbatim
  19. </li>
  20. <li> Basic graph operations are available in the OKlibrary.
  21. <ol>
  22. <li> For instance, to find the neighbourhood of a vertex in a graph:
  23. \verbatim
  24. (%i4) neighbours(1,g);
  25. (%o4) {2, 3}
  26. \endverbatim
  27. </li>
  28. <li> Or, to remove a vertex from a graph:
  29. \verbatim
  30. (%i5) remove_vertices_graph({2},g);
  31. (%o5) [{1, 3}, {{1, 3}}]
  32. (%i6) g;
  33. (%o6) [{1, 2, 3}, {{1, 2}, {1, 3}}]
  34. \endverbatim
  35. </li>
  36. </ol>
  37. </li>
  38. <li> For most real work we can exploit the Maxima graph library by converting
  39. a 2-element list graph to a Maxima graph using the g2mg function.
  40. \verbatim
  41. (%i7) mg:g2mg(g);
  42. (%o7) GRAPH
  43. (%i8) chromatic_number(mg);
  44. (%o8) 2
  45. \endverbatim
  46. </li>
  47. <li> We can also do the reverse, and convert a Maxima graph into a 2-element
  48. list graph using the mg2g function.
  49. \verbatim
  50. (%i9) mg2g(mg);
  51. (%o9) [{1, 2, 3}, {{1, 2}, {1, 3}}]
  52. \endverbatim
  53. </li>
  54. <li> There are many graph generators available in the Maxima graph library.
  55. </li>
  56. <li> The OKlibrary provides additional generators. For example,
  57. Kneser graphs - graphs where vertices are the m-element subets of {1,..,n} and
  58. edges join disjoint vertices. For example the Peterson-graph:
  59. \verbatim
  60. (%i10) k:g2mg(kneser_g(5,2))$
  61. (%i11) print_graph(k)$
  62. Graph on 10 vertices with 15 edges.
  63. Adjacencies:
  64. 10 : 5 2 1
  65. 9 : 6 3 1
  66. 8 : 7 4 1
  67. 7 : 8 3 2
  68. 6 : 9 4 2
  69. 5 : 10 4 3
  70. 4 : 8 6 5
  71. 3 : 9 7 5
  72. 2 : 10 7 6
  73. 1 : 10 9 8
  74. \endverbatim
  75. </li>
  76. </ol>
  77. */