Procházet zdrojové kódy

partially supplied

dominik.rieder před 8 roky
rodič
revize
26e20c6cd3

+ 1 - 1
src/ui/controller/LoadController.java

@@ -72,7 +72,7 @@ public class LoadController {
 		if (mode.equals(MODE.ALL) || mode.equals(MODE.CATEGORY)) {
 			MODEL.setCgIdx(new HashMap<String, Integer>());
 			MODEL.setCategories(new ArrayList<Category>());
-			MODEL.setEdgesOnCanvas(new ArrayList<>());
+			MODEL.setEdgesOnCanvas(new ArrayList<CpsEdge>());
 		}
 		if (mode.equals(MODE.ALL) || mode.equals(MODE.CATEGORY)) {
 			MODEL.setCvsObjIdx(new HashMap<Integer, Integer>());

+ 27 - 1
src/ui/controller/SimulationManager.java

@@ -5,6 +5,7 @@ import java.util.ArrayList;
 import classes.CpsEdge;
 import classes.CpsNode;
 import classes.CpsObject;
+import classes.HolonElement;
 import classes.HolonObject;
 import classes.HolonSwitch;
 import classes.subNet;
@@ -35,6 +36,7 @@ public class SimulationManager {
 		for(subNet singleSubNet: subNets){
 			float production = calculateEnergy("prod", singleSubNet, x);
 			float consumption = calculateEnergy("cons", singleSubNet, x);
+			float minConsumption = calculateMinimumEnergy( singleSubNet, x);
 			for(CpsEdge e: singleSubNet.getEdges()){
 				e.setFlow(production);
 			}
@@ -48,7 +50,13 @@ public class SimulationManager {
 								hl.setState(2);
 							}
 							if((production + consumption) < 0){
-								hl.setState(1);
+								if((production + minConsumption) >= 0){
+									hl.setState(4);
+									System.out.println("yellow");
+								}else{
+									hl.setState(1);
+									System.out.println("orange");
+								}
 							}
 							break;
 						}
@@ -89,6 +97,24 @@ public class SimulationManager {
 		return energy;
 	}
 	
+	public float calculateMinimumEnergy(subNet sN, int x){
+		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);
+			}
+			for(HolonElement he: hl.getElements()){
+				if(minElement < he.getTotalEnergyAtTimeStep(x) && he.getTotalEnergyAtTimeStep(x) < 0){
+					minElement = he.getTotalEnergyAtTimeStep(x);
+				}
+			}
+			System.out.println(minElement);
+			min = min + minElement;
+		}
+		return min;
+	}
+	
 	/**
 	 * generates all subNets from all objectsToHandle
 	 */

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

@@ -191,6 +191,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 							controller.getScale() + ((controller.getScale() / 20) * 2),
 							controller.getScale() + ((controller.getScale() / 20) * 2));
 				} else if (cps instanceof HolonObject) {
+					if (((HolonObject) cps).getState() == 4) {
+						g2.setColor(Color.YELLOW);
+					}
 					if (((HolonObject) cps).getState() == 3) {
 						g2.setColor(Color.lightGray);
 					}