gui/kruskalbox.cc
author deba
Mon, 27 Mar 2006 16:25:14 +0000
changeset 2019 e70c1f6849bc
parent 1884 9c061834b33b
permissions -rw-r--r--
Adding todo to preflow
Some naming convention renamings
hegyi@1876
     1
#include <kruskalbox.h>
hegyi@1876
     2
hegyi@1879
     3
enum {INPUT, OUTPUT, MAP_NUM};
hegyi@1879
     4
hegyi@1878
     5
KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
hegyi@1876
     6
{
hegyi@1878
     7
  init(t);
hegyi@1876
     8
}
hegyi@1876
     9
    
hegyi@1876
    10
void KruskalBox::run()
hegyi@1876
    11
{
hegyi@1884
    12
  if(
hegyi@1884
    13
     tabcbt.get_active_text()!="" &&
hegyi@1884
    14
     (edgemapcbts[INPUT])->get_active_text()!="" &&
hegyi@1884
    15
     (edgemapcbts[OUTPUT])->get_active_text()!=""
hegyi@1884
    16
     )
hegyi@1884
    17
    {
hegyi@1879
    18
hegyi@1884
    19
      Graph g=mapstorage->graph;
hegyi@1884
    20
      Graph::EdgeMap<double> * inputmap=
hegyi@1884
    21
	((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
hegyi@1884
    22
      Graph::EdgeMap<bool> outputmap(g);
hegyi@1884
    23
      double res=kruskal(g, *inputmap, outputmap);
hegyi@1879
    24
hegyi@1884
    25
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1884
    26
	{
hegyi@1884
    27
	  if(outputmap[i])
hegyi@1884
    28
	    {
hegyi@1884
    29
	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
hegyi@1884
    30
					       get_active_text()]))[i]=1;
hegyi@1884
    31
	    }
hegyi@1884
    32
	  else
hegyi@1884
    33
	    {
hegyi@1884
    34
	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
hegyi@1884
    35
					       get_active_text()]))[i]=0;
hegyi@1884
    36
	    }
hegyi@1884
    37
	}
hegyi@1881
    38
hegyi@1884
    39
      std::ostringstream o;
hegyi@1884
    40
      o << "Result: " << res;
hegyi@1884
    41
      resultlabel.set_text(o.str());
hegyi@1884
    42
hegyi@1884
    43
      mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
hegyi@1884
    44
      //   mapstorage->changeActiveMap(true, E_COLOR,
hegyi@1884
    45
      // 			      (edgemapcbts[OUTPUT])->get_active_text());
hegyi@1884
    46
      //   mapstorage->changeActiveMap(true, E_TEXT,
hegyi@1884
    47
      // 			      (edgemapcbts[INPUT])->get_active_text());
alpar@1880
    48
  
hegyi@1884
    49
    }
hegyi@1876
    50
}
hegyi@1876
    51
    
hegyi@1876
    52
void KruskalBox::build_box()
hegyi@1876
    53
{
hegyi@1884
    54
  std::vector<std::string> empty_vector;
hegyi@1884
    55
hegyi@1886
    56
  addMapSelector("Edgecosts: ", true);
hegyi@1886
    57
  addMapSelector("Edges of tree here: ", true);
hegyi@1879
    58
hegyi@1879
    59
  resultlabel.set_text("Result: algorithm is not run yet.");
hegyi@1879
    60
  pack_start(resultlabel);
hegyi@1876
    61
}