Prechádzať zdrojové kódy

#76: fixed bugs, added support for multiple elements, refactored methods of HolonElement to clarify code

I. Dix 7 rokov pred
rodič
commit
5476ea84f0

+ 80 - 88
src/classes/HolonElement.java

@@ -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();

+ 58 - 16
src/classes/HolonObject.java

@@ -131,7 +131,7 @@ public class HolonObject extends AbstractCpsObject {
         float temp = 0;
         for (HolonElement e : getElements()) {
             if (e.isActive()) {
-                temp += e.getTotalEnergy();
+                temp += e.getOverallEnergy();
             }
         }
         currentEnergy = temp;
@@ -148,7 +148,7 @@ public class HolonObject extends AbstractCpsObject {
         float temp = 0;
         for (HolonElement e : getElements()) {
             if (e.isActive()) {
-                temp = temp + e.getTotalEnergyAtTimeStep(x);
+                temp += e.getOverallEnergyAtTimeStep(x);
             }
         }
         currentEnergy = temp;
@@ -283,17 +283,18 @@ public class HolonObject extends AbstractCpsObject {
         if (getElements().size() == 0) {
             return false;
         }
-        float minConsum = getElements().get(0).getTotalEnergyAtTimeStep(x);
+        float minConsum = getElements().get(0).getOverallEnergyAtTimeStep(x);
         float prod = 0;
         for (HolonElement e : getElements()) {
             if (e.isActive()) {
-                if (e.getTotalEnergyAtTimeStep(x) > 0) {
-                    prod = prod + e.getTotalEnergyAtTimeStep(x);
+                float overallEnergy = e.getOverallEnergyAtTimeStep(x);
+                if (overallEnergy > 0) {
+                    prod = prod + overallEnergy;
                 }
-                if (minConsum < 0 && (e.getTotalEnergyAtTimeStep(x) > minConsum && e.getTotalEnergyAtTimeStep(x) < 0)) {
-                    minConsum = e.getTotalEnergyAtTimeStep(x);
-                } else if (minConsum >= 0 && e.getTotalEnergyAtTimeStep(x) < minConsum) {
-                    minConsum = e.getTotalEnergyAtTimeStep(x);
+                if (minConsum < 0 && (overallEnergy > minConsum && overallEnergy < 0)) {
+                    minConsum = overallEnergy;
+                } else if (minConsum >= 0 && overallEnergy < minConsum) {
+                    minConsum = overallEnergy;
                 }
             }
         }
@@ -372,7 +373,7 @@ public class HolonObject extends AbstractCpsObject {
         float tempFlex = 0;
         for (HolonElement e : getElements()) {
             if (e.isFlexible()) {
-                tempFlex += e.getFlexibleEnergyAvailable() * e.getAmount();
+                tempFlex += e.getFlexibleEnergyAvailablePerElement() * e.getAmount();
             }
         }
         this.totalFlex = tempFlex;
@@ -384,8 +385,8 @@ public class HolonObject extends AbstractCpsObject {
     public float getFlexProd() {
         float tempFlex = 0;
         for (HolonElement e : getElements()) {
-            if (e.getFlexibleEnergyAvailable() > 0) {
-                tempFlex += e.getFlexibleEnergyAvailable();
+            if (e.getFlexibleEnergyAvailablePerElement() > 0) {
+                tempFlex += e.getFlexibleEnergyAvailablePerElement() * e.getAmount();
             }
         }
         return tempFlex;
@@ -397,8 +398,8 @@ public class HolonObject extends AbstractCpsObject {
     public float getFlexCons() {
         float tempFlex = 0;
         for (HolonElement e : getElements()) {
-            if (e.getFlexibleEnergyAvailable() < 0) {
-                tempFlex += e.getFlexibleEnergyAvailable();
+            if (e.getFlexibleEnergyAvailablePerElement() < 0) {
+                tempFlex += e.getFlexibleEnergyAvailablePerElement() * e.getAmount();
             }
         }
         return tempFlex;
@@ -418,10 +419,10 @@ public class HolonObject extends AbstractCpsObject {
             float valueCons = 0;
             for (HolonElement e : getElements()) {
                 if (e.isActive() && e.getSign() == '+') {
-                    valueProd = valueProd + e.getTotalEnergyAtTimeStep(i);
+                    valueProd = valueProd + e.getOverallEnergyAtTimeStep(i);
                 }
                 if (e.isActive() && e.getSign() == '-') {
-                    valueCons = valueCons + e.getTotalEnergyAtTimeStep(i);
+                    valueCons = valueCons + e.getOverallEnergyAtTimeStep(i);
                 }
             }
             tempProd[i] = valueProd;
@@ -430,4 +431,45 @@ public class HolonObject extends AbstractCpsObject {
         this.trackingProd = tempProd;
         this.trackingCons = tempCons;
     }
+
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append("[HolonObject: ");
+        sb.append("id=").append(id)
+                .append(", name=").append(name)
+                .append(", state=");
+        switch (state) {
+            case NO_ENERGY:
+                sb.append("NO_ENERGY");
+                break;
+            case NOT_SUPPLIED:
+                sb.append("NOT_SUPPLIED");
+                break;
+            case SUPPLIED:
+                sb.append("SUPPLIED");
+                break;
+            case PRODUCER:
+                sb.append("PRODUCER");
+                break;
+            case PARTIALLY_SUPPLIED:
+                sb.append("PARTIALLY_SUPPLIED");
+                break;
+            case OVER_SUPPLIED:
+                sb.append("OVER_SUPPLIED");
+                break;
+        }
+        sb.append(", elements=[");
+        for (int i = 0; i < getElements().size(); i++) {
+            HolonElement el = getElements().get(i);
+            if (i != 0) {
+                sb.append(", ");
+            }
+            sb.append(el.getEleName());
+        }
+        sb.append("]]");
+
+        return sb.toString();
+    }
 }

+ 45 - 0
src/classes/SubNet.java

@@ -53,4 +53,49 @@ public class SubNet {
 	public ArrayList<HolonSwitch> getSwitches() {
 		return subNetSwitches;
 	}
+
+
+    public String toString(int timeStep) {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append("  Objects:");
+        for (int j = 0; j < getObjects().size(); j++) {
+            HolonObject hl = getObjects().get(j);
+            sb.append("    " + hl.getName() + " " + hl.getId());
+        }
+        System.out.println("  Edges:");
+        for (int j = 0; j < getEdges().size(); j++) {
+            CpsEdge edge = getEdges().get(j);
+            sb.append("     " + edge.getA().getName() + " connected To " + edge.getB().getName());
+        }
+        System.out.println("  Switches:");
+        for (int j = 0; j < getSwitches().size(); j++) {
+            HolonSwitch sw = getSwitches().get(j);
+            sb.append("    " + sw.getName() + " " + sw.getId() + " State:" + sw.getActiveAt()[timeStep]);
+        }
+
+        return sb.toString();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append("  Objects:");
+        for (int j = 0; j < getObjects().size(); j++) {
+            HolonObject hl = getObjects().get(j);
+            sb.append("    " + hl.getName() + " " + hl.getId());
+        }
+        System.out.println("  Edges:");
+        for (int j = 0; j < getEdges().size(); j++) {
+            CpsEdge edge = getEdges().get(j);
+            sb.append("     " + edge.getA().getName() + " connected To " + edge.getB().getName());
+        }
+        System.out.println("  Switches:");
+        for (int j = 0; j < getSwitches().size(); j++) {
+            HolonSwitch sw = getSwitches().get(j);
+            sb.append("    " + sw.getName() + " " + sw.getId() + " State:" + sw.getActiveAt());
+        }
+
+        return sb.toString();
+    }
 }

+ 8 - 8
src/tests/PraktikumHolonsTestClasses.java

@@ -184,18 +184,18 @@ public class PraktikumHolonsTestClasses {
 		HolonElement ele2 = new HolonElement("Fridge", 1, -50);
 		HolonElement ele3 = new HolonElement(ele2);
 
-		assertTrue("Array not empty", ele1.getEnergyAt()[0] == -20);
-		assertTrue("Array not empty", ele1.getEnergyAt()[2] == -20);
-		ele1.setEnergyAt(2, -10);
-		assertTrue("Array not empty", ele1.getEnergyAt()[2] == -10);
-		assertTrue("Name not correct", ele1.getEleName().equals("TV"));
-		ele1.setEleName(ele2.getEleName());
+        assertTrue("Array not empty", ele1.getAvailableEnergyPerElementAt()[0] == -20);
+        assertTrue("Array not empty", ele1.getAvailableEnergyPerElementAt()[2] == -20);
+        ele1.setAvailableEnergyPerElementAt(2, -10);
+        assertTrue("Array not empty", ele1.getAvailableEnergyPerElementAt()[2] == -10);
+        assertTrue("Name not correct", ele1.getEleName().equals("TV"));
+        ele1.setEleName(ele2.getEleName());
 		assertTrue("Name not correct", ele1.getEleName().equals("Fridge"));
 		assertTrue("Amount not correct", ele2.getAmount() == 1);
 		ele2.setAmount(5);
 		assertTrue("Amount not correct", ele2.getAmount() == 5);
-		assertTrue("Total Energy not Correct", ele2.getTotalEnergy() == ele2.getAmount() * ele2.getEnergy());
-		assertTrue("Sign not correct", ele2.getSign() == '-');
+        assertTrue("Total Energy not Correct", ele2.getOverallEnergy() == ele2.getAmount() * ele2.getEnergyPerElement());
+        assertTrue("Sign not correct", ele2.getSign() == '-');
 //		ele3.setSav("CVS");
 //		assertTrue("SAV not correct", ele3.getSav().equals("CVS"));
 	}

+ 12 - 12
src/ui/controller/HolonCanvasController.java

@@ -100,10 +100,10 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getEnergyAt()[tStep] > 0 && ele.isActive()) {
-                        val += ele.getEnergyAt()[tStep] * ele.getAmount();
-					}
-				}
+                    if (ele.getAvailableEnergyPerElementAt()[tStep] > 0 && ele.isActive()) {
+                        val += ele.getAvailableEnergyPerElementAt()[tStep] * ele.getAmount();
+                    }
+                }
 				if (val > 0)
 					prod += 1;
 			} else if (obj instanceof CpsUpperNode) {
@@ -131,10 +131,10 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getEnergyAt()[tStep] < 0 && ele.isActive()) {
-                        val += ele.getEnergyAt()[tStep] * ele.getAmount();
-					}
-				}
+                    if (ele.getAvailableEnergyPerElementAt()[tStep] < 0 && ele.isActive()) {
+                        val += ele.getAvailableEnergyPerElementAt()[tStep] * ele.getAmount();
+                    }
+                }
 			} else if (obj instanceof CpsUpperNode) {
 				val += getTotalConsumption(((CpsUpperNode) obj).getNodes());
 			}
@@ -148,10 +148,10 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getEnergyAt()[tStep] > 0 && ele.isActive()) {
-                        val += ele.getEnergyAt()[tStep] * ele.getAmount();
-					}
-				}
+                    if (ele.getAvailableEnergyPerElementAt()[tStep] > 0 && ele.isActive()) {
+                        val += ele.getAvailableEnergyPerElementAt()[tStep] * ele.getAmount();
+                    }
+                }
 			} else if (obj instanceof CpsUpperNode) {
 				val += getTotalProduction(((CpsUpperNode) obj).getNodes());
 			}

