Changeset 165:2cd447b0bd3a in glemon-0.x
- Timestamp:
- 10/13/06 17:31:58 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@2990
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
algowin.cc
r162 r165 44 44 ab=new DijkstraBox(tabnames); 45 45 set_title("Dijkstra Algorithm"); 46 break; 47 case 3: 48 ab=new SuurballeBox(tabnames); 49 set_title("Suurballe Algorithm"); 46 50 break; 47 51 default: -
dijkstrabox.cc
r163 r165 1 1 #include <dijkstrabox.h> 2 #include <lemon/dijkstra.h> 3 #include <lemon/suurballe.h> 4 #include <lemon/path.h> 2 5 3 6 enum {INPUT, OUTPUT, MAP_NUM}; … … 6 9 { 7 10 init(t); 11 } 12 13 SuurballeBox::SuurballeBox(std::vector<std::string> t):DijkstraBox(t) 14 { 15 Gtk::Adjustment * adjustment=new Gtk::Adjustment(2, 1, 20, 1, 5); 16 num_set = new Gtk::SpinButton(*adjustment, 5,0); 17 18 Gtk::Label * label=new Gtk::Label("No. of paths to find: "); 19 // hbox.pack_start(*label); 20 // hbox.pack_start(*num_set); 21 // hbox.show_all_children(); 22 23 table.attach(*label, 0,1,2,3); 24 table.attach(*num_set, 1,2,2,3); 25 26 27 // pack_start(hbox); 8 28 } 9 29 … … 19 39 { 20 40 const Graph &g=mapstorage->graph; 21 22 Graph::EdgeMap<double> * inputmap=23 (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];24 Graph::EdgeMap<double> * outputmap=25 (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];26 27 41 Node from, to; 28 int assigned=0; 42 43 get_from_to(from, to, (Graph&)g); 44 29 45 std::ostringstream o; 30 46 31 //zero out output map32 for (EdgeIt i(g); i!=INVALID; ++i)33 {34 (*outputmap)[i]=0;35 }36 37 for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i)38 {39 std::ostringstream text;40 text << (*((mapstorage->nodemap_storage)["label"]))[i];41 if(!(text.str().compare(source.get_active_text())))42 {43 from=i;44 assigned++;45 }46 if(!(text.str().compare(target.get_active_text())))47 {48 to=i;49 assigned++;50 }51 }52 47 if(!(from==to)) 53 48 { 49 Graph::EdgeMap<double> * inputmap= 50 (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]; 51 Graph::EdgeMap<double> * outputmap= 52 (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]; 53 54 //zero out output map 55 for (EdgeIt i(g); i!=INVALID; ++i) 56 { 57 (*outputmap)[i]=0; 58 } 59 54 60 Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, *inputmap); 55 61 dijkstra.run(from, to); 56 62 57 63 if(dijkstra.reached(to)) 58 64 { … … 74 80 } 75 81 resultlabel.set_text(o.str()); 76 82 77 83 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); 78 } 79 // mapstorage->changeActiveMap(true, E_COLOR, 80 // (edgemapcbts[OUTPUT])->get_active_text()); 81 // mapstorage->changeActiveMap(true, E_TEXT, 82 // (edgemapcbts[INPUT])->get_active_text()); 84 // mapstorage->changeActiveMap(true, E_COLOR, 85 // (edgemapcbts[OUTPUT])->get_active_text()); 86 // mapstorage->changeActiveMap(true, E_TEXT, 87 // (edgemapcbts[INPUT])->get_active_text()); 88 } 89 } 90 } 91 92 void SuurballeBox::run() 93 { 94 if( 95 tabcbt.get_active_text()!="" && 96 (edgemapcbts[INPUT])->get_active_text()!="" && 97 (edgemapcbts[OUTPUT])->get_active_text()!="" && 98 source.get_active_text()!="" && 99 target.get_active_text()!="" 100 ) 101 { 102 const Graph &g=mapstorage->graph; 103 Node from, to; 104 105 get_from_to(from, to, (Graph&)g); 106 107 std::ostringstream o; 108 109 if(!(from==to)) 110 { 111 Graph::EdgeMap<double> * inputmap= 112 (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]; 113 Graph::EdgeMap<double> * outputmap= 114 (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]; 115 116 //zero out output map 117 for (EdgeIt i(g); i!=INVALID; ++i) 118 { 119 (*outputmap)[i]=0; 120 } 121 122 Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, *inputmap, from, to); 123 124 int found=sb.run(num_set->get_value_as_int()); 125 if(found) 126 { 127 for(int j=0;j<found;j++) 128 { 129 DirPath<Graph> path(g); 130 sb.getPath(path, j); 131 for(int k=0;k<path.length();k++) 132 { 133 DirPath<Graph>::EdgeIt ei; 134 path.nth(ei,k); 135 (*outputmap)[ei]=j+1; 136 } 137 } 138 o << "Result: found " << found << " paths between "; 139 o << source.get_active_text() << " and " << target.get_active_text(); 140 } 141 else 142 { 143 o << "Result: failed to find shortest path between "; 144 o << source.get_active_text() << " and " << target.get_active_text(); 145 } 146 resultlabel.set_text(o.str()); 147 148 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); 149 // mapstorage->changeActiveMap(true, E_COLOR, 150 // (edgemapcbts[OUTPUT])->get_active_text()); 151 // mapstorage->changeActiveMap(true, E_TEXT, 152 // (edgemapcbts[INPUT])->get_active_text()); 153 } 83 154 } 84 155 } … … 108 179 } 109 180 181 void SuurballeBox::build_box() 182 { 183 } 184 110 185 void DijkstraBox::maplists_updated() 111 186 { … … 124 199 } 125 200 } 201 202 void DijkstraBox::get_from_to(Node & from, Node & to, Graph & g) 203 { 204 int assigned=0; 205 for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i) 206 { 207 std::ostringstream text; 208 text << (*((mapstorage->nodemap_storage)["label"]))[i]; 209 if(!(text.str().compare(source.get_active_text()))) 210 { 211 from=i; 212 assigned++; 213 } 214 if(!(text.str().compare(target.get_active_text()))) 215 { 216 to=i; 217 assigned++; 218 } 219 } 220 } -
dijkstrabox.h
r163 r165 8 8 #include <all_include.h> 9 9 #include <algobox.h> 10 #include <lemon/dijkstra.h>11 10 #include <libgnomecanvasmm.h> 12 11 #include <libgnomecanvasmm/polygon.h> … … 24 23 class DijkstraBox : public AlgoBox 25 24 { 25 protected: 26 26 ///Shows result of Dijkstra algorithm 27 27 Gtk::Label resultlabel; … … 37 37 Gtk::ComboBoxText target; 38 38 39 ///Gets to and from node from combobox 40 void get_from_to(Node &, Node &, Graph &); 41 39 42 public: 40 43 ///Calls \ref AlgoBox::init function to initialize class properly, automatically. … … 47 50 ///As postprocess this bool map should be transformed to 48 51 ///double map. 49 v oid run();52 virtual void run(); 50 53 51 54 ///Builds the graphical design of the interface. 52 v oid build_box();55 virtual void build_box(); 53 56 54 57 void maplists_updated(); 55 58 }; 59 60 class SuurballeBox : public DijkstraBox 61 { 62 ///number of paths to find 63 int num; 64 65 ///Widget to set numbewr of paths to find 66 Gtk::SpinButton * num_set; 67 68 ///Holder widget 69 Gtk::HBox hbox; 70 71 public: 72 SuurballeBox(std::vector<std::string> t); 73 void run(); 74 void build_box(); 75 }; 56 76 #endif //DIJKSTRABOX_H -
main_win.cc
r162 r165 110 110 ag->add( Gtk::Action::create("AlgoDijkstra", _("_Dijkstra")), 111 111 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 2) ); 112 ag->add( Gtk::Action::create("AlgoSuurballe", _("_Suurballe")), 113 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 3) ); 112 114 113 115 Gtk::RadioAction::Group tool_group; … … 163 165 " <menuitem action='AlgoKruskal'/>" 164 166 " <menuitem action='AlgoDijkstra'/>" 167 " <menuitem action='AlgoSuurballe'/>" 165 168 " </menu>" 166 169 " </menubar>"
Note: See TracChangeset
for help on using the changeset viewer.