Browse Source

partially supplied for single objects

dominik.rieder 8 years ago
parent
commit
c7912260a5
2 changed files with 37 additions and 7 deletions
  1. 26 0
      src/classes/HolonObject.java
  2. 11 7
      src/ui/controller/SimulationManager.java

+ 26 - 0
src/classes/HolonObject.java

@@ -191,4 +191,30 @@ public class HolonObject extends CpsObject {
 		}
 		return ele;
 	}
+	
+	public boolean checkIfPartiallySupplied(int x){
+		if(getElements().size() == 0){
+			return false;
+		}
+		float minConsum = getElements().get(0).getTotalEnergyAtTimeStep(x);
+		float prod = 0;
+		for (HolonElement e : getElements()) {
+			if (e.getActive()) {
+				if(e.getTotalEnergyAtTimeStep(x) > 0){
+					prod = prod + e.getTotalEnergyAtTimeStep(x);
+				}
+				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);
+				}
+			}
+		}
+		System.out.println("minCons: " + minConsum + " prod: " + prod);
+		if(minConsum < 0 && prod >= -minConsum){
+			return true;
+		}else{
+			return false;
+		}
+	}
 }

+ 11 - 7
src/ui/controller/SimulationManager.java

@@ -38,9 +38,9 @@ public class SimulationManager {
 			ResetConnections(singleSubNet.getObjects().get(0), new ArrayList<Integer>(), new ArrayList<CpsEdge>());
 		}
 		for(subNet singleSubNet: subNets){
-			float production = calculateEnergy("prod", singleSubNet, x);
-			float consumption = calculateEnergy("cons", singleSubNet, x);
-			float minConsumption = calculateMinimumEnergy( singleSubNet, x);
+			float production = calculateEnergy("prod", singleSubNet, timeStep);
+			float consumption = calculateEnergy("cons", singleSubNet, timeStep);
+			float minConsumption = calculateMinimumEnergy( singleSubNet, timeStep);
 			setFlow(singleSubNet);
 			for(HolonObject hl: singleSubNet.getObjects()){
 				if(!(hl.getState() == 0) && !(hl.getState() == 3)){
@@ -51,21 +51,25 @@ public class SimulationManager {
 							if((production + consumption) >= 0){
 								hl.setState(2);
 							}
-							if((production + consumption) < 0){
+							if((production + consumption) < 0 ){
 								if((production + minConsumption) >= 0){
 									hl.setState(4);
-								}else{
+								}else if(hl.checkIfPartiallySupplied(timeStep)){
+									hl.setState(4);
+								}else {
 									hl.setState(1);
 								}
 							}
 							break;
 						}
-						hl.setState(1);
+							hl.setState(1);
+					}
+					if(hl.checkIfPartiallySupplied(timeStep) && !(hl.getState() == 2)){
+						hl.setState(4);
 					}
 				}
 			}
 		}
-		//printNet();
 		canvas.repaint();
 	}