Browse Source

Switches funktionieren jetzt

dominik.rieder 7 years ago
parent
commit
279fb96f67
3 changed files with 51 additions and 13 deletions
  1. 7 1
      src/classes/subNet.java
  2. 44 11
      src/ui/controller/SimulationManager.java
  3. 0 1
      src/ui/view/EditEdgesPopUp.java

+ 7 - 1
src/classes/subNet.java

@@ -5,10 +5,12 @@ import java.util.ArrayList;
 public class subNet {
 	private ArrayList<HolonObject> subNetObjects;
 	private ArrayList<CpsEdge> subNetEdges;
+	private ArrayList<HolonSwitch> subNetSwitches;
 	
-	public subNet(ArrayList<HolonObject> objects, ArrayList<CpsEdge> edges){
+	public subNet(ArrayList<HolonObject> objects, ArrayList<CpsEdge> edges, ArrayList<HolonSwitch> switches){
 		subNetObjects = objects;
 		subNetEdges = edges;
+		subNetSwitches = switches;
 	}
 	
 	public ArrayList<HolonObject> getObjects(){
@@ -18,4 +20,8 @@ public class subNet {
 	public ArrayList<CpsEdge> getEdges(){
 		return subNetEdges;
 	}
+	
+	public ArrayList<HolonSwitch> getSwitches(){
+		return subNetSwitches;
+	}
 }

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

@@ -6,6 +6,7 @@ import classes.CpsEdge;
 import classes.CpsNode;
 import classes.CpsObject;
 import classes.HolonObject;
+import classes.HolonSwitch;
 import classes.subNet;
 import ui.model.Model;
 import ui.view.MyCanvas;
@@ -15,6 +16,7 @@ public class SimulationManager {
 	private ArrayList<CpsObject> objectsToHandle;
 	private ArrayList<subNet> subNets;
 	private MyCanvas canvas;
+	private int timeStep;
 	
 	public SimulationManager(Model m){
 		canvas = null;
@@ -28,6 +30,7 @@ public class SimulationManager {
 	 * @param x
 	 */
 	public void calculateStateForTimeStep(int x){
+		timeStep = x;
 		searchForSubNets();
 		for(subNet singleSubNet: subNets){
 			float production = calculateEnergy("prod", singleSubNet, x);
@@ -54,6 +57,7 @@ public class SimulationManager {
 				}
 			}
 		}
+		//printNet();
 		canvas.repaint();
 	}
 	
@@ -96,7 +100,7 @@ public class SimulationManager {
 		if(objectsToHandle.size() > 0){
 			while(!end){
 				cps = objectsToHandle.get(i);
-				subNet singleSubNet = new subNet(new ArrayList<HolonObject>(), new ArrayList<CpsEdge>());
+				subNet singleSubNet = new subNet(new ArrayList<HolonObject>(), new ArrayList<CpsEdge>(), new ArrayList<HolonSwitch>());
 				singleSubNet = buildSubNet(cps, new ArrayList<Integer>(), singleSubNet);
 				if(singleSubNet.getObjects().size() != 0){
 					subNets.add(singleSubNet);
@@ -106,7 +110,6 @@ public class SimulationManager {
 				}
 			}
 		}
-		//printNet();
 	}
 	
 	/**
@@ -121,21 +124,47 @@ public class SimulationManager {
 		if(cps instanceof HolonObject){
 			sN.getObjects().add((HolonObject) cps);
 		}
+		if(cps instanceof HolonSwitch){
+			sN.getSwitches().add((HolonSwitch) cps);
+		}
 		removeFromToHandle(cps.getID());
+		CpsObject A;
+		CpsObject B;
 		for(CpsEdge edge: cps.getConnections()){
-			if(!(sN.getEdges().contains(edge))){
-				sN.getEdges().add(edge);
+			A = edge.getA();
+			B = edge.getB();
+			if(!(cps instanceof HolonSwitch)){
+				if(!(sN.getEdges().contains(edge))){
+					sN.getEdges().add(edge);
+				}
 			}
-			if(!visited.contains(edge.getA().getID())){
-				sN = buildSubNet(edge.getA(), visited, sN);
+			if(!visited.contains(A.getID()) && legitState(A, cps)){
+					sN = buildSubNet(A, visited, sN);
 			}
-			if(!visited.contains(edge.getB().getID())){
-				sN = buildSubNet(edge.getB(), visited, sN);
+			if(!visited.contains(B.getID()) && legitState(B, cps)){
+					sN = buildSubNet(B, visited, sN);
 			}
 		}
 		return sN;
 	}
 	
+	public boolean legitState(CpsObject neighbor, CpsObject current){
+		if(current instanceof HolonSwitch){
+			if(((HolonSwitch) current).getActiveAt()[timeStep]){
+				if(neighbor instanceof HolonSwitch){
+					if(((HolonSwitch) neighbor).getActiveAt()[timeStep]){
+						return true;
+					}else{
+						return false;
+						}
+				}
+			}else{
+				return false;
+			}
+		}
+		return true;
+	}
+	
 	/**
 	 * removes an Object that already has been handled with
 	 * @param id
@@ -179,14 +208,18 @@ public class SimulationManager {
 			System.out.println("  Objects:");
 			for(int j = 0; j < subNets.get(i).getObjects().size(); j++){
 				HolonObject hl = subNets.get(i).getObjects().get(j);
-				System.out.println("  " + hl.getName() + " " + hl.getID());
+				System.out.println("    " + hl.getName() + " " + hl.getID());
 			}
 			System.out.println("  Edges:");
 			for(int j = 0; j < subNets.get(i).getEdges().size(); j++){
 				CpsEdge edge = subNets.get(i).getEdges().get(j);
-				System.out.println("  " + edge.getA().getName() + " connected To " + edge.getB().getName());
+				System.out.println("     " + edge.getA().getName() + " connected To " + edge.getB().getName());
+			}
+			System.out.println("  Switches:");
+			for(int j = 0; j < subNets.get(i).getSwitches().size(); j++){
+				HolonSwitch sw = subNets.get(i).getSwitches().get(j);
+				System.out.println("    " + sw.getName() + " " + sw.getID() + " State:" + sw.getActiveAt()[timeStep]);
 			}
-			
 		}
 	}
 	

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

@@ -131,7 +131,6 @@ public class EditEdgesPopUp extends JDialog{
 	}
 	
 	public void changeForNew(float cap){
-		System.out.println("Imhere");
 		canvas.setEdgeCapacity(cap);
 	}
 	public void changeForExisting(float cap){