Ignore:
Timestamp:
Sep 30, 2010, 5:33:45 PM (15 years ago)
Author:
gnappo
Message:

Aggiunto metodo per stampare i grafi in formato utile per kmetis; modificato politica di azione di mqi, ora agisce sulla partizione piu` grande.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/weka/clusterers/forMetisMQI/MQI.java

    r18 r20  
    8181
    8282        static private DirectedGraph<Node, Edge> prepareDirectedGraph(
    83                         Bisection partition, Node source, Node sink, boolean forConductance) {
    84                 Subgraph A = null;
    85                 Subgraph B = null;
    86                 if (partition.getSubgraph().getVertexCount() < partition
    87                                 .getComplement().getVertexCount()) {
    88                         A = partition.getSubgraph();
    89                         B = partition.getComplement();
    90                 } else {
    91                         A = partition.getComplement();
    92                         B = partition.getSubgraph();
    93                 }
     83                        Bisection bisection, Node source, Node sink, boolean forConductance) {
     84                Subgraph A = bisection.getLargerSubgraph();
     85                Subgraph B = bisection.getSmallerSubgraph();
    9486                int a = 0;
    9587                if (!forConductance)
     
    9890                        Iterator<Node> aIterator = A.iterator();
    9991                        while(aIterator.hasNext()) {
    100                                 a += partition.getGraph().degree(aIterator.next());
    101                         }
    102                 }
    103                 int c = partition.edgeCut() / 2;
     92                                a += bisection.getGraph().degree(aIterator.next());
     93                        }
     94                }
     95                int c = bisection.edgeCut() / 2;
    10496
    10597                DirectedGraph<Node, Edge> g = new DirectedSparseGraph<Node, Edge>();
     
    109101                        g.addVertex(u);
    110102                }
    111 
    112103                nodes = A.iterator();
    113104                int id = 0;
     
    153144                        if(forConductance)
    154145                                //FIXME: CONTROLLAMI
    155                                 g.addEdge(new Edge(Integer.toString(id), 1, c * partition.getGraph().degree(u)), u, sink);
     146                                g.addEdge(new Edge(Integer.toString(id), 1, c * bisection.getGraph().degree(u)), u, sink);
    156147                        else
    157148                                g.addEdge(new Edge(Integer.toString(id), 1, c), u, sink);
     
    173164                boolean finished = false;
    174165                Bisection bisection = partition;
    175                 Set<Node> cluster = new HashSet<Node>(partition.getSmallerNotEmptySubgraph()
     166                Set<Node> cluster = new HashSet<Node>(partition.getLargerSubgraph()
    176167                                .createInducedSubgraph().getVertices());
    177168                int maxFlowThreshold = Integer.MAX_VALUE;
     
    200191
    201192                        if (!forConductance)
    202                                 maxFlowThreshold = bisection.getSmallerNotEmptySubgraph()
     193                                maxFlowThreshold = bisection.getLargerSubgraph()
    203194                                                .getVertexCount()
    204195                                                * bisection.edgeCut() / 2;
    205196                        else {
    206                                 Iterator<Node> aIterator = bisection.getSmallerNotEmptySubgraph().iterator();
     197                                Iterator<Node> aIterator = bisection.getLargerSubgraph().iterator();
    207198                                maxFlowThreshold = 0;
    208199                                while(aIterator.hasNext())
     
    212203                        }
    213204                        alg.evaluate();
    214 //                       Util.viewFlowGraph(directedGraph, edgeFlowMap);
    215 //                      System.out.println("MAX FLOW: " + alg.getMaxFlow() + " THRESHOLD: "
    216 //                                      + maxFlowThreshold);
     205//                      Util.viewFlowGraph(directedGraph, edgeFlowMap);
     206                        System.out.println("MAX FLOW: " + alg.getMaxFlow() + " THRESHOLD: "
     207                                        + maxFlowThreshold);
    217208                        if (alg.getMaxFlow() < maxFlowThreshold) {
    218209                                Set<Node> dfsResult = DFSReversed(sink, directedGraph,
    219210                                                edgeFlowMap, new HashSet<Node>());
    220211                                dfsResult.remove(sink);
    221 //                              if (dfsResult.size() > 0) {
    222                                         cluster = dfsResult;
    223                                         bisection = new Bisection(new Subgraph(
    224                                                         bisection.getGraph(), cluster));
    225 //                                      System.out
    226 //                                                      .println("NEW BISECTION: " + bisection.toString());
    227 //                              } else
    228 //                                      finished = true;
     212                                cluster = dfsResult;
     213                                bisection = new Bisection(new Subgraph(
     214                                        bisection.getGraph(), cluster));
    229215                        } else
    230216                                finished = true;
Note: See TracChangeset for help on using the changeset viewer.