Parcourir la source

more code cleaning

I. Dix il y a 7 ans
Parent
commit
3f9b19ad50

+ 29 - 31
src/classes/AbstractCpsObject.java

@@ -1,10 +1,10 @@
 package classes;
 
-import java.awt.Color;
-import java.util.ArrayList;
-
 import com.google.gson.annotations.Expose;
 
+import java.awt.*;
+import java.util.ArrayList;
+
 /**
  * The abstract class "CpsObject" represents any possible object in the system
  * (except Edges). The representation of any object contains following
@@ -55,8 +55,8 @@ public abstract class AbstractCpsObject {
 		setObjName(objName);
 		setName(objName);
 		setImage("/Images/Dummy_House.png");
-		tags = new ArrayList<Integer>();
-		pseudoTags = new ArrayList<Integer>();
+		tags = new ArrayList<>();
+		pseudoTags = new ArrayList<>();
 	}
 
 	/**
@@ -70,7 +70,7 @@ public abstract class AbstractCpsObject {
 	public AbstractCpsObject(AbstractCpsObject obj) {
 		setObjName(obj.getObjName());
 		setName(obj.getObjName());
-		setConnections(new ArrayList<CpsEdge>());
+		setConnections(new ArrayList<>());
 		setPosition(new Position());
 		setId(IdCounter.nextId());
 		setImage(obj.getImage());
@@ -192,17 +192,7 @@ public abstract class AbstractCpsObject {
 
 	/**
 	 * Set the position of the Object in the canvas.
-	 * 
-	 * @param pos
-	 *            Coordinates
-	 */
-	public void setPosition(Position pos) {
-		this.position = pos;
-	}
-
-	/**
-	 * Set the position of the Object in the canvas.
-	 * 
+	 *
 	 * @param x
 	 *            X-Coord
 	 * @param y
@@ -214,13 +204,22 @@ public abstract class AbstractCpsObject {
 
 	/**
 	 * Get the actual position of the Object.
-	 * 
+	 *
 	 * @return Position Position of this Object
 	 */
 	public Position getPosition() {
 		return position;
 	}
 
+	/**
+	 * Set the position of the Object in the canvas.
+	 *
+	 * @param pos Coordinates
+	 */
+	public void setPosition(Position pos) {
+		this.position = pos;
+	}
+
 	/**
 	 * For save purpose.
 	 * 
@@ -290,8 +289,8 @@ public abstract class AbstractCpsObject {
 	 * Rest the tags to Null.
 	 */
 	public void resetTags() {
-		this.tags = new ArrayList<Integer>();
-		this.pseudoTags = new ArrayList<Integer>();
+		this.tags = new ArrayList<>();
+		this.pseudoTags = new ArrayList<>();
 	}
 
 	/**
@@ -304,25 +303,24 @@ public abstract class AbstractCpsObject {
 		this.tags = tags;
 	}
 
-	/**
-	 * For internal purpose (energy flow).
-	 * 
-	 * @param tags
-	 *            for internal purpose
-	 */
-	public void setPseudoTags(ArrayList<Integer> tags) {
-		this.pseudoTags = tags;
-	}
-
 	/**
 	 * Get the pseudo tags.
-	 * 
+	 *
 	 * @return ArrayList
 	 */
 	public ArrayList<Integer> getPseudoTags() {
 		return this.pseudoTags;
 	}
 
+	/**
+	 * For internal purpose (energy flow).
+	 *
+	 * @param tags for internal purpose
+	 */
+	public void setPseudoTags(ArrayList<Integer> tags) {
+		this.pseudoTags = tags;
+	}
+
 	/**
 	 * add a pseudo tag.
 	 * 

+ 16 - 11
src/classes/CpsEdge.java

@@ -16,6 +16,9 @@ public class CpsEdge {
     public static final int CON_UPPER_NODE = 0;
     public static final int CON_UPPER_NODE_AND_INSIDE = 1;
     public static final int CON_UPPER_NODE_NOT_INSIDE = 2;
+
+    public static final float CAPACITY_INFINITE = -1;
+    public static final float CAPACITY_TO_UPPER_NODE = -2;
     // Max. capacity of the Edge, if flow is greater than the status --> is
     // Working would be false
     @Expose
@@ -62,7 +65,7 @@ public class CpsEdge {
         this.maxCapacity = 100;
         flow = 0;
         isWorking = true;
-        pseudoTags = new ArrayList<Integer>();
+        pseudoTags = new ArrayList<>();
     }
 
     /**
@@ -80,8 +83,8 @@ public class CpsEdge {
         this.maxCapacity = maxCap;
         flow = 0;
         isWorking = true;
-        isConnected = 0;
-        pseudoTags = new ArrayList<Integer>();
+        isConnected = CON_UPPER_NODE;
+        pseudoTags = new ArrayList<>();
     }
 
     /**
@@ -127,9 +130,10 @@ public class CpsEdge {
     /**
      * Calculates the state of the edge (see description of isWorking).
      */
