1.1 --- a/dijkstrabox.cc Fri Oct 13 15:14:18 2006 +0000
1.2 +++ b/dijkstrabox.cc Fri Oct 13 15:31:58 2006 +0000
1.3 @@ -1,4 +1,7 @@
1.4 #include <dijkstrabox.h>
1.5 +#include <lemon/dijkstra.h>
1.6 +#include <lemon/suurballe.h>
1.7 +#include <lemon/path.h>
1.8
1.9 enum {INPUT, OUTPUT, MAP_NUM};
1.10
1.11 @@ -7,6 +10,23 @@
1.12 init(t);
1.13 }
1.14
1.15 +SuurballeBox::SuurballeBox(std::vector<std::string> t):DijkstraBox(t)
1.16 +{
1.17 + Gtk::Adjustment * adjustment=new Gtk::Adjustment(2, 1, 20, 1, 5);
1.18 + num_set = new Gtk::SpinButton(*adjustment, 5,0);
1.19 +
1.20 + Gtk::Label * label=new Gtk::Label("No. of paths to find: ");
1.21 +// hbox.pack_start(*label);
1.22 +// hbox.pack_start(*num_set);
1.23 +// hbox.show_all_children();
1.24 +
1.25 + table.attach(*label, 0,1,2,3);
1.26 + table.attach(*num_set, 1,2,2,3);
1.27 +
1.28 +
1.29 +// pack_start(hbox);
1.30 +}
1.31 +
1.32 void DijkstraBox::run()
1.33 {
1.34 if(
1.35 @@ -18,42 +38,28 @@
1.36 )
1.37 {
1.38 const Graph &g=mapstorage->graph;
1.39 + Node from, to;
1.40
1.41 - Graph::EdgeMap<double> * inputmap=
1.42 - (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
1.43 - Graph::EdgeMap<double> * outputmap=
1.44 - (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
1.45 + get_from_to(from, to, (Graph&)g);
1.46
1.47 - Node from, to;
1.48 - int assigned=0;
1.49 std::ostringstream o;
1.50
1.51 - //zero out output map
1.52 - for (EdgeIt i(g); i!=INVALID; ++i)
1.53 - {
1.54 - (*outputmap)[i]=0;
1.55 - }
1.56 -
1.57 - for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i)
1.58 - {
1.59 - std::ostringstream text;
1.60 - text << (*((mapstorage->nodemap_storage)["label"]))[i];
1.61 - if(!(text.str().compare(source.get_active_text())))
1.62 - {
1.63 - from=i;
1.64 - assigned++;
1.65 - }
1.66 - if(!(text.str().compare(target.get_active_text())))
1.67 - {
1.68 - to=i;
1.69 - assigned++;
1.70 - }
1.71 - }
1.72 if(!(from==to))
1.73 {
1.74 + Graph::EdgeMap<double> * inputmap=
1.75 + (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
1.76 + Graph::EdgeMap<double> * outputmap=
1.77 + (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
1.78 +
1.79 + //zero out output map
1.80 + for (EdgeIt i(g); i!=INVALID; ++i)
1.81 + {
1.82 + (*outputmap)[i]=0;
1.83 + }
1.84 +
1.85 Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, *inputmap);
1.86 dijkstra.run(from, to);
1.87 -
1.88 +
1.89 if(dijkstra.reached(to))
1.90 {
1.91 Node n=to;
1.92 @@ -73,13 +79,78 @@
1.93 o << source.get_active_text() << " and " << target.get_active_text();
1.94 }
1.95 resultlabel.set_text(o.str());
1.96 +
1.97 + mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
1.98 + // mapstorage->changeActiveMap(true, E_COLOR,
1.99 + // (edgemapcbts[OUTPUT])->get_active_text());
1.100 + // mapstorage->changeActiveMap(true, E_TEXT,
1.101 + // (edgemapcbts[INPUT])->get_active_text());
1.102 + }
1.103 + }
1.104 +}
1.105
1.106 +void SuurballeBox::run()
1.107 +{
1.108 + if(
1.109 + tabcbt.get_active_text()!="" &&
1.110 + (edgemapcbts[INPUT])->get_active_text()!="" &&
1.111 + (edgemapcbts[OUTPUT])->get_active_text()!="" &&
1.112 + source.get_active_text()!="" &&
1.113 + target.get_active_text()!=""
1.114 + )
1.115 + {
1.116 + const Graph &g=mapstorage->graph;
1.117 + Node from, to;
1.118 +
1.119 + get_from_to(from, to, (Graph&)g);
1.120 +
1.121 + std::ostringstream o;
1.122 +
1.123 + if(!(from==to))
1.124 + {
1.125 + Graph::EdgeMap<double> * inputmap=
1.126 + (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
1.127 + Graph::EdgeMap<double> * outputmap=
1.128 + (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
1.129 +
1.130 + //zero out output map
1.131 + for (EdgeIt i(g); i!=INVALID; ++i)
1.132 + {
1.133 + (*outputmap)[i]=0;
1.134 + }
1.135 +
1.136 + Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, *inputmap, from, to);
1.137 +
1.138 + int found=sb.run(num_set->get_value_as_int());
1.139 + if(found)
1.140 + {
1.141 + for(int j=0;j<found;j++)
1.142 + {
1.143 + DirPath<Graph> path(g);
1.144 + sb.getPath(path, j);
1.145 + for(int k=0;k<path.length();k++)
1.146 + {
1.147 + DirPath<Graph>::EdgeIt ei;
1.148 + path.nth(ei,k);
1.149 + (*outputmap)[ei]=j+1;
1.150 + }
1.151 + }
1.152 + o << "Result: found " << found << " paths between ";
1.153 + o << source.get_active_text() << " and " << target.get_active_text();
1.154 + }
1.155 + else
1.156 + {
1.157 + o << "Result: failed to find shortest path between ";
1.158 + o << source.get_active_text() << " and " << target.get_active_text();
1.159 + }
1.160 + resultlabel.set_text(o.str());
1.161 +
1.162 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
1.163 + // mapstorage->changeActiveMap(true, E_COLOR,
1.164 + // (edgemapcbts[OUTPUT])->get_active_text());
1.165 + // mapstorage->changeActiveMap(true, E_TEXT,
1.166 + // (edgemapcbts[INPUT])->get_active_text());
1.167 }
1.168 - // mapstorage->changeActiveMap(true, E_COLOR,
1.169 - // (edgemapcbts[OUTPUT])->get_active_text());
1.170 - // mapstorage->changeActiveMap(true, E_TEXT,
1.171 - // (edgemapcbts[INPUT])->get_active_text());
1.172 }
1.173 }
1.174
1.175 @@ -107,6 +178,10 @@
1.176 pack_start(resultlabel);
1.177 }
1.178
1.179 +void SuurballeBox::build_box()
1.180 +{
1.181 +}
1.182 +
1.183 void DijkstraBox::maplists_updated()
1.184 {
1.185 if(tabcbt.get_active_text()!="")
1.186 @@ -123,3 +198,23 @@
1.187 }
1.188 }
1.189 }
1.190 +
1.191 +void DijkstraBox::get_from_to(Node & from, Node & to, Graph & g)
1.192 +{
1.193 + int assigned=0;
1.194 + for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i)
1.195 + {
1.196 + std::ostringstream text;
1.197 + text << (*((mapstorage->nodemap_storage)["label"]))[i];
1.198 + if(!(text.str().compare(source.get_active_text())))
1.199 + {
1.200 + from=i;
1.201 + assigned++;
1.202 + }
1.203 + if(!(text.str().compare(target.get_active_text())))
1.204 + {
1.205 + to=i;
1.206 + assigned++;
1.207 + }
1.208 + }
1.209 +}