Browse Source

#76: introducing concept of over-supplied holon objects (+visualization by color)

I. Dix 7 years ago
parent
commit
20dc6dd275
2 changed files with 25 additions and 13 deletions
  1. 13 4
      src/classes/HolonObject.java
  2. 12 9
      src/ui/controller/SimulationManager.java

+ 13 - 4
src/classes/HolonObject.java

@@ -14,14 +14,16 @@ import java.util.ArrayList;
  */
 public class HolonObject extends AbstractCpsObject {
     /*
-     * 0 = no energy, 1 = not supplied, 2 = supplied, 3 producer, 4 Partially
-     * Supplied
+     * 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)
      */
     public final static int NO_ENERGY = 0;
     public final static int NOT_SUPPLIED = 1;
     public final static int SUPPLIED = 2;
     public final static int PRODUCER = 3;
     public final static int PARTIALLY_SUPPLIED = 4;
+    public final static int OVER_SUPPLIED = 5;
     /*
      * Color of the actual state (red = no supplied, yellow = partially supplied
      * and green = supplied)
@@ -70,8 +72,8 @@ public class HolonObject extends AbstractCpsObject {
     }
 
     /**
-     * sets the State, wether object is a producer, zero Energy, supplied or
-     * not.
+     * sets the State, whether object is a producer, zero Energy, supplied,
+     * partially or over-supplied
      */
     public void setState() {
         if (getCurrentEnergy() > 0) {
@@ -229,6 +231,13 @@ public class HolonObject extends AbstractCpsObject {
 
             case PARTIALLY_SUPPLIED:
                 stateColor = Color.YELLOW;
+                break;
+
+            case OVER_SUPPLIED:
+                // find different purple-tones at
+                // http://www.rapidtables.com/web/color/purple-color.htm
+                stateColor = new Color(138, 43, 226);
+                break;
         }
     }
 

+ 12 - 9
src/ui/controller/SimulationManager.java

@@ -56,17 +56,19 @@ public class SimulationManager {
             float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
             setFlowSimulation(singleSubNet);
             for (HolonObject hl : singleSubNet.getObjects()) {
-                if (!(hl.getState() == 0) && !(hl.getState() == 3)) {
+                if (hl.getState() != HolonObject.NO_ENERGY
+                        && hl.getState() != HolonObject.PRODUCER) {
                     for (int i = 0; i < hl.getConnections().size(); i++) {
                         CpsEdge edge = hl.getConnectedTo().get(i);
                         if (edge.isWorking() && edge.getFlow() > 0
                                 || edge.getCapacity() == CpsEdge.CAPACITY_INFINITE) {
-                            // 0 = no energy, 1 = not supplied, 2 = supplied, 3
-                            // = producer, 4 = partially supplied
                             if ((production + consumption) >= 0) {
-                                hl.setState(HolonObject.SUPPLIED);
-                            }
-                            if ((production + consumption) < 0) {
+                                if (wastedEnergy > 0) {
+                                    hl.setState(HolonObject.OVER_SUPPLIED);
+                                } else {
+                                    hl.setState(HolonObject.SUPPLIED);
+                                }
+                            } else {
                                 if ((production + minConsumption) >= 0) {
                                     hl.setState(HolonObject.PARTIALLY_SUPPLIED);
                                 } else if (hl.checkIfPartiallySupplied(timeStep)) {
@@ -77,9 +79,10 @@ public class SimulationManager {
                             }
                             break;
                         }
-                        hl.setState(HolonObject.NOT_SUPPLIED);
                     }
-                    if (hl.checkIfPartiallySupplied(timeStep) && !(hl.getState() == 2)) {
+                    if (hl.checkIfPartiallySupplied(timeStep)
+                            && hl.getState() != HolonObject.SUPPLIED
+                            && hl.getState() != HolonObject.OVER_SUPPLIED) {
                         hl.setState(HolonObject.PARTIALLY_SUPPLIED);
                     }
                 }
@@ -444,7 +447,7 @@ public class SimulationManager {
     }
 
     /**
-     * removes an Object that already has been handled with.
+     * removes an Object that already has been handled.
      *
      * @param id the Object ID
      */