-
     public void calculateState() {
-        if (flow > maxCapacity && maxCapacity != -1 && maxCapacity != -2) {
+        if (flow > maxCapacity
+                && maxCapacity != CAPACITY_INFINITE
+                && maxCapacity != CAPACITY_TO_UPPER_NODE) {
             isWorking = false;
             flow = 0;
         }
@@ -176,7 +180,7 @@ public class CpsEdge {
      *
      * @return the state
      */
-    public boolean getState() {
+    public boolean isWorking() {
         return isWorking;
     }
 
@@ -185,7 +189,7 @@ public class CpsEdge {
      *
      * @param state the state
      */
-    public void setState(boolean state) {
+    public void setWorkingState(boolean state) {
         isWorking = state;
     }
 
@@ -219,10 +223,11 @@ public class CpsEdge {
     }
 
     /**
-     * checks wether tags contains all given tags
+     * checks whether list contains all given tags
      *
      * @param toCheck tags that are checked
-     * @return true if all are contained in tags, false otherwise
+     * @param list    list to be checked
+     * @return true if all tags in toCheck are contained in list, false otherwise
      */
     public boolean containsTags(ArrayList<Integer> list, ArrayList<Integer> toCheck) {
         if (toCheck.size() == 0) {
@@ -265,8 +270,8 @@ public class CpsEdge {
 
     public void setConnected(int state) {
         isConnected = state;
-        if (state == 1) {
-            maxCapacity = -2;
+        if (state == CON_UPPER_NODE_AND_INSIDE) {
+            maxCapacity = CAPACITY_TO_UPPER_NODE;
         }
     }
 

+ 5 - 4
src/exampleAlgorithms/RepairAllEdges.java

@@ -1,10 +1,11 @@
 package exampleAlgorithms;
 
 import api.CpsAlgorithm;
+import classes.AbstractCpsObject;
+import classes.CpsEdge;
+import classes.CpsUpperNode;
 import ui.controller.Control;
 import ui.model.Model;
-import ui.view.UpperNodeCanvas;
-import classes.*;
 
 public class RepairAllEdges implements CpsAlgorithm {
 
@@ -25,7 +26,7 @@ public class RepairAllEdges implements CpsAlgorithm {
 				repairAllEdgesInUpperNode((CpsUpperNode) obj);
 			}
 			for (CpsEdge e : obj.getConnections()) {
-				e.setState(true);
+				e.setWorkingState(true);
 			}
 		}
 	}
@@ -36,7 +37,7 @@ public class RepairAllEdges implements CpsAlgorithm {
 				repairAllEdgesInUpperNode((CpsUpperNode) obj);
 			}
 			for (CpsEdge e : obj.getConnections()) {
-				e.setState(true);
+				e.setWorkingState(true);
 			}
 		}
 	}

+ 17 - 17
src/tests/PraktikumHolonsTestClasses.java

@@ -113,13 +113,13 @@ public class PraktikumHolonsTestClasses {
 //
 //		assertTrue("Manuel Mode is on", !test2.getManualMode());
 //		test2.switchState();
-//		assertTrue(test2.getState());
-//		assertTrue(test2.getState(1));
+//		assertTrue(test2.isWorking());
+//		assertTrue(test2.isWorking(1));
 //		test2.setManualMode(true);
 //		test2.switchState();
 //		test2.switchState();
-//		assertTrue(test2.getState());
-//		assertTrue(test2.getState(1));
+//		assertTrue(test2.isWorking());
+//		assertTrue(test2.isWorking(1));
 //		assertTrue("Manuel Mode is off", test2.getManualMode());
 //		assertTrue("ManuelActive is off", test2.getActiveManual());
 //		test2.switchState();
@@ -149,24 +149,24 @@ public class PraktikumHolonsTestClasses {
 		edge1.setCapacity(200);
 		assertTrue("Flow was not changed", edge1.getFlow() == 50);
 		assertTrue("Capacity not right", edge1.getCapacity() == 200);
-		assertTrue("line broken", edge2.getState());
-		edge2.calculateState();
-		assertTrue("line broken", edge2.getState());
-		edge2.setFlow(200);
-		edge2.calculateState();
-		assertTrue("line not broken", !edge2.getState());
-		edge1.setCapacity(-1);
-		edge1.calculateState();
+        assertTrue("line broken", edge2.isWorking());
+        edge2.calculateState();
+        assertTrue("line broken", edge2.isWorking());
+        edge2.setFlow(200);
+        edge2.calculateState();
+        assertTrue("line not broken", !edge2.isWorking());
+        edge1.setCapacity(-1);
+        edge1.calculateState();
 		edge1.setCapacity(500);
 		edge1.calculateState();
 		node1 = (CpsNode) edge1.getB();
 		node2 = (CpsNode) edge2.getA();
 		assertTrue("Not Same", node1 == node2);
-		assertTrue("State not right", edge1.getState());
-		edge1.setState(false);
-		assertTrue("State not right", !edge1.getState());
-		edge2.setTags(new ArrayList<>());
-		edge1.setTags(new ArrayList<>());
+        assertTrue("State not right", edge1.isWorking());
+        edge1.setWorkingState(false);
+        assertTrue("State not right", !edge1.isWorking());
+        edge2.setTags(new ArrayList<>());
+        edge1.setTags(new ArrayList<>());
 		assertTrue("Tags not Empty", edge2.getTags().isEmpty());
 		edge2.addTag(1);
 		assertTrue("Tags not Empty", edge1.getTags().isEmpty());

+ 578 - 591
src/ui/controller/SimulationManager.java

@@ -1,604 +1,591 @@
 package ui.controller;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import classes.AbstractCpsObject;
-import classes.CpsEdge;
-import classes.CpsUpperNode;
-import classes.HolonElement;
-import classes.HolonObject;
-import classes.HolonSwitch;
-import classes.SubNet;
+import classes.*;
 import ui.model.Model;
 import ui.view.FlexiblePane;
 import ui.view.MyCanvas;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+
 /**
  * Controller for Simulation.
- * 
+ *
  * @author Gruppe14
  */
 public class SimulationManager {
-	private Model model;
-	private ArrayList<AbstractCpsObject> objectsToHandle;
-	private ArrayList<CpsEdge> allConnections;
-	private ArrayList<SubNet> subNets;
-	private ArrayList<CpsEdge> brokenEdges;
-	private MyCanvas canvas;
-	private int timeStep;
-	private HashMap<Integer, Float> tagTable = new HashMap<Integer, Float>();
-	private FlexiblePane flexPane;
-	/**
-	 * Constructor.
-	 * 
-	 * @param m
-	 *            Model
-	 */
-	public SimulationManager(Model m) {
-		canvas = null;
-		model = m;
-		subNets = new ArrayList<SubNet>();
-		brokenEdges = new ArrayList<CpsEdge>();
-	}
-
-	/**
-	 * calculates the flow of the edges and the supply for objects.
-	 * 
-	 * @param x
-	 *            current Iteration
-	 */
-	public void calculateStateForTimeStep(int x) {
-		reset();
-		timeStep = x;
-		searchForSubNets();
-		for (SubNet singleSubNet : subNets) {
-			resetConnections(singleSubNet.getObjects().get(0), new ArrayList<Integer>(), new ArrayList<CpsEdge>());
-		}
-		for (SubNet singleSubNet : subNets) {
-			float production = calculateEnergy("prod", singleSubNet, timeStep);
-			float consumption = calculateEnergy("cons", singleSubNet, timeStep);
-			float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
-			setFlowSimulation(singleSubNet);
-			for (HolonObject hl : singleSubNet.getObjects()) {
-				if (!(hl.getState() == 0) && !(hl.getState() == 3)) {
-					for (int i = 0; i < hl.getConnections().size(); i++) {
-						CpsEdge edge = hl.getConnectedTo().get(i);
-						if (edge.getState() && edge.getFlow() > 0 || edge.getCapacity() == -1) {
-							// 0 = no energy, 1 = not supplied, 2 = supplied, 3
-							// = producer, 4 = partially supplied
-							if ((production + consumption) >= 0) {
-								hl.setState(2);
-							}
-							if ((production + consumption) < 0) {
-								if ((production + minConsumption) >= 0) {
-									hl.setState(4);
-								} else if (hl.checkIfPartiallySupplied(timeStep)) {
-									hl.setState(4);
-								} else {
-									hl.setState(1);
-								}
-							}
-							break;
-						}
-						hl.setState(1);
-					}
-					if (hl.checkIfPartiallySupplied(timeStep) && !(hl.getState() == 2)) {
-						hl.setState(4);
-					}
-				}
-			}
-		}
-		canvas.repaint();
-		//printNet();
-		flexPane.recalculate();
-	}
-
-	/**
-	 * Set Flow Simulation.
-	 * 
-	 * @param sN
-	 *            Subnet
-	 */
-	public void setFlowSimulation(SubNet sN) {
-		ArrayList<AbstractCpsObject> producers = new ArrayList<AbstractCpsObject>();
-		AbstractCpsObject tmp = null;
-		tagTable = new HashMap<Integer, Float>();
-		for (HolonObject hl : sN.getObjects()) {
-			float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
-			if (energy > 0) {
-				tagTable.put(hl.getId(), energy);
-				hl.addTag(hl.getId());
-				for (CpsEdge edge : hl.getConnections()) {
-					if (edge.getState()) {
-						if (edge.getA().getId() == hl.getId()) {
-							edge.getB().addTag(hl.getId());
-							tmp = edge.getB();
-						}
-						if (edge.getB().getId() == hl.getId()) {
-							edge.getA().addTag(hl.getId());
-							tmp = edge.getA();
-						}
-						edge.setFlow(edge.getFlow() + energy);
-						edge.calculateState();
-						edge.addTag(hl.getId());
-						if (edge.getState() && !producers.contains(tmp)) {
-							if(tmp instanceof HolonSwitch){
-								if(((HolonSwitch)tmp).getState(timeStep)){
-									producers.add(tmp);
-								}
-							}else if(!(tmp instanceof CpsUpperNode)){
-								producers.add(tmp);
-							}
-						}
-					}
-				}
-			}
-		}
-		setFlowSimRec(producers, 0);
-	}
-
-	/**
-	 * Set Flow Rimulation Rec.
-	 * 
-	 * @param nodes
-	 *            the nodes
-	 * @param iter
-	 *            the Iteration
-	 */
-	public void setFlowSimRec(ArrayList<AbstractCpsObject> nodes, int iter) {
-		ArrayList<AbstractCpsObject> newNodes = new ArrayList<AbstractCpsObject>();
-		ArrayList<CpsEdge> changedEdges = new ArrayList<CpsEdge>();
-		AbstractCpsObject tmp;
-		if(nodes.size() != 0){
-			for(AbstractCpsObject cps: nodes){
-				if(legitState(cps)){
-					for(CpsEdge edge: cps.getConnections()){
-						if(edge.getState() && (!(edge.containsTags(edge.getTags(), cps.getTag())))){
-							if(edge.getA().getId() == cps.getId()){
-								tmp = edge.getB();
-							}else{
-								tmp = edge.getA();
-							}	
-							for(Integer tag: cps.getTag()){
-								if(!(edge.getTags().contains(tag)) && !(edge.getPseudoTags().contains(tag))){
-									edge.setFlow(edge.getFlow() + tagTable.get(tag));
-									edge.addTag(tag);
-								}
-							}
-							// uppernodes do not spread energy
-							if(!(tmp instanceof CpsUpperNode)){
-								for(Integer tag: tmp.getTag()){
-									if(!(edge.getTags().contains(tag)) && tagTable.get(tag) != null && !(edge.getPseudoTags().contains(tag))){
-										edge.setFlow(edge.getFlow() + tagTable.get(tag));
-										edge.addPseudoTag(tag);
-										changedEdges.add(edge);
-									}
-								}
-							}
-							edge.calculateState();
-							if(edge.getState() && !(tmp instanceof CpsUpperNode)){
-								tmp.addAllPseudoTags(cps.getTag());
-								if(!newNodes.contains(tmp)){
-								newNodes.add(tmp);
-								}
-							}
-						}
-					}
-				}
-			}
-			setPseudoTags(newNodes, changedEdges);
-			setFlowSimRec(newNodes, iter+1);
-		}
-	}
-
-	/**
-	 * Set the Pseudo Tags.
-	 * 
-	 * @param nodes
-	 *            Array of AbstractCpsObjects
-	 */
-	public void setPseudoTags(ArrayList<AbstractCpsObject> nodes, ArrayList<CpsEdge> edges) {
-		for (AbstractCpsObject node : nodes) {
-			node.recalculateTags();
-			node.setPseudoTags(new ArrayList<Integer>());
-		}
-		for(CpsEdge edge : edges){
-			edge.recalculateTags();
-			edge.setPseudoTag(new ArrayList<Integer>());
-		}
-	}
-
-	/**
-	 * Print the nodes.
-	 * 
-	 * @param nodes
-	 *            Array of AbstractCpsObject
-	 */
-	public void printNodes(ArrayList<AbstractCpsObject> nodes) {
-		System.out.println("new Nodes:");
-		for (AbstractCpsObject node : nodes) {
-			System.out.println(node.getId());
-		}
-	}
-
-	/**
-	 * Get String.
-	 * 
-	 * @param tags
-	 *            the tags
-	 * @return the String
-	 */
-	public String getString(ArrayList<Integer> tags) {
-		String result = "";
-		for (Integer i : tags) {
-			result = result + ", " + i;
-		}
-		return result;
-	}
-
-	/**
-	 * Merge the Lists.
-	 * 
-	 * @param a
-	 *            first liust
-	 * @param b
-	 *            second list
-	 * @return the Result
-	 */
-	public ArrayList<Integer> mergeLists(ArrayList<Integer> a, ArrayList<Integer> b) {
-		ArrayList<Integer> result = new ArrayList<Integer>();
-		for (Integer i : a) {
-			if (!(result.contains(i))) {
-				result.add(i);
-			}
-		}
-		for (Integer j : b) {
-			if (!(result.contains(j))) {
-				result.add(j);
-			}
-		}
-		return result;
-	}
-
-	/**
-	 * Reset the Connection.
-	 * 
-	 * @param cps
-	 *            CpsObject
-	 * @param visitedObj
-	 *            the visited Objects
-	 * @param visitedEdges
-	 *            the visited Edges
-	 */
-	public void resetConnections(AbstractCpsObject cps, ArrayList<Integer> visitedObj,
-			ArrayList<CpsEdge> visitedEdges) {
-		visitedObj.add(cps.getId());
-		cps.resetTags();
-		for (CpsEdge e : cps.getConnections()) {
-			if (!(visitedEdges.contains(e))) {
-				e.setFlow(0);
-				e.calculateState();
-				e.setTags(new ArrayList<Integer>());
-				visitedEdges.add(e);
-				if (!(visitedObj.contains(e.getA().getId()))) {
-					resetConnections(e.getA(), visitedObj, visitedEdges);
-					e.getA().resetTags();
-				}
-				if (!(visitedObj.contains(e.getB().getId()))) {
-					resetConnections(e.getB(), visitedObj, visitedEdges);
-					e.getB().resetTags();
-				}
-			}
-		}
-	}
-
-	/**
-	 * calculates the energy of either all producers or consumers.
-	 * 
-	 * @param type
-	 *            Type
-	 * @param sN
-	 *            Subnet
-	 * @param x
-	 *            Integer
-	 * 
-	 * @return The Energy
-	 */
-	public float calculateEnergy(String type, SubNet sN, int x) {
-		float energy = 0;
-		for (HolonObject hl : sN.getObjects()) {
-			if (type.equals("prod")) {
-				if (hl.getCurrentEnergyAtTimeStep(x) > 0) {
-					energy = energy + hl.getCurrentEnergyAtTimeStep(x);
-					hl.setState(3);
-				}
-			}
-			if (type.equals("cons")) {
-				if (hl.getCurrentEnergyAtTimeStep(x) < 0) {
-					energy = energy + hl.getCurrentEnergyAtTimeStep(x);
-					hl.setState(1);
-				}
-			}
-			if (hl.getCurrentEnergyAtTimeStep(x) == 0) {
-				hl.setState(0);
-			}
-		}
-		return energy;
-	}
-
-	/**
-	 * Calculate the Minimum Energy.
-	 * 
-	 * @param sN
-	 *            Subnet
-	 * @param x
-	 *            Integer
-	 * @return the Calculated minimum 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);
-				}
-			}
-			min = min + minElement;
-		}
-		return min;
-	}
-
-	/**
-	 * generates all subNets from all objectsToHandle.
-	 */
-	public void searchForSubNets() {
-		subNets = new ArrayList<SubNet>();
-		brokenEdges.clear();
-		boolean end = false;
-		int i = 0;
-		AbstractCpsObject cps;
-		if (objectsToHandle.size() > 0) {
-			while (!end) {
-				cps = objectsToHandle.get(i);
-					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);
-					}
-					if (0 == objectsToHandle.size()) {
-						end = true;
-					}
-			}
-		}
-	}
-
-	/**
-	 * recursivly generates a subnet of all objects, that one specific object is
-	 * connected to.
-	 * 
-	 * @param cps
-	 *            AbstractCpsObject
-	 * @param visited
-	 *            visited Array of Integer
-	 * @param sN
-	 *            Subnets
-	 * @return Subnet
-	 */
-	public SubNet buildSubNet(AbstractCpsObject cps, ArrayList<Integer> visited, SubNet sN) {
-		visited.add(cps.getId());
-		if (cps instanceof HolonObject) {
-			sN.getObjects().add((HolonObject) cps);
-		}
-		if (cps instanceof HolonSwitch) {
-			sN.getSwitches().add((HolonSwitch) cps);
-		}
-		removeFromToHandle(cps.getId());
-		AbstractCpsObject a;
-		AbstractCpsObject b;
-		for (CpsEdge edge : cps.getConnections()) {
-			if(edge.getState()){
-				a = edge.getA();
-				b = edge.getB();
-				if (!(cps instanceof HolonSwitch)) {
-					if (!(sN.getEdges().contains(edge))) {
-						sN.getEdges().add(edge);
-					}
-				}
-				if(cps instanceof HolonSwitch && ((HolonSwitch)cps).getState(timeStep)){
-					if (!(sN.getEdges().contains(edge))) {
-						sN.getEdges().add(edge);
-					}
-				}
-				if (!visited.contains(a.getId()) && legitState(cps) && !(a instanceof CpsUpperNode)) {
-					sN = buildSubNet(a, visited, sN);
-				}
-				if (!visited.contains(b.getId()) && legitState(cps) && !(b instanceof CpsUpperNode)) {
-					sN = buildSubNet(b, visited, sN);
-				}
-				if(a instanceof CpsUpperNode && a.getId() != cps.getId()){
-					edge.setConnected(2);
-					checkForConnectedStates(b, (CpsUpperNode)a, edge);
-				}
-				if(b instanceof CpsUpperNode && b.getId() != cps.getId()){
-					edge.setConnected(2);
-					checkForConnectedStates(a, (CpsUpperNode)b, edge);
-				}
-			}else{
-				brokenEdges.add(edge);
-			}
-		}
-		return sN;
-	}
-
-	/**
-	 * is the Switch in a legitimate State.
-	 * 
-	 * @param neighbor AbstractCpsObject
-	 * @param current AbstractCpsObject
-	 * @return boolean
-	 */
-	public boolean legitState(AbstractCpsObject current) {
-		if (current instanceof HolonSwitch) {
-			if (((HolonSwitch) current).getState(timeStep)) {
-				return true;
-			}else{
-				return false;
-			}
-		}
-		return true;
-	}
-
-	/**
-	 * removes an Object that already has been handled with.
-	 * 
-	 * @param id the Object ID
-	 */
-	public void removeFromToHandle(int id) {
-		for (int i = 0; i < objectsToHandle.size(); i++) {
-			if (objectsToHandle.get(i).getId() == id) {
-				objectsToHandle.remove(i);
-			}
-		}
-	}
-
-	/**
-	 * ensures that objectsToHandle only contains HolonObjects.
-	 */
-	public void cleanObjectsToHandle() {
-		for (int i = 0; i < objectsToHandle.size(); i++) {
-			if (!(objectsToHandle.get(i) instanceof HolonObject)) {
-				objectsToHandle.remove(i);
-			}
-		}
-	}
-
-	/**
-	 * copies the data of an array of Objects.
-	 * 
-	 * @param toCopy the ArrayList of CpsObjects co Copy
-	 */
-	public void copyObjects(ArrayList<AbstractCpsObject> toCopy) {
-		for (AbstractCpsObject cps : toCopy) {
-			if(cps instanceof CpsUpperNode){
-				copyObjects(((CpsUpperNode)cps).getNodes());
-			}else{
-				objectsToHandle.add(cps);
-			}
-		}
-	}
-
-	/**
-	 * Prints the Components auf all subnets.
-	 */
-	public void printNet() {
-		for (int i = 0; i < subNets.size(); i++) {
-			System.out.println("SUBNET NR:" + i);
-			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("  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("  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]);
-			}
-		}
-	}
-
-	/**
-	 * Set the Canvas.
-	 * 
-	 * @param can
-	 *            the Canvas
-	 */
-	public void setCanvas(MyCanvas can) {
-		canvas = can;
-	}
-
-	/**
-	 * Reset all Data to the current state of the Model.
-	 */
-	public void reset() {
-		objectsToHandle = new ArrayList<AbstractCpsObject>();
-		copyObjects(model.getObjectsOnCanvas());
-	}
-	
-	/**
-	 * Resets the State of all Edges
-	 */
-	public void resetEdges(){
-		for(CpsEdge e: brokenEdges){
-			e.setState(true);
-		}
-	}
-	
-	/**
-	 * Resets the State for the whole Simulation Model
-	 */
-	public void resetSimulation(){
-		reset();
-		resetEdges();
-	}
-
-	/**
-	 * Get all Subnets.
-	 * 
-	 * @return all Subnets
-	 */
-	public ArrayList<SubNet> getSubNets() {
-		return subNets;
-	}
-	
-	/**
-	 * Get broken Edges
-	 */
-	public ArrayList<CpsEdge> getBrokenEdges(){
-		return brokenEdges;
-	}
-	
-	/**
-	 * checks wether a given object is connected to an object inside the upperNode.
-	 * if yes, the state for the edge is changed in "connected" or "not connected"
-	 * @param cps
-	 * @param cUNode
-	 */
-	public void checkForConnectedStates(AbstractCpsObject cps, CpsUpperNode cUNode, CpsEdge theEdge){
-		AbstractCpsObject tmp;
-		for(CpsEdge edge: cps.getConnections()){
-			if(edge.getA().getId() == cps.getId()){
-				tmp = edge.getB();
-			} else{
-				tmp = edge.getA();
-			}
-			if(cUNode.getNodes().contains(tmp)){
-				if(tmp instanceof CpsUpperNode){
-					checkForConnectedStates(cps, (CpsUpperNode)tmp, theEdge);
-				}else{
-					theEdge.setConnected(1);
-					break;
-				}
-			}
-		}
-	}
-
-	public void setFlexiblePane(FlexiblePane fp) {
-		flexPane = fp;
-	}
-	
-	public FlexiblePane getFlexiblePane(){
-		return flexPane;
-	}
+    private Model model;
+    private ArrayList<AbstractCpsObject> objectsToHandle;
+    //	private ArrayList<CpsEdge> allConnections;
+    private ArrayList<SubNet> subNets;
+    private ArrayList<CpsEdge> brokenEdges;
+    private MyCanvas canvas;
+    private int timeStep;
+    private HashMap<Integer, Float> tagTable = new HashMap<>();
+    private FlexiblePane flexPane;
+
+    /**
+     * Constructor.
+     *
+     * @param m Model
+     */
+    public SimulationManager(Model m) {
+        canvas = null;
+        model = m;
+        subNets = new ArrayList<>();
+        brokenEdges = new ArrayList<>();
+    }
+
+    /**
+     * calculates the flow of the edges and the supply for objects.
+     *
+     * @param x current Iteration
+     */
+    public void calculateStateForTimeStep(int x) {
+        reset();
+        timeStep = x;
+        searchForSubNets();
+        for (SubNet singleSubNet : subNets) {
+            resetConnections(singleSubNet.getObjects().get(0), new ArrayList<>(), new ArrayList<>());
+        }
+        for (SubNet singleSubNet : subNets) {
+            float production = calculateEnergy("prod", singleSubNet, timeStep);
+            float consumption = calculateEnergy("cons", singleSubNet, timeStep);
+            float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
+            setFlowSimulation(singleSubNet);
+            for (HolonObject hl : singleSubNet.getObjects()) {
+                if (!(hl.getState() == 0) && !(hl.getState() == 3)) {
+                    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(2);
+                            }
+                            if ((production + consumption) < 0) {
+                                if ((production + minConsumption) >= 0) {
+                                    hl.setState(4);
+                                } else if (hl.checkIfPartiallySupplied(timeStep)) {
+                                    hl.setState(4);
+                                } else {
+                                    hl.setState(1);
+                                }
+                            }
+                            break;
+                        }
+                        hl.setState(1);
+                    }
+                    if (hl.checkIfPartiallySupplied(timeStep) && !(hl.getState() == 2)) {
+                        hl.setState(4);
+                    }
+                }
+            }
+        }
+        canvas.repaint();
+        //printNet();
+        flexPane.recalculate();
+    }
+
+    /**
+     * Set Flow Simulation.
+     *
+     * @param sN Subnet
+     */
+    public void setFlowSimulation(SubNet sN) {
+        ArrayList<AbstractCpsObject> producers = new ArrayList<>();
+        AbstractCpsObject tmp = null;
+        tagTable = new HashMap<>();
+        // traverse all objects in this subnet
+        for (HolonObject hl : sN.getObjects()) {
+            float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
+            // if their production is higher than their consumption
+            if (energy > 0) {
+                tagTable.put(hl.getId(), energy);
+                hl.addTag(hl.getId());
+                for (CpsEdge edge : hl.getConnections()) {
+                    if (edge.isWorking()) {
+                        // set other end of edge as tmp-object
+                        // and add this end to the other end's tag-list
+                        AbstractCpsObject a = edge.getA();
+                        AbstractCpsObject b = edge.getB();
+                        if (a.getId() == hl.getId()) {
+                            b.addTag(hl.getId());
+                            tmp = b;
+                        }
+                        if (b.getId() == hl.getId()) {
+                            a.addTag(hl.getId());
+                            tmp = a;
+                        }
+
+                        edge.setFlow(edge.getFlow() + energy);
+                        edge.calculateState();
+                        edge.addTag(hl.getId());
+                        if (edge.isWorking() && !producers.contains(tmp)) {
+                            if (tmp instanceof HolonSwitch) {
+                                if (((HolonSwitch) tmp).getState(timeStep)) {
+                                    producers.add(tmp);
+                                }
+                            } else if (!(tmp instanceof CpsUpperNode)) {
+                                producers.add(tmp);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        setFlowSimRec(producers, 0);
+    }
+
+    /**
+     * Set Flow Simulation Rec.
+     *
+     * @param nodes the nodes
+     * @param iter  the Iteration
+     */
+    public void setFlowSimRec(ArrayList<AbstractCpsObject> nodes, int iter) {
+        ArrayList<AbstractCpsObject> newNodes = new ArrayList<>();
+        ArrayList<CpsEdge> changedEdges = new ArrayList<>();
+        AbstractCpsObject tmp;
+        if (nodes.size() != 0) {
+            for (AbstractCpsObject cps : nodes) {
+                // check whether the cps is in a legit state if it is a switch
+                if (legitState(cps)) {
+                    for (CpsEdge edge : cps.getConnections()) {
+                        // is edge working
+                        // and does the edge's tag-list not (yet) contain all tags of the cps
+                        if (edge.isWorking()
+                                && (!(edge.containsTags(edge.getTags(), cps.getTag())))) {
+                            if (edge.getA().getId() == cps.getId()) {
+                                tmp = edge.getB();
+                            } else {
+                                tmp = edge.getA();
+                            }
+                            for (Integer tag : cps.getTag()) {
+                                if (!(edge.getTags().contains(tag))
+                                        && !(edge.getPseudoTags().contains(tag))) {
+                                    edge.setFlow(edge.getFlow() + tagTable.get(tag));
+                                    edge.addTag(tag);
+                                }
+                            }
+                            // uppernodes do not spread energy
+                            if (!(tmp instanceof CpsUpperNode)) {
+                                for (Integer tag : tmp.getTag()) {
+                                    if (!(edge.getTags().contains(tag))
+                                            && tagTable.get(tag) != null
+                                            && !(edge.getPseudoTags().contains(tag))) {
+                                        edge.setFlow(edge.getFlow() + tagTable.get(tag));
+                                        edge.addPseudoTag(tag);
+                                        changedEdges.add(edge);
+                                    }
+                                }
+                            }
+                            edge.calculateState();
+                            if (edge.isWorking()
+                                    && !(tmp instanceof CpsUpperNode)) {
+                                tmp.addAllPseudoTags(cps.getTag());
+                                if (!newNodes.contains(tmp)) {
+                                    newNodes.add(tmp);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            setPseudoTags(newNodes, changedEdges);
+            setFlowSimRec(newNodes, iter + 1);
+        }
+    }
+
+    /**
+     * Set the Pseudo Tags.
+     *
+     * @param nodes Array of AbstractCpsObjects
+     */
+    public void setPseudoTags(ArrayList<AbstractCpsObject> nodes, ArrayList<CpsEdge> edges) {
+        for (AbstractCpsObject node : nodes) {
+            node.recalculateTags();
+            node.setPseudoTags(new ArrayList<>());
+        }
+        for (CpsEdge edge : edges) {
+            edge.recalculateTags();
+            edge.setPseudoTag(new ArrayList<>());
+        }
+    }
+
+//    /**
+//     * Print the nodes.
+//     *
+//     * @param nodes
+//     *            Array of AbstractCpsObject
+//     */
+//	public void printNodes(ArrayList<AbstractCpsObject> nodes) {
+//		for (AbstractCpsObject node : nodes) {
+//			System.out.println(node.getId());
+//		}
+//	}
+
+//    /**
+//     * Get String.
+//     *
+//     * @param tags
+//     *            the tags
+//     * @return the String
+//     */
+//	public String getString(ArrayList<Integer> tags) {
+//		String result = "";
+//		for (Integer i : tags) {
+//			result = result + ", " + i;
+//		}
+//		return result;
+//	}
+
+//    /**
+//     * Merge the Lists.
+//     *
+//     * @param a
+//     *            first liust
+//     * @param b
+//     *            second list
+//     * @return the Result
+//     */
+//	public ArrayList<Integer> mergeLists(ArrayList<Integer> a, ArrayList<Integer> b) {
+//		ArrayList<Integer> result = new ArrayList<>();
+//		for (Integer i : a) {
+//			if (!(result.contains(i))) {
+//				result.add(i);
+//			}
+//		}
+//		for (Integer j : b) {
+//			if (!(result.contains(j))) {
+//				result.add(j);
+//			}
+//		}
+//		return result;
+//	}
+
+    /**
+     * Reset the Connection.
+     *
+     * @param cps          CpsObject
+     * @param visitedObj   the visited Objects
+     * @param visitedEdges the visited Edges
+     */
+    public void resetConnections(AbstractCpsObject cps, ArrayList<Integer> visitedObj,
+                                 ArrayList<CpsEdge> visitedEdges) {
+        visitedObj.add(cps.getId());
+        cps.resetTags();
+        for (CpsEdge e : cps.getConnections()) {
+            if (!(visitedEdges.contains(e))) {
+                e.setFlow(0);
+                e.calculateState();
+                e.setTags(new ArrayList<>());
+                visitedEdges.add(e);
+                if (!(visitedObj.contains(e.getA().getId()))) {
+                    resetConnections(e.getA(), visitedObj, visitedEdges);
+                    e.getA().resetTags();
+                }
+                if (!(visitedObj.contains(e.getB().getId()))) {
+                    resetConnections(e.getB(), visitedObj, visitedEdges);
+                    e.getB().resetTags();
+                }
+            }
+        }
+    }
+
+    /**
+     * calculates the energy of either all producers or consumers.
+     *
+     * @param type Type
+     * @param sN   Subnet
+     * @param x    Integer
+     * @return The Energy
+     */
+    public float calculateEnergy(String type, SubNet sN, int x) {
+        float energy = 0;
+        for (HolonObject hl : sN.getObjects()) {
+            if (type.equals("prod")) {
+                if (hl.getCurrentEnergyAtTimeStep(x) > 0) {
+                    energy = energy + hl.getCurrentEnergyAtTimeStep(x);
+                    hl.setState(3);
+                }
+            }
+            if (type.equals("cons")) {
+                if (hl.getCurrentEnergyAtTimeStep(x) < 0) {
+                    energy = energy + hl.getCurrentEnergyAtTimeStep(x);
+                    hl.setState(1);
+                }
+            }
+            if (hl.getCurrentEnergyAtTimeStep(x) == 0) {
+                hl.setState(0);
+            }
+        }
+        return energy;
+    }
+
+    /**
+     * Calculate the Minimum Energy.
+     *
+     * @param sN Subnet
+     * @param x  Integer
+     * @return the Calculated minimum 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);
+                }
+            }
+            min = min + minElement;
+        }
+        return min;
+    }
+
+    /**
+     * generates all subNets from all objectsToHandle.
+     */
+    public void searchForSubNets() {
+        subNets = new ArrayList<>();
+        brokenEdges.clear();
+        boolean end = false;
+        int i = 0;
+        AbstractCpsObject cps;
+        if (objectsToHandle.size() > 0) {
+            while (!end) {
+                cps = objectsToHandle.get(i);
+                SubNet singleSubNet = new SubNet(new ArrayList<>(), new ArrayList<>(),
+                        new ArrayList<>());
+                singleSubNet = buildSubNet(cps, new ArrayList<>(), singleSubNet);
+                if (singleSubNet.getObjects().size() != 0) {
+                    subNets.add(singleSubNet);
+                }
+                if (0 == objectsToHandle.size()) {
+                    end = true;
+                }
+            }
+        }
+    }
+
+    /**
+     * recursivly generates a subnet of all objects, that one specific object is
+     * connected to.
+     *
+     * @param cps     AbstractCpsObject
+     * @param visited visited Array of Integer
+     * @param sN      Subnets
+     * @return Subnet
+     */
+    public SubNet buildSubNet(AbstractCpsObject cps, ArrayList<Integer> visited, SubNet sN) {
+        visited.add(cps.getId());
+        if (cps instanceof HolonObject) {
+            sN.getObjects().add((HolonObject) cps);
+        }
+        if (cps instanceof HolonSwitch) {
+            sN.getSwitches().add((HolonSwitch) cps);
+        }
+        removeFromToHandle(cps.getId());
+        AbstractCpsObject a;
+        AbstractCpsObject b;
+        for (CpsEdge edge : cps.getConnections()) {
+            if (edge.isWorking()) {
+                a = edge.getA();
+                b = edge.getB();
+                if (!(cps instanceof HolonSwitch)) {
+                    if (!(sN.getEdges().contains(edge))) {
+                        sN.getEdges().add(edge);
+                    }
+                }
+                if (cps instanceof HolonSwitch && ((HolonSwitch) cps).getState(timeStep)) {
+                    if (!(sN.getEdges().contains(edge))) {
+                        sN.getEdges().add(edge);
+                    }
+                }
+                if (!visited.contains(a.getId()) && legitState(cps) && !(a instanceof CpsUpperNode)) {
+                    sN = buildSubNet(a, visited, sN);
+                }
+                if (!visited.contains(b.getId()) && legitState(cps) && !(b instanceof CpsUpperNode)) {
+                    sN = buildSubNet(b, visited, sN);
+                }
+                if (a instanceof CpsUpperNode && a.getId() != cps.getId()) {
+                    edge.setConnected(CpsEdge.CON_UPPER_NODE_NOT_INSIDE);
+                    checkForConnectedStates(b, (CpsUpperNode) a, edge);
+                }
+                if (b instanceof CpsUpperNode && b.getId() != cps.getId()) {
+                    edge.setConnected(CpsEdge.CON_UPPER_NODE_NOT_INSIDE);
+                    checkForConnectedStates(a, (CpsUpperNode) b, edge);
+                }
+            } else {
+                brokenEdges.add(edge);
+            }
+        }
+        return sN;
+    }
+
+    /**
+     * is the Switch in a legitimate State.
+     *
+     * @param current AbstractCpsObject
+     * @return boolean
+     */
+    public boolean legitState(AbstractCpsObject current) {
+        if (current instanceof HolonSwitch) {
+            return ((HolonSwitch) current).getState(timeStep);
+        }
+        return true;
+    }
+
+    /**
+     * removes an Object that already has been handled with.
+     *
+     * @param id the Object ID
+     */
+    public void removeFromToHandle(int id) {
+        for (int i = 0; i < objectsToHandle.size(); i++) {
+            if (objectsToHandle.get(i).getId() == id) {
+                objectsToHandle.remove(i);
+            }
+        }
+    }
+
+//    /**
+//     * ensures that objectsToHandle only contains HolonObjects.
+//     */
+//	public void cleanObjectsToHandle() {
+//		for (int i = 0; i < objectsToHandle.size(); i++) {
+//			if (!(objectsToHandle.get(i) instanceof HolonObject)) {
+//				objectsToHandle.remove(i);
+//			}
+//		}
+//	}
+
+    /**
+     * copies the data of an array of Objects.
+     *
+     * @param toCopy the ArrayList of CpsObjects co Copy
+     */
+    public void copyObjects(ArrayList<AbstractCpsObject> toCopy) {
+        for (AbstractCpsObject cps : toCopy) {
+            if (cps instanceof CpsUpperNode) {
+                copyObjects(((CpsUpperNode) cps).getNodes());
+            } else {
+                objectsToHandle.add(cps);
+            }
+        }
+    }
+
+    /**
+     * Prints the Components auf all subnets.
+     */
+    public void printNet() {
+        for (int i = 0; i < subNets.size(); i++) {
+            System.out.println("SUBNET NR:" + i);
+            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("  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("  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]);
+            }
+        }
+    }
+
+    /**
+     * Set the Canvas.
+     *
+     * @param can the Canvas
+     */
+    public void setCanvas(MyCanvas can) {
+        canvas = can;
+    }
+
+    /**
+     * Reset all Data to the current state of the Model.
+     */
+    public void reset() {
+        objectsToHandle = new ArrayList<>();
+        copyObjects(model.getObjectsOnCanvas());
+    }
+
+    /**
+     * Resets the State of all Edges
+     */
+    public void resetEdges() {
+        for (CpsEdge e : brokenEdges) {
+            e.setWorkingState(true);
+        }
+    }
+
+    /**
+     * Resets the State for the whole Simulation Model
+     */
+    public void resetSimulation() {
+        reset();
+        resetEdges();
+    }
+
+    /**
+     * Get all Subnets.
+     *
+     * @return all Subnets
+     */
+    public ArrayList<SubNet> getSubNets() {
+        return subNets;
+    }
+
+    /**
+     * Get broken Edges
+     */
+    public ArrayList<CpsEdge> getBrokenEdges() {
+        return brokenEdges;
+    }
+
+    /**
+     * checks wether a given object is connected to an object inside the upperNode.
+     * if yes, the state for the edge is changed in "connected" or "not connected"
+     *
+     * @param cps
+     * @param cUNode
+     */
+    public void checkForConnectedStates(AbstractCpsObject cps, CpsUpperNode cUNode, CpsEdge theEdge) {
+        AbstractCpsObject tmp;
+        for (CpsEdge edge : cps.getConnections()) {
+            if (edge.getA().getId() == cps.getId()) {
+                tmp = edge.getB();
+            } else {
+                tmp = edge.getA();
+            }
+            if (cUNode.getNodes().contains(tmp)) {
+                if (tmp instanceof CpsUpperNode) {
+                    checkForConnectedStates(cps, (CpsUpperNode) tmp, theEdge);
+                } else {
+                    theEdge.setConnected(CpsEdge.CON_UPPER_NODE_AND_INSIDE);
+                    break;
+                }
+            }
+        }
+    }
+
+    public FlexiblePane getFlexiblePane() {
+        return flexPane;
+    }
+
+    public void setFlexiblePane(FlexiblePane fp) {
+        flexPane = fp;
+    }
 
 }

+ 7 - 13
src/ui/controller/UpdateController.java

@@ -1,21 +1,15 @@
 package ui.controller;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import classes.AbstractCpsObject;
-import classes.CpsEdge;
-import classes.CpsUpperNode;
-import classes.HolonElement;
-import classes.HolonObject;
-import classes.HolonSwitch;
-import classes.SubNet;
+import classes.*;
 import ui.model.Model;
 import ui.view.DefaulTable;
 import ui.view.Languages;
 import ui.view.PropertyTable;
 import ui.view.UpperNodeCanvas;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+
 /**
  * This class is for all update methods and more ;)
  * 
@@ -329,9 +323,9 @@ public class UpdateController {
 			Object[] tempCapacity = { Languages.getLanguage()[81], model.getSelectedEdge().getCapacity() };
 			model.getPropertyTable().addRow(tempCapacity);
 			// Status displayed
-			Object[] tempStatus = { Languages.getLanguage()[82], model.getSelectedEdge().getState() };
-			model.getPropertyTable().addRow(tempStatus);
-			// For edges, the only possible editable cell is the max
+            Object[] tempStatus = {Languages.getLanguage()[82], model.getSelectedEdge().isWorking()};
+            model.getPropertyTable().addRow(tempStatus);
+            // For edges, the only possible editable cell is the max
 			// flow
 			model.getPropertyTable().setCellEditable(0, 1, false);
 			model.getPropertyTable().setCellEditable(2, 1, true);

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

@@ -105,9 +105,9 @@ public abstract class AbstractCanvas extends JPanel {
 
 
     protected void setEdgeState(CpsEdge con) {
-        if (con.getState()) {
+        if (con.isWorking()) {
             g2.setColor(Color.GREEN);
-            if (con.getCapacity() != -1) {
+            if (con.getCapacity() != CpsEdge.CAPACITY_INFINITE) {
                 g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
             }
         } else {

+ 9 - 19
src/ui/view/EditEdgesPopUp.java

@@ -1,26 +1,16 @@
 package ui.view;
 
-import java.awt.BorderLayout;
-import java.awt.Font;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-import javax.swing.JTextField;
-import javax.swing.border.EmptyBorder;
-
 import classes.AbstractCpsObject;
 import classes.CpsEdge;
 import classes.CpsUpperNode;
 import ui.controller.Control;
 
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
 /**
  * Popup for Editing Edges.
  * 
@@ -202,9 +192,9 @@ public class EditEdgesPopUp extends JDialog {
 		 */
 		for (CpsEdge edge : controller.getModel().getEdgesOnCanvas()) {
 			edge.setCapacity(cap);
-			edge.setState(true);
-		}
-		for (AbstractCpsObject abs : controller.getModel().getObjectsOnCanvas()) {
+            edge.setWorkingState(true);
+        }
+        for (AbstractCpsObject abs : controller.getModel().getObjectsOnCanvas()) {
 			if (abs instanceof CpsUpperNode) {
 				changeInUpperNode((CpsUpperNode) abs, cap);
 			}

+ 1 - 1
src/ui/view/GUI.java

@@ -1145,7 +1145,7 @@ public class GUI<E> implements CategoryListener {
                     // Status edition through a check box
                     if (selValueYBool == 3) {
                         Boolean bbTemp = Boolean.parseBoolean(btemp.toString());
-                        model.getSelectedEdge().setState(bbTemp);
+                        model.getSelectedEdge().setWorkingState(bbTemp);
                     }
                 }
                 canvas.repaint();