Browse Source

eval done

DESKTOP-L7IQHES\Jonas 2 years ago
parent
commit
01e164c7ec

BIN
exampleNetworks/MyExamples/scenario01-25h.holon


BIN
exampleNetworks/MyExamples/scenario02-25h.holon


BIN
exampleNetworks/MyExamples/scenario03-50h.holon


+ 1 - 1
src/classes/holonControlUnit/CommunicationModule.java

@@ -55,7 +55,7 @@ public class CommunicationModule {
 				receiveNeighborhoodMsg(msg);
 				break;
 			case STATE_REQUEST:
-				this.hcu.getStateEstimator().receiveStateRequest(msg.getSender(), this.gson.fromJson(msg.getBody(), StateRequestMsg.class));
+				this.hcu.receiveStateRequest(msg.getSender(), this.gson.fromJson(msg.getBody(), StateRequestMsg.class));
 				break;
 			case STATE:
 				this.hcu.getStateEstimator().receiveState(msg.getSender(), this.gson.fromJson(msg.getBody(), StateMsg.class));

+ 2 - 1
src/classes/holonControlUnit/FlexibilityManager.java

@@ -25,6 +25,7 @@ public class FlexibilityManager {
 		FlexManager fm = getFlexManager(timeStep);
 		
 		List<Flexibility> offeredFlexes = fm.getAllFlexWrapperWithState(FlexState.OFFERED).stream().map(fw -> fw.getFlex()).collect(Collectors.toList());
+//		System.out.println("offered flexes: "+offeredFlexes+"\nall: "+fm.getAllFlexWrapper().stream().map(fw -> fw.getFlex()).collect(Collectors.toList()));
 		List<List<Flexibility>> offeredPerm = getAllPermutations(offeredFlexes);
 		HashMap<Float, List<Flexibility>> map = new HashMap<>();
 		for(List<Flexibility> l : offeredPerm) {
@@ -64,7 +65,7 @@ public class FlexibilityManager {
 		}
 		if(map.containsKey(min)) {
 			fm.orderFlexFromList(map.get(min));
-//			System.out.println(this.hcu.getHolon().getUniqueID()+" ordered flexes "+map.get(min));
+//			System.out.println(this.hcu.getHolon().getUniqueID()+" ordered flexes "+map.get(min)+" "+requiredPower+" "+currentPower);
 			this.appliedFlexCounter += map.get(min).size();
 			return min;
 		}

+ 23 - 0
src/classes/holonControlUnit/HolonControlUnit.java

@@ -18,6 +18,7 @@ public class HolonControlUnit {
 	private StateEstimator stateEstimator;
 	private TargetStateAssembler stateAssembler;
 	private CommunicationModule communicator;
+	private ArrayList<StateMsg> states;
 	
 	public HolonControlUnit(Holon h) {
 		this.holon = h;
@@ -28,6 +29,7 @@ public class HolonControlUnit {
 		this.stateEstimator = new StateEstimator(this);
 		this.stateAssembler = new TargetStateAssembler(this);
 		this.communicator = new CommunicationModule(this);
+		this.states = new ArrayList<StateMsg>();
 	}
 
 	public ArrayList<Holon> getSubHolon() {
@@ -79,6 +81,7 @@ public class HolonControlUnit {
 	}
 	
 	public void computeState(int timeStep) {
+//		System.out.println("compute state for "+this.holon.name+"\n\tchild holons "+this.hierarchyController.getSubHolons());
 		//compute current state
 		this.stateEstimator.computeState(timeStep);
 		//compute target state
@@ -86,6 +89,26 @@ public class HolonControlUnit {
 		//evaluate optimization scheme
 		this.optimizer.evaluateOptimizationScheme(timeStep);
 	}
+	
+	public void receiveStateRequest(String sender, StateRequestMsg req) {
+		int timeStep = req.getTimeStep();
+		if(!sender.equals(this.hierarchyController.getSuperHolon()) || timeStep < 0) {
+			return;
+		}
+		
+		if(this.states.size() > timeStep) {
+			String body = this.communicator.getGson().toJson(this.states.get(timeStep));
+			this.communicator.sendMsg(sender, Message.Type.STATE, body);
+		} else {
+			computeState(timeStep);
+			StateMsg stateMsg = new StateMsg(this.stateEstimator.getPowerUsage(), this.stateEstimator.getNetThroughput(), 
+					this.stateEstimator.getPredictedPowerUsage(), this.stateEstimator.getStateIndicator());
+			//send current state to sender (super holon)
+			String body = this.communicator.getGson().toJson(stateMsg);
+			this.communicator.sendMsg(sender, Message.Type.STATE, body);
+			this.states.add(stateMsg);
+		}
+	}
 
 	public boolean matchPowerRange(float power, float des, ArrayList<Float> prePower, float threshold) {
 		float diff =  Math.abs(des -  threshold * des);

+ 0 - 20
src/classes/holonControlUnit/StateEstimator.java

@@ -36,7 +36,6 @@ public class StateEstimator {
 	private float netThroughput;
 	private HashMap<String, StateMsg> childStates;
 	private ArrayList<Float> predictedPowerUsage;
-	private ArrayList<StateMsg> states;
 //	private HashMap<String, Float> powerUsagesInsideHolarchy;
 	
 	public StateEstimator(HolonControlUnit hcu) {
@@ -44,7 +43,6 @@ public class StateEstimator {
 		this.stateInd = StateIndicator.DESIRED;
 //		this.powerUsagesInsideHolarchy = new HashMap<String, Float>();
 		this.childStates = new HashMap<String, StateMsg>();
-		this.states = new ArrayList<StateMsg>();
 	}
 
 	public StateIndicator getStateIndicator() {
@@ -144,24 +142,6 @@ public class StateEstimator {
 			return;
 		this.childStates.put(sender, stateMsg);
 	}
-	
-	public void receiveStateRequest(String sender, StateRequestMsg req) {
-		int timeStep = req.getTimeStep();
-		if(!sender.equals(this.hcu.getHierarchyController().getSuperHolon()) || timeStep < 0)
-			return;
-		
-		if(this.states.size() > timeStep) {
-			String body = this.hcu.getCommunicator().getGson().toJson(this.states.get(timeStep));
-			this.hcu.getCommunicator().sendMsg(sender, Message.Type.STATE, body);
-		} else {
-			computeState(timeStep);
-			StateMsg stateMsg = new StateMsg(this.powerUsage, this.netThroughput, this.predictedPowerUsage, this.stateInd);
-			//send current state to sender (super holon)
-			String body = this.hcu.getCommunicator().getGson().toJson(stateMsg);
-			this.hcu.getCommunicator().sendMsg(sender, Message.Type.STATE, body);
-			this.states.add(stateMsg);
-		}
-	}
 
 	public float getPowerUsage() {
 		return this.powerUsage;

+ 6 - 2
src/classes/holonControlUnit/TargetStateAssembler.java

@@ -26,13 +26,17 @@ public class TargetStateAssembler {
 	}
 	
 	public void assembleTargetState(int timeStep) {
-		if(this.order == null || this.order.getTimeStep() >= timeStep-1) {
+		if(timeStep <= 1) {
+			//for init
+			this.desiredPowerUsage = this.hcu.getStateEstimator().getPredictedPowerUsage().get(0);
+		} else if(this.order == null || this.order.getTimeStep() < timeStep-1) {
 			this.desiredPowerUsage =  0f;
 		} else {
 			this.desiredPowerUsage = this.order.getDesiredPowerUsage();
 		}
 //		this.ordersForSubholon.clear();
-//		System.out.println(this.hcu.getHolon().getUniqueID()+" opt scheme: "+this.hcu.getOptimizer().getOptimizationScheme());
+//		System.out.println(this.hcu.getHolon().name+" opt scheme: "+this.hcu.getOptimizer().getOptimizationScheme());
+//		System.out.println(this.hcu.getHolon().getUniqueID()+" power: "+this.hcu.getStateEstimator().getPowerUsage()+" des: "+this.desiredPowerUsage);
 
 		//balance the sub holons
 		OptimizationScheme optScheme = this.hcu.getOptimizer().getOptimizationScheme();

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

@@ -536,7 +536,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 		
 		VisualRepresentationalState  visualState = controller.getSimManager().getActualVisualRepresentationalState();
 		//VisualState Representation:
-		if(visualState == null) System.out.println("AHHH"); 
+		if(visualState == null) System.err.println("AHHH"); 
 		for(ExitCable cable : visualState.getExitCableList()) {
 			paintExitCable(g2d, cable);
 		}

+ 2 - 2
tests/holon_control_unit_evaluation/Main.java

@@ -32,8 +32,8 @@ public class Main {
 //        IndexTranslator.model = model;
 //        view.getFrmCyberPhysical().setVisible(true);
         
-        String fileName = "C:\\Users\\Jonas\\Dropbox\\Mein PC (DESKTOP-L7IQHES)\\Documents\\Uni\\TUD\\Bachelorarbeit\\Eval\\inputs\\scenario02-25h_"+System.currentTimeMillis();
-		String path = "C:\\Users\\Jonas\\Dropbox\\Mein PC (DESKTOP-L7IQHES)\\Documents\\Uni\\TUD\\Bachelorarbeit\\HOLEG\\exampleNetworks\\MyExamples\\scenario02-25h.holon";
+        String fileName = "C:\\Users\\Jonas\\Dropbox\\Mein PC (DESKTOP-L7IQHES)\\Documents\\Uni\\TUD\\Bachelorarbeit\\bachelor-evaluation\\Eval\\inputs\\scenario03-50h_"+System.currentTimeMillis();
+		String path = "C:\\Users\\Jonas\\Dropbox\\Mein PC (DESKTOP-L7IQHES)\\Documents\\Uni\\TUD\\Bachelorarbeit\\HOLEG\\exampleNetworks\\MyExamples\\scenario03-50h.holon";
         PrintStream systemOut = System.out;
 		
         Model model = new Model();