# HG changeset patch # User hegyi # Date 1160753518 0 # Node ID 2cd447b0bd3a0aebc9be9ddb113c8151414a4774 # Parent 70e3c3646283dddb6636fa1f5e85b3426c061c7d Suurballe algorithm is implemented in glemon. diff -r 70e3c3646283 -r 2cd447b0bd3a algowin.cc --- a/algowin.cc Fri Oct 13 15:14:18 2006 +0000 +++ b/algowin.cc Fri Oct 13 15:31:58 2006 +0000 @@ -44,6 +44,10 @@ ab=new DijkstraBox(tabnames); set_title("Dijkstra Algorithm"); break; + case 3: + ab=new SuurballeBox(tabnames); + set_title("Suurballe Algorithm"); + break; default: break; } diff -r 70e3c3646283 -r 2cd447b0bd3a dijkstrabox.cc --- a/dijkstrabox.cc Fri Oct 13 15:14:18 2006 +0000 +++ b/dijkstrabox.cc Fri Oct 13 15:31:58 2006 +0000 @@ -1,4 +1,7 @@ #include +#include +#include +#include enum {INPUT, OUTPUT, MAP_NUM}; @@ -7,6 +10,23 @@ init(t); } +SuurballeBox::SuurballeBox(std::vector t):DijkstraBox(t) +{ + Gtk::Adjustment * adjustment=new Gtk::Adjustment(2, 1, 20, 1, 5); + num_set = new Gtk::SpinButton(*adjustment, 5,0); + + Gtk::Label * label=new Gtk::Label("No. of paths to find: "); +// hbox.pack_start(*label); +// hbox.pack_start(*num_set); +// hbox.show_all_children(); + + table.attach(*label, 0,1,2,3); + table.attach(*num_set, 1,2,2,3); + + +// pack_start(hbox); +} + void DijkstraBox::run() { if( @@ -18,42 +38,28 @@ ) { const Graph &g=mapstorage->graph; + Node from, to; - Graph::EdgeMap * inputmap= - (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]; - Graph::EdgeMap * outputmap= - (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]; + get_from_to(from, to, (Graph&)g); - Node from, to; - int assigned=0; std::ostringstream o; - //zero out output map - for (EdgeIt i(g); i!=INVALID; ++i) - { - (*outputmap)[i]=0; - } - - for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i) - { - std::ostringstream text; - text << (*((mapstorage->nodemap_storage)["label"]))[i]; - if(!(text.str().compare(source.get_active_text()))) - { - from=i; - assigned++; - } - if(!(text.str().compare(target.get_active_text()))) - { - to=i; - assigned++; - } - } if(!(from==to)) { + Graph::EdgeMap * inputmap= + (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]; + Graph::EdgeMap * outputmap= + (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]; + + //zero out output map + for (EdgeIt i(g); i!=INVALID; ++i) + { + (*outputmap)[i]=0; + } + Dijkstra > dijkstra(g, *inputmap); dijkstra.run(from, to); - + if(dijkstra.reached(to)) { Node n=to; @@ -73,13 +79,78 @@ o << source.get_active_text() << " and " << target.get_active_text(); } resultlabel.set_text(o.str()); + + mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); + // mapstorage->changeActiveMap(true, E_COLOR, + // (edgemapcbts[OUTPUT])->get_active_text()); + // mapstorage->changeActiveMap(true, E_TEXT, + // (edgemapcbts[INPUT])->get_active_text()); + } + } +} +void SuurballeBox::run() +{ + if( + tabcbt.get_active_text()!="" && + (edgemapcbts[INPUT])->get_active_text()!="" && + (edgemapcbts[OUTPUT])->get_active_text()!="" && + source.get_active_text()!="" && + target.get_active_text()!="" + ) + { + const Graph &g=mapstorage->graph; + Node from, to; + + get_from_to(from, to, (Graph&)g); + + std::ostringstream o; + + if(!(from==to)) + { + Graph::EdgeMap * inputmap= + (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]; + Graph::EdgeMap * outputmap= + (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]; + + //zero out output map + for (EdgeIt i(g); i!=INVALID; ++i) + { + (*outputmap)[i]=0; + } + + Suurballe > sb((Graph&)g, *inputmap, from, to); + + int found=sb.run(num_set->get_value_as_int()); + if(found) + { + for(int j=0;j path(g); + sb.getPath(path, j); + for(int k=0;k::EdgeIt ei; + path.nth(ei,k); + (*outputmap)[ei]=j+1; + } + } + o << "Result: found " << found << " paths between "; + o << source.get_active_text() << " and " << target.get_active_text(); + } + else + { + o << "Result: failed to find shortest path between "; + o << source.get_active_text() << " and " << target.get_active_text(); + } + resultlabel.set_text(o.str()); + mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); + // mapstorage->changeActiveMap(true, E_COLOR, + // (edgemapcbts[OUTPUT])->get_active_text()); + // mapstorage->changeActiveMap(true, E_TEXT, + // (edgemapcbts[INPUT])->get_active_text()); } - // mapstorage->changeActiveMap(true, E_COLOR, - // (edgemapcbts[OUTPUT])->get_active_text()); - // mapstorage->changeActiveMap(true, E_TEXT, - // (edgemapcbts[INPUT])->get_active_text()); } } @@ -107,6 +178,10 @@ pack_start(resultlabel); } +void SuurballeBox::build_box() +{ +} + void DijkstraBox::maplists_updated() { if(tabcbt.get_active_text()!="") @@ -123,3 +198,23 @@ } } } + +void DijkstraBox::get_from_to(Node & from, Node & to, Graph & g) +{ + int assigned=0; + for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i) + { + std::ostringstream text; + text << (*((mapstorage->nodemap_storage)["label"]))[i]; + if(!(text.str().compare(source.get_active_text()))) + { + from=i; + assigned++; + } + if(!(text.str().compare(target.get_active_text()))) + { + to=i; + assigned++; + } + } +} diff -r 70e3c3646283 -r 2cd447b0bd3a dijkstrabox.h --- a/dijkstrabox.h Fri Oct 13 15:14:18 2006 +0000 +++ b/dijkstrabox.h Fri Oct 13 15:31:58 2006 +0000 @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -23,6 +22,7 @@ ///-implement \ref run function class DijkstraBox : public AlgoBox { +protected: ///Shows result of Dijkstra algorithm Gtk::Label resultlabel; @@ -36,6 +36,9 @@ ///Combobox for select target node Gtk::ComboBoxText target; + ///Gets to and from node from combobox + void get_from_to(Node &, Node &, Graph &); + public: ///Calls \ref AlgoBox::init function to initialize class properly, automatically. DijkstraBox(std::vector t); @@ -46,11 +49,28 @@ ///at the moment. While Dijkstra nedds a bool map as output. ///As postprocess this bool map should be transformed to ///double map. - void run(); + virtual void run(); ///Builds the graphical design of the interface. - void build_box(); + virtual void build_box(); void maplists_updated(); }; + +class SuurballeBox : public DijkstraBox +{ + ///number of paths to find + int num; + + ///Widget to set numbewr of paths to find + Gtk::SpinButton * num_set; + + ///Holder widget + Gtk::HBox hbox; + +public: + SuurballeBox(std::vector t); + void run(); + void build_box(); +}; #endif //DIJKSTRABOX_H diff -r 70e3c3646283 -r 2cd447b0bd3a main_win.cc --- a/main_win.cc Fri Oct 13 15:14:18 2006 +0000 +++ b/main_win.cc Fri Oct 13 15:31:58 2006 +0000 @@ -109,6 +109,8 @@ sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) ); ag->add( Gtk::Action::create("AlgoDijkstra", _("_Dijkstra")), sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 2) ); + ag->add( Gtk::Action::create("AlgoSuurballe", _("_Suurballe")), + sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 3) ); Gtk::RadioAction::Group tool_group; ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")), @@ -162,6 +164,7 @@ " " " " " " + " " " " " " " "