Last change
on this file since 8 was
8,
checked in by gnappo, 14 years ago
|
Aggiunta la libreria Jung per lavorare con i grafi. Primi esperimenti. A breve riorganizzazione completa del codice per usufruire della libreria.
|
File size:
915 bytes
|
Line | |
---|
1 | package weka.clusterers.forMetisMQI; |
---|
2 | |
---|
3 | import java.util.Stack; |
---|
4 | |
---|
5 | public class GraphAlgorithms { |
---|
6 | |
---|
7 | public KLPartition KL(Graph g) { |
---|
8 | KLPartition partition = new KLPartition(g); |
---|
9 | KLPartition result = partition; |
---|
10 | int bestEdgeCut = Integer.MAX_VALUE; |
---|
11 | int u = partition.getCandidate(); |
---|
12 | while(u != -1) { |
---|
13 | partition.swap(u); |
---|
14 | if(partition.edgeCut() <= bestEdgeCut) { |
---|
15 | bestEdgeCut = partition.edgeCut(); |
---|
16 | result = partition.clone(); |
---|
17 | } |
---|
18 | u = partition.getCandidate(); |
---|
19 | } |
---|
20 | return result; |
---|
21 | } |
---|
22 | |
---|
23 | public void METIS(Graph g) { |
---|
24 | KLPartition partition = null; |
---|
25 | Coarse.setFinerSize(10); |
---|
26 | Stack<CoarserGraphElement> stack = Coarse.coarse(g); |
---|
27 | |
---|
28 | if(stack.size() > 0) { |
---|
29 | partition = KL(stack.peek().getContracted()); |
---|
30 | System.out.println(partition.toString()); |
---|
31 | partition = new Uncoarse().uncoarse(stack, partition); |
---|
32 | System.out.println(partition.toString()); |
---|
33 | } |
---|
34 | |
---|
35 | MQI.start(partition); |
---|
36 | |
---|
37 | } |
---|
38 | |
---|
39 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.