No Description
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.

AbstractSolution.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package org.insa.graphs.algorithm;
  2. import java.time.Duration;
  3. /**
  4. * Base class for solution classes returned by the algorithm. This class
  5. * contains the basic information that any solution should have: status of the
  6. * solution (unknown, infeasible, etc.), solving time and the original input
  7. * data.
  8. */
  9. public abstract class AbstractSolution {
  10. /**
  11. * Possible status for a solution.
  12. *
  13. */
  14. public enum Status {
  15. UNKNOWN, INFEASIBLE, FEASIBLE, OPTIMAL,
  16. };
  17. // Status of the solution.
  18. private final Status status;
  19. // Solving time for the solution.
  20. private Duration solvingTime;
  21. // Original input of the solution.
  22. private final AbstractInputData data;
  23. /**
  24. * Create a new abstract solution with unknown status.
  25. *
  26. * @param data
  27. */
  28. protected AbstractSolution(AbstractInputData data) {
  29. this.data = data;
  30. this.solvingTime = Duration.ZERO;
  31. this.status = Status.UNKNOWN;
  32. }
  33. /**
  34. *
  35. * @param data
  36. * @param status
  37. */
  38. protected AbstractSolution(AbstractInputData data, Status status) {
  39. this.data = data;
  40. this.status = status;
  41. }
  42. /**
  43. * @return Original input for this solution.
  44. */
  45. public AbstractInputData getInputData() {
  46. return data;
  47. }
  48. /**
  49. * @return Status of this solution.
  50. */
  51. public Status getStatus() {
  52. return status;
  53. }
  54. /**
  55. * @return Solving time of this solution.
  56. */
  57. public Duration getSolvingTime() {
  58. return solvingTime;
  59. }
  60. /**
  61. * Set the solving time of this solution.
  62. *
  63. * @param solvingTime Solving time for the solution.
  64. */
  65. protected void setSolvingTime(Duration solvingTime) {
  66. this.solvingTime = solvingTime;
  67. }
  68. /**
  69. * @return true if the solution is feasible or optimal.
  70. */
  71. public boolean isFeasible() {
  72. return status == Status.FEASIBLE || status == Status.OPTIMAL;
  73. }
  74. }