DecoratedGroupNode.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package ui.model;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.stream.Collector;
  5. import java.util.stream.Collectors;
  6. import classes.CpsNode;
  7. import classes.CpsUpperNode;
  8. import classes.IntermediateCalculationCable;
  9. import ui.model.DecoratedHolonObject.HolonObjectState;
  10. import classes.ExitCable;
  11. /**
  12. * For the @VisualRepresentationalState only.
  13. * @author Tom
  14. *
  15. */
  16. public class DecoratedGroupNode {
  17. private CpsUpperNode model;
  18. private ArrayList<Supplier> supplierList;
  19. private ArrayList<Passiv> passivList;
  20. private ArrayList<Consumer> consumerList;
  21. private ArrayList<CpsNode> nodeList;
  22. /**
  23. * Cables that only exist on that group node. From a object in that group node to a object in that group Node.
  24. * Not exit the group node (a layer down).
  25. */
  26. private ArrayList<DecoratedCable> internCableList;
  27. /**
  28. * Cables that exit this group node (a Layer Up). From a object in this group node to a object in a upper layer.
  29. */
  30. private ArrayList<ExitCable> exitCableList;
  31. private ArrayList<DecoratedSwitch> switchList;
  32. private ArrayList<DecoratedGroupNode> groupNodeList;
  33. public DecoratedGroupNode(CpsUpperNode model) {
  34. this.model = model;
  35. this.supplierList = new ArrayList<Supplier>();
  36. this.passivList = new ArrayList<Passiv>();
  37. this.consumerList = new ArrayList<Consumer>();
  38. this.nodeList = new ArrayList<CpsNode>();
  39. this.internCableList = new ArrayList<DecoratedCable>();
  40. this.exitCableList = new ArrayList<ExitCable>();
  41. this.switchList = new ArrayList<DecoratedSwitch>();
  42. this.groupNodeList = new ArrayList<DecoratedGroupNode>();
  43. }
  44. public CpsUpperNode getModel() {
  45. return model;
  46. }
  47. public ArrayList<Supplier> getSupplierList() {
  48. return supplierList;
  49. }
  50. public ArrayList<Passiv> getPassivList() {
  51. return passivList;
  52. }
  53. public ArrayList<Consumer> getConsumerList() {
  54. return consumerList;
  55. }
  56. public ArrayList<CpsNode> getNodeList() {
  57. return nodeList;
  58. }
  59. public ArrayList<DecoratedCable> getInternCableList() {
  60. return internCableList;
  61. }
  62. public ArrayList<ExitCable> getExitCableList() {
  63. return exitCableList;
  64. }
  65. public ArrayList<DecoratedSwitch> getSwitchList() {
  66. return switchList;
  67. }
  68. public ArrayList<DecoratedGroupNode> getGroupNodeList() {
  69. return groupNodeList;
  70. }
  71. //Returns the amount of holons and count himself
  72. public int getAmountOfHolons() {
  73. return 1 + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfHolons()).reduce(0, Integer::sum);
  74. }
  75. //Gather Informations:
  76. public int getAmountOfSupplier() {
  77. return supplierList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfSupplier()).reduce(0, Integer::sum);
  78. }
  79. public int getAmountOfConsumer() {
  80. return consumerList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumer()).reduce(0,Integer::sum);
  81. }
  82. public int getAmountOfPassiv() {
  83. return passivList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfPassiv()).reduce(0, Integer::sum);
  84. }
  85. public int getAmountOfConsumerWithState(HolonObjectState state) {
  86. return ((int) consumerList.stream().map(con -> con.getState()).filter(rightState -> (rightState == state)).count()) + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(state)).reduce(0, Integer::sum);
  87. }
  88. public int getAmountOfElemntsFromHolonObjects() {
  89. return passivList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
  90. supplierList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
  91. consumerList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
  92. groupNodeList.stream().map(groupNode -> groupNode.getAmountOfElemntsFromHolonObjects()).reduce(0, Integer::sum);
  93. }
  94. public int getAmountOfAktiveElemntsFromHolonObjects() {
  95. return passivList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
  96. supplierList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
  97. consumerList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
  98. groupNodeList.stream().map(groupNode -> groupNode.getAmountOfAktiveElemntsFromHolonObjects()).reduce(0, Integer::sum);
  99. }
  100. public float getConsumptionFromConsumer() {
  101. return consumerList.stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.f, Float::sum)+
  102. groupNodeList.stream().map(groupNode -> groupNode.getConsumptionFromConsumer()).reduce(0.f, Float::sum);
  103. }
  104. public float getProductionFromSupplier() {
  105. return supplierList.stream().map(sup -> sup.getEnergyToSupplyNetwork()).reduce(0.f, Float::sum)+
  106. groupNodeList.stream().map(groupNode -> groupNode.getProductionFromSupplier()).reduce(0.f, Float::sum);
  107. }
  108. public float getAverageConsumption() {
  109. return getConsumptionFromConsumer() / (float)getAmountOfHolons();
  110. }
  111. public float getAverageProduction() {
  112. return getProductionFromSupplier() / (float)getAmountOfHolons();
  113. }
  114. public String toString() {
  115. return
  116. "GroupNode" + model.getId() + " with [Supplier:" + getAmountOfSupplier()
  117. + ", NotSupplied:" + getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED)
  118. + ", PartiallySupplied:" + getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED)
  119. + ", Supplied:" + getAmountOfConsumerWithState(HolonObjectState.SUPPLIED)
  120. + ", OverSupplied:" + getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED)
  121. + ", Passiv:"+ getAmountOfPassiv() + "]";
  122. }
  123. }