Graph.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package com.example.data_structure.domain;
  2. import java.util.ArrayList;
  3. public class Graph {
  4. private boolean isDirected; //是否有向
  5. private boolean isWeighted; //是否带权
  6. private int nodeNum; //结点数
  7. private int edgeNum;//边数
  8. private ArrayList<String> nodeList; //各结点名称
  9. private ArrayList<ArrayList<Boolean>> graph; //图中结点和边的连接关系
  10. private ArrayList<ArrayList<Double>>weight;//各边权重
  11. /**
  12. * 没有权重的图的构造方法
  13. * @param isDirected
  14. * @param nodeNum
  15. * @param edgeNum
  16. * @param nodeList
  17. * @param graph
  18. */
  19. public Graph(boolean isDirected, int nodeNum, int edgeNum, ArrayList<String> nodeList, ArrayList<ArrayList<Boolean>> graph) {
  20. this.isDirected = isDirected;
  21. this.isWeighted=false;
  22. this.nodeNum = nodeNum;
  23. this.edgeNum = edgeNum;
  24. this.nodeList = nodeList;
  25. this.graph = graph;
  26. this.weight=null;
  27. }
  28. /**
  29. * 带权图构造方法
  30. * @param isDirected
  31. * @param isWeighted
  32. * @param nodeNum
  33. * @param edgeNum
  34. * @param nodeList
  35. * @param graph
  36. * @param weight
  37. */
  38. public Graph(boolean isDirected, boolean isWeighted, int nodeNum, int edgeNum, ArrayList<String> nodeList, ArrayList<ArrayList<Boolean>> graph, ArrayList<ArrayList<Double>> weight) {
  39. this.isDirected = isDirected;
  40. this.isWeighted = isWeighted;
  41. this.nodeNum = nodeNum;
  42. this.edgeNum = edgeNum;
  43. this.nodeList = nodeList;
  44. this.graph = graph;
  45. this.weight = weight;
  46. }
  47. /**
  48. * 获取计算最小生成树过程中每一步的结果,返回一个结果列表
  49. * @return
  50. */
  51. public ArrayList<Graph> getMinimalSpanningTree(){
  52. return null;
  53. }
  54. /**
  55. * 获取广度优先遍历的结点遍历顺序
  56. * @return
  57. */
  58. public ArrayList<String> getBreadthFirstTraversal(){
  59. return null;
  60. }
  61. /**
  62. * 获取深度优先遍历的结点遍历顺序
  63. * @return
  64. */
  65. public ArrayList<String> getDepthFirstTraversal(){
  66. return null;
  67. }
  68. /*getter*/
  69. public boolean isDirected() {
  70. return isDirected;
  71. }
  72. public boolean isWeighted() {
  73. return isWeighted;
  74. }
  75. public int getNodeNum() {
  76. return nodeNum;
  77. }
  78. public int getEdgeNum() {
  79. return edgeNum;
  80. }
  81. public ArrayList<String> getNodeList() {
  82. return nodeList;
  83. }
  84. public ArrayList<ArrayList<Boolean>> getGraph() {
  85. return graph;
  86. }
  87. public ArrayList<ArrayList<Double>> getWeight() {
  88. return weight;
  89. }
  90. /*setter*/
  91. public void setDirected(boolean directed) {
  92. isDirected = directed;
  93. }
  94. public void setWeighted(boolean weighted) {
  95. isWeighted = weighted;
  96. }
  97. public void setNodeNum(int nodeNum) {
  98. this.nodeNum = nodeNum;
  99. }
  100. public void setEdgeNum(int edgeNum) {
  101. this.edgeNum = edgeNum;
  102. }
  103. public void setNodeList(ArrayList<String> nodeList) {
  104. this.nodeList = nodeList;
  105. }
  106. public void setGraph(ArrayList<ArrayList<Boolean>> graph) {
  107. this.graph = graph;
  108. }
  109. public void setWeight(ArrayList<ArrayList<Double>> weight) {
  110. this.weight = weight;
  111. }
  112. }