kruskalbox.cc
author hegyi
Fri, 06 Jan 2006 23:16:51 +0000
branchgui
changeset 115 9e5196647a5a
parent 111 ab3107255754
child 116 2bd795bb9984
permissions -rw-r--r--
Forgotten file committed.
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@114
    12
  if(
hegyi@114
    13
     tabcbt.get_active_text()!="" &&
hegyi@114
    14
     (edgemapcbts[INPUT])->get_active_text()!="" &&
hegyi@114
    15
     (edgemapcbts[OUTPUT])->get_active_text()!=""
hegyi@114
    16
     )
hegyi@114
    17
    {
hegyi@109
    18
hegyi@114
    19
      Graph g=mapstorage->graph;
hegyi@114
    20
      Graph::EdgeMap<double> * inputmap=
hegyi@114
    21
	((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
hegyi@114
    22
      Graph::EdgeMap<bool> outputmap(g);
hegyi@114
    23
      double res=kruskal(g, *inputmap, outputmap);
hegyi@109
    24
hegyi@114
    25
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@114
    26
	{
hegyi@114
    27
	  if(outputmap[i])
hegyi@114
    28
	    {
hegyi@114
    29
	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
hegyi@114
    30
					       get_active_text()]))[i]=1;
hegyi@114
    31
	    }
hegyi@114
    32
	  else
hegyi@114
    33
	    {
hegyi@114
    34
	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
hegyi@114
    35
					       get_active_text()]))[i]=0;
hegyi@114
    36
	    }
hegyi@114
    37
	}
hegyi@111
    38
hegyi@114
    39
      std::ostringstream o;
hegyi@114
    40
      o << "Result: " << res;
hegyi@114
    41
      resultlabel.set_text(o.str());
hegyi@114
    42
hegyi@114
    43
      mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
hegyi@114
    44
      //   mapstorage->changeActiveMap(true, E_COLOR,
hegyi@114
    45
      // 			      (edgemapcbts[OUTPUT])->get_active_text());
hegyi@114
    46
      //   mapstorage->changeActiveMap(true, E_TEXT,
hegyi@114
    47
      // 			      (edgemapcbts[INPUT])->get_active_text());
alpar@110
    48
  
hegyi@114
    49
    }
hegyi@106
    50
}
hegyi@106
    51
    
hegyi@106
    52
void KruskalBox::build_box()
hegyi@106
    53
{
hegyi@114
    54
  std::vector<std::string> empty_vector;
hegyi@114
    55
hegyi@109
    56
  edgemapcbts.resize(MAP_NUM);
hegyi@106
    57
hegyi@114
    58
  edgemapcbts[0]=new MapSelector(empty_vector,"","Edgecosts: ",true, false);
hegyi@114
    59
  edgemapcbts[0]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
hegyi@109
    60
hegyi@114
    61
  pack_start(*(edgemapcbts[INPUT]));
hegyi@106
    62
hegyi@114
    63
  edgemapcbts[1]=new MapSelector(empty_vector,"","Edges of tree here: ",true, false);
hegyi@114
    64
  edgemapcbts[1]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
hegyi@106
    65
hegyi@114
    66
  pack_start(*(edgemapcbts[OUTPUT]));
hegyi@109
    67
hegyi@109
    68
  resultlabel.set_text("Result: algorithm is not run yet.");
hegyi@109
    69
  pack_start(resultlabel);
hegyi@106
    70
}