Changeset 201:879e47e5b731 in glemon-0.x for dijkstrabox.cc
- Timestamp:
- 01/02/08 22:03:09 (16 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dijkstrabox.cc
r194 r201 51 51 52 52 void DijkstraBox::run() 53 { 54 if( 55 tabcbt.get_active_text()!="" && 56 (edgemapcbts[INPUT])->get_active_text()!="" && 57 (edgemapcbts[OUTPUT])->get_active_text()!="" && 58 source.get_active_text()!="" && 59 target.get_active_text()!="" 60 ) 61 { 62 const Graph &g=mapstorage->graph; 63 Node from, to; 64 65 get_from_to(from, to, (Graph&)g); 66 67 std::ostringstream o; 68 69 if(!(from==to)) 70 { 71 std::string inputmapName = edgemapcbts[INPUT]->get_active_text(); 72 std::string outputmapName = edgemapcbts[OUTPUT]->get_active_text(); 73 74 MapStorage::NumericEdgeMap& inputmap = mapstorage->getNumericEdgeMap(inputmapName); 75 MapStorage::NumericEdgeMap& outputmap = mapstorage->getNumericEdgeMap(outputmapName); 76 77 //zero out output map 78 for (EdgeIt i(g); i!=INVALID; ++i) 79 { 80 outputmap[i]=0; 81 } 82 83 Dijkstra<Graph, MapStorage::NumericEdgeMap > dijkstra(g, inputmap); 84 dijkstra.run(from, to); 85 86 if(dijkstra.reached(to)) 87 { 88 Node n=to; 89 int length=0; 90 while (n!=INVALID && n!=from) 91 { 92 Edge e=dijkstra.predEdge(n); 93 outputmap[e]=1; 94 n=dijkstra.predNode(n); 95 length++; 96 } 97 o << "Result: " << length << " long path, with cost " << dijkstra.dist(to); 98 } 99 else 100 { 101 o << "Result: failed to find shortest path between "; 102 o << source.get_active_text() << " and " << target.get_active_text(); 103 } 104 resultlabel.set_text(o.str()); 105 106 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); 107 // mapstorage->changeActiveMap(true, E_COLOR, 108 // (edgemapcbts[OUTPUT])->get_active_text()); 109 // mapstorage->changeActiveMap(true, E_TEXT, 110 // (edgemapcbts[INPUT])->get_active_text()); 111 } 112 } 113 } 114 115 void SuurballeBox::run() 53 116 { 54 117 if( … … 69 132 if(!(from==to)) 70 133 { 71 Graph::EdgeMap<double> *inputmap=72 (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];73 Graph::EdgeMap<double> *outputmap=74 (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];134 MapStorage::NumericEdgeMap& inputmap= 135 mapstorage->getNumericEdgeMap(edgemapcbts[INPUT]->get_active_text()); 136 MapStorage::NumericEdgeMap& outputmap= 137 mapstorage->getNumericEdgeMap(edgemapcbts[OUTPUT]->get_active_text()); 75 138 76 139 //zero out output map 77 140 for (EdgeIt i(g); i!=INVALID; ++i) 78 141 { 79 (*outputmap)[i]=0;142 outputmap[i]=0; 80 143 } 81 144 82 Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, *inputmap); 83 dijkstra.run(from, to); 84 85 if(dijkstra.reached(to)) 86 { 87 Node n=to; 88 int length=0; 89 while (n!=INVALID && n!=from) 90 { 91 Edge e=dijkstra.predEdge(n); 92 (*outputmap)[e]=1; 93 n=dijkstra.predNode(n); 94 length++; 95 } 96 o << "Result: " << length << " long path, with cost " << dijkstra.dist(to); 97 } 98 else 99 { 100 o << "Result: failed to find shortest path between "; 101 o << source.get_active_text() << " and " << target.get_active_text(); 102 } 103 resultlabel.set_text(o.str()); 104 105 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); 106 // mapstorage->changeActiveMap(true, E_COLOR, 107 // (edgemapcbts[OUTPUT])->get_active_text()); 108 // mapstorage->changeActiveMap(true, E_TEXT, 109 // (edgemapcbts[INPUT])->get_active_text()); 110 } 111 } 112 } 113 114 void SuurballeBox::run() 115 { 116 if( 117 tabcbt.get_active_text()!="" && 118 (edgemapcbts[INPUT])->get_active_text()!="" && 119 (edgemapcbts[OUTPUT])->get_active_text()!="" && 120 source.get_active_text()!="" && 121 target.get_active_text()!="" 122 ) 123 { 124 const Graph &g=mapstorage->graph; 125 Node from, to; 126 127 get_from_to(from, to, (Graph&)g); 128 129 std::ostringstream o; 130 131 if(!(from==to)) 132 { 133 Graph::EdgeMap<double> * inputmap= 134 (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]; 135 Graph::EdgeMap<double> * outputmap= 136 (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]; 137 138 //zero out output map 139 for (EdgeIt i(g); i!=INVALID; ++i) 140 { 141 (*outputmap)[i]=0; 142 } 143 144 Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, *inputmap, from, to); 145 Suurballe<Graph, MapStorage::NumericEdgeMap > sb((Graph&)g, inputmap, from, to); 145 146 146 147 int found=sb.run(num_set->get_value_as_int()); … … 153 154 for(int k=0;k<path.length();k++) 154 155 { 155 (*outputmap)[path.nth(k)]=j+1;156 outputmap[path.nth(k)]=j+1; 156 157 } 157 158 } … … 181 182 signal_upon_maplist_updated().connect(sigc::mem_fun(*this, &DijkstraBox::maplists_updated)); 182 183 183 addMapSelector("Cost map: ", true );184 addMapSelector("Edges of path here: ", true );184 addMapSelector("Cost map: ", true, NUM); 185 addMapSelector("Edges of path here: ", true, NUM); 185 186 186 187 Gtk::Label * source_label=new Gtk::Label("Source: "); … … 213 214 { 214 215 std::ostringstream text; 215 text << (*((mapstorage->nodemap_storage)["label"]))[i];216 text << mapstorage->getLabel(i); 216 217 source.prepend_text(text.str()); 217 218 target.prepend_text(text.str()); … … 226 227 { 227 228 std::ostringstream text; 228 text << (*((mapstorage->nodemap_storage)["label"]))[i];229 text << mapstorage->getLabel(i); 229 230 if(!(text.str().compare(source.get_active_text()))) 230 231 {
Note: See TracChangeset
for help on using the changeset viewer.