University stuff.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import java.util.ArrayList;
  2. class Task {
  3. int id;
  4. int time;
  5. String name;
  6. int manpower;
  7. Task[] deps;
  8. ArrayList<Task> tasksWhichDepend = new ArrayList<>();
  9. boolean timesCalculated = false;
  10. int earliestStart = -1;
  11. int latestStart = -1;
  12. int slack = 0;
  13. int earliestFinished = -1;
  14. int startIndex = -1;
  15. ArrayList<Task> findCycle(ArrayList<Task> seen) {
  16. seen = new ArrayList<Task>(seen);
  17. seen.add(this);
  18. for (Task dep: deps) {
  19. ArrayList<Task> nseen = new ArrayList<Task>(seen);
  20. if (nseen.contains(dep)) {
  21. ArrayList<Task> l = new ArrayList<>();
  22. l.add(dep);
  23. l.add(this);
  24. return l;
  25. }
  26. ArrayList<Task> l = dep.findCycle(seen);
  27. if (l != null) {
  28. l.add(this);
  29. return l;
  30. }
  31. }
  32. return null;
  33. }
  34. ArrayList<Task> findCycle() {
  35. ArrayList<Task> seen = new ArrayList<>();
  36. return findCycle(seen);
  37. }
  38. void calcTimes() {
  39. if (this.timesCalculated)
  40. return;
  41. int firstPossibleStart = 0;
  42. for (Task t: this.deps) {
  43. t.calcTimes();
  44. if (t.earliestFinished > firstPossibleStart)
  45. firstPossibleStart = t.earliestFinished;
  46. }
  47. this.earliestStart = firstPossibleStart;
  48. this.earliestFinished = firstPossibleStart + this.time;
  49. this.timesCalculated = true;
  50. }
  51. void calcLatestStart() {
  52. int biggestPossibleSlack = Integer.MAX_VALUE;
  53. for (Task t: this.tasksWhichDepend) {
  54. int slack = t.earliestStart - (this.earliestStart + this.time);
  55. if (slack < biggestPossibleSlack)
  56. biggestPossibleSlack = slack;
  57. }
  58. if (biggestPossibleSlack == Integer.MAX_VALUE)
  59. this.slack = 0;
  60. else
  61. this.slack = biggestPossibleSlack;
  62. this.latestStart = this.earliestStart + this.slack;
  63. }
  64. public String identify() {
  65. return id+" ("+name+")";
  66. }
  67. }