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