kruskalbox.cc
changeset 1 67188bd752db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/kruskalbox.cc	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,83 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#include <lemon/kruskal.h>
    1.23 +
    1.24 +#include <mapstorage.h>
    1.25 +#include <mapselector.h>
    1.26 +#include <algobox.h>
    1.27 +#include <kruskalbox.h>
    1.28 +
    1.29 +enum {INPUT, OUTPUT, MAP_NUM};
    1.30 +
    1.31 +KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
    1.32 +{
    1.33 +  init(t);
    1.34 +}
    1.35 +    
    1.36 +void KruskalBox::run()
    1.37 +{
    1.38 +  if(
    1.39 +      tabcbt.get_active_text()!="" &&
    1.40 +      (arcmapcbts[INPUT])->get_active_text()!="" &&
    1.41 +      (arcmapcbts[OUTPUT])->get_active_text()!=""
    1.42 +    )
    1.43 +  {
    1.44 +
    1.45 +    const Digraph &g=mapstorage->getDigraph();
    1.46 +    std::string input_map_name = arcmapcbts[INPUT]->get_active_text();
    1.47 +    Digraph::ArcMap<bool> outputmap(g);
    1.48 +    const MapStorage::NumericArcMap& inputmap=
    1.49 +      mapstorage->getNumericArcMap(input_map_name);
    1.50 +    double res=kruskal(g, inputmap, outputmap);
    1.51 +
    1.52 +    for (ArcIt i(g); i!=INVALID; ++i)
    1.53 +    {
    1.54 +      if(outputmap[i])
    1.55 +      {
    1.56 +        mapstorage->set(arcmapcbts[OUTPUT]->get_active_text(), i, 1.0);
    1.57 +      }
    1.58 +      else
    1.59 +      {
    1.60 +        mapstorage->set(arcmapcbts[OUTPUT]->get_active_text(), i, 0.0);
    1.61 +      }
    1.62 +    }
    1.63 +
    1.64 +    std::ostringstream o;
    1.65 +    o << "Result: " << res;
    1.66 +    resultlabel.set_text(o.str());
    1.67 +
    1.68 +    mapstorage->mapChanged(true, (arcmapcbts[OUTPUT])->get_active_text());
    1.69 +    //   mapstorage->changeActiveMap(true, E_COLOR,
    1.70 +    // 			      (arcmapcbts[OUTPUT])->get_active_text());
    1.71 +    //   mapstorage->changeActiveMap(true, E_TEXT,
    1.72 +    // 			      (arcmapcbts[INPUT])->get_active_text());
    1.73 +
    1.74 +  }
    1.75 +}
    1.76 +    
    1.77 +void KruskalBox::build_box()
    1.78 +{
    1.79 +  std::vector<std::string> empty_vector;
    1.80 +
    1.81 +  addMapSelector("Arccosts: ", true, NUM);
    1.82 +  addMapSelector("Arcs of tree here: ", true, NUM);
    1.83 +
    1.84 +  resultlabel.set_text("Result: algorithm is not run yet.");
    1.85 +  pack_start(resultlabel);
    1.86 +}