|
@@ -16,38 +16,47 @@ public class SimulationManager {
|
|
|
|
|
|
public SimulationManager(Model m){
|
|
public SimulationManager(Model m){
|
|
model = m;
|
|
model = m;
|
|
- copyObjects(m.getObjectsOnCanvas());
|
|
|
|
subNets = new ArrayList<subNet>();
|
|
subNets = new ArrayList<subNet>();
|
|
}
|
|
}
|
|
|
|
|
|
- public void calculateStateForTimeStep(){
|
|
|
|
|
|
+
|
|
|
|
+ public void calculateStateForTimeStep(int x){
|
|
searchForSubNets();
|
|
searchForSubNets();
|
|
for(subNet singleSubNet: subNets){
|
|
for(subNet singleSubNet: subNets){
|
|
- float production = calculateEnergy("prod", singleSubNet);
|
|
|
|
- float consumption = calculateEnergy("cons", singleSubNet);
|
|
|
|
|
|
+ float production = calculateEnergy("prod", singleSubNet, x);
|
|
|
|
+ float consumption = calculateEnergy("cons", singleSubNet, x);
|
|
for(CpsEdge e: singleSubNet.getEdges()){
|
|
for(CpsEdge e: singleSubNet.getEdges()){
|
|
e.setFlow(production);
|
|
e.setFlow(production);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public float calculateEnergy(String type, subNet sN){
|
|
|
|
|
|
+ /**
|
|
|
|
+ * calculates the energy of either all producers or consumers
|
|
|
|
+ * @param type
|
|
|
|
+ * @param sN
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public float calculateEnergy(String type, subNet sN, int x){
|
|
float energy = 0;
|
|
float energy = 0;
|
|
for(HolonObject hl: sN.getObjects()){
|
|
for(HolonObject hl: sN.getObjects()){
|
|
if(type.equals("prod")){
|
|
if(type.equals("prod")){
|
|
- if(hl.getCurrentEnergy() > 0){
|
|
|
|
- energy = energy + hl.getCurrentEnergy();
|
|
|
|
|
|
+ if(hl.getCurrentEnergyAtTimeStep(x) > 0){
|
|
|
|
+ energy = energy + hl.getCurrentEnergyAtTimeStep(x);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(type.equals("cons")){
|
|
if(type.equals("cons")){
|
|
- if(hl.getCurrentEnergy() < 0){
|
|
|
|
- energy = energy + hl.getCurrentEnergy();
|
|
|
|
|
|
+ if(hl.getCurrentEnergyAtTimeStep(x) < 0){
|
|
|
|
+ energy = energy + hl.getCurrentEnergyAtTimeStep(x);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return energy;
|
|
return energy;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * generates all subNets from all objectsToHandle
|
|
|
|
+ */
|
|
public void searchForSubNets(){
|
|
public void searchForSubNets(){
|
|
subNets = new ArrayList<subNet>();
|
|
subNets = new ArrayList<subNet>();
|
|
boolean end = false;
|
|
boolean end = false;
|
|
@@ -69,6 +78,13 @@ public class SimulationManager {
|
|
printNet();
|
|
printNet();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * recursivly generates a subnet of all objects, that one specific object is connected to
|
|
|
|
+ * @param cps
|
|
|
|
+ * @param visited
|
|
|
|
+ * @param sN
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
public subNet buildSubNet(CpsObject cps, ArrayList<Integer> visited, subNet sN){
|
|
public subNet buildSubNet(CpsObject cps, ArrayList<Integer> visited, subNet sN){
|
|
visited.add(cps.getID());
|
|
visited.add(cps.getID());
|
|
if(cps instanceof HolonObject){
|
|
if(cps instanceof HolonObject){
|
|
@@ -89,6 +105,10 @@ public class SimulationManager {
|
|
return sN;
|
|
return sN;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * removes an Object that already has been handled with
|
|
|
|
+ * @param id
|
|
|
|
+ */
|
|
public void removeFromToHandle(int id){
|
|
public void removeFromToHandle(int id){
|
|
for(int i = 0; i < objectsToHandle.size(); i++){
|
|
for(int i = 0; i < objectsToHandle.size(); i++){
|
|
if(objectsToHandle.get(i).getID() == id){
|
|
if(objectsToHandle.get(i).getID() == id){
|
|
@@ -97,6 +117,9 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * ensures that objectsToHandle only contains HolonObjects
|
|
|
|
+ */
|
|
public void cleanObjectsToHandle(){
|
|
public void cleanObjectsToHandle(){
|
|
for(int i = 0; i < objectsToHandle.size(); i++){
|
|
for(int i = 0; i < objectsToHandle.size(); i++){
|
|
if(!(objectsToHandle.get(i) instanceof HolonObject)){
|
|
if(!(objectsToHandle.get(i) instanceof HolonObject)){
|
|
@@ -105,6 +128,10 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * copies the data of an array of Objects
|
|
|
|
+ * @param toCopy
|
|
|
|
+ */
|
|
public void copyObjects(ArrayList<CpsObject> toCopy){
|
|
public void copyObjects(ArrayList<CpsObject> toCopy){
|
|
objectsToHandle = new ArrayList<CpsObject>();
|
|
objectsToHandle = new ArrayList<CpsObject>();
|
|
for(CpsObject cps: toCopy){
|
|
for(CpsObject cps: toCopy){
|
|
@@ -112,6 +139,9 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Prints the Components auf all subnets
|
|
|
|
+ */
|
|
public void printNet(){
|
|
public void printNet(){
|
|
for(int i = 0; i < subNets.size(); i++){
|
|
for(int i = 0; i < subNets.size(); i++){
|
|
System.out.println("SUBNET NR:" + i);
|
|
System.out.println("SUBNET NR:" + i);
|
|
@@ -129,5 +159,9 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void reset(){
|
|
|
|
+ copyObjects(model.getObjectsOnCanvas());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|