gui/kruskalbox.cc
author hegyi
Fri, 06 Jan 2006 14:36:46 +0000
changeset 1882 2c3f6c7e01b4
parent 1880 0d6da6e6a775
child 1884 9c061834b33b
permissions -rw-r--r--
MapSelector has become a standalone class.
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;
alpar@1880
    13
  Graph::EdgeMap<double> * inputmap=
alpar@1880
    14
    ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
hegyi@1879
    15
  Graph::EdgeMap<bool> outputmap(g);
hegyi@1879
    16
  double res=kruskal(g, *inputmap, outputmap);
hegyi@1879
    17
hegyi@1879
    18
  for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1879
    19
  {
hegyi@1879
    20
    if(outputmap[i])
hegyi@1879
    21
      {
alpar@1880
    22
	(*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
alpar@1880
    23
					 get_active_text()]))[i]=1;
hegyi@1879
    24
      }
hegyi@1879
    25
    else
hegyi@1879
    26
      {
alpar@1880
    27
	(*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
alpar@1880
    28
					 get_active_text()]))[i]=0;
hegyi@1879
    29
      }
hegyi@1879
    30
  }
hegyi@1879
    31
hegyi@1879
    32
  std::ostringstream o;
hegyi@1879
    33
  o << "Result: " << res;
hegyi@1879
    34
  resultlabel.set_text(o.str());
hegyi@1881
    35
hegyi@1881
    36
  mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
hegyi@1881
    37
  //   mapstorage->changeActiveMap(true, E_COLOR,
hegyi@1881
    38
  // 			      (edgemapcbts[OUTPUT])->get_active_text());
hegyi@1881
    39
  //   mapstorage->changeActiveMap(true, E_TEXT,
hegyi@1881
    40
  // 			      (edgemapcbts[INPUT])->get_active_text());
alpar@1880
    41
  
hegyi@1876
    42
}
hegyi@1876
    43
    
hegyi@1876
    44
void KruskalBox::build_box()
hegyi@1876
    45
{
hegyi@1879
    46
  edgemapcbts.resize(MAP_NUM);
hegyi@1879
    47
  Gtk::HBox * hbox;
hegyi@1876
    48
hegyi@1879
    49
  hbox=new Gtk::HBox();
hegyi@1879
    50
hegyi@1879
    51
  label=new Gtk::Label("Edgecosts: ");
hegyi@1876
    52
hegyi@1876
    53
  edgemapcbts[0]=new Gtk::ComboBoxText();
hegyi@1876
    54
hegyi@1876
    55
  hbox->pack_start(*label);
hegyi@1879
    56
  hbox->pack_start(*(edgemapcbts[INPUT]));
hegyi@1876
    57
  pack_start(*hbox);
hegyi@1879
    58
hegyi@1879
    59
  hbox=new Gtk::HBox();
hegyi@1879
    60
hegyi@1879
    61
  label=new Gtk::Label("Edges of tree here: ");
hegyi@1879
    62
hegyi@1879
    63
  edgemapcbts[1]=new Gtk::ComboBoxText();
hegyi@1879
    64
hegyi@1879
    65
  hbox->pack_start(*label);
hegyi@1879
    66
  hbox->pack_start(*(edgemapcbts[OUTPUT]));
hegyi@1879
    67
  pack_start(*hbox);
hegyi@1879
    68
hegyi@1879
    69
  resultlabel.set_text("Result: algorithm is not run yet.");
hegyi@1879
    70
  pack_start(resultlabel);
hegyi@1876
    71
}