kruskalbox.cc
changeset 3 2cc5ed6e6255
equal deleted inserted replaced
-1:000000000000 0:93a8bcaf82fd
       
     1 /* -*- C++ -*-
       
     2  *
       
     3  * This file is a part of LEMON, a generic C++ optimization library
       
     4  *
       
     5  * Copyright (C) 2003-2006
       
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
       
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
       
     8  *
       
     9  * Permission to use, modify and distribute this software is granted
       
    10  * provided that this copyright notice appears in all copies. For
       
    11  * precise terms see the accompanying LICENSE file.
       
    12  *
       
    13  * This software is provided "AS IS" with no warranty of any kind,
       
    14  * express or implied, and with no claim as to its suitability for any
       
    15  * purpose.
       
    16  *
       
    17  */
       
    18 
       
    19 #include <lemon/kruskal.h>
       
    20 
       
    21 #include <mapstorage.h>
       
    22 #include <mapselector.h>
       
    23 #include <algobox.h>
       
    24 #include <kruskalbox.h>
       
    25 
       
    26 enum {INPUT, OUTPUT, MAP_NUM};
       
    27 
       
    28 KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
       
    29 {
       
    30   init(t);
       
    31 }
       
    32     
       
    33 void KruskalBox::run()
       
    34 {
       
    35   if(
       
    36       tabcbt.get_active_text()!="" &&
       
    37       (arcmapcbts[INPUT])->get_active_text()!="" &&
       
    38       (arcmapcbts[OUTPUT])->get_active_text()!=""
       
    39     )
       
    40   {
       
    41 
       
    42     const Digraph &g=mapstorage->getDigraph();
       
    43     std::string input_map_name = arcmapcbts[INPUT]->get_active_text();
       
    44     Digraph::ArcMap<bool> outputmap(g);
       
    45     const MapStorage::NumericArcMap& inputmap=
       
    46       mapstorage->getNumericArcMap(input_map_name);
       
    47     double res=kruskal(g, inputmap, outputmap);
       
    48 
       
    49     for (ArcIt i(g); i!=INVALID; ++i)
       
    50     {
       
    51       if(outputmap[i])
       
    52       {
       
    53         mapstorage->set(arcmapcbts[OUTPUT]->get_active_text(), i, 1.0);
       
    54       }
       
    55       else
       
    56       {
       
    57         mapstorage->set(arcmapcbts[OUTPUT]->get_active_text(), i, 0.0);
       
    58       }
       
    59     }
       
    60 
       
    61     std::ostringstream o;
       
    62     o << "Result: " << res;
       
    63     resultlabel.set_text(o.str());
       
    64 
       
    65     mapstorage->mapChanged(true, (arcmapcbts[OUTPUT])->get_active_text());
       
    66     //   mapstorage->changeActiveMap(true, E_COLOR,
       
    67     // 			      (arcmapcbts[OUTPUT])->get_active_text());
       
    68     //   mapstorage->changeActiveMap(true, E_TEXT,
       
    69     // 			      (arcmapcbts[INPUT])->get_active_text());
       
    70 
       
    71   }
       
    72 }
       
    73     
       
    74 void KruskalBox::build_box()
       
    75 {
       
    76   std::vector<std::string> empty_vector;
       
    77 
       
    78   addMapSelector("Arccosts: ", true, NUM);
       
    79   addMapSelector("Arcs of tree here: ", true, NUM);
       
    80 
       
    81   resultlabel.set_text("Result: algorithm is not run yet.");
       
    82   pack_start(resultlabel);
       
    83 }