/** * <<<<<<< HEAD ���ߵ�valueֵ���й��� ======= 按边的value值进行过滤 >>>>>>> seuvislogwws/master * * @param filter * @return */ public SankeyGraph FilterByEdgeValue(double filter) { Set<Integer> nodeset = new HashSet<Integer>(); Iterator<? extends Edge> iterator_links = this.links.iterator(); while (iterator_links.hasNext()) { Edge edge = iterator_links.next(); double value = ((StreamEdge) edge).getValue(); if (value < filter) iterator_links.remove(); // �Ƴ�� else { nodeset.add(edge.getSource()); nodeset.add(edge.getTarget()); } } Iterator<? extends Node> iterator_nodes = this.nodes.iterator(); while (iterator_nodes.hasNext()) { Node node = iterator_nodes.next(); if (!nodeset.contains(node.getName())) { // ����nodes�� iterator_nodes.remove(); } } // System.out.println( "���˺�nodes�Ĵ�С�� "+this.nodes.size()); // �����˹���json����ٴΰ�node��name��0��ʼ�ź� int index = 0; for (Node n : this.nodes) { int old_name = n.getName(); int new_name = index++; n.setName(new_name); for (Edge e : this.links) { if (e.getSource() == old_name) e.setSource(new_name); if (e.getTarget() == old_name) e.setTarget(new_name); } } return this; }
private int getDistance(Vertex node, Vertex target) { for (Edge edge : edges) { if (edge.getSource().equals(node) && edge.getDestination().equals(target)) { return edge.getWeight(); } } throw new RuntimeException("Should not happen"); }
private List<Vertex> getNeighbors(Vertex node) { List<Vertex> neighbors = new ArrayList<Vertex>(); for (Edge edge : edges) { if (edge.getSource().equals(node) && !isSettled(edge.getDestination())) { neighbors.add(edge.getDestination()); } } return neighbors; }