Kruskal algorithm can be run from GUI from now on.
1.1 --- a/algobox.cc Thu Jan 05 12:30:09 2006 +0000
1.2 +++ b/algobox.cc Thu Jan 05 16:54:34 2006 +0000
1.3 @@ -59,9 +59,9 @@
1.4 emit_tab_change();
1.5 }
1.6
1.7 -void AlgoBox::update_maplist( void * ms)
1.8 +void AlgoBox::update_maplist(MapStorage * ms)
1.9 {
1.10 - mapstorage=(MapStorage *)ms;
1.11 + mapstorage=ms;
1.12 std::vector<std::string> nml;
1.13 std::vector<std::string> eml;
1.14 if(mapstorage!=NULL)
1.15 @@ -69,7 +69,7 @@
1.16 mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
1.17 mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
1.18 nml=mapstorage->getNodeMapList();
1.19 - eml=mapstorage->getNodeMapList();
1.20 + eml=mapstorage->getEdgeMapList();
1.21 }
1.22 for(int i=0;i<(int)nodemapcbts.size();i++)
1.23 {
2.1 --- a/algobox.h Thu Jan 05 12:30:09 2006 +0000
2.2 +++ b/algobox.h Thu Jan 05 16:54:34 2006 +0000
2.3 @@ -33,7 +33,7 @@
2.4 void emit_tab_change();
2.5
2.6 void update_tablist( std::vector< std::string > tl );
2.7 - void update_maplist( void * );
2.8 + void update_maplist( MapStorage * );
2.9
2.10 void nodemaplist_changed(std::string);
2.11 void edgemaplist_changed(std::string);
3.1 --- a/algowin.cc Thu Jan 05 12:30:09 2006 +0000
3.2 +++ b/algowin.cc Thu Jan 05 16:54:34 2006 +0000
3.3 @@ -71,7 +71,7 @@
3.4 ab->update_tablist(tabnames);
3.5 }
3.6
3.7 -void AlgoWin::update_maplist(void * mapstorage)
3.8 +void AlgoWin::update_maplist(MapStorage * mapstorage)
3.9 {
3.10 ab->update_maplist(mapstorage);
3.11 }
4.1 --- a/algowin.h Thu Jan 05 12:30:09 2006 +0000
4.2 +++ b/algowin.h Thu Jan 05 16:54:34 2006 +0000
4.3 @@ -6,10 +6,13 @@
4.4 class AlgoWin;
4.5
4.6 #include <all_include.h>
4.7 +//#include <mapstorage.h>
4.8 #include <algobox.h>
4.9 #include <libgnomecanvasmm.h>
4.10 #include <libgnomecanvasmm/polygon.h>
4.11
4.12 +class MapStorage;
4.13 +
4.14 enum {GENERAL, KRUSKAL, ALGO_NUM}; // algorithm IDs;
4.15
4.16 class AlgoWin : public Gtk::Window
4.17 @@ -34,7 +37,7 @@
4.18 AlgoWin(int, std::vector<std::string>);
4.19
4.20 void update_tablist(std::vector<std::string> tabnames);
4.21 - void update_maplist( void *);
4.22 + void update_maplist(MapStorage *);
4.23
4.24 void on_hide();
4.25 };
5.1 --- a/graph_displayer_canvas-event.cc Thu Jan 05 12:30:09 2006 +0000
5.2 +++ b/graph_displayer_canvas-event.cc Thu Jan 05 16:54:34 2006 +0000
5.3 @@ -850,49 +850,4 @@
5.4 std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
5.5 }
5.6 }
5.7 -
5.8 }
5.9 -
5.10 -int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
5.11 -{
5.12 - //create the new map
5.13 - Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> ((mytab.mapstorage).graph, default_value);
5.14 -
5.15 - //if addition was not successful addEdgeMap returns one.
5.16 - //cause can be that there is already a map named like the new one
5.17 - if((mytab.mapstorage).addEdgeMap(mapname,emptr, default_value))
5.18 - {
5.19 - return 1;
5.20 - }
5.21 -
5.22 -
5.23 - //add it to the list of the displayable maps
5.24 - mytab.registerNewEdgeMap(mapname);
5.25 -
5.26 - //display it
5.27 - changeEdgeText(mapname);
5.28 -
5.29 - return 0;
5.30 -}
5.31 -
5.32 -int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
5.33 -{
5.34 - //create the new map
5.35 - Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> ((mytab.mapstorage).graph,default_value);
5.36 -
5.37 - //if addition was not successful addNodeMap returns one.
5.38 - //cause can be that there is already a map named like the new one
5.39 - if((mytab.mapstorage).addNodeMap(mapname,emptr, default_value))
5.40 - {
5.41 - return 1;
5.42 - }
5.43 -
5.44 - //add it to the list of the displayable maps
5.45 - mytab.registerNewNodeMap(mapname);
5.46 -
5.47 - //display it
5.48 - changeNodeText(mapname);
5.49 -
5.50 - return 0;
5.51 -}
5.52 -
6.1 --- a/kruskalbox.cc Thu Jan 05 12:30:09 2006 +0000
6.2 +++ b/kruskalbox.cc Thu Jan 05 16:54:34 2006 +0000
6.3 @@ -1,5 +1,7 @@
6.4 #include <kruskalbox.h>
6.5
6.6 +enum {INPUT, OUTPUT, MAP_NUM};
6.7 +
6.8 KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
6.9 {
6.10 init(t);
6.11 @@ -7,22 +9,56 @@
6.12
6.13 void KruskalBox::run()
6.14 {
6.15 -
6.16 - std::cout << "Kruskal inditasa, de meg nincsen keszen." << std::endl;
6.17 + Graph g=mapstorage->graph;
6.18 + Graph::EdgeMap<double> * inputmap=((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
6.19 + Graph::EdgeMap<bool> outputmap(g);
6.20 + double res=kruskal(g, *inputmap, outputmap);
6.21 +
6.22 + for (EdgeIt i(g); i!=INVALID; ++i)
6.23 + {
6.24 + if(outputmap[i])
6.25 + {
6.26 + (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=1;
6.27 + }
6.28 + else
6.29 + {
6.30 + (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=0;
6.31 + }
6.32 + }
6.33 +
6.34 + std::ostringstream o;
6.35 + o << "Result: " << res;
6.36 + resultlabel.set_text(o.str());
6.37 +
6.38 + mapstorage->changeActiveMap(true, E_COLOR, (edgemapcbts[OUTPUT])->get_active_text());
6.39 + mapstorage->changeActiveMap(true, E_TEXT, (edgemapcbts[INPUT])->get_active_text());
6.40 }
6.41
6.42 void KruskalBox::build_box()
6.43 {
6.44 - edgemapcbts.resize(1);
6.45 - Gtk::HBox * hbox=new Gtk::HBox();
6.46 + edgemapcbts.resize(MAP_NUM);
6.47 + Gtk::HBox * hbox;
6.48
6.49 - std::ostringstream o;
6.50 - o << "Edgecosts: ";
6.51 - label=new Gtk::Label(o.str());
6.52 + hbox=new Gtk::HBox();
6.53 +
6.54 + label=new Gtk::Label("Edgecosts: ");
6.55
6.56 edgemapcbts[0]=new Gtk::ComboBoxText();
6.57
6.58 hbox->pack_start(*label);
6.59 - hbox->pack_start(*(edgemapcbts[0]));
6.60 + hbox->pack_start(*(edgemapcbts[INPUT]));
6.61 pack_start(*hbox);
6.62 +
6.63 + hbox=new Gtk::HBox();
6.64 +
6.65 + label=new Gtk::Label("Edges of tree here: ");
6.66 +
6.67 + edgemapcbts[1]=new Gtk::ComboBoxText();
6.68 +
6.69 + hbox->pack_start(*label);
6.70 + hbox->pack_start(*(edgemapcbts[OUTPUT]));
6.71 + pack_start(*hbox);
6.72 +
6.73 + resultlabel.set_text("Result: algorithm is not run yet.");
6.74 + pack_start(resultlabel);
6.75 }
7.1 --- a/kruskalbox.h Thu Jan 05 12:30:09 2006 +0000
7.2 +++ b/kruskalbox.h Thu Jan 05 16:54:34 2006 +0000
7.3 @@ -13,6 +13,8 @@
7.4
7.5 class KruskalBox : public AlgoBox
7.6 {
7.7 + Gtk::Label resultlabel;
7.8 +
7.9 public:
7.10 KruskalBox(std::vector<std::string> t);
7.11
8.1 --- a/new_map_win.cc Thu Jan 05 12:30:09 2006 +0000
8.2 +++ b/new_map_win.cc Thu Jan 05 16:54:34 2006 +0000
8.3 @@ -120,6 +120,7 @@
8.4 def_val_ch[j]=ch2var[ polishform[i] ][j];
8.5 }
8.6 polishstack.push(atof(def_val_ch));
8.7 + delete def_val_ch;
8.8 }
8.9 operation=false;
8.10 break;
8.11 @@ -164,6 +165,8 @@
8.12
8.13 //display it
8.14 //gdc.changeEdgeText(mapname);
8.15 +
8.16 + //delete emptr;
8.17 }
8.18 else //!edge.get_active()
8.19 {
8.20 @@ -204,6 +207,7 @@
8.21 def_val_ch[j]=ch2var[ polishform[i] ][j];
8.22 }
8.23 polishstack.push(atof(def_val_ch));
8.24 + delete def_val_ch;
8.25 }
8.26 operation=false;
8.27 break;
8.28 @@ -248,6 +252,8 @@
8.29
8.30 //display it
8.31 //gdc.changeNodeText(mapname);
8.32 +
8.33 + //delete emptr;
8.34 }
8.35 if(!abortion)
8.36 {