|
@@ -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);
|