|
@@ -38,13 +38,14 @@ public class SimulationManager {
|
|
|
float consumption = calculateEnergy("cons", singleSubNet, x);
|
|
|
float minConsumption = calculateMinimumEnergy( singleSubNet, x);
|
|
|
for(CpsEdge e: singleSubNet.getEdges()){
|
|
|
- e.setFlow(production);
|
|
|
+ e.setFlow(0);
|
|
|
}
|
|
|
+ setFlow(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()){
|
|
|
+ if(edge.getState() && edge.getFlow() > 0){
|
|
|
// 0 = no energy, 1 = not supplied, 2 = supplied
|
|
|
if((production + consumption) >= 0){
|
|
|
hl.setState(2);
|
|
@@ -69,6 +70,32 @@ public class SimulationManager {
|
|
|
canvas.repaint();
|
|
|
}
|
|
|
|
|
|
+ public void setFlow(subNet sN){
|
|
|
+ for(HolonObject hl: sN.getObjects()){
|
|
|
+ if(hl.getCurrentEnergyAtTimeStep(timeStep) > 0){
|
|
|
+ fillConnectionsFor(hl, new ArrayList<Integer>(), new ArrayList<CpsEdge>(), hl.getCurrentEnergyAtTimeStep(timeStep));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void fillConnectionsFor(CpsObject cps, ArrayList<Integer> visitedObj, ArrayList<CpsEdge> visitedEdges ,float energy ){
|
|
|
+ visitedObj.add(cps.getID());
|
|
|
+ for(CpsEdge e: cps.getConnections()){
|
|
|
+ if(!(visitedEdges.contains(e))){
|
|
|
+ e.setFlow(e.getFlow() + energy);
|
|
|
+ if(e.getState()){
|
|
|
+ visitedEdges.add(e);
|
|
|
+ if(!(visitedObj.contains(e.getA().getID()))){
|
|
|
+ fillConnectionsFor(e.getA(), visitedObj, visitedEdges, energy);
|
|
|
+ }
|
|
|
+ if(!(visitedObj.contains(e.getB().getID()))){
|
|
|
+ fillConnectionsFor(e.getB(), visitedObj, visitedEdges, energy);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* calculates the energy of either all producers or consumers
|
|
|
* @param type
|
|
@@ -109,7 +136,6 @@ public class SimulationManager {
|
|
|
minElement = he.getTotalEnergyAtTimeStep(x);
|
|
|
}
|
|
|
}
|
|
|
- System.out.println(minElement);
|
|
|
min = min + minElement;
|
|
|
}
|
|
|
return min;
|