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.
     1 #include <kruskalbox.h>
     2 
     3 enum {INPUT, OUTPUT, MAP_NUM};
     4 
     5 KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
     6 {
     7   init(t);
     8 }
     9     
    10 void KruskalBox::run()
    11 {
    12   if(
    13      tabcbt.get_active_text()!="" &&
    14      (edgemapcbts[INPUT])->get_active_text()!="" &&
    15      (edgemapcbts[OUTPUT])->get_active_text()!=""
    16      )
    17     {
    18 
    19       Graph g=mapstorage->graph;
    20       Graph::EdgeMap<double> * inputmap=
    21 	((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
    22       Graph::EdgeMap<bool> outputmap(g);
    23       double res=kruskal(g, *inputmap, outputmap);
    24 
    25       for (EdgeIt i(g); i!=INVALID; ++i)
    26 	{
    27 	  if(outputmap[i])
    28 	    {
    29 	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
    30 					       get_active_text()]))[i]=1;
    31 	    }
    32 	  else
    33 	    {
    34 	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
    35 					       get_active_text()]))[i]=0;
    36 	    }
    37 	}
    38 
    39       std::ostringstream o;
    40       o << "Result: " << res;
    41       resultlabel.set_text(o.str());
    42 
    43       mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
    44       //   mapstorage->changeActiveMap(true, E_COLOR,
    45       // 			      (edgemapcbts[OUTPUT])->get_active_text());
    46       //   mapstorage->changeActiveMap(true, E_TEXT,
    47       // 			      (edgemapcbts[INPUT])->get_active_text());
    48   
    49     }
    50 }
    51     
    52 void KruskalBox::build_box()
    53 {
    54   std::vector<std::string> empty_vector;
    55 
    56   edgemapcbts.resize(MAP_NUM);
    57 
    58   edgemapcbts[0]=new MapSelector(empty_vector,"","Edgecosts: ",true, false);
    59   edgemapcbts[0]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
    60 
    61   pack_start(*(edgemapcbts[INPUT]));
    62 
    63   edgemapcbts[1]=new MapSelector(empty_vector,"","Edges of tree here: ",true, false);
    64   edgemapcbts[1]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
    65 
    66   pack_start(*(edgemapcbts[OUTPUT]));
    67 
    68   resultlabel.set_text("Result: algorithm is not run yet.");
    69   pack_start(resultlabel);
    70 }