# HG changeset patch # User hegyi # Date 1136480074 0 # Node ID 9f8dc346ac6e18867e59d6290edf2a5182422dc7 # Parent bf355fd6563e478e4be1b0a3bae2049ac665b613 Kruskal algorithm can be run from GUI from now on. diff -r bf355fd6563e -r 9f8dc346ac6e algobox.cc --- a/algobox.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/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 bf355fd6563e -r 9f8dc346ac6e algobox.h --- a/algobox.h Thu Jan 05 12:30:09 2006 +0000 +++ b/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 bf355fd6563e -r 9f8dc346ac6e algowin.cc --- a/algowin.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/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 bf355fd6563e -r 9f8dc346ac6e algowin.h --- a/algowin.h Thu Jan 05 12:30:09 2006 +0000 +++ b/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 bf355fd6563e -r 9f8dc346ac6e graph_displayer_canvas-event.cc --- a/graph_displayer_canvas-event.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/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 bf355fd6563e -r 9f8dc346ac6e kruskalbox.cc --- a/kruskalbox.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/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 bf355fd6563e -r 9f8dc346ac6e kruskalbox.h --- a/kruskalbox.h Thu Jan 05 12:30:09 2006 +0000 +++ b/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 bf355fd6563e -r 9f8dc346ac6e new_map_win.cc --- a/new_map_win.cc Thu Jan 05 12:30:09 2006 +0000 +++ b/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) {