|
@@ -7,7 +7,7 @@ import java.util.LinkedList;
|
|
|
|
|
|
/**
|
|
|
* The class "HolonElement" represents any possible element that can be added to
|
|
|
- * a CpsObject (such as TV (consumer) or any energy source/producer).
|
|
|
+ * a CpsObject (such as TV (consumer) or any energyPerElement source/producer).
|
|
|
*
|
|
|
* @author Gruppe14
|
|
|
*/
|
|
@@ -21,10 +21,10 @@ public class HolonElement {
|
|
|
/* Quantity */
|
|
|
@Expose
|
|
|
private int amount;
|
|
|
- /* Currently used energy (- indicates consuming of energy, + indicates producing energy)*/
|
|
|
+ /* Currently used energy per element (- indicates consumation of energy, + indicates production of energy)*/
|
|
|
@Expose
|
|
|
- private float energy;
|
|
|
- /* Whether the gadget is active or not (currently uses/poduces the energy in energy) */
|
|
|
+ private float energyPerElement;
|
|
|
+ /* Whether the gadget is active or not (currently uses/produces the energy in energyPerElement) */
|
|
|
@Expose
|
|
|
private boolean active;
|
|
|
/*
|
|
@@ -53,13 +53,14 @@ public class HolonElement {
|
|
|
private int id;
|
|
|
/*
|
|
|
* Energy at each point of the graph with 100 predefined points. At the
|
|
|
- * beginning, it starts with all values at energy
|
|
|
+ * beginning, it starts with all values at energyPerElement.
|
|
|
+ * If switched to flexible, this represents the maximum of usable energy
|
|
|
*/
|
|
|
- private float[] energyAt;
|
|
|
+ private float[] availableEnergyPerElementAt;
|
|
|
|
|
|
/**
|
|
|
* Create a new HolonElement with a user-defined name, amount of the same
|
|
|
- * element and energy per element.
|
|
|
+ * element and energyPerElement.
|
|
|
*
|
|
|
* @param eleName String
|
|
|
* @param amount int
|
|
@@ -68,10 +69,10 @@ public class HolonElement {
|
|
|
public HolonElement(String eleName, int amount, float energy) {
|
|
|
setEleName(eleName);
|
|
|
setAmount(amount);
|
|
|
- setEnergy(energy);
|
|
|
+ setEnergyPerElement(energy);
|
|
|
setActive(true);
|
|
|
setSign(energy);
|
|
|
- setEnergyAt(energy);
|
|
|
+ setAvailableEnergyPerElementAt(energy);
|
|
|
setGraphPoints(new LinkedList<>());
|
|
|
setId(IdCounterElem.nextId());
|
|
|
setFlexibleEnergyAvailable(0);
|
|
@@ -84,10 +85,10 @@ public class HolonElement {
|
|
|
public HolonElement(String eleName, int amount, float energy, int id) {
|
|
|
setEleName(eleName);
|
|
|
setAmount(amount);
|
|
|
- setEnergy(energy);
|
|
|
+ setEnergyPerElement(energy);
|
|
|
setActive(true);
|
|
|
setSign(energy);
|
|
|
- setEnergyAt(energy);
|
|
|
+ setAvailableEnergyPerElementAt(energy);
|
|
|
setGraphPoints(new LinkedList<>());
|
|
|
setId(id);
|
|
|
setFlexibleEnergyAvailable(0);
|
|
@@ -102,12 +103,12 @@ public class HolonElement {
|
|
|
public HolonElement(HolonElement element) {
|
|
|
setEleName(element.getEleName());
|
|
|
setAmount(element.getAmount());
|
|
|
- setEnergy(element.getEnergy());
|
|
|
+ setEnergyPerElement(element.getEnergyPerElement());
|
|
|
setActive(element.isActive());
|
|
|
- setSign(element.getEnergy());
|
|
|
- setEnergyAt(element.getEnergy());
|
|
|
- for (int i = 0; i < energyAt.length; i++) {
|
|
|
- energyAt[i] = element.getEnergyAt()[i];
|
|
|
+ setSign(element.getEnergyPerElement());
|
|
|
+ setAvailableEnergyPerElementAt(element.getEnergyPerElement());
|
|
|
+ for (int i = 0; i < availableEnergyPerElementAt.length; i++) {
|
|
|
+ availableEnergyPerElementAt[i] = element.getAvailableEnergyPerElementAt()[i];
|
|
|
}
|
|
|
setGraphPoints(new LinkedList<>());
|
|
|
for (Point p : element.getGraphPoints()) {
|
|
@@ -120,35 +121,42 @@ public class HolonElement {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the Array of energy (100 values).
|
|
|
+ * Get the Array of energyPerElement (100 values).
|
|
|
*
|
|
|
- * @return energyAt Array of Floats
|
|
|
+ * @return availableEnergyPerElementAt Array of Floats
|
|
|
*/
|
|
|
- public float[] getEnergyAt() {
|
|
|
- return energyAt;
|
|
|
+ public float[] getAvailableEnergyPerElementAt() {
|
|
|
+ return availableEnergyPerElementAt;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set energy to any value to the whole array.
|
|
|
+ * Set energyPerElement to any value to the whole array.
|
|
|
*
|
|
|
* @param energy the value
|
|
|
*/
|
|
|
- public void setEnergyAt(float energy) {
|
|
|
- this.energyAt = new float[100];
|
|
|
- for (int i = 0; i < energyAt.length; i++) {
|
|
|
- this.energyAt[i] = energy;
|
|
|
+ public void setAvailableEnergyPerElementAt(float energy) {
|
|
|
+ this.availableEnergyPerElementAt = new float[100];
|
|
|
+ for (int i = 0; i < availableEnergyPerElementAt.length; i++) {
|
|
|
+ this.availableEnergyPerElementAt[i] = energy;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set energy to any value at a given position.
|
|
|
+ * Get the energyPerElement currently available
|
|
|
+ */
|
|
|
+ public float getAvailableEnergyAt(int timestep) {
|
|
|
+ return this.availableEnergyPerElementAt[timestep];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set energyPerElement to any value at a given position.
|
|
|
*
|
|
|
* @param pos int
|
|
|
- * @param energy float
|
|
|
+ * @param energyPerElement float
|
|
|
*/
|
|
|
- public void setEnergyAt(int pos, float energy) {
|
|
|
- this.energyAt[pos] = energy;
|
|
|
- }
|
|
|
+// public void setAvailableEnergyPerElementAt(int pos, float energyPerElement) {
|
|
|
+// this.availableEnergyPerElementAt[pos] = energyPerElement;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* Get the user-defined Name.
|
|
@@ -187,22 +195,22 @@ public class HolonElement {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the energy value of the selected Element.
|
|
|
+ * Get the energyPerElement value of the selected Element.
|
|
|
*
|
|
|
- * @return the energy
|
|
|
+ * @return the energyPerElement
|
|
|
*/
|
|
|
- public float getEnergy() {
|
|
|
- return energy;
|
|
|
+ public float getEnergyPerElement() {
|
|
|
+ return energyPerElement;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set the energy value of the selected Element.
|
|
|
+ * Set the energyPerElement value of the selected Element.
|
|
|
*
|
|
|
- * @param energy the energy to set
|
|
|
+ * @param energyPerElement the energyPerElement to set
|
|
|
*/
|
|
|
- public void setEnergy(float energy) {
|
|
|
- this.energy = energy;
|
|
|
- setSign(energy);
|
|
|
+ public void setEnergyPerElement(float energyPerElement) {
|
|
|
+ this.energyPerElement = energyPerElement;
|
|
|
+ setSign(energyPerElement);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -221,43 +229,33 @@ public class HolonElement {
|
|
|
*/
|
|
|
public void setActive(boolean active) {
|
|
|
this.active = active;
|
|
|
-
|
|
|
- if (!active && flexible) {
|
|
|
- setEnergy(0);
|
|
|
- setEnergyAt(0);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Multiply the amount of gadgets, given by the user, and the
|
|
|
* consumption/production. If the switch isWorking is turned off for on
|
|
|
- * gadget, the energy of this gadget have to be subtracted.
|
|
|
+ * gadget, the energyPerElement of this gadget have to be subtracted.
|
|
|
*
|
|
|
* @return totalEnergy (actual)
|
|
|
*/
|
|
|
- public float getTotalEnergy() {
|
|
|
-// if (flexible) {
|
|
|
-// totalEnergy = ((float) amount) * (energy + flexibleEnergyAvailable);
|
|
|
-// } else {
|
|
|
- totalEnergy = ((float) amount) * energy;
|
|
|
-// }
|
|
|
+ public float getOverallEnergy() {
|
|
|
+ totalEnergy = ((float) amount) * energyPerElement;
|
|
|
return totalEnergy;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the energy value at a selected time x.
|
|
|
+ * Get the energyPerElement value at a selected time x.
|
|
|
*
|
|
|
* @param x int
|
|
|
- * @return energy value
|
|
|
- */
|
|
|
- public float getTotalEnergyAtTimeStep(int x) {
|
|
|
-// float result =((float) amount) * energyAt[x];
|
|
|
-// if (flexible) {
|
|
|
-// result = ((float) amount) * (energyAt[x] + flexibleEnergyAvailable);
|
|
|
-// } else {
|
|
|
-// result = ((float) amount) * energyAt[x];
|
|
|
-// }
|
|
|
- return ((float) amount) * energyAt[x];
|
|
|
+ * @return energyPerElement value
|
|
|
+ */
|
|
|
+ public float getOverallEnergyAtTimeStep(int x) {
|
|
|
+ if (flexible) {
|
|
|
+ // TODO: what happens if energyPerElement > availableEnergyPerElementAt[x]?
|
|
|
+ return ((float) amount) * energyPerElement;
|
|
|
+ } else {
|
|
|
+ return ((float) amount) * availableEnergyPerElementAt[x];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -302,7 +300,7 @@ public class HolonElement {
|
|
|
/**
|
|
|
* Get the flexibleEnergyAvailable of an element
|
|
|
*/
|
|
|
- public float getFlexibleEnergyAvailable() {
|
|
|
+ public float getFlexibleEnergyAvailablePerElement() {
|
|
|
return this.flexibleEnergyAvailable;
|
|
|
}
|
|
|
|
|
@@ -321,35 +319,25 @@ public class HolonElement {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set the flexibleEnergyAvailable of an element
|
|
|
+ * Set the flexibleEnergyAvailable of an element, ~switches energyPerElement and flexible energyPerElement
|
|
|
*/
|
|
|
public void setFlexible(boolean b) {
|
|
|
- this.flexible = b;
|
|
|
-
|
|
|
// if flexibleEnergyAvailable was set to true
|
|
|
- if (b) {
|
|
|
- // set active to false
|
|
|
- this.active = false;
|
|
|
-
|
|
|
- // move energy to flexibleEnergyAvailable (becomes the possible-to-use energy)
|
|
|
- if (getEnergy() != 0) {
|
|
|
- setFlexibleEnergyAvailable(getEnergy());
|
|
|
- // and set actually used energy to zero (can be changed by algorithms, the grid itself or the user)
|
|
|
- setEnergy(0);
|
|
|
- setEnergyAt(0);
|
|
|
+ if (b && !this.flexible) {
|
|
|
+ this.flexible = b;
|
|
|
+ // move energyPerElement to flexibleEnergyAvailable (becomes the possible-to-use energyPerElement)
|
|
|
+ if (getEnergyPerElement() != 0) {
|
|
|
+ setFlexibleEnergyAvailable(getEnergyPerElement());
|
|
|
+ setEnergyPerElement(0);
|
|
|
}
|
|
|
- } else {
|
|
|
- // move the energy to actually used energy and set flexible amount to 0
|
|
|
- if (getFlexibleEnergyAvailable() != 0) {
|
|
|
- setEnergy(getFlexibleEnergyAvailable());
|
|
|
- setEnergyAt(getEnergy());
|
|
|
+ } else if (!b && this.flexible) {
|
|
|
+ this.flexible = b;
|
|
|
+ // move the energyPerElement to actually used energyPerElement and set flexible amount to 0
|
|
|
+ if (getFlexibleEnergyAvailablePerElement() != 0) {
|
|
|
+ setEnergyPerElement(getFlexibleEnergyAvailablePerElement());
|
|
|
}
|
|
|
setFlexibleEnergyAvailable(0);
|
|
|
}
|
|
|
-
|
|
|
-// System.out.println("after setFlexible(" + String.valueOf(b) + "):");
|
|
|
-// System.out.println("flexible " + flexible + ", active: " + active + ", energy: " + energy
|
|
|
-// + ", flexible energy: " + flexibleEnergyAvailable + "\n");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -388,9 +376,13 @@ public class HolonElement {
|
|
|
public String toString() {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("[HolonElement: ");
|
|
|
- sb.append("id=").append(id).append(", eleName=").append(eleName).append(", amount=").append(amount)
|
|
|
- .append(", active=").append(active).append(", flexible=").append(flexible)
|
|
|
- .append(", energy used=").append(energy).append(", flexible energy available=").append(flexibleEnergyAvailable);
|
|
|
+ sb.append("id=").append(id)
|
|
|
+ .append(", eleName=").append(eleName)
|
|
|
+ .append(", amount=").append(amount)
|
|
|
+ .append(", active=").append(active)
|
|
|
+ .append(", flexible=").append(flexible)
|
|
|
+ .append(", energyPerElement used=").append(energyPerElement)
|
|
|
+ .append(", flexible energyPerElement available=").append(flexibleEnergyAvailable);
|
|
|
sb.append("]");
|
|
|
|
|
|
return sb.toString();
|