|
@@ -26,24 +26,22 @@ public class Holon {
|
|
public Model model;
|
|
public Model model;
|
|
private MinimumModel minModel;
|
|
private MinimumModel minModel;
|
|
/** stores whether the part between this holon and the child is occupied by the superholon */
|
|
/** stores whether the part between this holon and the child is occupied by the superholon */
|
|
- private boolean canRunIndependentFromParent;
|
|
|
|
|
|
+ private HashMap<Holon, ArrayList<Edge>> pathsToChildren;
|
|
|
|
|
|
public Holon(String name, Model model) {
|
|
public Holon(String name, Model model) {
|
|
this.name = name;
|
|
this.name = name;
|
|
- this.parent = parent;
|
|
|
|
this.holonObject = null;
|
|
this.holonObject = null;
|
|
isPhysical = false;
|
|
isPhysical = false;
|
|
this.uniqueID = UUID.randomUUID().toString();
|
|
this.uniqueID = UUID.randomUUID().toString();
|
|
this.model = model;
|
|
this.model = model;
|
|
this.holonControlUnit = new HolonControlUnit(this);
|
|
this.holonControlUnit = new HolonControlUnit(this);
|
|
this.minModel = new MinimumModel(new ArrayList<AbstractCanvasObject>(), new ArrayList<Edge>());
|
|
this.minModel = new MinimumModel(new ArrayList<AbstractCanvasObject>(), new ArrayList<Edge>());
|
|
- this.canRunIndependentFromParent = true;
|
|
|
|
|
|
+ this.pathsToChildren = new HashMap<Holon, ArrayList<Edge>>();
|
|
}
|
|
}
|
|
|
|
|
|
public Holon(HolonObject object, Model model) {
|
|
public Holon(HolonObject object, Model model) {
|
|
holonObject = object;
|
|
holonObject = object;
|
|
object.holon = this;
|
|
object.holon = this;
|
|
- this.parent = parent;
|
|
|
|
name = object.getName();
|
|
name = object.getName();
|
|
elements.addAll(object.getElements());
|
|
elements.addAll(object.getElements());
|
|
for(HolonElement ele : elements) {
|
|
for(HolonElement ele : elements) {
|
|
@@ -56,7 +54,7 @@ public class Holon {
|
|
ArrayList<AbstractCanvasObject> list = new ArrayList<AbstractCanvasObject>();
|
|
ArrayList<AbstractCanvasObject> list = new ArrayList<AbstractCanvasObject>();
|
|
list.add(object);
|
|
list.add(object);
|
|
this.minModel = new MinimumModel(list, new ArrayList<Edge>());
|
|
this.minModel = new MinimumModel(list, new ArrayList<Edge>());
|
|
- this.canRunIndependentFromParent = true;
|
|
|
|
|
|
+ this.pathsToChildren = new HashMap<Holon, ArrayList<Edge>>();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -73,25 +71,35 @@ public class Holon {
|
|
}
|
|
}
|
|
|
|
|
|
public void addChild(Holon child) {
|
|
public void addChild(Holon child) {
|
|
|
|
+ if(child.equals(this)) {
|
|
|
|
+ System.err.println(this.uniqueID+" wants to merge itself");
|
|
|
|
+ }
|
|
if(!this.childHolons.contains(child)) {
|
|
if(!this.childHolons.contains(child)) {
|
|
- child.parent = this;
|
|
|
|
|
|
+ child.setParent(this);
|
|
this.childHolons.add(child);
|
|
this.childHolons.add(child);
|
|
}
|
|
}
|
|
- this.holonControlUnit.addSubHolon(child);
|
|
|
|
|
|
+ if(this.parent != null) {
|
|
|
|
+ this.holonControlUnit.addSubHolon(child);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void addChildHolon(Holon child, int index) {
|
|
public void addChildHolon(Holon child, int index) {
|
|
if(!this.childHolons.contains(child)) {
|
|
if(!this.childHolons.contains(child)) {
|
|
- child.parent = this;
|
|
|
|
|
|
+ child.setParent(this);
|
|
childHolons.add(index, child);
|
|
childHolons.add(index, child);
|
|
}
|
|
}
|
|
- this.holonControlUnit.addSubHolon(child);
|
|
|
|
|
|
+ if(this.parent != null) {
|
|
|
|
+ this.holonControlUnit.addSubHolon(child);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void removeChildHolon(Holon child) {
|
|
public void removeChildHolon(Holon child) {
|
|
- child.parent = null;
|
|
|
|
|
|
+ child.setParent(null);
|
|
childHolons.remove(child);
|
|
childHolons.remove(child);
|
|
|
|
+ if(this.parent == null)
|
|
|
|
+ return;
|
|
this.holonControlUnit.getHierarchyController().removeSubHolon(child.getUniqueID());
|
|
this.holonControlUnit.getHierarchyController().removeSubHolon(child.getUniqueID());
|
|
|
|
+ this.pathsToChildren.remove(child);
|
|
revalidateMinModel();
|
|
revalidateMinModel();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -99,7 +107,7 @@ public class Holon {
|
|
if(parent != null) {
|
|
if(parent != null) {
|
|
parent.removeChildHolon(this);
|
|
parent.removeChildHolon(this);
|
|
}
|
|
}
|
|
- parent = model.getStateHolon();
|
|
|
|
|
|
+ this.setParent(model.getStateHolon());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -113,7 +121,9 @@ public class Holon {
|
|
|
|
|
|
public void setParent(Holon parent) {
|
|
public void setParent(Holon parent) {
|
|
this.parent = parent;
|
|
this.parent = parent;
|
|
- this.holonControlUnit.getHierarchyController().setSuperHolon(parent.getUniqueID());
|
|
|
|
|
|
+ if(parent != null) {
|
|
|
|
+ this.holonControlUnit.getHierarchyController().setSuperHolon(parent.getUniqueID());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public HolonObject getHolonObject() {
|
|
public HolonObject getHolonObject() {
|
|
@@ -144,7 +154,7 @@ public class Holon {
|
|
|
|
|
|
|
|
|
|
public void removeAllRefrences() {
|
|
public void removeAllRefrences() {
|
|
- parent = null;
|
|
|
|
|
|
+ this.setParent(null);
|
|
this.childHolons.clear();
|
|
this.childHolons.clear();
|
|
this.elements.clear();
|
|
this.elements.clear();
|
|
}
|
|
}
|
|
@@ -152,6 +162,11 @@ public class Holon {
|
|
|
|
|
|
|
|
|
|
public int getLayer() {
|
|
public int getLayer() {
|
|
|
|
+ if(this.parent == null)
|
|
|
|
+ return 0;
|
|
|
|
+ if(this.parent.equals(this)) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
return parent != null ? parent.getLayer() + 1 : 0;
|
|
return parent != null ? parent.getLayer() + 1 : 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -186,7 +201,7 @@ public class Holon {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ @Deprecated
|
|
public void checkRepairHolarchy(HashMap<HolonObject, DecoratedNetwork> table, Holon stateHolon) {
|
|
public void checkRepairHolarchy(HashMap<HolonObject, DecoratedNetwork> table, Holon stateHolon) {
|
|
if(childHolons.isEmpty()) {
|
|
if(childHolons.isEmpty()) {
|
|
return;
|
|
return;
|
|
@@ -207,7 +222,7 @@ public class Holon {
|
|
if(isPureAbstract) {
|
|
if(isPureAbstract) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- boolean isPhysicalConnected = model.checkHolonObjectsAreConnected(this, other);
|
|
|
|
|
|
+ boolean isPhysicalConnected = model.checkHolonObjectsAreConnected(this, other, 0f);
|
|
if(!isPhysicalConnected) {
|
|
if(!isPhysicalConnected) {
|
|
removeList.add(other);
|
|
removeList.add(other);
|
|
}
|
|
}
|
|
@@ -240,49 +255,90 @@ public class Holon {
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public ArrayList<AbstractCanvasObject> getAllObjects(){
|
|
|
|
+ ArrayList<AbstractCanvasObject> list = new ArrayList<AbstractCanvasObject>();
|
|
|
|
+
|
|
|
|
+ list.addAll(this.minModel.getHolonObjectList());
|
|
|
|
+ list.addAll(this.minModel.getNodeList());
|
|
|
|
+ list.addAll(this.minModel.getSwitchList());
|
|
|
|
+ list.addAll(this.minModel.getUppderNodeList());
|
|
|
|
+
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
public MinimumModel getMinimumModel() {
|
|
public MinimumModel getMinimumModel() {
|
|
return this.minModel;
|
|
return this.minModel;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public HashMap<Holon, ArrayList<Edge>> getPathsToChildren() {
|
|
|
|
+ return pathsToChildren;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * merge this holon as a child with the holon specified by the id
|
|
|
|
+ * @param id
|
|
|
|
+ */
|
|
|
|
+ public void merge(String id) {
|
|
|
|
+ if(id.equals("State Holon")) {
|
|
|
|
+ this.split(this.model.getStateHolon());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Holon h = this.model.getHolonsByID().get(id);
|
|
|
|
+ if(h != null) {
|
|
|
|
+ h.split(this);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * merge this holon with the specified child holon
|
|
|
|
+ * @param child
|
|
|
|
+ */
|
|
public void merge(Holon child) {
|
|
public void merge(Holon child) {
|
|
if(!this.model.getHolonsByID().containsKey(child.getUniqueID())) {
|
|
if(!this.model.getHolonsByID().containsKey(child.getUniqueID())) {
|
|
System.err.println("could not find: "+child.getHolonObject());
|
|
System.err.println("could not find: "+child.getHolonObject());
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if(this.childHolons.contains(child)) {
|
|
if(this.childHolons.contains(child)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- if(this.getLayer() == 0) {
|
|
|
|
|
|
+
|
|
|
|
+ if(this.parent == null) {
|
|
this.addChild(child);
|
|
this.addChild(child);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- //check if path between this holon and child holon is already occupied
|
|
|
|
- ArrayList<HolonObject> holarchy = getAllHolonObjects();
|
|
|
|
- holarchy.addAll(child.getAllHolonObjects());
|
|
|
|
- HashMap<Float, ArrayList<Edge>> paths = this.model.getShortestPathToHolarchy(this.minModel, child.getMinimumModel(), holarchy);
|
|
|
|
|
|
+ HashMap<Float, ArrayList<Edge>> paths = this.model.getShortestPathToHolarchy(this.minModel, child.getMinimumModel());
|
|
HashMap<Float, ArrayList<Edge>> free_paths = new HashMap<Float, ArrayList<Edge>>();
|
|
HashMap<Float, ArrayList<Edge>> free_paths = new HashMap<Float, ArrayList<Edge>>();
|
|
HashMap<Float, ArrayList<Edge>> occ_paths = new HashMap<Float, ArrayList<Edge>>();
|
|
HashMap<Float, ArrayList<Edge>> occ_paths = new HashMap<Float, ArrayList<Edge>>();
|
|
HashMap<ArrayList<Edge>, Holon> occ_by = new HashMap<ArrayList<Edge>, Holon>();
|
|
HashMap<ArrayList<Edge>, Holon> occ_by = new HashMap<ArrayList<Edge>, Holon>();
|
|
-
|
|
|
|
|
|
+
|
|
for(Float f : paths.keySet()) {
|
|
for(Float f : paths.keySet()) {
|
|
ArrayList<Edge> path = paths.get(f);
|
|
ArrayList<Edge> path = paths.get(f);
|
|
Holon holder = isPathOccupied(path);
|
|
Holon holder = isPathOccupied(path);
|
|
- if(holder == null || holder.getLayer() == 0 || holder.equals(this.parent)) {
|
|
|
|
|
|
+ if(holder == null || holder.getParent() == null || holder.equals(this) || holder.equals(this.parent)) {
|
|
|
|
+ //path between this holon and child holon is free
|
|
free_paths.put(f, path);
|
|
free_paths.put(f, path);
|
|
} else {
|
|
} else {
|
|
|
|
+ //path between this holon and child holon is already occupied
|
|
occ_paths.put(f, path);
|
|
occ_paths.put(f, path);
|
|
occ_by.put(path, holder);
|
|
occ_by.put(path, holder);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if(free_paths.size() > 0) {
|
|
if(free_paths.size() > 0) {
|
|
- //there is a free path, take it and add child directly
|
|
|
|
|
|
+ //there is a free path, take it and add child directly to sub holons
|
|
|
|
+ ArrayList<Edge> path = free_paths.get(getShortestPath(free_paths));
|
|
|
|
+ Holon holder = this.containsPath(path, this);
|
|
|
|
+ if(holder != null && !holder.equals(this)) {
|
|
|
|
+ //the path already used by a child holon
|
|
|
|
+ holder.merge(child);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
this.addChild(child);
|
|
this.addChild(child);
|
|
- this.addChildToMinModel(child, free_paths.get(getShortestPath(free_paths)));
|
|
|
|
- if(this.getLayer() > 1) {
|
|
|
|
|
|
+ this.addChildToMinModel(child, path);
|
|
|
|
+ this.pathsToChildren.put(child, path);
|
|
|
|
+ if(this.parent != null && this.parent.getParent() != null) {
|
|
this.parent.recalculateMinModel();
|
|
this.parent.recalculateMinModel();
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
@@ -291,21 +347,17 @@ public class Holon {
|
|
System.err.println("something went wrong when looking for shortest path while merging "+this.uniqueID+" and "+child.getUniqueID());
|
|
System.err.println("something went wrong when looking for shortest path while merging "+this.uniqueID+" and "+child.getUniqueID());
|
|
}
|
|
}
|
|
ArrayList<ArrayList<Edge>> shortestPaths = sortPaths(occ_paths);
|
|
ArrayList<ArrayList<Edge>> shortestPaths = sortPaths(occ_paths);
|
|
- for(int i=0; i< shortestPaths.size(); i++) {
|
|
|
|
- //check if holon should merge with holder of this path
|
|
|
|
- ArrayList<Edge> path = shortestPaths.get(i);
|
|
|
|
- Holon holder = occ_by.get(path);
|
|
|
|
- //if true try to merge with holon which is using the path
|
|
|
|
- if(holder != null && holder.getLayer() > 0) {
|
|
|
|
- this.split(holder);
|
|
|
|
- this.addChild(child);
|
|
|
|
- this.addChildToMinModel(child, path);
|
|
|
|
- if(this.parent != null && this.getLayer() > 1) {
|
|
|
|
- this.parent.recalculateMinModel();
|
|
|
|
- }
|
|
|
|
- this.canRunIndependentFromParent = false;
|
|
|
|
|
|
+ //take the shortest path occupied by another holon
|
|
|
|
+ ArrayList<Edge> path = shortestPaths.get(0);
|
|
|
|
+ Holon holder = occ_by.get(path);
|
|
|
|
+ if(holder != null && holder.getParent() != null) {
|
|
|
|
+ this.split(holder);
|
|
|
|
+ this.addChild(child);
|
|
|
|
+ this.addChildToMinModel(child, path);
|
|
|
|
+ this.pathsToChildren.put(child, path);
|
|
|
|
+ if(this.parent != null && this.parent.getParent() != null) {
|
|
|
|
+ this.parent.recalculateMinModel();
|
|
}
|
|
}
|
|
- break;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -355,23 +407,26 @@ public class Holon {
|
|
* removes this holon from current superholon and merge with new superholon
|
|
* removes this holon from current superholon and merge with new superholon
|
|
*/
|
|
*/
|
|
public void split(Holon newParent) {
|
|
public void split(Holon newParent) {
|
|
- if(newParent == null) {
|
|
|
|
- System.err.println("can not split without new super holon");
|
|
|
|
|
|
+ //ensure that this holarchy can run independent(path is not occupied by superholon) from the superholon
|
|
|
|
+ if(!this.parent.canRunIndependent(this)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- //ensure that this holarchy can run independent(path is not occupied by superholon) from the superholon
|
|
|
|
- if(!this.canRunIndependentFromParent) {
|
|
|
|
- return;
|
|
|
|
|
|
+ if(newParent == null) {
|
|
|
|
+ newParent = this.model.getStateHolon();
|
|
}
|
|
}
|
|
|
|
|
|
if(this.parent != null) {
|
|
if(this.parent != null) {
|
|
this.parent.removeChildHolon(this);
|
|
this.parent.removeChildHolon(this);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ this.holonControlUnit.getHierarchyController().resetVirtualNeighbors();
|
|
newParent.merge(this);
|
|
newParent.merge(this);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void splitById(String id) {
|
|
|
|
+ this.model.getHolonsByID().get(id).split(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* recalculates the min model after a holon was added to a subholon
|
|
* recalculates the min model after a holon was added to a subholon
|
|
* does NOT recalculate the shortest paths between its subholons
|
|
* does NOT recalculate the shortest paths between its subholons
|
|
@@ -394,11 +449,10 @@ public class Holon {
|
|
edges.add(icws.getModel());
|
|
edges.add(icws.getModel());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
this.minModel = new MinimumModel(objects, edges);
|
|
this.minModel = new MinimumModel(objects, edges);
|
|
|
|
|
|
//notify superholon to recalculate its minModel
|
|
//notify superholon to recalculate its minModel
|
|
- if(this.parent != null && this.getLayer() > 0) {
|
|
|
|
|
|
+ if(this.parent != null && this.parent.getParent() != null && this.parent != this) {
|
|
this.parent.recalculateMinModel();
|
|
this.parent.recalculateMinModel();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -408,7 +462,7 @@ public class Holon {
|
|
* @param child
|
|
* @param child
|
|
*/
|
|
*/
|
|
private void addChildToMinModel(Holon child, ArrayList<Edge> path) {
|
|
private void addChildToMinModel(Holon child, ArrayList<Edge> path) {
|
|
- if(this.minModel.getHolonObjectList().contains(child.getHolonObject()) || getLayer() == 0)
|
|
|
|
|
|
+ if(this.minModel.getHolonObjectList().contains(child.getHolonObject()) || this.parent == null)
|
|
return;
|
|
return;
|
|
|
|
|
|
ArrayList<Edge> edgeList = new ArrayList<Edge>();
|
|
ArrayList<Edge> edgeList = new ArrayList<Edge>();
|
|
@@ -434,7 +488,6 @@ public class Holon {
|
|
objects.add(b);
|
|
objects.add(b);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
this.minModel = new MinimumModel(objects, edgeList);
|
|
this.minModel = new MinimumModel(objects, edgeList);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -442,16 +495,17 @@ public class Holon {
|
|
* revalidate this min model after a subholon was removed
|
|
* revalidate this min model after a subholon was removed
|
|
*/
|
|
*/
|
|
public void revalidateMinModel() {
|
|
public void revalidateMinModel() {
|
|
- if(getLayer() == 0)
|
|
|
|
|
|
+ if(this.parent == null)
|
|
return;
|
|
return;
|
|
|
|
|
|
- this.canRunIndependentFromParent = true;
|
|
|
|
ArrayList<AbstractCanvasObject> list = new ArrayList<AbstractCanvasObject>();
|
|
ArrayList<AbstractCanvasObject> list = new ArrayList<AbstractCanvasObject>();
|
|
list.add(this.holonObject);
|
|
list.add(this.holonObject);
|
|
this.minModel = new MinimumModel(list, new ArrayList<Edge>());
|
|
this.minModel = new MinimumModel(list, new ArrayList<Edge>());
|
|
for(int i=0; i< this.childHolons.size(); i++) {
|
|
for(int i=0; i< this.childHolons.size(); i++) {
|
|
Holon child = this.childHolons.remove(0);
|
|
Holon child = this.childHolons.remove(0);
|
|
- this.merge(child);
|
|
|
|
|
|
+ if(this.model.checkHolonObjectsAreConnected(this, child, this.holonControlUnit.getStateEstimator().getNetThroughput())) {
|
|
|
|
+ this.merge(child);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if(this.parent != null) {
|
|
if(this.parent != null) {
|
|
@@ -459,11 +513,22 @@ public class Holon {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void revalidateMinModelAfterLoad() {
|
|
|
|
+ if(this.childHolons.size() == 0) {
|
|
|
|
+ this.revalidateMinModel();
|
|
|
|
+ } else {
|
|
|
|
+ List<Holon> list = List.copyOf(this.childHolons);
|
|
|
|
+ for(Holon child : list) {
|
|
|
|
+ child.revalidateMinModelAfterLoad();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* returns the holon which uses the specified path if it is included in min model, otherwise null
|
|
* returns the holon which uses the specified path if it is included in min model, otherwise null
|
|
*/
|
|
*/
|
|
public Holon containsPath(ArrayList<Edge> path, Holon requester) {
|
|
public Holon containsPath(ArrayList<Edge> path, Holon requester) {
|
|
- if(this.minModel.containsPath(path) || this.getLayer() == 0) {
|
|
|
|
|
|
+ if(this.minModel.containsPath(path) || this.parent == null) {
|
|
for(Holon child : this.childHolons) {
|
|
for(Holon child : this.childHolons) {
|
|
if(child.equals(requester))
|
|
if(child.equals(requester))
|
|
continue;
|
|
continue;
|
|
@@ -475,7 +540,57 @@ public class Holon {
|
|
|
|
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ for(Edge e : path) {
|
|
|
|
+ AbstractCanvasObject a = e.getA();
|
|
|
|
+ AbstractCanvasObject b = e.getB();
|
|
|
|
+ if(a instanceof HolonObject && this.childHolons.contains(((HolonObject) a).holon))
|
|
|
|
+ return ((HolonObject) a).holon;
|
|
|
|
+ if(b instanceof HolonObject && this.childHolons.contains(((HolonObject) b).holon))
|
|
|
|
+ return ((HolonObject) b).holon;
|
|
|
|
+ if(this.getAllObjects().contains(a) || this.getAllObjects().contains(b))
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * checks whether the requester can run without this holon (none of the paths inside the requesters model is occupied by this model)
|
|
|
|
+ * @param requester
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public boolean canRunIndependent(Holon requester) {
|
|
|
|
+ if(this.parent == null || this.parent.getParent() == null)
|
|
|
|
+ return true;
|
|
|
|
+
|
|
|
|
+ ArrayList<AbstractCanvasObject> objects = new ArrayList<AbstractCanvasObject>();
|
|
|
|
+ objects.addAll(requester.getMinimumModel().getHolonObjectList());
|
|
|
|
+ objects.addAll(requester.getMinimumModel().getNodeList());
|
|
|
|
+ objects.addAll(requester.getMinimumModel().getSwitchList());
|
|
|
|
+
|
|
|
|
+ for(Holon child : this.childHolons) {
|
|
|
|
+ if(child.equals(requester))
|
|
|
|
+ continue;
|
|
|
|
+ ArrayList<Edge> path = this.pathsToChildren.get(child);
|
|
|
|
+ ArrayList<AbstractCanvasObject> pathObjects = new ArrayList<AbstractCanvasObject>();
|
|
|
|
+ for(Edge e : path) {
|
|
|
|
+ AbstractCanvasObject a = e.getA();
|
|
|
|
+ AbstractCanvasObject b = e.getB();
|
|
|
|
+ if(!pathObjects.contains(a))
|
|
|
|
+ pathObjects.add(a);
|
|
|
|
+ if(!pathObjects.contains(b))
|
|
|
|
+ pathObjects.add(b);
|
|
|
|
+ }
|
|
|
|
+ for(AbstractCanvasObject aco : pathObjects) {
|
|
|
|
+ if(objects.contains(aco))
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean isASuperiorHolon(String holon) {
|
|
|
|
+ return this.parent != null ? (this.parent.getUniqueID().equals(holon) || this.parent.isASuperiorHolon(holon)) : false;
|
|
|
|
+ }
|
|
}
|
|
}
|