gui/kruskalbox.cc
author hegyi
Thu, 05 Jan 2006 16:54:34 +0000
changeset 1879 01d41844ef46
parent 1878 409a31271efd
child 1880 0d6da6e6a775
permissions -rw-r--r--
Kruskal algorithm can be run from GUI from now on.
hegyi@1876
     1
#include <kruskalbox.h>
hegyi@1876
     2
hegyi@1879
     3
enum {INPUT, OUTPUT, MAP_NUM};
hegyi@1879
     4
hegyi@1878
     5
KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
hegyi@1876
     6
{
hegyi@1878
     7
  init(t);
hegyi@1876
     8
}
hegyi@1876
     9
    
hegyi@1876
    10
void KruskalBox::run()
hegyi@1876
    11
{
hegyi@1879
    12
  Graph g=mapstorage->graph;
hegyi@1879
    13
  Graph::EdgeMap<double> * inputmap=((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
hegyi@1879
    14
  Graph::EdgeMap<bool> outputmap(g);
hegyi@1879
    15
  double res=kruskal(g, *inputmap, outputmap);
hegyi@1879
    16
hegyi@1879
    17
  for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1879
    18
  {
hegyi@1879
    19
    if(outputmap[i])
hegyi@1879
    20
      {
hegyi@1879
    21
	(*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=1;
hegyi@1879
    22
      }
hegyi@1879
    23
    else
hegyi@1879
    24
      {
hegyi@1879
    25
	(*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=0;
hegyi@1879
    26
      }
hegyi@1879
    27
  }
hegyi@1879
    28
hegyi@1879
    29
  std::ostringstream o;
hegyi@1879
    30
  o << "Result: " << res;
hegyi@1879
    31
  resultlabel.set_text(o.str());
hegyi@1879
    32
hegyi@1879
    33
  mapstorage->changeActiveMap(true, E_COLOR, (edgemapcbts[OUTPUT])->get_active_text());
hegyi@1879
    34
  mapstorage->changeActiveMap(true, E_TEXT, (edgemapcbts[INPUT])->get_active_text());
hegyi@1876
    35
}
hegyi@1876
    36
    
hegyi@1876
    37
void KruskalBox::build_box()
hegyi@1876
    38
{
hegyi@1879
    39
  edgemapcbts.resize(MAP_NUM);
hegyi@1879
    40
  Gtk::HBox * hbox;
hegyi@1876
    41
hegyi@1879
    42
  hbox=new Gtk::HBox();
hegyi@1879
    43
hegyi@1879
    44
  label=new Gtk::Label("Edgecosts: ");
hegyi@1876
    45
hegyi@1876
    46
  edgemapcbts[0]=new Gtk::ComboBoxText();
hegyi@1876
    47
hegyi@1876
    48
  hbox->pack_start(*label);
hegyi@1879
    49
  hbox->pack_start(*(edgemapcbts[INPUT]));
hegyi@1876
    50
  pack_start(*hbox);
hegyi@1879
    51
hegyi@1879
    52
  hbox=new Gtk::HBox();
hegyi@1879
    53
hegyi@1879
    54
  label=new Gtk::Label("Edges of tree here: ");
hegyi@1879
    55
hegyi@1879
    56
  edgemapcbts[1]=new Gtk::ComboBoxText();
hegyi@1879
    57
hegyi@1879
    58
  hbox->pack_start(*label);
hegyi@1879
    59
  hbox->pack_start(*(edgemapcbts[OUTPUT]));
hegyi@1879
    60
  pack_start(*hbox);
hegyi@1879
    61
hegyi@1879
    62
  resultlabel.set_text("Result: algorithm is not run yet.");
hegyi@1879
    63
  pack_start(resultlabel);
hegyi@1876
    64
}