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