|
@@ -6,6 +6,7 @@ import ui.model.Model;
|
|
|
import ui.view.UnitGraph;
|
|
|
|
|
|
import java.awt.*;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
/**
|
|
@@ -16,35 +17,43 @@ import java.util.LinkedList;
|
|
|
*/
|
|
|
public class HolonElement implements IGraphedElement{
|
|
|
|
|
|
- /* Points on the UnitGraph */
|
|
|
+ /** Points on the UnitGraph */
|
|
|
private LinkedList<Point> graphPoints;
|
|
|
- /* Name of the Object: House, 1 */
|
|
|
+
|
|
|
+ /** Points of new TestGraph
|
|
|
+ * Represent the Graph
|
|
|
+ * the X component from a Point is period
|
|
|
+ * the Y component from a Point is the percentage
|
|
|
+ * currently saved in int -> TODO serelized float point class
|
|
|
+ * */
|
|
|
+ private LinkedList<Point> testGraphPoints;
|
|
|
+ /** Name of the object, e.g. House, 1 */
|
|
|
@Expose
|
|
|
private String objName;
|
|
|
- /* Name of the gadget: TV */
|
|
|
+ /** Name of the gadget, e.g. TV */
|
|
|
@Expose
|
|
|
private String eleName;
|
|
|
- /* Quantity */
|
|
|
+ /** Amount of same elements */
|
|
|
@Expose
|
|
|
private int amount;
|
|
|
- /* Currently used energy per element (- indicates consumation of energy, + indicates production of energy)*/
|
|
|
+ /** Currently used energy per element (- indicates consumation of energy, + indicates production of energy)*/
|
|
|
@Expose
|
|
|
private float energyPerElement;
|
|
|
- /* Whether the gadget is active or not (currently uses/produces the energy in energyPerElement) */
|
|
|
+ /** Whether the gadget is active or not (currently uses/produces the energy in energyPerElement) */
|
|
|
@Expose
|
|
|
private boolean active;
|
|
|
- /* Gives us whether this element is flexible and can flexibly use any part of the energy in flexibleEnergyAvailable */
|
|
|
+ /** Gives us whether this element is flexible and can flexibly use any part of the energy in flexibleEnergyAvailable */
|
|
|
@Expose
|
|
|
private boolean flexible;
|
|
|
- /* Flexibility (meaning the actual */
|
|
|
+ /** Flexibility (meaning the actual */
|
|
|
@Expose
|
|
|
private float flexibleEnergyAvailable;
|
|
|
|
|
|
|
|
|
- /* Place where the Object is Stored */
|
|
|
+ /** Place where the Object is Stored */
|
|
|
@Expose
|
|
|
private Pair<String, String> saving;
|
|
|
- /* ID */
|
|
|
+ /** ID */
|
|
|
@Expose
|
|
|
private int id;
|
|
|
|
|
@@ -76,29 +85,12 @@ public class HolonElement implements IGraphedElement{
|
|
|
this(eleName, amount, energy, IdCounterElem.nextId(),model);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Create a new HolonElement with a user-defined name, amount of the same
|
|
|
- * element and energyPerElement.
|
|
|
- *
|
|
|
- * @param eleName String
|
|
|
- * @param amount int
|
|
|
- * @param energy float
|
|
|
- * @param model Model
|
|
|
- * @deprecated Constructing a HolonElement without a model
|
|
|
- * make sit detached from a real simulation.
|
|
|
- *
|
|
|
- * This constructor only exists for dry tests
|
|
|
- * for whether HolonElements generally function as intended.
|
|
|
- */
|
|
|
- @Deprecated public HolonElement(String eleName, int amount, float energy) {
|
|
|
- this(eleName, amount, energy, IdCounterElem.nextId(),null);//TODO: This is just for the old tests...
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* same as standard constructor, but with already given id (so the counter is not increased twice)
|
|
|
*/
|
|
|
public HolonElement(String eleName, int amount, float energy, int id, Model model){
|
|
|
- setLocalPeriod(model==null?UnitGraph.STANDARD_GRAPH_ACCURACY:model.getGraphIterations());
|
|
|
+ setLocalPeriod(model==null? UnitGraph.STANDARD_GRAPH_ACCURACY : model.getGraphIterations());
|
|
|
setStretching(IGraphedElement.STRETCH_BY_DEFAULT);
|
|
|
setEleName(eleName);
|
|
|
setAmount(amount);
|
|
@@ -106,6 +98,9 @@ public class HolonElement implements IGraphedElement{
|
|
|
setActive(true);
|
|
|
setAvailableEnergyPerElementAt(energy);
|
|
|
setGraphPoints(new LinkedList<>());
|
|
|
+ System.out.println("heiNEW");
|
|
|
+ setTestGraphPoints(new LinkedList<>());
|
|
|
+ initTestGraphPoints(100);
|
|
|
setId(id);
|
|
|
setFlexibleEnergyAvailable(0);
|
|
|
setFlexible(false);
|
|
@@ -129,9 +124,14 @@ public class HolonElement implements IGraphedElement{
|
|
|
availableEnergyPerElementAt[i] = element.getAvailableEnergyAt(i);
|
|
|
}
|
|
|
setGraphPoints(new LinkedList<>());
|
|
|
+ setTestGraphPoints(new LinkedList<>());
|
|
|
for (Point p : element.getGraphPoints()) {
|
|
|
this.graphPoints.add(new Point((int) p.getX(), (int) p.getY()));
|
|
|
}
|
|
|
+ System.out.println("hei");
|
|
|
+ for (Point p : element.getTestGraphPoints()) {
|
|
|
+ this.testGraphPoints.add(new Point((int) p.getX(), (int) p.getY()));
|
|
|
+ }
|
|
|
setSaving(null);
|
|
|
setId(IdCounterElem.nextId());
|
|
|
setFlexibleEnergyAvailable(0);
|
|
@@ -146,14 +146,6 @@ public class HolonElement implements IGraphedElement{
|
|
|
this.objName = objName;
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * Get the Array of energyPerElement (100 values).
|
|
|
- *
|
|
|
- * @return availableEnergyPerElementAt Array of Floats
|
|
|
- */
|
|
|
- /*public float[] getAvailableEnergyPerElementAt() {
|
|
|
- return availableEnergyPerElementAt;
|
|
|
- }*/
|
|
|
|
|
|
/**
|
|
|
* Set energyPerElement to any value to the whole array.
|
|
@@ -174,6 +166,21 @@ public class HolonElement implements IGraphedElement{
|
|
|
return this.availableEnergyPerElementAt[UnitGraph.getEffectiveIndex(this, timestep)];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param timestep
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public float testFunctiongetAvailableEnergyAt(int timestep) {
|
|
|
+ if(getTestGraphPoints()==null)return 0;
|
|
|
+ this.getTestGraphPoints().iterator();
|
|
|
+ for(Iterator<Point> iterator = getTestGraphPoints().iterator(); iterator.hasNext();)
|
|
|
+ {
|
|
|
+ System.out.println(iterator.next());
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
/**
|
|
|
* Set energyPerElement to any value at a given position.
|
|
|
*
|
|
@@ -230,13 +237,22 @@ public class HolonElement implements IGraphedElement{
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Return if the HolonElemnt is a Producer
|
|
|
- * @return boolean true when the energy used be each element is higher then 0
|
|
|
+ * Check the HolonElemnet is a Producer
|
|
|
+ * @return true when the energy used be each element is higher then 0
|
|
|
*/
|
|
|
public boolean isProducer()
|
|
|
{
|
|
|
return (energyPerElement > 0);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Check the HolonElemnet is a Consumer
|
|
|
+ * @return true when the energy used be each element is lower then 0
|
|
|
+ */
|
|
|
+ public boolean isConsumer()
|
|
|
+ {
|
|
|
+ return (energyPerElement < 0);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Set the energyPerElement value of the selected Element.
|
|
@@ -280,14 +296,14 @@ public class HolonElement implements IGraphedElement{
|
|
|
/**
|
|
|
* Get the energyPerElement value at a selected time x.
|
|
|
*
|
|
|
- * @param x int
|
|
|
+ * @param timestep int
|
|
|
* @return energyPerElement value
|
|
|
*/
|
|
|
- public float getOverallEnergyAtTimeStep(int x) {
|
|
|
+ public float getOverallEnergyAtTimeStep(int timestep) {
|
|
|
if (flexible) {
|
|
|
return ((float) amount) * energyPerElement;
|
|
|
} else {
|
|
|
- return ((float) amount) * availableEnergyPerElementAt[UnitGraph.getEffectiveIndex(this, x)];
|
|
|
+ return ((float) amount) * availableEnergyPerElementAt[UnitGraph.getEffectiveIndex(this, timestep)];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -420,4 +436,20 @@ public class HolonElement implements IGraphedElement{
|
|
|
public void setStretching(boolean stretch) {
|
|
|
this.stretch=stretch;
|
|
|
}
|
|
|
+
|
|
|
+//--> Test Area --> TODO Neue float Point Klasse
|
|
|
+ public void initTestGraphPoints(int percentage)
|
|
|
+ {
|
|
|
+ testGraphPoints.clear();
|
|
|
+ testGraphPoints.add(new Point(0,percentage));
|
|
|
+ testGraphPoints.add(new Point(100,percentage));
|
|
|
+ }
|
|
|
+ public LinkedList<Point> getTestGraphPoints() {
|
|
|
+ return testGraphPoints;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setTestGraphPoints(LinkedList<Point> testGraphPoints) {
|
|
|
+ this.testGraphPoints = testGraphPoints;
|
|
|
+ }
|
|
|
}
|