+ 46 - 62
src/ui/controller/LoadController.java

@@ -1,41 +1,26 @@
 package ui.controller;
 
-import java.awt.Point;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import classes.*;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.apache.commons.compress.utils.IOUtils;
+import ui.model.Model;
+
+import java.awt.*;
+import java.io.*;
 import java.nio.file.Files;
 import java.nio.file.StandardCopyOption;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Hashtable;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.zip.ZipException;
-import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveException;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
-import org.apache.commons.compress.archivers.ArchiveStreamFactory;
-import org.apache.commons.compress.utils.IOUtils;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import classes.Category;
-import classes.CpsEdge;
-import classes.CpsUpperNode;
-import classes.AbstractCpsObject;
-import classes.HolonElement;
-import classes.HolonObject;
-import classes.HolonSwitch;
-import classes.IdCounter;
-import classes.IdCounterElem;
-import ui.model.Model;
 
 /**
  * Controller for the Loading.
@@ -43,21 +28,6 @@ import ui.model.Model;
  * @author Gruppe14
  */
 public class LoadController {
-	/**
-	 * enum Mode.
-	 */
-	public enum MODE {
-		COMPLETE, PARTIAL, CATEGORY
-	}
-
-	public enum EDGETYPE {
-		CANVAS, CONNECTION, NODE, OLD
-	}
-
-	public enum GRAPHTYPE {
-		SWITCH, ELEMENT
-	}
-
 	private Model model;
 	private CategoryController cgC;
 	private CanvasController cvsC;
@@ -65,10 +35,9 @@ public class LoadController {
 	private NodeController uppC;
 	private MultiPurposeController mpC;
 	private JsonParser parser;
-
 	/**
 	 * Constructor.
-	 * 
+	 *
 	 * @param model
 	 *            Model
 	 * @param cg
@@ -93,7 +62,7 @@ public class LoadController {
 
 	/**
 	 * Reads the the JSON File and load the state into the Model.
-	 * 
+	 *
 	 * @param path
 	 *            the Path
 	 * @throws IOException
@@ -129,7 +98,7 @@ public class LoadController {
 
 	/**
 	 * Loads the Files from the Savefile
-	 * 
+	 *
 	 * @param folder
 	 * @param trim
 	 * @throws IOException
@@ -154,7 +123,7 @@ public class LoadController {
 
 	/**
 	 * distribute the Edges
-	 * 
+	 *
 	 * @param edges
 	 * @param json
 	 * @param objDispatch
@@ -183,7 +152,7 @@ public class LoadController {
 
 	/**
 	 * Distribute the given keys for right processing
-	 * 
+	 *
 	 * @param keys
 	 * @param json
 	 * @param objDispatch
@@ -217,7 +186,7 @@ public class LoadController {
 
 	/**
 	 * Init the Global Parameters
-	 * 
+	 *
 	 * @param keys
 	 * @param json
 	 */
@@ -258,7 +227,7 @@ public class LoadController {
 
 	/**
 	 * Load a given Category
-	 * 
+	 *
 	 * @param jsonElement
 	 */
 	private void loadCategory(JsonElement jsonElement) {
@@ -269,7 +238,7 @@ public class LoadController {
 
 	/**
 	 * Load a given Object in Category by Deserialization
-	 * 
+	 *
 	 * @param jsonElement
 	 */
 	private void loadCategoryObject(JsonElement jsonElement) {
@@ -286,7 +255,7 @@ public class LoadController {
 
 	/**
 	 * Load a given Element in Category by Deserialization
-	 * 
+	 *
 	 * @param jsonElement
 	 */
 	private void loadCategoryElements(JsonElement jsonElement) {
@@ -299,7 +268,7 @@ public class LoadController {
 
 	/**
 	 * Load a given Object in Canvas by Deserialization
-	 * 
+	 *
 	 * @param jsonElement
 	 * @param objDispatch
 	 */
@@ -328,7 +297,7 @@ public class LoadController {
 
 	/**
 	 * Load a given Element in Canvas by Deserialization
-	 * 
+	 *
 	 * @param jsonElement
 	 * @param objDispatch
 	 * @param eleDispatch
@@ -353,7 +322,7 @@ public class LoadController {
 
 	/**
 	 * Load a given Edge by Deserialization
-	 * 
+	 *
 	 * @param type
 	 * @param jsonElement
 	 * @param objDispatch
@@ -404,7 +373,7 @@ public class LoadController {
 
 	/**
 	 * Load a Unitgraph by Deserialization
-	 * 
+	 *
 	 * @param type
 	 * @param jsonElement
 	 * @param objDispatch
@@ -530,7 +499,7 @@ public class LoadController {
 
 	/**
 	 * Init new Arrays which havent been serialized along the object
-	 * 
+	 *
 	 * @param obj
 	 */
 	public void initObjects(AbstractCpsObject obj) {
@@ -561,18 +530,18 @@ public class LoadController {
 
 	/**
 	 * Init Elements
-	 * 
+	 *
 	 * @param ele
 	 */
 	public void initElements(HolonElement ele) {
 
-		ele.setEnergyAt(ele.getEnergy());
+		ele.setAvailableEnergyPerElementAt(ele.getEnergyPerElement());
 		ele.setGraphPoints(new LinkedList<Point>());
 	}
 
 	/**
 	 * Init Edges
-	 * 
+	 *
 	 * @param edge
 	 */
 	public void initCpsEdge(CpsEdge edge) {
@@ -584,7 +553,7 @@ public class LoadController {
 
 	/**
 	 * Get Set of Keys
-	 * 
+	 *
 	 * @param json
 	 * @return
 	 */
@@ -592,4 +561,19 @@ public class LoadController {
 		return json.entrySet().stream().map(i -> i.getKey()).collect(Collectors.toCollection(ArrayList::new));
 	}
 
+	/**
+	 * enum Mode.
+	 */
+	public enum MODE {
+		COMPLETE, PARTIAL, CATEGORY
+	}
+
+	public enum EDGETYPE {
+		CANVAS, CONNECTION, NODE, OLD
+	}
+
+	public enum GRAPHTYPE {
+		SWITCH, ELEMENT
+	}
+
 }

+ 47 - 51
src/ui/controller/SimulationManager.java

@@ -54,14 +54,14 @@ public class SimulationManager {
         for (SubNet singleSubNet : subNets) {
             float production = calculateEnergy("prod", singleSubNet, timeStep);
             float consumption = calculateEnergy("cons", singleSubNet, timeStep);
-            // wasted energy is computed by sum, since consumption is a negative value
-            float wastedEnergy = production + consumption;
+            // surplus of energy is computed by sum, since consumption is a negative value
+            float energySurplus = production + consumption;
 
             float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
 
             // --------------- use flexible devices ---------------
-            if (wastedEnergy > 0 && model.useFlexibleDevices()) {
-                turnOnFlexibleDevices(singleSubNet, wastedEnergy);
+            if (energySurplus != 0 && model.useFlexibleDevices()) {
+                turnOnFlexibleDevices(singleSubNet, energySurplus, x);
 
                 if (!flexDevicesTurnedOnThisTurn.isEmpty()) {
                     System.out.println("The following devices were turned on in this turn: ");
@@ -71,7 +71,7 @@ public class SimulationManager {
                 // recompute after having examined/turned on all flexible devices
                 production = calculateEnergy("prod", singleSubNet, timeStep);
                 consumption = calculateEnergy("cons", singleSubNet, timeStep);
-                wastedEnergy = production + consumption;
+                energySurplus = production + consumption;
             }
 
             // --------------- set flow simulation ---------------
@@ -86,7 +86,7 @@ public class SimulationManager {
                         if (edge.isWorking() && edge.getFlow() > 0
                                 || edge.getCapacity() == CpsEdge.CAPACITY_INFINITE) {
                             if ((production + consumption) >= 0) {
-                                if (wastedEnergy > 0) {
+                                if (energySurplus > 0) {
                                     hl.setState(HolonObject.OVER_SUPPLIED);
                                 } else {
                                     hl.setState(HolonObject.SUPPLIED);
@@ -119,33 +119,46 @@ public class SimulationManager {
      * search for all flexible devices in the network and turn them on, until wasted energy = 0
      * or all devices have been examined
      *
-     * @param subNet       the subnet
-     * @param wastedEnergy the currently wasted energy
+     * @param subNet        the subnet
+     * @param energySurplus the current surplus of energy
      */
-    private void turnOnFlexibleDevices(SubNet subNet, float wastedEnergy) {
+    private void turnOnFlexibleDevices(SubNet subNet, float energySurplus, int timestep) {
         for (HolonObject holonOb : subNet.getObjects()) {
             for (HolonElement holonEl : holonOb.getElements()) {
-                // if this element is flexible
-                float actuallyUsedEnergy = holonEl.isActive() ? holonEl.getEnergy() : 0;
-                float energyAvailable = holonEl.getFlexibleEnergyAvailable() - actuallyUsedEnergy;
-                if (holonEl.isFlexible() && energyAvailable < 0) {
-                    // if there is more wasted Energy than energy that this device can give
-                    if (Math.abs(energyAvailable) <= Math.abs(wastedEnergy)) {
-                        holonEl.setActive(true);
-                        wastedEnergy += energyAvailable;
-                        holonEl.setEnergy(energyAvailable);
-                        flexDevicesTurnedOnThisTurn.put(holonEl, energyAvailable);
-                    }
-                    // else if we just need to turn on part of the flexible energy available
-                    else {
-                        holonEl.setActive(true);
-                        float energyNeeded = -wastedEnergy;
-                        wastedEnergy += energyNeeded;   // should give 0, but was kept this was for consistency
-                        holonEl.setEnergy(energyNeeded);
-                        flexDevicesTurnedOnThisTurn.put(holonEl, energyNeeded);
+
+                if (holonEl.isFlexible() && holonEl.isActive()) {
+                    // if this element is flexible
+                    float actuallyUsedEnergy = holonEl.getEnergyPerElement();
+                    float energyAvailable = holonEl.getAvailableEnergyAt(timestep) - actuallyUsedEnergy;
+
+                    // ------------- flexible consumer -------------
+                    if (energyAvailable < 0 && energySurplus > 0) {
+//                        System.out.println("flexible consumer in " + subNet.toString(timestep));
+                        // if there is more wasted Energy than energy that this device can give
+                        if (Math.abs(energyAvailable) <= Math.abs(energySurplus)) {
+                            energySurplus += energyAvailable;
+                            // set the new energy consumption to the maximum
+                            holonEl.setEnergyPerElement(holonEl.getAvailableEnergyAt(timestep));
+                            flexDevicesTurnedOnThisTurn.put(holonEl, energyAvailable);
+                        }
+                        // else if we just need to turn on part of the flexible energy available
+                        else {
+                            float energyNeeded = -energySurplus;
+                            energySurplus += energyNeeded;   // should give 0, but was kept this was for consistency
+                            // add to the currently used energy the energy needed divided through the amount of elements
+                            float newEnergyConsumption = holonEl.getEnergyPerElement() + energyNeeded / holonEl.getAmount();
+                            holonEl.setEnergyPerElement(newEnergyConsumption);
+                            flexDevicesTurnedOnThisTurn.put(holonEl, energyNeeded);
+                        }
+
+                        System.out.println("One element was turned on, wastedEnergy after: " + energySurplus + "\n");
                     }
 
-                    System.out.println("One element was turned on, wastedEnergy after: " + wastedEnergy + "\n");
+                    // ------------- flexible producer -------------
+                    else if (energyAvailable > 0 && energySurplus < 0) {
+                        // System.out.println("flexible producer in " + subNet.toString(timestep));
+                        // TODO
+                    }
                 }
             }
         }
@@ -347,12 +360,13 @@ public class SimulationManager {
         float min = 0;
         float minElement = 0;
         for (HolonObject hl : sN.getObjects()) {
-            if (hl.getElements().size() > 0 && hl.getElements().get(0).getTotalEnergyAtTimeStep(x) < 0) {
-                minElement = hl.getElements().get(0).getTotalEnergyAtTimeStep(x);
+            if (hl.getElements().size() > 0 && hl.getElements().get(0).getOverallEnergyAtTimeStep(x) < 0) {
+                minElement = hl.getElements().get(0).getOverallEnergyAtTimeStep(x);
             }
             for (HolonElement he : hl.getElements()) {
-                if (minElement < he.getTotalEnergyAtTimeStep(x) && he.getTotalEnergyAtTimeStep(x) < 0) {
-                    minElement = he.getTotalEnergyAtTimeStep(x);
+                float overallEnergy = he.getOverallEnergyAtTimeStep(x);
+                if (minElement < overallEnergy && overallEnergy < 0) {
+                    minElement = overallEnergy;
                 }
             }
             min = min + minElement;
@@ -497,25 +511,7 @@ public class SimulationManager {
         for (int i = 0; i < subNets.size(); i++) {
             SubNet subNet = subNets.get(i);
             System.out.println("SUBNET NR:" + i);
-            printSingleNetToConsole(subNet);
-        }
-    }
-
-    private void printSingleNetToConsole(SubNet subNet) {
-        System.out.println("  Objects:");
-        for (int j = 0; j < subNet.getObjects().size(); j++) {
-            HolonObject hl = subNet.getObjects().get(j);
-            System.out.println("    " + hl.getName() + " " + hl.getId());
-        }
-        System.out.println("  Edges:");
-        for (int j = 0; j < subNet.getEdges().size(); j++) {
-            CpsEdge edge = subNet.getEdges().get(j);
-            System.out.println("     " + edge.getA().getName() + " connected To " + edge.getB().getName());
-        }
-        System.out.println("  Switches:");
-        for (int j = 0; j < subNet.getSwitches().size(); j++) {
-            HolonSwitch sw = subNet.getSwitches().get(j);
-            System.out.println("    " + sw.getName() + " " + sw.getId() + " State:" + sw.getActiveAt()[timeStep]);
+            subNet.toString(timeStep);
         }
     }
 

+ 3 - 3
src/ui/controller/UpdateController.java

@@ -58,8 +58,8 @@ public class UpdateController {
 			for (AbstractCpsObject o : objects) {
 				if (o instanceof HolonObject) {
 					for (HolonElement he : ((HolonObject) o).getElements()) {
-						Object[] temp = { o.getName() + ", " + o.getId(), he.getId(), he.getEleName(), he.getEnergy(),
-								he.getFlexibleEnergyAvailable(), he.getAmount(), he.isActive(), he.isFlexible()};
+						Object[] temp = {o.getName() + ", " + o.getId(), he.getId(), he.getEleName(), he.getEnergyPerElement(),
+								he.getFlexibleEnergyAvailablePerElement(), he.getAmount(), he.isActive(), he.isFlexible()};
 						table.addRow(temp);
 					}
 				}
@@ -68,7 +68,7 @@ public class UpdateController {
 			AbstractCpsObject o = objects.get(0);
 			if (o instanceof HolonObject) {
 				for (HolonElement he : ((HolonObject) o).getElements()) {
-					Object[] temp = {he.getId(), he.getEleName(), he.getEnergy(), he.getFlexibleEnergyAvailable(), he.getAmount(),
+					Object[] temp = {he.getId(), he.getEleName(), he.getEnergyPerElement(), he.getFlexibleEnergyAvailablePerElement(), he.getAmount(),
 							he.isActive(), he.isFlexible()};
                     table.addRow(temp);
 				}

+ 36 - 53
src/ui/view/AddObjectPopUp.java

@@ -1,36 +1,21 @@
 package ui.view;
 
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.FlowLayout;
-import java.awt.Image;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URLDecoder;
-import java.security.CodeSource;
-import java.util.ArrayList;
-
-import javax.swing.*;
-import javax.swing.border.EmptyBorder;
-import javax.swing.filechooser.FileNameExtensionFilter;
-
 import classes.AbstractCpsObject;
 import classes.HolonElement;
 import classes.HolonObject;
 import classes.Pair;
 import ui.controller.Control;
 
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.net.URLDecoder;
+import java.security.CodeSource;
+import java.util.ArrayList;
+
 /**
  * Popup for adding a Holon Object to a Category.
  * 
@@ -310,15 +295,38 @@ public class AddObjectPopUp extends JDialog {
 		}
 	}
 
+	/**
+	 * Get Jar Containing Folder.
+	 *
+	 * @param aclass aClass
+	 * @return String
+	 * @throws Exception Exception
+	 */
+	public static String getJarContainingFolder(Class aclass) throws Exception {
+		CodeSource codeSource = aclass.getProtectionDomain().getCodeSource();
+
+		File jarFile;
+
+		if (codeSource.getLocation() != null) {
+			jarFile = new File(codeSource.getLocation().toURI());
+		} else {
+			String path = aclass.getResource(aclass.getSimpleName() + ".class").getPath();
+			String jarFilePath = path.substring(path.indexOf(":") + 1, path.indexOf("!"));
+			jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
+			jarFile = new File(jarFilePath);
+		}
+		return jarFile.getParentFile().getAbsolutePath();
+	}
+
 	/**
 	 * adds a Holon Element.
-	 * 
+	 *
 	 * @param hl
 	 *            the HolonElement
 	 */
 	public void addElement(HolonElement hl) {
 		hElements.add(hl);
-		listModel.addElement(hl.getAmount() + "x: " + hl.getEleName() + " " + hl.getEnergy() + "U");
+		listModel.addElement(hl.getAmount() + "x: " + hl.getEleName() + " " + hl.getEnergyPerElement() + "U");
 	}
 
 	/**
@@ -378,7 +386,7 @@ public class AddObjectPopUp extends JDialog {
 
 	/**
 	 * Edit the Information.
-	 * 
+	 *
 	 * @param obj
 	 *            the CpsObject
 	 */
@@ -386,31 +394,6 @@ public class AddObjectPopUp extends JDialog {
 		objectName.setText(obj.getName());
 	}
 
-	/**
-	 * Get Jar Containing Folder.
-	 * 
-	 * @param aclass
-	 *            aClass
-	 * @return String
-	 * @throws Exception
-	 *             Exception
-	 */
-	public static String getJarContainingFolder(Class aclass) throws Exception {
-		CodeSource codeSource = aclass.getProtectionDomain().getCodeSource();
-
-		File jarFile;
-
-		if (codeSource.getLocation() != null) {
-			jarFile = new File(codeSource.getLocation().toURI());
-		} else {
-			String path = aclass.getResource(aclass.getSimpleName() + ".class").getPath();
-			String jarFilePath = path.substring(path.indexOf(":") + 1, path.indexOf("!"));
-			jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
-			jarFile = new File(jarFilePath);
-		}
-		return jarFile.getParentFile().getAbsolutePath();
-	}
-
 	/**
 	 * Return the Object.
 	 * 

+ 5 - 6
src/ui/view/GUI.java

@@ -852,7 +852,7 @@ public class GUI implements CategoryListener {
                     HolonElement ele = addElementPopUp.getElement();
                     if (ele != null) {
                         controller.addElementCanvasObject(tempCpsObject.getId(), ele.getEleName(), ele.getAmount(),
-                                ele.getEnergy(), ele.getId());
+                                ele.getEnergyPerElement(), ele.getId());
                     }
                     updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
                     updCon.refreshTableProperties(model.getPropertyTable());
@@ -1005,7 +1005,7 @@ public class GUI implements CategoryListener {
                             // Energy Update
                             else if (selectedValueX == 3) {
                                 Float ftemp = Float.parseFloat(newStuff);
-                                eleTemp.setEnergy(ftemp);
+                                eleTemp.setEnergyPerElement(ftemp);
                             }
                             // Flexibility
                             else if (selectedValueX == 4) {
@@ -1056,7 +1056,7 @@ public class GUI implements CategoryListener {
                             } // Energy Update
                             else if (selectedValueX == 2) {
                                 Float ftemp = Float.parseFloat(newStuff);
-                                eleTemp.setEnergy(ftemp);
+                                eleTemp.setEnergyPerElement(ftemp);
                             } // Flexibility
                             else if (selectedValueX == 3) {
                                 Float ftemp = Float.parseFloat(newStuff);
@@ -1731,7 +1731,6 @@ public class GUI implements CategoryListener {
         timePanel = new TimePanel(model, controller);
         timePanel.setBorder(null);
         ((JSlider) (timePanel.getComponent(1))).addChangeListener(changeEvent -> {
-            System.out.println("Hi");
             int i = model.getCurIteration();
             controller.calculateStateForTimeStep(i);
             unitGraph.repaint();
@@ -2250,8 +2249,8 @@ public class GUI implements CategoryListener {
         model.getSingleTable().setValueAt(eleBTemp.isFlexible(), selectedValueBY, 6);
         model.getSingleTable().setValueAt(eleBTemp.isActive(), selectedValueBY, 5);
         model.getSingleTable().setValueAt(eleBTemp.getAmount(), selectedValueBY, 4);
-        model.getSingleTable().setValueAt(eleBTemp.getFlexibleEnergyAvailable(), selectedValueBY, 3);
-        model.getSingleTable().setValueAt(eleBTemp.getEnergy(), selectedValueBY, 2);
+        model.getSingleTable().setValueAt(eleBTemp.getFlexibleEnergyAvailablePerElement(), selectedValueBY, 3);
+        model.getSingleTable().setValueAt(eleBTemp.getEnergyPerElement(), selectedValueBY, 2);
     }
 
     /**

+ 0 - 1
src/ui/view/MyCanvas.java

@@ -293,7 +293,6 @@ public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMoti
                 unitGraph.update(model.getSelectedCpsObjects());
 
             } catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
-                // TODO Auto-generated catch block
                 JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
                 JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
             }

+ 19 - 19
src/ui/view/StatisticGraph.java

@@ -165,7 +165,7 @@ public class StatisticGraph extends JPanel {
         float temp = 0;
         for (HolonElement e : obj.getElements()) {
             if (e.isActive()) {
-                temp = temp + e.getEnergyAt()[model.getCurIteration()];
+                temp = temp + e.getAvailableEnergyPerElementAt()[model.getCurIteration()];
             }
         }
         return temp;
@@ -181,16 +181,16 @@ public class StatisticGraph extends JPanel {
             switch (set.getProperty()) {
                 case TrackedDataSet.CONSUMPTION:
                     for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
-                        if (h.getEnergy() < 0) {
-                            val += (h.getEnergy() + h.getFlexibleEnergyAvailable()) * h.getAmount();
+                        if (h.getEnergyPerElement() < 0) {
+                            val += (h.getEnergyPerElement() + h.getFlexibleEnergyAvailablePerElement()) * h.getAmount();
                         }
                     }
                     val *= -1;
                     break;
                 case TrackedDataSet.PRODUCTION:
                     for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
-                        if (h.getEnergy() > 0) {
-                            val += (h.getEnergy() + h.getFlexibleEnergyAvailable()) * h.getAmount();
+                        if (h.getEnergyPerElement() > 0) {
+                            val += (h.getEnergyPerElement() + h.getFlexibleEnergyAvailablePerElement()) * h.getAmount();
                         }
                     }
                     break;
@@ -323,16 +323,16 @@ public class StatisticGraph extends JPanel {
             switch (set.getProperty()) {
                 case TrackedDataSet.CONSUMPTION:
                     for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
-                        if (h.getTotalEnergyAtTimeStep(model.getCurIteration()) < 0 && h.isActive()) {
-                            val += Math.abs(h.getTotalEnergyAtTimeStep(model.getCurIteration()));
+                        if (h.getOverallEnergyAtTimeStep(model.getCurIteration()) < 0 && h.isActive()) {
+                            val += Math.abs(h.getOverallEnergyAtTimeStep(model.getCurIteration()));
                         }
                         set.setValAt(val, model.getCurIteration());
                     }
                     break;
                 case TrackedDataSet.PRODUCTION:
                     for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
-                        if (h.getTotalEnergyAtTimeStep(model.getCurIteration()) > 0 && h.isActive()) {
-                            val += Math.abs(h.getTotalEnergyAtTimeStep(model.getCurIteration()));
+                        if (h.getOverallEnergyAtTimeStep(model.getCurIteration()) > 0 && h.isActive()) {
+                            val += Math.abs(h.getOverallEnergyAtTimeStep(model.getCurIteration()));
                         }
                         set.setValAt(val, model.getCurIteration());
                     }
@@ -611,8 +611,8 @@ public class StatisticGraph extends JPanel {
         for (AbstractCpsObject obj : objects) {
             if (obj instanceof HolonObject) {
                 for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getEnergy() > 0) {
-                        val += (ele.getEnergy() + ele.getFlexibleEnergyAvailable()) * ele.getAmount();
+                    if (ele.getEnergyPerElement() > 0) {
+                        val += (ele.getEnergyPerElement() + ele.getFlexibleEnergyAvailablePerElement()) * ele.getAmount();
                     }
                 }
             } else if (obj instanceof CpsUpperNode) {
@@ -631,8 +631,8 @@ public class StatisticGraph extends JPanel {
         for (AbstractCpsObject obj : objects) {
             if (obj instanceof HolonObject) {
                 for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getEnergy() < 0) {
-                        val += (ele.getEnergy() + ele.getFlexibleEnergyAvailable()) * ele.getAmount();
+                    if (ele.getEnergyPerElement() < 0) {
+                        val += (ele.getEnergyPerElement() + ele.getFlexibleEnergyAvailablePerElement()) * ele.getAmount();
                     }
                 }
             } else if (obj instanceof CpsUpperNode) {
@@ -653,7 +653,7 @@ public class StatisticGraph extends JPanel {
         for (AbstractCpsObject obj : objects) {
             if (obj instanceof HolonObject) {
                 for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    val += (ele.getEnergy() + ele.getFlexibleEnergyAvailable()) * ele.getAmount();
+                    val += (ele.getEnergyPerElement() + ele.getFlexibleEnergyAvailablePerElement()) * ele.getAmount();
                 }
             } else if (obj instanceof CpsUpperNode) {
                 val += getMaxWastedEnergy(((CpsUpperNode) obj).getNodes());
@@ -673,8 +673,8 @@ public class StatisticGraph extends JPanel {
         for (AbstractCpsObject obj : objects) {
             if (obj instanceof HolonObject) {
                 for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getTotalEnergyAtTimeStep(tStep) > 0 && ele.isActive()) {
-                        val += ele.getTotalEnergyAtTimeStep(tStep);
+                    if (ele.getOverallEnergyAtTimeStep(tStep) > 0 && ele.isActive()) {
+                        val += ele.getOverallEnergyAtTimeStep(tStep);
                     }
                 }
             } else if (obj instanceof CpsUpperNode) {
@@ -693,8 +693,8 @@ public class StatisticGraph extends JPanel {
         for (AbstractCpsObject obj : objects) {
             if (obj instanceof HolonObject) {
                 for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getEnergyAt()[tStep] < 0 && ele.isActive()) {
-                        val += ele.getTotalEnergyAtTimeStep(tStep);
+                    if (ele.getAvailableEnergyPerElementAt()[tStep] < 0 && ele.isActive()) {
+                        val += ele.getOverallEnergyAtTimeStep(tStep);
                     }
                 }
             } else if (obj instanceof CpsUpperNode) {
@@ -714,7 +714,7 @@ public class StatisticGraph extends JPanel {
             if (obj instanceof HolonObject) {
                 for (HolonElement ele : ((HolonObject) obj).getElements()) {
                     if (ele.isActive()) {
-                        val += ele.getTotalEnergyAtTimeStep(tStep);
+                        val += ele.getOverallEnergyAtTimeStep(tStep);
                     }
                 }
             } else if (obj instanceof CpsUpperNode) {

+ 13 - 5
src/ui/view/UnitGraph.java

@@ -610,12 +610,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	 *            which should be visualized
 	 */
 	public void repaintWithNewElement(ArrayList<HolonElement> selectedElement) {
-		arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getEnergyAt();
+		arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getAvailableEnergyPerElementAt();
 		tempElements = selectedElement;
 		pointList = selectedElement.get(selectedElement.size() - 1).getGraphPoints();
 		isSwitch = false;
 		isElement = true;
-		maximum = selectedElement.get(selectedElement.size() - 1).getEnergy();
+		maximum = getMaximum(selectedElement.get(selectedElement.size() - 1));
 		// First time clicked on the Element
 		if (pointList.isEmpty()) {
 			pointList.addFirst(new Point(0, 0));
@@ -697,12 +697,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	@SuppressWarnings("unchecked")
 	public void fillArrayofValue() {
 		for (HolonElement he : tempElements) {
-			maximum = he.getEnergy();
+			maximum = getMaximum(he);
 			he.setGraphPoints((LinkedList<Point>) pointList.clone());
 			for (int i = 0; i < arrayOfFloats.length; i++) {
-				he.getEnergyAt()[i] = convertToValueY(getYValueAt2((int) (i * width / (model.getIterations() - 1))));
+				he.getAvailableEnergyPerElementAt()[i] = convertToValueY(getYValueAt2((int) (i * width / (model.getIterations() - 1))));
 			}
-			arrayOfFloats = he.getEnergyAt();
+			arrayOfFloats = he.getAvailableEnergyPerElementAt();
 		}
 	}
 
@@ -846,4 +846,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
             fillArrayofBooleans();
         }
     }
+
+	float getMaximum(HolonElement ele) {
+		if (ele.isFlexible()) {
+			return ele.getFlexibleEnergyAvailablePerElement();
+		} else {
+			return ele.getEnergyPerElement();
+		}
+	}
 }