kruskalbox.cc
author hegyi
Tue, 19 Sep 2006 07:43:55 +0000
changeset 149 930e838ad5b6
parent 116 2bd795bb9984
child 174 95872af46fc4
permissions -rw-r--r--
Node and edge editor button are the same furthermore.
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
alpar@145
    19
      const 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@116
    56
  addMapSelector("Edgecosts: ", true);
hegyi@116
    57
  addMapSelector("Edges of tree here: ", true);
hegyi@109
    58
hegyi@109
    59
  resultlabel.set_text("Result: algorithm is not run yet.");
hegyi@109
    60
  pack_start(resultlabel);
hegyi@106
    61
}