SubNet.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package classes;
  2. import java.util.ArrayList;
  3. /**
  4. * The class "subNet" represents ....
  5. *
  6. * @author Gruppe14
  7. *
  8. */
  9. public class SubNet {
  10. private ArrayList<HolonObject> subNetObjects;
  11. private ArrayList<CpsEdge> subNetEdges;
  12. private ArrayList<HolonSwitch> subNetSwitches;
  13. private ArrayList<HolonBattery> subNetBatteries;
  14. //for genetic Algorithm. The spare energy which is used by nobody
  15. public float spareProduction = 0;
  16. /**
  17. * Constructor for a Subnet.
  18. *
  19. * @param objects
  20. * Objects in the Subnet
  21. * @param edges
  22. * Edges in the Subnet
  23. * @param switches
  24. * Switches in the Subnet
  25. */
  26. public SubNet(ArrayList<HolonObject> objects, ArrayList<CpsEdge> edges, ArrayList<HolonSwitch> switches, ArrayList<HolonBattery> batteries) {
  27. subNetObjects = objects;
  28. subNetEdges = edges;
  29. subNetSwitches = switches;
  30. subNetBatteries = batteries;
  31. }
  32. /**
  33. * Return all Objects in the Subnet.
  34. *
  35. * @return all Objects in the Subnet
  36. */
  37. public ArrayList<HolonObject> getObjects() {
  38. return subNetObjects;
  39. }
  40. /**
  41. * Return all Edges in the Subnet.
  42. *
  43. * @return all Edges in the Subnet
  44. */
  45. public ArrayList<CpsEdge> getEdges() {
  46. return subNetEdges;
  47. }
  48. /**
  49. * Return all Switches in the Subnet.
  50. *
  51. * @return all Switches in the Subnet
  52. */
  53. public ArrayList<HolonSwitch> getSwitches() {
  54. return subNetSwitches;
  55. }
  56. public ArrayList<HolonBattery> getBatteries() {
  57. return subNetBatteries;
  58. }
  59. public String toString(int timeStep) {
  60. StringBuilder sb = new StringBuilder();
  61. sb.append(" Objects:");
  62. for (int j = 0; j < getObjects().size(); j++) {
  63. HolonObject hl = getObjects().get(j);
  64. sb.append(" " + hl.getName() + " " + hl.getId());
  65. }
  66. sb.append(" Edges:");
  67. for (int j = 0; j < getEdges().size(); j++) {
  68. CpsEdge edge = getEdges().get(j);
  69. sb.append(" " + edge.getA().getName() + " connected To " + edge.getB().getName());
  70. }
  71. sb.append(" Switches:");
  72. for (int j = 0; j < getSwitches().size(); j++) {
  73. HolonSwitch sw = getSwitches().get(j);
  74. sb.append(" " + sw.getName() + " " + sw.getId() + " State:" + sw.getState(timeStep));
  75. }
  76. return sb.toString();
  77. }
  78. public String toString() {
  79. StringBuilder sb = new StringBuilder();
  80. sb.append("\nObjects:");
  81. for (HolonObject hl: getObjects()) {
  82. sb.append(" " + hl.getName() + "[ID:" + hl.getId()+ "]");
  83. }
  84. sb.append("\nEdges:");
  85. for (CpsEdge edge :getEdges()) {
  86. sb.append(" " + edge.getA().getName() + " connected To " + edge.getB().getName());
  87. }
  88. sb.append("\nSwitches:");
  89. for (HolonSwitch sw : getSwitches()) {
  90. sb.append(" " + sw.getName() + "[ID:" + sw.getId()+ "]" + " State:" + sw.getValueArray());//TODO: I don't like this
  91. }
  92. sb.append("\nBatteries:");
  93. for (HolonBattery hB: getBatteries()) {
  94. sb.append(" " + hB.getName() + "[ID:" + hB.getId()+ "]");
  95. }
  96. return sb.toString();
  97. }
  98. }