StorageElement.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package algo;
  2. import com.google.gson.annotations.Expose;
  3. import algo.StorageObject.Mode;
  4. import classes.HolonElement;
  5. import ui.model.Model;
  6. public class StorageElement extends HolonElement {
  7. @Expose
  8. private Mode status;
  9. @Expose
  10. private float stateOfCharge;
  11. @Expose
  12. private float capacity;
  13. @Expose
  14. private float maxInRatio;
  15. @Expose
  16. private float maxOutRatio;
  17. public StorageElement(String eleName, int amount, float energy, Model model) {
  18. super(eleName, amount, energy, model);
  19. this.stateOfCharge = 4000;
  20. this.maxInRatio = 5000;
  21. this.maxOutRatio = 5000;
  22. this.capacity = 10000 * 60;// for example tesla power wall 10kwh, 10kw per hour thus * 60 if iteration =
  23. // minutes//TODO:!
  24. this.status = Mode.STANDBY;
  25. }
  26. public float getEnergyPerElement() {
  27. switch (status) {
  28. case STANDBY:
  29. return 0;
  30. default:
  31. return this.energyPerElement;
  32. }
  33. }
  34. public float getPossibleProduction() {
  35. if (stateOfCharge > 0) {
  36. if (stateOfCharge >= maxOutRatio) {
  37. return maxOutRatio;
  38. } else {
  39. return stateOfCharge;
  40. }
  41. } else {
  42. return 0;
  43. }
  44. }
  45. /**
  46. *
  47. * @param status Mode of currect operation
  48. * @param energy float how much energy is needed from storage/ can be collected
  49. * by the storage
  50. * @return float how much energy was collected/emited
  51. */
  52. public float setStatusAndSetEnergy(Mode status, float energy) {
  53. this.status = status;
  54. switch (status) {
  55. case STANDBY:
  56. this.setEnergyPerElement(0);
  57. return 0;
  58. case EMIT:
  59. if (stateOfCharge >= energy) { // enough energy stored than wanted
  60. if (energy >= maxInRatio) { // more energy wanted than can be given
  61. this.setEnergyPerElement(maxOutRatio);
  62. // stateOfCharge = stateOfCharge - maxOutRatio;//TODO: not hear but in simulation manager
  63. return maxOutRatio;
  64. } else { // less energy wanted that can be given
  65. this.setEnergyPerElement(energy);
  66. // stateOfCharge = stateOfCharge - energy;
  67. return energy;
  68. }
  69. } else {// not enough energy stored than wanted
  70. if (stateOfCharge == 0) { // no energy stored at all
  71. this.status = Mode.STANDBY;
  72. return 0;
  73. } else { // emit energy that is available even though is less that wanted
  74. this.setEnergyPerElement(stateOfCharge);
  75. // stateOfCharge = 0;
  76. return stateOfCharge;
  77. }
  78. }
  79. case COLLECT:
  80. if (energy >= maxInRatio) { // more engery given than can be collected
  81. if (stateOfCharge + maxInRatio > capacity) { // Storage nearly full only load rest to get full
  82. this.setEnergyPerElement(-(capacity - stateOfCharge));
  83. // stateOfCharge = capacity;
  84. return capacity - stateOfCharge;
  85. } else { // load with maximal of what can be collected
  86. this.setEnergyPerElement(-maxInRatio);
  87. // stateOfCharge = stateOfCharge + maxInRatio;
  88. return maxInRatio;
  89. }
  90. } else { // less engery given than can be taken in
  91. if (capacity == stateOfCharge) { // storage full no energy collected
  92. this.status = Mode.STANDBY;
  93. return 0;
  94. } else {
  95. if (stateOfCharge + energy > capacity) { // Storage nearly full only load rest to get full
  96. this.setEnergyPerElement(-(capacity - stateOfCharge));
  97. // stateOfCharge = capacity;
  98. return capacity - stateOfCharge;
  99. } else { // take all engery that is available
  100. this.setEnergyPerElement(-energy);
  101. // stateOfCharge = stateOfCharge + energy;
  102. return energy;
  103. }
  104. }
  105. }
  106. default:
  107. System.out.println("no status available");
  108. return 0;
  109. }
  110. }
  111. public Mode getStatus() {
  112. return this.status;
  113. }
  114. public void chargeCalc(){
  115. switch (status){
  116. case COLLECT:
  117. stateOfCharge = stateOfCharge - getEnergyPerElement();
  118. break;
  119. case EMIT:
  120. stateOfCharge = stateOfCharge + getEnergyPerElement();
  121. break;
  122. default:
  123. }
  124. if(stateOfCharge <= 0 || stateOfCharge >= capacity){
  125. status = Mode.STANDBY;
  126. setEnergyPerElement(0);
  127. }
  128. }
  129. public void setStateOfCharge(float stateOfCharge){
  130. if(stateOfCharge < capacity){
  131. this.stateOfCharge = stateOfCharge;
  132. }else{
  133. this.stateOfCharge = capacity;
  134. }
  135. }
  136. public enum Mode {
  137. COLLECT, EMIT, STANDBY
  138. }
  139. }