public double getWeightFactor(GraphEdge eachEdge) { int weightSum = getWeightSum(); return (double) eachEdge.getWeight() / (double) weightSum; }
public double getWeightFactor(GraphEdge eachEdge) { int weightSum = getWeightSum(); return (double) eachEdge.getWeight() / (double) weightSum; }
public BusinessServiceEdge(GraphEdge graphEdge, AbstractBusinessServiceVertex source, AbstractBusinessServiceVertex target) { super(BusinessServicesTopologyProvider.TOPOLOGY_NAMESPACE, String.format("connection:%s:%s", source.getId(), target.getId()), source, target); this.source = source; this.target = target; this.mapFunction = graphEdge.getMapFunction(); this.weight = graphEdge.getWeight(); setTooltipText(String.format("Map function: %s, Weight: %s", graphEdge.getMapFunction().getClass().getSimpleName(), graphEdge.getWeight())); }
/** * Apply the edges weights to the associated statuses set in the map, * ignoring the actual status stored in the edge. Can be used for simulations * without needing to change the actual edge's status. * * @param edgesWithStatus * @return */ public static List<StatusWithIndex> weighStatuses(Map<GraphEdge, Status> edgesWithStatus) { // Find the greatest common divisor of all the weights int gcd = edgesWithStatus.keySet().stream() .map(GraphEdge::getWeight) .reduce((a,b) -> BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue()) .orElse(1); // Multiply the statuses based on their relative weight List<StatusWithIndex> statuses = Lists.newArrayList(); int k = 0; for (Entry<GraphEdge, Status> entry : edgesWithStatus.entrySet()) { int relativeWeight = Math.floorDiv(entry.getKey().getWeight(), gcd); for (int i = 0; i < relativeWeight; i++) { statuses.add(new StatusWithIndex(entry.getValue(), k)); } k++; } return statuses; }
getLabel(eachEdge, explanation), createStatusLabel(null, eachEdge.getStatus()), eachEdge.getWeight(), toString(explanation.getWeightFactor(eachEdge)), toString(explanation.getStatusFactor(eachEdge, Status.CRITICAL)),