Browse Source

Begin of Cleaning

Tom Troppmann 5 years ago
parent
commit
7e9f896def

+ 13 - 133
src/classes/HolonObject.java

@@ -15,20 +15,21 @@ import javafx.util.converter.PercentageStringConverter;
  * @author Gruppe14
  */
 public class HolonObject extends AbstractCpsObject {
-    /*
-     * the constants showing a HolonObject's current state
-     * (whether it needs no energy, whether it is not supplied, fully supplied,
-     * a producer, partially supplied or over-supplied)
-     */
-	//TODO: enum
+	@Deprecated
 	enum State{
 		NO_ENERGY, NOT_SUPPLIED, SUPPLIED, PRODUCER, PARTIALLY_SUPPLIED, OVER_SUPPLIED
 	}
+	@Deprecated
     public final static int NO_ENERGY = 0;
+	@Deprecated
     public final static int NOT_SUPPLIED = 1;
+	@Deprecated
     public final static int SUPPLIED = 2;
+	@Deprecated
     public final static int PRODUCER = 3;
+	@Deprecated
     public final static int PARTIALLY_SUPPLIED = 4;
+	@Deprecated
     public final static int OVER_SUPPLIED = 5;
     
     /*
@@ -48,7 +49,8 @@ public class HolonObject extends AbstractCpsObject {
     private float[] trackingCons;
     /* Total Flexibility */
     private float totalFlex;
-    @Expose
+    @Deprecated
+    @Expose 
     private int state = 0;
     /**
      * Energy level that was supplied by other HolonObjects in the current Calculation
@@ -68,7 +70,6 @@ public class HolonObject extends AbstractCpsObject {
     public HolonObject(String objName) {
         super(objName);
         setElements(new ArrayList<>());
-        setState();
         setTrackingProd(new float[100]);
         setTrackingCons(new float[100]);
     }
@@ -81,33 +82,11 @@ public class HolonObject extends AbstractCpsObject {
     public HolonObject(AbstractCpsObject obj) {
         super(obj);
         setElements(copyElements(((HolonObject) obj).getElements()));
-        setState();
         setTrackingProd(new float[100]);
         setTrackingCons(new float[100]);
     }
 
-    /**
-     * sets the State, whether object is a producer, zero Energy, supplied,
-     * partially or over-supplied
-     */
-    public void setState() {
-        if (getMaxActiveEnergy() > 0) {
-            setState(PRODUCER);
-            stateColor = Color.lightGray;
-        } else {
-            if (getMaxActiveEnergy() == 0) {
-                setState(NO_ENERGY);
-                stateColor = Color.WHITE;
-            } else {
-                if (checkIfPartiallySupplied(0)) {
-                    stateColor = Color.yellow;
-                } else {
-                    stateColor = new Color(230, 120, 100);
-                }
-
-            }
-        }
-    }
+ 
 
     /**
      * Getter for all Elements in the HolonObject.
@@ -163,30 +142,6 @@ public class HolonObject extends AbstractCpsObject {
     
 
     
-    /**
-     * Getter for the current energy at a given timestep.
-     *
-     * @param x timestep
-     * @return corresponding energy
-     */
-    public float getCurrentEnergyAtTimeStep(int x) {
-        float cons = 0;
-        float prod = currentSupply;
-        float t;
-        for (HolonElement e : getElements()) {
-            if (e.isActive()) {
-                t = e.getOverallEnergyAtTimeStep(x);
-                if(t<0){
-                	cons+=t;
-                }else{
-                	prod+=t;
-                }
-            }
-        }
-        currentEnergy = prod + cons;
-        suppliedPercentage = prod / -cons;
-        return currentEnergy;
-    }
 
     /**
      * Getter for the current energy at a given timestep.
@@ -194,6 +149,7 @@ public class HolonObject extends AbstractCpsObject {
      * @param x timestep
      * @return corresponding energy
      */
+    @Deprecated
     public float getCurrentEnergyAtTimeStepWithoutFlexiblesAndResetFlexibles(int x) {
         float temp = 0;
         for (HolonElement e : getElements()) {
@@ -245,6 +201,7 @@ public class HolonObject extends AbstractCpsObject {
      *
      * @return state the State of the Element
      */
+    @Deprecated
     public int getState() {
         return this.state;
     }
@@ -254,6 +211,7 @@ public class HolonObject extends AbstractCpsObject {
      *
      * @param state boolean if the Object is fully supplied
      */
+    @Deprecated
     public void setState(int state) {
         this.state = state;
         switch (state) {
@@ -319,84 +277,6 @@ public class HolonObject extends AbstractCpsObject {
         return ele;
     }
 
-    /**
-     * Check if Partially Supplied.
-     *
-     * @param x current Iteration
-     * @return boolean is partially supplied
-     */
-    public boolean checkIfPartiallySupplied(int x) {
-        
-    	if (getElements().size() == 0) {
-            return false;
-        }
-        float minConsum = 0;
-        // Search for a activ element
-		for (HolonElement e : getElements()) {
-			if (e.isActive()) {
-				float overallEnergy = e.getOverallEnergyAtTimeStep(x);
-				if (overallEnergy < 0) {
-					// Is a consumer
-					minConsum = overallEnergy;
-				}
-			}
-		}
-        float prod = 0;
-        float cons = 0;
-        for (HolonElement e : getElements()) {
-            if (e.isActive()) {
-                float overallEnergy = e.getOverallEnergyAtTimeStep(x);
-                if (overallEnergy > 0) {
-                    prod += overallEnergy;
-                }else{
-                	cons += overallEnergy;
-                }
-                if (minConsum < 0 && (overallEnergy > minConsum && overallEnergy < 0)) {
-                    minConsum = overallEnergy;   
-                }
-            }
-        }
-        suppliedPercentage = -(prod + currentSupply)/cons;
-        // System.out.println("minCons: " + minConsum + " prod: " + prod);
-        if (minConsum < 0 && prod >= -minConsum) {
-            return true;
-        } else {
-            return false;
-        }
-    }
-    
-    /**
-     * 
-     * @param x
-     * @return
-     */
-    public float getSelfMadeEnergy(int x)
-    {
-    	return getElements().stream()
-    			.map(e ->(e.isActive() && e.getOverallEnergyAtTimeStep(x) > 0) ? e.getOverallEnergyAtTimeStep(x) : 0.0f)
-    			.reduce(0.0f, (a , b) -> a + b );
-    }
-    /**
-     * Calculates the minimumEnergy Needed to turn on atleast on device
-     * of this HolonObject
-     * @param timestep Timestep of the calculation
-     * @return minEnergy, -inf if no Devices are consuming power
-     */
-    public float getMinEnergy(int timestep) {
-        if (getElements().size() == 0) {
-            return Float.NEGATIVE_INFINITY;
-        }
-        float minConsum = Float.NEGATIVE_INFINITY;
-        for (HolonElement e : getElements()) {
-            if (e.isActive()) {
-                float overallEnergy = e.getOverallEnergyAtTimeStep(timestep);
-                if (minConsum < 0 && (overallEnergy > minConsum && overallEnergy < 0)) {
-                    minConsum = overallEnergy;
-                } 
-            }
-        }
-        return minConsum;
-    }
   
     
     

+ 4 - 4
src/classes/comparator/EnergyMinToMaxComparator.java

@@ -24,10 +24,10 @@ public class EnergyMinToMaxComparator implements Comparator<HolonObject> {
 
 	@Override
 	public int compare(HolonObject o1, HolonObject o2) {
-		float minEnergy1 = o1.getMinEnergy(timeStep);
-		float minEnergy2 = o2.getMinEnergy(timeStep);
-		float totalEnergy1 = o1.getCurrentEnergyAtTimeStep(timeStep);
-		float totalEnergy2 = o2.getCurrentEnergyAtTimeStep(timeStep);
+		float minEnergy1 = o1.getMinimumConsumingElementEnergy(timeStep);
+		float minEnergy2 = o2.getMinimumConsumingElementEnergy(timeStep);
+		float totalEnergy1 = o1.getEnergyAtTimeStep(timeStep);
+		float totalEnergy2 = o2.getEnergyAtTimeStep(timeStep);
 		float difference1 = totalEnergy1 - minEnergy1;
 		float difference2 = totalEnergy2 - minEnergy2;
 		if(difference1 < difference2)

+ 2 - 2
src/classes/comparator/MinEnergyComparator.java

@@ -23,8 +23,8 @@ public class MinEnergyComparator implements Comparator<HolonObject> {
 
 	@Override
 	public int compare(HolonObject o1, HolonObject o2) {
-		float minEnergy1 = o1.getMinEnergy(timeStep);
-		float minEnergy2 = o2.getMinEnergy(timeStep);
+		float minEnergy1 = o1.getMinimumConsumingElementEnergy(timeStep);
+		float minEnergy2 = o2.getMinimumConsumingElementEnergy(timeStep);
 		if(minEnergy1<minEnergy2)
 			return 1;
 		else if (minEnergy1 == minEnergy2) 

+ 2 - 2
src/classes/comparator/TotalEnergyComparator.java

@@ -23,8 +23,8 @@ public class TotalEnergyComparator implements Comparator<HolonObject> {
 
 	@Override
 	public int compare(HolonObject o1, HolonObject o2) {
-		float totalEnergy1 = o1.getCurrentEnergyAtTimeStep(timeStep);
-		float totalEnergy2 = o2.getCurrentEnergyAtTimeStep(timeStep);
+		float totalEnergy1 = o1.getEnergyAtTimeStep(timeStep);
+		float totalEnergy2 = o2.getEnergyAtTimeStep(timeStep);
 		if(totalEnergy1<totalEnergy2)
 			return -1;
 		else if (totalEnergy1 == totalEnergy2) 

+ 2 - 2
src/ui/controller/SimulationManager.java

@@ -531,7 +531,7 @@ public class SimulationManager {
 		tagTable = new HashMap<>();
 		// traverse all objects in this subnet
 		for (HolonObject hl : sN.getObjects()) {
-			float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
+			float energy = hl.getEnergyAtTimeStep(timeStep);
 			// if their production is higher than their consumption
 			if (energy > 0) {
 				tagTable.put(hl.getId(), energy);
@@ -740,7 +740,7 @@ public class SimulationManager {
 	private float calculateEnergyWithFlexDevices(String type, SubNet sN, int x) {
 		float energy = 0;
 		for (HolonObject hl : sN.getObjects()) {
-			float currentEnergy = hl.getCurrentEnergyAtTimeStep(x);
+			float currentEnergy = hl.getEnergyAtTimeStep(x);
 
 			if (type.equals("prod")) {
 				if (currentEnergy > 0) {

+ 2 - 2
src/ui/view/AbstractCanvas.java

@@ -348,7 +348,7 @@ public abstract class AbstractCanvas extends JPanel {
 				
 				if (showedInformation[1] && cps instanceof HolonObject) {
 					g2.setColor(Color.BLACK);
-					float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
+					float totalEnergy = ((HolonObject) cps).getEnergyAtTimeStep(model.getCurIteration());
 					g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
 							cps.getPosition().y - controller.getScaleDiv2() - 10);
 				}else if (showedInformation[1] && cps instanceof HolonBattery)
@@ -367,7 +367,7 @@ public abstract class AbstractCanvas extends JPanel {
 
 				if (showedInformation[1]) {
 					g2.setColor(Color.BLACK);
-					float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
+					float totalEnergy = ((HolonObject) cps).getEnergyAtTimeStep(model.getCurIteration());
 					g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
 							cps.getPosition().y - controller.getScaleDiv2() - 10);
 				}

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

@@ -425,7 +425,7 @@ public class StatisticGraph extends JPanel {
                 case TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS:
                     for (SubNet sub : controller.getSimManager().getSubNets()) {
                         for (HolonObject obj : sub.getObjects()) {
-                            if (obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) > 0) {
+                            if (obj.getEnergyAtTimeStep(model.getCurIteration()) > 0) {
                                 val++;
                             }
                         }
@@ -466,9 +466,9 @@ public class StatisticGraph extends JPanel {
                     float cons = 0;
                     for (SubNet sub : controller.getSimManager().getSubNets()) {
                         for (HolonObject obj : sub.getObjects()) {
-                            if (obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) > 0) {
+                            if (obj.getEnergyAtTimeStep(model.getCurIteration()) > 0) {
                                 prod++;
-                            } else if (obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) < 0) {
+                            } else if (obj.getEnergyAtTimeStep(model.getCurIteration()) < 0) {
                                 cons++;
                             }
                         }

+ 6 - 34
tests/tests/PraktikumHolonsTestClasses.java

@@ -64,7 +64,7 @@ public class PraktikumHolonsTestClasses {
 		test2.setElements(arr);
 		assertTrue("Should not be Empty", !test2.getElements().isEmpty());
 		assertTrue("Current Energy not corrent", test2.getMaxActiveEnergy() == 20);
-		assertTrue("Current Energy not corrent", test2.getCurrentEnergyAtTimeStep(20) == 20);
+		assertTrue("Current Energy not corrent", test2.getEnergyAtTimeStep(20) == 20);
 		String str = test2.toStringElements();
 		assertTrue("String not corrent", str.equals("Element, Element"));
 		test2.deleteElement(0);
@@ -72,36 +72,9 @@ public class PraktikumHolonsTestClasses {
 		assertTrue("Current Energy not corrent", test2.getMaxActiveEnergy() == 20);
 		assertTrue("Should be Empty", test3.getElements().isEmpty());
 		test3.setElements(test2.copyElements(test2.getElements()));
-		assertTrue("Should be Empty", !test3.getElements().isEmpty());
-		assertTrue("Should be state 0", test3.getState() == 0);
-		test3.setState(1);
-		assertTrue("Should be state 1", test3.getState() == 1);
-		test3.setState(2);
-		assertTrue("Should be state 2", test3.getState() == 2);
-		test3.setState(3);
-		assertTrue("Should be state 3", test3.getState() == 3);
-		test3.setState(4);
-		assertTrue("Should be state 4", test3.getState() == 4);
+		
 		assertTrue("Element not Found", test3.searchElement("Element") != null);
 		test1.setElements(new ArrayList<>());
-		assertTrue("Not Empty", !test1.checkIfPartiallySupplied(1));
-		test3.addElement(new HolonElement("Element2", 1, -10, IdCounterElem.nextId(),null));
-		assertTrue("Not Partially Supplied", test3.checkIfPartiallySupplied(1));
-		test3.addElement(new HolonElement("Element2", 2, -10, IdCounterElem.nextId(),null));
-		assertTrue("Not Partially Supplied", test3.checkIfPartiallySupplied(1));
-		test1.addElement(new HolonElement("Element2", 2, -10, IdCounterElem.nextId(),null));
-		assertTrue("minSupply < 0", !test1.checkIfPartiallySupplied(1));
-		Color color = test3.getColor();
-		test3.setColor(new Color(0, 255, 255));
-		assertTrue(color.getBlue() != test3.getColor().getBlue());
-		test3.addElement(new HolonElement("Element3", 3, 50, IdCounterElem.nextId(),null));
-		test3.setState();
-		assertTrue("Should be state 3", test3.getState() == 3);
-		test1.setState();
-		assertTrue("Should be state 0", test1.getState() == 0);
-		test2.setState();
-		test2.setBorderColor(color);
-		assertTrue("Color not Same", color == test2.getBorderColor());
 	}
 
 	/**
@@ -181,11 +154,10 @@ public class PraktikumHolonsTestClasses {
 	 */
 	@Test
 	public void testHolonElement() {
-		HolonElement ele1 = new HolonElement("TV", 2, -20, IdCounterElem.nextId(),null);
-		HolonElement ele2 = new HolonElement("Fridge", 1, -50, IdCounterElem.nextId(),null);
-
-        assertTrue("Array not empty", ele1.getEnergyAtTimeStep(0) == -20);
-        assertTrue("Array not empty", ele1.getEnergyAtTimeStep(2) == -20);
+		HolonElement ele1 = new HolonElement("TV", 2, -20f, IdCounterElem.nextId(),null);
+		HolonElement ele2 = new HolonElement("Fridge", 1, -50f, IdCounterElem.nextId(),null);
+        assertTrue("Array not empty",  ele1.getEnergyAtTimeStep(0) == -40);
+        assertTrue("Array not empty", ele1.getEnergyAtTimeStep(2) == -40);
         assertTrue("Name not correct", ele1.getEleName().equals("TV"));
         ele1.setEleName(ele2.getEleName());
 		assertTrue("Name not correct", ele1.getEleName().equals("Fridge"));