StorageElement.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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:
  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. public float setStatusAndSetEnergy(Mode status, float energyWanted) {
  52. this.status = status;
  53. switch (status) {
  54. case STANDBY:
  55. this.setEnergyPerElement(0);
  56. return 0;
  57. case EMIT:
  58. if (energyWanted >= maxOutRatio) { // more energy wanted than can be giving
  59. if (stateOfCharge >= maxOutRatio) { // more energy wanted than can be given
  60. this.setEnergyPerElement(maxOutRatio);
  61. return maxOutRatio;
  62. } else { // less energy stored that can be given
  63. return notEnoughChargedToEmitWantedEnergy();
  64. }
  65. } else {// not enough energy stored than what can be given
  66. if (stateOfCharge >= energyWanted) { // more energy stored than wanted
  67. this.setEnergyPerElement(energyWanted);
  68. return energyWanted;
  69. } else { // less energy stored than wanted
  70. return notEnoughChargedToEmitWantedEnergy();
  71. }
  72. }
  73. case COLLECT:
  74. if (energyWanted >= maxInRatio) { // more engery given than can be collected
  75. if (stateOfCharge + maxInRatio > capacity) { // Storage nearly full only load rest to get full
  76. this.setEnergyPerElement(-(capacity - stateOfCharge));
  77. // stateOfCharge = capacity;
  78. return capacity - stateOfCharge;
  79. } else { // load with maximal of what can be collected
  80. this.setEnergyPerElement(-maxInRatio);
  81. // stateOfCharge = stateOfCharge + maxInRatio;
  82. return maxInRatio;
  83. }
  84. } else { // less engery given than can be taken in
  85. if (capacity == stateOfCharge) { // storage full no energy collected
  86. this.status = Mode.STANDBY;
  87. return 0;
  88. } else {
  89. if (stateOfCharge + energyWanted > capacity) { // Storage nearly full only load rest to get full
  90. this.setEnergyPerElement(-(capacity - stateOfCharge));
  91. // stateOfCharge = capacity;
  92. return capacity - stateOfCharge;
  93. } else { // take all engery that is available
  94. this.setEnergyPerElement(-energyWanted);
  95. // stateOfCharge = stateOfCharge + energy;
  96. return energyWanted;
  97. }
  98. }
  99. }
  100. default:
  101. System.out.println("no status available");
  102. return 0;
  103. }
  104. }
  105. public Mode getStatus() {
  106. return this.status;
  107. }
  108. public void chargeCalc(){
  109. System.out.println("stateofcharge" + getId()+ "before:" + stateOfCharge + " with incomming " + status + " " + getEnergyPerElement() );
  110. switch (status){
  111. case COLLECT:
  112. stateOfCharge = stateOfCharge - getEnergyPerElement();
  113. break;
  114. case EMIT:
  115. stateOfCharge = stateOfCharge - getEnergyPerElement();
  116. break;
  117. default:
  118. }
  119. if(stateOfCharge <= 0 || stateOfCharge >= capacity){
  120. status = Mode.STANDBY;
  121. setEnergyPerElement(0);
  122. }
  123. System.out.println("stateofcharge after:" + stateOfCharge + " now as " + status + " " + getEnergyPerElement() );
  124. }
  125. public void setStateOfCharge(float stateOfCharge){
  126. if(stateOfCharge < capacity){
  127. this.stateOfCharge = stateOfCharge;
  128. }else{
  129. this.stateOfCharge = capacity;
  130. }
  131. }
  132. private float notEnoughChargedToEmitWantedEnergy(){
  133. if(stateOfCharge <= 0){
  134. this.status = Mode.STANDBY;
  135. this.setEnergyPerElement(0);
  136. return 0;
  137. }else{
  138. this.setEnergyPerElement(stateOfCharge);
  139. return stateOfCharge;
  140. }
  141. }
  142. public enum Mode {
  143. COLLECT, EMIT, STANDBY
  144. }
  145. }