Use hg changeset hash instead of svn revision.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include <mapstorage.h>
20 #include <mapselector.h>
22 #include <dijkstrabox.h>
24 #include <lemon/dijkstra.h>
26 //No Suurballe in Lemon 1.0
27 //#include <lemon/suurballe.h>
28 #include <lemon/path.h>
30 enum {INPUT, OUTPUT, MAP_NUM};
32 DijkstraBox::DijkstraBox(std::vector<std::string> t):AlgoBox()
37 SuurballeBox::SuurballeBox(std::vector<std::string> t):DijkstraBox(t)
39 Gtk::Adjustment * adjustment=new Gtk::Adjustment(2, 1, 20, 1, 5);
40 num_set = new Gtk::SpinButton(*adjustment, 5,0);
42 Gtk::Label * label=new Gtk::Label("No. of paths to find: ");
43 // hbox.pack_start(*label);
44 // hbox.pack_start(*num_set);
45 // hbox.show_all_children();
47 table.attach(*label, 0,1,2,3);
48 table.attach(*num_set, 1,2,2,3);
54 void DijkstraBox::run()
57 tabcbt.get_active_text()!="" &&
58 (arcmapcbts[INPUT])->get_active_text()!="" &&
59 (arcmapcbts[OUTPUT])->get_active_text()!="" &&
60 source.get_active_text()!="" &&
61 target.get_active_text()!=""
64 const Digraph &g=mapstorage->digraph;
67 get_from_to(from, to, (Digraph&)g);
73 std::string inputmapName = arcmapcbts[INPUT]->get_active_text();
74 std::string outputmapName = arcmapcbts[OUTPUT]->get_active_text();
76 MapStorage::NumericArcMap& inputmap = mapstorage->getNumericArcMap(inputmapName);
77 MapStorage::NumericArcMap& outputmap = mapstorage->getNumericArcMap(outputmapName);
80 for (ArcIt i(g); i!=INVALID; ++i)
85 Dijkstra<Digraph, MapStorage::NumericArcMap > dijkstra(g, inputmap);
86 dijkstra.run(from, to);
88 if(dijkstra.reached(to))
92 while (n!=INVALID && n!=from)
94 Arc e=dijkstra.predArc(n);
96 n=dijkstra.predNode(n);
99 o << "Result: " << length << " long path, with cost " << dijkstra.dist(to);
103 o << "Result: failed to find shortest path between ";
104 o << source.get_active_text() << " and " << target.get_active_text();
106 resultlabel.set_text(o.str());
108 mapstorage->mapChanged(true, (arcmapcbts[OUTPUT])->get_active_text());
109 // mapstorage->changeActiveMap(true, E_COLOR,
110 // (arcmapcbts[OUTPUT])->get_active_text());
111 // mapstorage->changeActiveMap(true, E_TEXT,
112 // (arcmapcbts[INPUT])->get_active_text());
117 void SuurballeBox::run()
120 tabcbt.get_active_text()!="" &&
121 (arcmapcbts[INPUT])->get_active_text()!="" &&
122 (arcmapcbts[OUTPUT])->get_active_text()!="" &&
123 source.get_active_text()!="" &&
124 target.get_active_text()!=""
127 const Digraph &g=mapstorage->digraph;
130 get_from_to(from, to, (Digraph&)g);
132 std::ostringstream o;
136 MapStorage::NumericArcMap& inputmap=
137 mapstorage->getNumericArcMap(arcmapcbts[INPUT]->get_active_text());
138 MapStorage::NumericArcMap& outputmap=
139 mapstorage->getNumericArcMap(arcmapcbts[OUTPUT]->get_active_text());
141 //zero out output map
142 for (ArcIt i(g); i!=INVALID; ++i)
147 //No Suurballe in Lemon 1.0
148 //Suurballe<Digraph, MapStorage::NumericArcMap > sb((Digraph&)g, inputmap, from, to);
151 //No Suurballe in Lemon 1.0
152 //found=sb.run(num_set->get_value_as_int());
155 for(int j=0;j<found;j++)
158 //No Suurballe in Lemon 1.0
160 for(int k=0;k<path.length();k++)
162 outputmap[path.nth(k)]=j+1;
165 o << "Result: found " << found << " paths between ";
166 o << source.get_active_text() << " and " << target.get_active_text();
170 o << "Result: failed to find shortest path between ";
171 o << source.get_active_text() << " and " << target.get_active_text();
173 resultlabel.set_text(o.str());
175 mapstorage->mapChanged(true, (arcmapcbts[OUTPUT])->get_active_text());
176 // mapstorage->changeActiveMap(true, E_COLOR,
177 // (arcmapcbts[OUTPUT])->get_active_text());
178 // mapstorage->changeActiveMap(true, E_TEXT,
179 // (arcmapcbts[INPUT])->get_active_text());
184 void DijkstraBox::build_box()
186 //if active tab is changed, labels of digraph nodes had to be loaded into comboboxes
187 //this can be done after the maps are loaded into ComboBoxes
188 signal_upon_maplist_updated().connect(sigc::mem_fun(*this, &DijkstraBox::maplists_updated));
190 addMapSelector("Cost map: ", true, NUM);
191 addMapSelector("Arcs of path here: ", true, NUM);
193 Gtk::Label * source_label=new Gtk::Label("Source: ");
194 Gtk::Label * target_label=new Gtk::Label("Target: ");
196 table.attach(*source_label, 0,1,0,1);
197 table.attach(*target_label, 0,1,1,2);
198 table.attach(source, 1,2,0,1);
199 table.attach(target, 1,2,1,2);
204 resultlabel.set_text("Result: algorithm is not run yet.");
205 pack_start(resultlabel);
208 void SuurballeBox::build_box()
212 void DijkstraBox::maplists_updated()
214 if(tabcbt.get_active_text()!="")
218 const Digraph &g=mapstorage->digraph;
219 for (NodeIt i(g); i!=INVALID; ++i)
221 std::ostringstream text;
222 text << mapstorage->getLabel(i);
223 source.prepend_text(text.str());
224 target.prepend_text(text.str());
229 void DijkstraBox::get_from_to(Node & from, Node & to, Digraph & g)
232 for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i)
234 std::ostringstream text;
235 text << mapstorage->getLabel(i);
236 if(!(text.str().compare(source.get_active_text())))
241 if(!(text.str().compare(target.get_active_text())))