Dépôt du be graphe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractInputData.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package org.insa.graphs.algorithm;
  2. import org.insa.graphs.model.Arc;
  3. import org.insa.graphs.model.Graph;
  4. import org.insa.graphs.model.GraphStatistics;
  5. /**
  6. * Base class for algorithm input data classes. This class contains the basic
  7. * data that are required by most graph algorithms, i.e. a graph, a mode (time /
  8. * length) and a filter for the arc.
  9. *
  10. */
  11. public abstract class AbstractInputData {
  12. /**
  13. * Enum specifying the top mode of the algorithms.
  14. *
  15. * @see ArcInspector
  16. */
  17. public enum Mode {
  18. TIME, LENGTH
  19. }
  20. // Graph
  21. private final Graph graph;
  22. // Arc filter.
  23. protected final ArcInspector arcInspector;
  24. /**
  25. * Create a new AbstractInputData instance for the given graph, mode and filter.
  26. *
  27. * @param graph Graph for this input data.
  28. * @param arcInspector Arc inspector for this input data.
  29. */
  30. protected AbstractInputData(Graph graph, ArcInspector arcInspector) {
  31. this.graph = graph;
  32. this.arcInspector = arcInspector;
  33. }
  34. /**
  35. * @return Graph associated with this input.
  36. */
  37. public Graph getGraph() {
  38. return graph;
  39. }
  40. /**
  41. * Retrieve the cost associated with the given arc according to the underlying
  42. * arc inspector.
  43. *
  44. * @param arc Arc for which cost should be retrieved.
  45. *
  46. * @return Cost for the given arc.
  47. *
  48. * @see ArcInspector
  49. */
  50. public double getCost(Arc arc) {
  51. return this.arcInspector.getCost(arc);
  52. }
  53. /**
  54. * @return Mode associated with this input data.
  55. *
  56. * @see Mode
  57. */
  58. public Mode getMode() {
  59. return this.arcInspector.getMode();
  60. }
  61. /**
  62. * Retrieve the maximum speed associated with this input data, or
  63. * {@link GraphStatistics#NO_MAXIMUM_SPEED} if none is associated. The maximum
  64. * speed associated with input data is different from the maximum speed
  65. * associated with graph (accessible via {@link Graph#getGraphInformation()}).
  66. *
  67. * @return The maximum speed for this inspector, or
  68. * {@link GraphStatistics#NO_MAXIMUM_SPEED} if none is set.
  69. */
  70. public int getMaximumSpeed() {
  71. return this.arcInspector.getMaximumSpeed();
  72. }
  73. /**
  74. * Check if the given arc is allowed for the filter corresponding to this input.
  75. *
  76. * @param arc Arc to check.
  77. *
  78. * @return true if the given arc is allowed.
  79. *
  80. * @see ArcInspector
  81. */
  82. public boolean isAllowed(Arc arc) {
  83. return this.arcInspector.isAllowed(arc);
  84. }
  85. }