COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/kruskalbox.cc @ 1879:01d41844ef46

Last change on this file since 1879:01d41844ef46 was 1879:01d41844ef46, checked in by Hegyi Péter, 18 years ago

Kruskal algorithm can be run from GUI from now on.

File size: 1.5 KB
RevLine 
[1876]1#include <kruskalbox.h>
2
[1879]3enum {INPUT, OUTPUT, MAP_NUM};
4
[1878]5KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
[1876]6{
[1878]7  init(t);
[1876]8}
9   
10void KruskalBox::run()
11{
[1879]12  Graph g=mapstorage->graph;
13  Graph::EdgeMap<double> * inputmap=((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
14  Graph::EdgeMap<bool> outputmap(g);
15  double res=kruskal(g, *inputmap, outputmap);
16
17  for (EdgeIt i(g); i!=INVALID; ++i)
18  {
19    if(outputmap[i])
20      {
21        (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=1;
22      }
23    else
24      {
25        (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=0;
26      }
27  }
28
29  std::ostringstream o;
30  o << "Result: " << res;
31  resultlabel.set_text(o.str());
32
33  mapstorage->changeActiveMap(true, E_COLOR, (edgemapcbts[OUTPUT])->get_active_text());
34  mapstorage->changeActiveMap(true, E_TEXT, (edgemapcbts[INPUT])->get_active_text());
[1876]35}
36   
37void KruskalBox::build_box()
38{
[1879]39  edgemapcbts.resize(MAP_NUM);
40  Gtk::HBox * hbox;
[1876]41
[1879]42  hbox=new Gtk::HBox();
43
44  label=new Gtk::Label("Edgecosts: ");
[1876]45
46  edgemapcbts[0]=new Gtk::ComboBoxText();
47
48  hbox->pack_start(*label);
[1879]49  hbox->pack_start(*(edgemapcbts[INPUT]));
[1876]50  pack_start(*hbox);
[1879]51
52  hbox=new Gtk::HBox();
53
54  label=new Gtk::Label("Edges of tree here: ");
55
56  edgemapcbts[1]=new Gtk::ComboBoxText();
57
58  hbox->pack_start(*label);
59  hbox->pack_start(*(edgemapcbts[OUTPUT]));
60  pack_start(*hbox);
61
62  resultlabel.set_text("Result: algorithm is not run yet.");
63  pack_start(resultlabel);
[1876]64}
Note: See TracBrowser for help on using the repository browser.