# HG changeset patch # User hegyi # Date 1136480074 0 # Node ID 01d41844ef461f1035899098dce8b60d59e10931 # Parent 409a31271efd209a88dd96ae37421bc1ac73f794 Kruskal algorithm can be run from GUI from now on. diff -r 409a31271efd -r 01d41844ef46 gui/algobox.cc --- a/gui/algobox.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/gui/algobox.cc Thu Jan 05 16:54:34 2006 +0000 @@ -59,9 +59,9 @@ emit_tab_change(); } -void AlgoBox::update_maplist( void * ms) +void AlgoBox::update_maplist(MapStorage * ms) { - mapstorage=(MapStorage *)ms; + mapstorage=ms; std::vector nml; std::vector eml; if(mapstorage!=NULL) @@ -69,7 +69,7 @@ mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed)); mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed)); nml=mapstorage->getNodeMapList(); - eml=mapstorage->getNodeMapList(); + eml=mapstorage->getEdgeMapList(); } for(int i=0;i<(int)nodemapcbts.size();i++) { diff -r 409a31271efd -r 01d41844ef46 gui/algobox.h --- a/gui/algobox.h Thu Jan 05 12:30:09 2006 +0000 +++ b/gui/algobox.h Thu Jan 05 16:54:34 2006 +0000 @@ -33,7 +33,7 @@ void emit_tab_change(); void update_tablist( std::vector< std::string > tl ); - void update_maplist( void * ); + void update_maplist( MapStorage * ); void nodemaplist_changed(std::string); void edgemaplist_changed(std::string); diff -r 409a31271efd -r 01d41844ef46 gui/algowin.cc --- a/gui/algowin.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/gui/algowin.cc Thu Jan 05 16:54:34 2006 +0000 @@ -71,7 +71,7 @@ ab->update_tablist(tabnames); } -void AlgoWin::update_maplist(void * mapstorage) +void AlgoWin::update_maplist(MapStorage * mapstorage) { ab->update_maplist(mapstorage); } diff -r 409a31271efd -r 01d41844ef46 gui/algowin.h --- a/gui/algowin.h Thu Jan 05 12:30:09 2006 +0000 +++ b/gui/algowin.h Thu Jan 05 16:54:34 2006 +0000 @@ -6,10 +6,13 @@ class AlgoWin; #include +//#include #include #include #include +class MapStorage; + enum {GENERAL, KRUSKAL, ALGO_NUM}; // algorithm IDs; class AlgoWin : public Gtk::Window @@ -34,7 +37,7 @@ AlgoWin(int, std::vector); void update_tablist(std::vector tabnames); - void update_maplist( void *); + void update_maplist(MapStorage *); void on_hide(); }; diff -r 409a31271efd -r 01d41844ef46 gui/graph_displayer_canvas-event.cc --- a/gui/graph_displayer_canvas-event.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/gui/graph_displayer_canvas-event.cc Thu Jan 05 16:54:34 2006 +0000 @@ -850,49 +850,4 @@ std::cerr << "ERROR!!!! Invalid edge found!" << std::endl; } } - } - -int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) -{ - //create the new map - Graph::EdgeMap * emptr=new Graph::EdgeMap ((mytab.mapstorage).graph, default_value); - - //if addition was not successful addEdgeMap returns one. - //cause can be that there is already a map named like the new one - if((mytab.mapstorage).addEdgeMap(mapname,emptr, default_value)) - { - return 1; - } - - - //add it to the list of the displayable maps - mytab.registerNewEdgeMap(mapname); - - //display it - changeEdgeText(mapname); - - return 0; -} - -int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) -{ - //create the new map - Graph::NodeMap * emptr=new Graph::NodeMap ((mytab.mapstorage).graph,default_value); - - //if addition was not successful addNodeMap returns one. - //cause can be that there is already a map named like the new one - if((mytab.mapstorage).addNodeMap(mapname,emptr, default_value)) - { - return 1; - } - - //add it to the list of the displayable maps - mytab.registerNewNodeMap(mapname); - - //display it - changeNodeText(mapname); - - return 0; -} - diff -r 409a31271efd -r 01d41844ef46 gui/kruskalbox.cc --- a/gui/kruskalbox.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/gui/kruskalbox.cc Thu Jan 05 16:54:34 2006 +0000 @@ -1,5 +1,7 @@ #include +enum {INPUT, OUTPUT, MAP_NUM}; + KruskalBox::KruskalBox(std::vector t):AlgoBox() { init(t); @@ -7,22 +9,56 @@ void KruskalBox::run() { - - std::cout << "Kruskal inditasa, de meg nincsen keszen." << std::endl; + Graph g=mapstorage->graph; + Graph::EdgeMap * inputmap=((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]); + Graph::EdgeMap outputmap(g); + double res=kruskal(g, *inputmap, outputmap); + + for (EdgeIt i(g); i!=INVALID; ++i) + { + if(outputmap[i]) + { + (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=1; + } + else + { + (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=0; + } + } + + std::ostringstream o; + o << "Result: " << res; + resultlabel.set_text(o.str()); + + mapstorage->changeActiveMap(true, E_COLOR, (edgemapcbts[OUTPUT])->get_active_text()); + mapstorage->changeActiveMap(true, E_TEXT, (edgemapcbts[INPUT])->get_active_text()); } void KruskalBox::build_box() { - edgemapcbts.resize(1); - Gtk::HBox * hbox=new Gtk::HBox(); + edgemapcbts.resize(MAP_NUM); + Gtk::HBox * hbox; - std::ostringstream o; - o << "Edgecosts: "; - label=new Gtk::Label(o.str()); + hbox=new Gtk::HBox(); + + label=new Gtk::Label("Edgecosts: "); edgemapcbts[0]=new Gtk::ComboBoxText(); hbox->pack_start(*label); - hbox->pack_start(*(edgemapcbts[0])); + hbox->pack_start(*(edgemapcbts[INPUT])); pack_start(*hbox); + + hbox=new Gtk::HBox(); + + label=new Gtk::Label("Edges of tree here: "); + + edgemapcbts[1]=new Gtk::ComboBoxText(); + + hbox->pack_start(*label); + hbox->pack_start(*(edgemapcbts[OUTPUT])); + pack_start(*hbox); + + resultlabel.set_text("Result: algorithm is not run yet."); + pack_start(resultlabel); } diff -r 409a31271efd -r 01d41844ef46 gui/kruskalbox.h --- a/gui/kruskalbox.h Thu Jan 05 12:30:09 2006 +0000 +++ b/gui/kruskalbox.h Thu Jan 05 16:54:34 2006 +0000 @@ -13,6 +13,8 @@ class KruskalBox : public AlgoBox { + Gtk::Label resultlabel; + public: KruskalBox(std::vector t); diff -r 409a31271efd -r 01d41844ef46 gui/new_map_win.cc --- a/gui/new_map_win.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/gui/new_map_win.cc Thu Jan 05 16:54:34 2006 +0000 @@ -120,6 +120,7 @@ def_val_ch[j]=ch2var[ polishform[i] ][j]; } polishstack.push(atof(def_val_ch)); + delete def_val_ch; } operation=false; break; @@ -164,6 +165,8 @@ //display it //gdc.changeEdgeText(mapname); + + //delete emptr; } else //!edge.get_active() { @@ -204,6 +207,7 @@ def_val_ch[j]=ch2var[ polishform[i] ][j]; } polishstack.push(atof(def_val_ch)); + delete def_val_ch; } operation=false; break; @@ -248,6 +252,8 @@ //display it //gdc.changeNodeText(mapname); + + //delete emptr; } if(!abortion) {