|
@@ -1,20 +1,18 @@
|
|
|
-package classes;
|
|
|
+package model;
|
|
|
|
|
|
import com.google.gson.annotations.Expose;
|
|
|
import com.google.gson.annotations.SerializedName;
|
|
|
|
|
|
-import classes.IdCounter.CounterType;
|
|
|
import interfaces.TimelineDependent;
|
|
|
-import ui.controller.FlexManager;
|
|
|
+import model.Flexibility.FlexState;
|
|
|
import ui.controller.IndexTranslator;
|
|
|
-
|
|
|
-import java.awt.*;
|
|
|
-import java.awt.geom.Point2D;
|
|
|
-import java.awt.geom.Point2D.Double;
|
|
|
+import ui.model.IdCounter;
|
|
|
+import ui.model.IdCounter.CounterType;
|
|
|
+import utility.Vector2Float;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.ListIterator;
|
|
|
-
|
|
|
+import java.util.AbstractMap.SimpleEntry;
|
|
|
|
|
|
* The class "HolonElement" represents any possible element that can be added to
|
|
|
* a CpsObject (such as TV (consumer) or any energyPerElement source/producer).
|
|
@@ -23,40 +21,45 @@ import java.util.ListIterator;
|
|
|
*/
|
|
|
public class HolonElement implements TimelineDependent{
|
|
|
|
|
|
+
|
|
|
+ * MODEL
|
|
|
+ */
|
|
|
+
|
|
|
+ public HolonObject parentObject;
|
|
|
|
|
|
* Represent the Graph
|
|
|
* the X component from a Point is period from 0..1
|
|
|
* the Y component from a Point is the percentage from 0..1
|
|
|
* */
|
|
|
- private LinkedList<Point2D.Double> graphPoints;
|
|
|
+ private LinkedList<Vector2Float> graphPoints;
|
|
|
|
|
|
@Expose
|
|
|
- private String eleName;
|
|
|
+ @SerializedName(value = "name", alternate = "eleName")
|
|
|
+ private String name;
|
|
|
|
|
|
@Expose
|
|
|
@SerializedName(value = "energy", alternate = "energyPerElement")
|
|
|
private float energy;
|
|
|
|
|
|
@Expose
|
|
|
- private boolean active;
|
|
|
+ public boolean active;
|
|
|
|
|
|
|
|
|
- public HolonObject parentObject;
|
|
|
|
|
|
|
|
|
|
|
|
+ public enum Priority {
|
|
|
+ Low, Medium, High, Essential
|
|
|
+ }
|
|
|
|
|
|
@Expose
|
|
|
- private Priority priority = Priority.Low;
|
|
|
+ public Priority priority = Priority.Low;
|
|
|
|
|
|
- public enum Priority {
|
|
|
- Low, Medium, High, Essential
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
@Expose
|
|
|
- private Pair<String, String> saving;
|
|
|
+ private SimpleEntry<String, String> saving;
|
|
|
|
|
|
@Expose
|
|
|
private int id;
|
|
@@ -97,14 +100,13 @@ public class HolonElement implements TimelineDependent{
|
|
|
public HolonElement(HolonObject parentObject, String eleName, float energy, int id){
|
|
|
this.parentObject = parentObject;
|
|
|
setUseLocalPeriod(false);
|
|
|
- setEleName(eleName);
|
|
|
- setEnergyPerElement(energy);
|
|
|
- setActive(true);
|
|
|
+ setName(eleName);
|
|
|
+ setEnergy(energy);
|
|
|
+ this.active = true;
|
|
|
setGraphPoints(new LinkedList<>());
|
|
|
initGraphPoints();
|
|
|
sampleGraph();
|
|
|
- setId(id);
|
|
|
- this.priority = Priority.Low;
|
|
|
+ this.id = id;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -117,22 +119,26 @@ public class HolonElement implements TimelineDependent{
|
|
|
this.priority = element.getPriority();
|
|
|
setLocalPeriod(element.getLocalPeriod());
|
|
|
setUseLocalPeriod(element.isUsingLocalPeriod());
|
|
|
- setEleName(element.getName());
|
|
|
+ setName(element.getName());
|
|
|
setLocalPeriod(element.getLocalPeriod());
|
|
|
- setEnergyPerElement(element.getEnergy());
|
|
|
- setActive(element.isActive());
|
|
|
+ setEnergy(element.getEnergy());
|
|
|
+ this.active = element.active;
|
|
|
setGraphPoints(new LinkedList<>());
|
|
|
- for (Point2D.Double p : element.getGraphPoints()) {
|
|
|
- this.graphPoints.add(new Point2D.Double(p.getX(), p.getY()));
|
|
|
+ for (Vector2Float p : element.getGraphPoints()) {
|
|
|
+ this.graphPoints.add(new Vector2Float(p));
|
|
|
}
|
|
|
sampleGraph();
|
|
|
setSaving(null);
|
|
|
- setId(IdCounter.nextId(CounterType.Element));
|
|
|
-
|
|
|
+ this.id = IdCounter.nextId(CounterType.Element);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+ public int getId() {
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
* Get the user-defined Name.
|
|
@@ -140,7 +146,7 @@ public class HolonElement implements TimelineDependent{
|
|
|
* @return the name String
|
|
|
*/
|
|
|
public String getName() {
|
|
|
- return eleName;
|
|
|
+ return name;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -148,8 +154,8 @@ public class HolonElement implements TimelineDependent{
|
|
|
*
|
|
|
* @param name the name to set
|
|
|
*/
|
|
|
- public void setEleName(String name) {
|
|
|
- this.eleName = name;
|
|
|
+ public void setName(String name) {
|
|
|
+ this.name = name;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -161,15 +167,15 @@ public class HolonElement implements TimelineDependent{
|
|
|
public float getEnergy() {
|
|
|
return energy;
|
|
|
}
|
|
|
- public Priority getPriority() {
|
|
|
- return priority;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void setPriority(Priority priority) {
|
|
|
- this.priority = priority;
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
+ * Set the energyPerElement value of the selected Element.
|
|
|
+ *
|
|
|
+ * @param energyPerElement the energyPerElement to set
|
|
|
+ */
|
|
|
+ public void setEnergy(float energyPerElement) {
|
|
|
+ this.energy = energyPerElement;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -189,80 +195,34 @@ public class HolonElement implements TimelineDependent{
|
|
|
{
|
|
|
return (energy < 0);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- * Set the energyPerElement value of the selected Element.
|
|
|
- *
|
|
|
- * @param energyPerElement the energyPerElement to set
|
|
|
- */
|
|
|
- public void setEnergyPerElement(float energyPerElement) {
|
|
|
- this.energy = energyPerElement;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * Get the Status of the Element (see description of variables).
|
|
|
- *
|
|
|
- * @return the active
|
|
|
- */
|
|
|
- public boolean isActive() {
|
|
|
- return active;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isOn(FlexManager flexManager) {
|
|
|
-
|
|
|
-
|
|
|
- return flexManager.isAFlexInUseOfHolonElement(this) ^ active;
|
|
|
- }
|
|
|
- public boolean isFlexActive(FlexManager flexManager) {
|
|
|
- return flexManager.isAFlexInUseOfHolonElement(this);
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- * Set the Status of the Element (see description of variables).
|
|
|
- *
|
|
|
- * @param active the active to set
|
|
|
- */
|
|
|
- public void setActive(boolean active) {
|
|
|
- this.active = active;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * Get the energyPerElement currently(at given time step) available
|
|
|
- */
|
|
|
- public float getEnergyAtTimeStep(int timestep) {
|
|
|
- return energy * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
|
|
|
+
|
|
|
+
|
|
|
+ public Priority getPriority() {
|
|
|
+ return priority;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public void setPriority(Priority priority) {
|
|
|
+ this.priority = priority;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
-
|
|
|
- * Get the Id of the selected HolonElement.
|
|
|
- *
|
|
|
- * @return id the id
|
|
|
- */
|
|
|
- public int getId() {
|
|
|
- return id;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- * Set the ID of the HolonElement (one time only).
|
|
|
- *
|
|
|
- * @param id the id
|
|
|
- */
|
|
|
- public void setId(int id) {
|
|
|
- this.id = id;
|
|
|
- }
|
|
|
|
|
|
|
|
|
* @return the saving
|
|
|
*/
|
|
|
- public Pair<String, String> getSaving() {
|
|
|
+ public SimpleEntry<String, String> getSaving() {
|
|
|
return saving;
|
|
|
}
|
|
|
|
|
|
|
|
|
* @param saving the saving to set
|
|
|
*/
|
|
|
- public void setSaving(Pair<String, String> saving) {
|
|
|
+ public void setSaving(SimpleEntry<String, String> saving) {
|
|
|
this.saving = saving;
|
|
|
}
|
|
|
|
|
@@ -271,7 +231,7 @@ public class HolonElement implements TimelineDependent{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("[HolonElement: ");
|
|
|
sb.append("id=").append(id)
|
|
|
- .append(", eleName=").append(eleName)
|
|
|
+ .append(", eleName=").append(name)
|
|
|
.append(", parentName=").append(parentObject.getName())
|
|
|
.append(", active=").append(active)
|
|
|
.append(", energyPerElement used=").append(energy);
|
|
@@ -286,14 +246,14 @@ public class HolonElement implements TimelineDependent{
|
|
|
private void initGraphPoints()
|
|
|
{
|
|
|
graphPoints.clear();
|
|
|
- graphPoints.add(new Point2D.Double(0,1.0));
|
|
|
- graphPoints.add(new Point2D.Double(1,1.0));
|
|
|
+ graphPoints.add(new Vector2Float(0f,1.0f));
|
|
|
+ graphPoints.add(new Vector2Float(1f,1.0f));
|
|
|
}
|
|
|
|
|
|
* Getter for the graphPoint List.
|
|
|
* @return {@link HolonElement#graphPoints}
|
|
|
*/
|
|
|
- public LinkedList<Point2D.Double> getGraphPoints() {
|
|
|
+ public LinkedList<Vector2Float> getGraphPoints() {
|
|
|
return graphPoints;
|
|
|
}
|
|
|
|
|
@@ -301,8 +261,8 @@ public class HolonElement implements TimelineDependent{
|
|
|
* Setter for the graphPoint List.
|
|
|
* @param testGraphPoints is new {@link HolonElement#graphPoints}
|
|
|
*/
|
|
|
- public void setGraphPoints(LinkedList<Point2D.Double> testGraphPoints) {
|
|
|
- this.graphPoints = testGraphPoints;
|
|
|
+ public void setGraphPoints(LinkedList<Vector2Float> graphPoints) {
|
|
|
+ this.graphPoints = graphPoints;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -316,7 +276,7 @@ public class HolonElement implements TimelineDependent{
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public LinkedList<Double> getStateGraph() {
|
|
|
+ public LinkedList<Vector2Float> getStateGraph() {
|
|
|
return getGraphPoints();
|
|
|
}
|
|
|
|
|
@@ -339,9 +299,9 @@ public class HolonElement implements TimelineDependent{
|
|
|
*/
|
|
|
private float[] sampleGraph(int sampleLength)
|
|
|
{
|
|
|
- ListIterator<Point2D.Double> iter = this.graphPoints.listIterator();
|
|
|
- Point.Double before = iter.next();
|
|
|
- Point.Double after = iter.next();
|
|
|
+ ListIterator<Vector2Float> iter = this.graphPoints.listIterator();
|
|
|
+ Vector2Float before = iter.next();
|
|
|
+ Vector2Float after = iter.next();
|
|
|
float [] sampleCurve = new float[sampleLength];
|
|
|
for(int i = 0; i<sampleLength ; i++)
|
|
|
{
|
|
@@ -370,14 +330,14 @@ public class HolonElement implements TimelineDependent{
|
|
|
* @param end is the end Point of the Curve.
|
|
|
* @return the percentage from the Curve at the X Value based on t.
|
|
|
*/
|
|
|
- private double getYBetweenTwoPoints(double t, Point.Double start, Point.Double end) {
|
|
|
+ private double getYBetweenTwoPoints(double t, Vector2Float start, Vector2Float end) {
|
|
|
|
|
|
- double mitte = (start.x + end.x)* 0.5;
|
|
|
- Point.Double bezier = getBezierPoint(t, start, new Point.Double(mitte, start.y), new Point.Double(mitte, end.y), end);
|
|
|
+ float mitte = (start.x + end.x)* 0.5f;
|
|
|
+ Vector2Float bezier = getBezierPoint(t, start, new Vector2Float(mitte, start.y), new Vector2Float(mitte, end.y), end);
|
|
|
return bezier.y;
|
|
|
}
|
|
|
|
|
|
- * Helper method for {@link HolonElement#getYBetweenTwoPoints(double, Point.Double, Point.Double)}.
|
|
|
+ * Helper method for {@link HolonElement#getYBetweenTwoPoints(double, Vector2Float, Vector2Float)}.
|
|
|
* <p>
|
|
|
* A Method for a normal Cubic Bezier Curve. A Cubic Bezier curve has four control points.
|
|
|
* @param t is in Range [0,1] how much it traverse along the curve.
|
|
@@ -387,22 +347,22 @@ public class HolonElement implements TimelineDependent{
|
|
|
* @param p3 EndPoint
|
|
|
* @return the BezierPosition at t.
|
|
|
*/
|
|
|
- private Point.Double getBezierPoint(double t, Point.Double p0, Point.Double p1,Point.Double p2,Point.Double p3) {
|
|
|
+ private Vector2Float getBezierPoint(double t, Vector2Float p0, Vector2Float p1,Vector2Float p2,Vector2Float p3) {
|
|
|
|
|
|
* Calculate Bezi�r:
|
|
|
* B(t) = (1-t)^3 * P0 + 3*(1-t)^2 * t * P1 + 3*(1-t)*t^2 * P2 + t^3 * P3 , 0 < t < 1
|
|
|
*
|
|
|
* Source:
|
|
|
*/
|
|
|
- Point.Double bezier = new Point.Double();
|
|
|
+ Vector2Float bezier = new Vector2Float();
|
|
|
double OneSubT = 1-t;
|
|
|
double OneSubT2 = Math.pow(OneSubT, 2);
|
|
|
double OneSubT3 = Math.pow(OneSubT, 3);
|
|
|
double t2 = Math.pow(t , 2);
|
|
|
double t3 = Math.pow(t , 3);
|
|
|
|
|
|
- bezier.x = OneSubT3 * p0.x + 3 * OneSubT2 * t * p1.x + 3 * OneSubT * t2 * p2.x + t3 * p3.x;
|
|
|
- bezier.y = OneSubT3 * p0.y + 3 * OneSubT2 * t * p1.y + 3 * OneSubT * t2 * p2.y + t3 * p3.y;
|
|
|
+ bezier.x = (float)(OneSubT3 * p0.x + 3 * OneSubT2 * t * p1.x + 3 * OneSubT * t2 * p2.x + t3 * p3.x);
|
|
|
+ bezier.y = (float)(OneSubT3 * p0.y + 3 * OneSubT2 * t * p1.y + 3 * OneSubT * t2 * p2.y + t3 * p3.y);
|
|
|
return bezier;
|
|
|
|
|
|
}
|
|
@@ -427,4 +387,36 @@ public class HolonElement implements TimelineDependent{
|
|
|
this.isUsingLocalPeriod=state;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * STATE
|
|
|
+ */
|
|
|
+
|
|
|
+ private float actualEnergy = 0;
|
|
|
+
|
|
|
+ public void calculateState(int timestep) {
|
|
|
+ flexList.forEach(flex -> flex.calculateState(timestep));
|
|
|
+ float energyWhenActive = energy * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
|
|
|
+ actualEnergy = isOn() ? energyWhenActive : 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ * Get the energyPerElement currently(at given time step) available
|
|
|
+ */
|
|
|
+ public float calculateExpectedEnergyAtTimeStep(int timestep) {
|
|
|
+ float energyWhenActive = energy * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
|
|
|
+ return active ? energyWhenActive : 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public float getActualEnergy() {
|
|
|
+ return actualEnergy;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isOn() {
|
|
|
+
|
|
|
+
|
|
|
+ return isFlexActive() ^ active;
|
|
|
+ }
|
|
|
+ public boolean isFlexActive() {
|
|
|
+ return flexList.stream().anyMatch(flex -> flex.getState() == FlexState.IN_USE || flex.getState() == FlexState.ON_COOLDOWN);
|
|
|
+ }
|
|
|
+
|
|
|
}
|