Added two new classes.
1 #include <dijkstrabox.h>
2 #include <lemon/dijkstra.h>
3 #include <lemon/suurballe.h>
4 #include <lemon/path.h>
6 enum {INPUT, OUTPUT, MAP_NUM};
8 DijkstraBox::DijkstraBox(std::vector<std::string> t):AlgoBox()
13 SuurballeBox::SuurballeBox(std::vector<std::string> t):DijkstraBox(t)
15 Gtk::Adjustment * adjustment=new Gtk::Adjustment(2, 1, 20, 1, 5);
16 num_set = new Gtk::SpinButton(*adjustment, 5,0);
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();
23 table.attach(*label, 0,1,2,3);
24 table.attach(*num_set, 1,2,2,3);
30 void DijkstraBox::run()
33 tabcbt.get_active_text()!="" &&
34 (edgemapcbts[INPUT])->get_active_text()!="" &&
35 (edgemapcbts[OUTPUT])->get_active_text()!="" &&
36 source.get_active_text()!="" &&
37 target.get_active_text()!=""
40 const Graph &g=mapstorage->graph;
43 get_from_to(from, to, (Graph&)g);
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()];
55 for (EdgeIt i(g); i!=INVALID; ++i)
60 Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, *inputmap);
61 dijkstra.run(from, to);
63 if(dijkstra.reached(to))
67 while (n!=INVALID && n!=from)
69 Edge e=dijkstra.predEdge(n);
71 n=dijkstra.predNode(n);
74 o << "Result: " << length << " long path, with cost " << dijkstra.dist(to);
78 o << "Result: failed to find shortest path between ";
79 o << source.get_active_text() << " and " << target.get_active_text();
81 resultlabel.set_text(o.str());
83 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->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());
92 void SuurballeBox::run()
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()!=""
102 const Graph &g=mapstorage->graph;
105 get_from_to(from, to, (Graph&)g);
107 std::ostringstream o;
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()];
116 //zero out output map
117 for (EdgeIt i(g); i!=INVALID; ++i)
122 Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, *inputmap, from, to);
124 int found=sb.run(num_set->get_value_as_int());
127 for(int j=0;j<found;j++)
131 for(int k=0;k<path.length();k++)
133 Path<Graph>::EdgeIt ei;
135 (*outputmap)[ei]=j+1;
138 o << "Result: found " << found << " paths between ";
139 o << source.get_active_text() << " and " << target.get_active_text();
143 o << "Result: failed to find shortest path between ";
144 o << source.get_active_text() << " and " << target.get_active_text();
146 resultlabel.set_text(o.str());
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());
157 void DijkstraBox::build_box()
159 //if active tab is changed, labels of graph nodes had to be loaded into comboboxes
160 //this can be done after the maps are loaded into ComboBoxes
161 signal_upon_maplist_updated().connect(sigc::mem_fun(*this, &DijkstraBox::maplists_updated));
163 addMapSelector("Cost map: ", true);
164 addMapSelector("Edges of path here: ", true);
166 Gtk::Label * source_label=new Gtk::Label("Source: ");
167 Gtk::Label * target_label=new Gtk::Label("Target: ");
169 table.attach(*source_label, 0,1,0,1);
170 table.attach(*target_label, 0,1,1,2);
171 table.attach(source, 1,2,0,1);
172 table.attach(target, 1,2,1,2);
177 resultlabel.set_text("Result: algorithm is not run yet.");
178 pack_start(resultlabel);
181 void SuurballeBox::build_box()
185 void DijkstraBox::maplists_updated()
187 if(tabcbt.get_active_text()!="")
191 const Graph &g=mapstorage->graph;
192 for (NodeIt i(g); i!=INVALID; ++i)
194 std::ostringstream text;
195 text << (*((mapstorage->nodemap_storage)["label"]))[i];
196 source.prepend_text(text.str());
197 target.prepend_text(text.str());
202 void DijkstraBox::get_from_to(Node & from, Node & to, Graph & g)
205 for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i)
207 std::ostringstream text;
208 text << (*((mapstorage->nodemap_storage)["label"]))[i];
209 if(!(text.str().compare(source.get_active_text())))
214 if(!(text.str().compare(target.get_active_text())))