StorageElement.java 4.6 KB

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