Changeset 9 for src/main/java/weka/clusterers/forMetisMQI/KLPartition.java
- Timestamp:
- Sep 14, 2010, 2:11:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/forMetisMQI/KLPartition.java
r8 r9 1 1 package weka.clusterers.forMetisMQI; 2 2 3 import java.util. ArrayList;3 import java.util.HashSet; 4 4 import java.util.Iterator; 5 import java.util. List;5 import java.util.Set; 6 6 7 7 … … 12 12 private Subgraph b = null; 13 13 14 private List<Integer> marked = null;14 private Set<Node> marked = null; 15 15 16 16 private KLPartition() { … … 18 18 19 19 public KLPartition(Subgraph s) { 20 Graph g = s.getGraph();20 UndirectedGraph g = s.getGraph(); 21 21 a = s; 22 22 b = new Subgraph(g); 23 Iterator< Integer> graphIterator = g.iterator();23 Iterator<Node> graphIterator = g.getVertices().iterator(); 24 24 while(graphIterator.hasNext()) { 25 intu = graphIterator.next();25 Node u = graphIterator.next(); 26 26 if(!s.contains(u)) 27 b.add Node(u);27 b.addVertex(u); 28 28 } 29 marked = new ArrayList<Integer>();29 marked = new HashSet<Node>(); 30 30 } 31 31 32 public KLPartition( Graph g){32 public KLPartition(UndirectedGraph g){ 33 33 a = new Subgraph(g); 34 34 b = new Subgraph(g); 35 Iterator< Integer> graph = g.vtxsPermutation().iterator();35 Iterator<Node> graph = g.vtxsPermutation().iterator(); 36 36 int i = 0; 37 37 while(graph.hasNext()) { 38 intu = graph.next();38 Node u = graph.next(); 39 39 if((i%2)==0) 40 a.add Node(u);40 a.addVertex(u); 41 41 else 42 b.add Node(u);42 b.addVertex(u); 43 43 i++; 44 44 } 45 marked = new ArrayList<Integer>();45 marked = new HashSet<Node>(); 46 46 } 47 47 48 48 /** 49 * Returns the node marked as candidate for swapping or -1if there aren't node available49 * Returns the node marked as candidate for swapping or <code>null</code> if there aren't node available 50 50 * for swapping. 51 51 * @return 52 52 */ 53 public intgetCandidate() {54 intu;55 if(a. size() > b.size()) {53 public Node getCandidate() { 54 Node u; 55 if(a.getVertexCount() > b.getVertexCount()) { 56 56 u = a.getCandidate(marked); 57 if(u == -1)57 if(u == null) 58 58 u = b.getCandidate(marked); 59 59 } else { 60 60 u = b.getCandidate(marked); 61 if(u == -1)61 if(u == null) 62 62 u = a.getCandidate(marked); 63 63 } 64 if(u != -1) {64 if(u != null) { 65 65 marked.add(u); 66 66 } … … 68 68 } 69 69 70 public void swap( intu) {70 public void swap(Node u) { 71 71 Subgraph from = fromSubgraph(u); 72 72 Subgraph to = toSubgraph(u); 73 from.remove (u);74 to.add Node(u);73 from.removeVertex(u); 74 to.addVertex(u); 75 75 } 76 76 77 private Subgraph fromSubgraph( intu) {77 private Subgraph fromSubgraph(Node u) { 78 78 Subgraph ret = null; 79 79 if(a.contains(u)) … … 84 84 } 85 85 86 private Subgraph toSubgraph( intu) {86 private Subgraph toSubgraph(Node u) { 87 87 Subgraph ret = null; 88 88 if(!a.contains(u)) … … 106 106 } 107 107 108 @Override 109 public KLPartition clone(){ 108 public KLPartition copy(){ 110 109 KLPartition clone = new KLPartition(); 111 110 clone.a = (Subgraph) a.clone(); 112 111 clone.b = (Subgraph) b.clone(); 113 clone.marked = new ArrayList<Integer>(); 114 for(int i = 0; i < marked.size(); i++) { 115 clone.marked.add(marked.get(i)); 116 } 112 clone.marked = new HashSet<Node>(); 117 113 return clone; 118 114 }
Note: See TracChangeset
for help on using the changeset viewer.