/** * <p>Returns a {@code String} representation of the Shared Risk Group.</p> * @return {@code String} representation of the SRG */ public String toString () { if (isDynamicSrg()) return "SRG" + index + ". Dynamic: " + dynamicSrgImplementation.toString(); else return "SRG" + index + ", links: " + linksIfNonDynamic + ", nodes: " + nodesIfNonDynamic; }
public boolean isStaticEmptySrg () { return !isDynamicSrg() && this.linksIfNonDynamic.isEmpty() && this.nodesIfNonDynamic.isEmpty(); }
/** * <p>Returns the set of links associated to the SRG (fail, when the SRG is in failure state).</p> * @return The set of failing links, as an unmodifiable set */ public SortedSet<Link> getLinksAllLayers() { if (isDynamicSrg()) return dynamicSrgImplementation.getLinksAllLayers(); return Collections.unmodifiableSortedSet(linksIfNonDynamic); }
public void setDynamicImplementation (DynamicSrgImplementation impl) { if (!isDynamicSrg()) throw new Net2PlanException ("The SRG is not dynamic"); this.dynamicSrgImplementation = impl; }
/** * <p>Returns the set of nodes associated to the SRG (fail, when the SRG is in failure state)</p> * @return The set of failing nodes, as an unmodifiable set */ public SortedSet<Node> getNodes() { if (isDynamicSrg()) return dynamicSrgImplementation.getNodes(); return Collections.unmodifiableSortedSet(nodesIfNonDynamic); }
public boolean isDynamicCurrentlyEmptySrg () { return isDynamicSrg() && this.getLinksAllLayers().isEmpty() && this.getNodes().isEmpty(); }
void copyFrom (SharedRiskGroup origin) { if ((this.id != origin.id) || (this.index != origin.index)) throw new RuntimeException ("Bad"); if ((this.netPlan == null) || (origin.netPlan == null) || (this.netPlan == origin.netPlan)) throw new RuntimeException ("Bad"); this.meanTimeToFailInHours = origin.meanTimeToFailInHours; this.meanTimeToRepairInHours = origin.meanTimeToRepairInHours; if (origin.isDynamicSrg()) { this.linksIfNonDynamic.clear(); this.nodesIfNonDynamic.clear(); try { this.dynamicSrgImplementation = (DynamicSrgImplementation) Class.forName(origin.dynamicSrgImplementation.getClass().getName()).newInstance(); } catch (Exception e) { e.printStackTrace(); throw new Net2PlanException ("SRG Dynamic initialization error");} this.dynamicSrgImplementation.initialize(origin.dynamicSrgImplementation.getInitializationString (), this.netPlan); } else { this.linksIfNonDynamic.clear (); for (Link e : origin.linksIfNonDynamic) this.linksIfNonDynamic.add(this.netPlan.getLinkFromId (e.id)); this.nodesIfNonDynamic.clear (); for (Node n : origin.nodesIfNonDynamic) this.nodesIfNonDynamic.add(this.netPlan.getNodeFromId (n.id)); this.dynamicSrgImplementation = null; } }
void checkCachesConsistency () { super.checkCachesConsistency (); assert getNodes ().stream().allMatch(n->n.getNetPlan()== this.netPlan); assert getLinksAllLayers ().stream().allMatch(n->n.getNetPlan()== this.netPlan); if (isDynamicSrg()) { for (Link link : linksIfNonDynamic) if (!link.cache_nonDynamicSrgs.contains(this)) throw new RuntimeException ("Bad"); for (Node node : nodesIfNonDynamic) if (!node.cache_nodeNonDynamicSRGs.contains(this)) throw new RuntimeException ("Bad"); } }
/** * <p>Removes this SRG.</p> */ public void remove() { checkAttachedToNetPlanObject(); netPlan.checkIsModifiable(); if (!isDynamicSrg()) { for (Node node : nodesIfNonDynamic) node.cache_nodeNonDynamicSRGs.remove (this); for (Link link : linksIfNonDynamic) link.cache_nonDynamicSrgs.remove (this); } else { dynamicSrgImplementation.remove(); // release memory } for (String tag : tags) netPlan.cache_taggedElements.get(tag).remove(this); netPlan.cache_id2srgMap.remove (id); NetPlan.removeNetworkElementAndShiftIndexes(netPlan.srgs , index); if (isDynamicSrg()) netPlan.cache_dynamicSrgs.remove(this); final NetPlan npOld = this.netPlan; removeId(); if (ErrorHandling.isDebugEnabled()) npOld.checkCachesConsistency(); }
/** * <p>Adds a node to the SRG. If the node is already part of the SRG, no action is taken</p> * @param node Node to add */ public void addNode(Node node) { if (isDynamicSrg()) throw new Net2PlanException ("Cannot modify dynamic SRGs"); checkAttachedToNetPlanObject(); netPlan.checkIsModifiable(); node.checkAttachedToNetPlanObject(this.netPlan); if (this.nodesIfNonDynamic.contains(node)) return; node.cache_nodeNonDynamicSRGs.add(this); this.nodesIfNonDynamic.add(node); if (ErrorHandling.isDebugEnabled()) netPlan.checkCachesConsistency(); }
/** * <p>Removes a link from the set of links of the SRG. If the link is not in the SRG, no action is taken</p> * @param e Link to be removed */ public void removeLink (Link e) { if (isDynamicSrg()) throw new Net2PlanException ("Cannot modify dynamic SRGs"); checkAttachedToNetPlanObject(); netPlan.checkIsModifiable(); e.cache_nonDynamicSrgs.remove (this); linksIfNonDynamic.remove (e); if (ErrorHandling.isDebugEnabled()) netPlan.checkCachesConsistency(); }
/** * <p>Removes a node from the set of nodes of the SRG. If the node is not in the SRG, no action is taken</p> * @param n Node to be removed */ public void removeNode (Node n) { if (isDynamicSrg()) throw new Net2PlanException ("Cannot modify dynamic SRGs"); checkAttachedToNetPlanObject(); netPlan.checkIsModifiable(); n.cache_nodeNonDynamicSRGs.remove (this); nodesIfNonDynamic.remove (n); if (ErrorHandling.isDebugEnabled()) netPlan.checkCachesConsistency(); }
boolean isDeepCopy (SharedRiskGroup e2) { if (!super.isDeepCopy(e2)) return false; if (this.meanTimeToFailInHours != e2.meanTimeToFailInHours) return false; if (this.meanTimeToRepairInHours != e2.meanTimeToRepairInHours) return false; if (this.isDynamicSrg()) { if (!e2.isDynamicSrg()) return false; if (!this.dynamicSrgImplementation.getClass().getName().equals(e2.dynamicSrgImplementation.getClass().getName())) return false; if (!this.dynamicSrgImplementation.getInitializationString().equals(e2.dynamicSrgImplementation.getInitializationString())) return false; if (!NetPlan.isDeepCopy(this.getLinksAllLayers() , e2.getLinksAllLayers())) return false; if (!NetPlan.isDeepCopy(this.getNodes() , e2.getNodes())) return false; } else { if (e2.isDynamicSrg()) return false; if (!NetPlan.isDeepCopy(this.nodesIfNonDynamic , e2.nodesIfNonDynamic)) return false; if (!NetPlan.isDeepCopy(this.linksIfNonDynamic, e2.linksIfNonDynamic)) return false; } return true; }
/** * <p>Adds a link to the SRG. If the link is already part of the srg, no action is taken.</p> * @param link Link to add */ public void addLink(Link link) { if (isDynamicSrg()) throw new Net2PlanException ("Cannot modify dynamic SRGs"); checkAttachedToNetPlanObject(); netPlan.checkIsModifiable(); link.checkAttachedToNetPlanObject(this.netPlan); if (this.linksIfNonDynamic.contains(link)) return; link.cache_nonDynamicSrgs.add(this); this.linksIfNonDynamic.add(link); if (ErrorHandling.isDebugEnabled()) netPlan.checkCachesConsistency(); }
if (!srg.isDynamicSrg()) if (this.cache_nonDynamicSrgs.contains(srg) != srg.getLinksAllLayers().contains(this)) throw new RuntimeException ("Bad");
@Override public List<AjtColumnInfo<SharedRiskGroup>> getNonBasicUserDefinedColumnsVisibleOrNot() { final NetPlan np = callback.getDesign(); final NetworkLayer layer = this.getTableNetworkLayer(); final List<AjtColumnInfo<SharedRiskGroup>> res = new LinkedList<> (); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Collection.class, null , "Nodes", "The nodes belonging to this SRG", null , d->d.getNodes() , AGTYPE.SUMCOLLECTIONCOUNT , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Collection.class, null , "Links", "The links in this layer belonging to this SRG", null , d->d.getLinks(layer) , AGTYPE.SUMCOLLECTIONCOUNT , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Collection.class, null , "Links all layers", "The links in this layer or other layers belonging to this SRG", null , d->d.getLinksAllLayers() , AGTYPE.SUMCOLLECTIONCOUNT , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Double.class, null , "MTTF (hours)" , "The average Mean-Time-To-Fail value measued in hours (the time since the element is repaired until it fails again)", (d,val)->d.setMeanTimeToFailInHours((Double) val), d->d.getMeanTimeToFailInHours() , AGTYPE.MAXDOUBLE , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Double.class, null , "MTTR (hours)" , "The average Mean-Time-To-Repair value measued in hours (the time betweem the element fails, and is up again since it is repaired)", (d,val)->d.setMeanTimeToRepairInHours((Double) val), d->d.getMeanTimeToRepairInHours() , AGTYPE.MAXDOUBLE , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Double.class, null , "Availability" , "The probability of findig the element not failed (MTTF / (MTTF + MTTR)) ", (d,val)->d.setMeanTimeToRepairInHours((Double) val), d->d.getMeanTimeToRepairInHours() , AGTYPE.MAXDOUBLE , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Boolean.class, null , "Is dynamic SRG?" , "Indicates if the SRG is dnyamic (and then its belonging nodes and links may change)", null , d->d.isDynamicSrg() , AGTYPE.NOAGGREGATION , null)); return res; }
if (originSrg.isDynamicSrg())
this.checkInThisNetPlan(defaultLayer); assert this.cache_dynamicSrgs.equals (srgs.stream().filter(s->s.isDynamicSrg()).collect(Collectors.toCollection(TreeSet::new))); assert srgs.stream().allMatch(s->!s.wasRemoved());
if (thisSrg == null) thisSrg = this.addSRG(other.getMeanTimeToFailInHours(), other.getMeanTimeToRepairInHours(), null); else if (thisSrg.isDynamicSrg()) continue; // dynamic SRGs are not merged final SortedSet<Node> thisNodes = other.getNodes().stream().map(x->(Node) thatToThisTranslation.get(x)).collect(Collectors.toCollection(TreeSet::new)); final SortedSet<Link> thisLinks = other.getLinksAllLayers().stream().map(x->(Link) thatToThisTranslation.get(x)).collect(Collectors.toCollection(TreeSet::new));
writer.writeAttribute("meanTimeToFailInHours", Double.toString(srg.meanTimeToFailInHours)); writer.writeAttribute("meanTimeToRepairInHours", Double.toString(srg.meanTimeToRepairInHours)); writer.writeAttribute("isDynamic", Boolean.toString(srg.isDynamicSrg())); if (srg.isDynamicSrg())