dijkstrabox.cc
changeset 201 879e47e5b731
parent 194 6b2b718420eb
     1.1 --- a/dijkstrabox.cc	Wed May 02 20:33:58 2007 +0000
     1.2 +++ b/dijkstrabox.cc	Wed Jan 02 21:03:09 2008 +0000
     1.3 @@ -52,63 +52,64 @@
     1.4  void DijkstraBox::run()
     1.5  {
     1.6    if(
     1.7 -     tabcbt.get_active_text()!="" &&
     1.8 -     (edgemapcbts[INPUT])->get_active_text()!="" &&
     1.9 -     (edgemapcbts[OUTPUT])->get_active_text()!="" &&
    1.10 -     source.get_active_text()!="" &&
    1.11 -     target.get_active_text()!=""
    1.12 -     )
    1.13 +      tabcbt.get_active_text()!="" &&
    1.14 +      (edgemapcbts[INPUT])->get_active_text()!="" &&
    1.15 +      (edgemapcbts[OUTPUT])->get_active_text()!="" &&
    1.16 +      source.get_active_text()!="" &&
    1.17 +      target.get_active_text()!=""
    1.18 +    )
    1.19 +  {
    1.20 +    const Graph &g=mapstorage->graph;
    1.21 +    Node from, to;
    1.22 +
    1.23 +    get_from_to(from, to, (Graph&)g);
    1.24 +
    1.25 +    std::ostringstream o;
    1.26 +
    1.27 +    if(!(from==to))
    1.28      {
    1.29 -      const Graph &g=mapstorage->graph;
    1.30 -      Node from, to;
    1.31 +      std::string inputmapName = edgemapcbts[INPUT]->get_active_text();
    1.32 +      std::string outputmapName = edgemapcbts[OUTPUT]->get_active_text();
    1.33  
    1.34 -      get_from_to(from, to, (Graph&)g);
    1.35 +      MapStorage::NumericEdgeMap& inputmap = mapstorage->getNumericEdgeMap(inputmapName);
    1.36 +      MapStorage::NumericEdgeMap& outputmap = mapstorage->getNumericEdgeMap(outputmapName);
    1.37  
    1.38 -      std::ostringstream o;
    1.39 +      //zero out output map
    1.40 +      for (EdgeIt i(g); i!=INVALID; ++i)
    1.41 +      {
    1.42 +        outputmap[i]=0;
    1.43 +      }
    1.44  
    1.45 -      if(!(from==to))
    1.46 -	{
    1.47 -	  Graph::EdgeMap<double> * inputmap=
    1.48 -	    (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
    1.49 -	  Graph::EdgeMap<double> * outputmap=
    1.50 -	    (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
    1.51 +      Dijkstra<Graph, MapStorage::NumericEdgeMap > dijkstra(g, inputmap);
    1.52 +      dijkstra.run(from, to);
    1.53  
    1.54 -	  //zero out output map
    1.55 -	  for (EdgeIt i(g); i!=INVALID; ++i)
    1.56 -	    {
    1.57 -	      (*outputmap)[i]=0;
    1.58 -	    }
    1.59 -	  
    1.60 -	  Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, *inputmap);
    1.61 -	  dijkstra.run(from, to);
    1.62 -	  
    1.63 -	  if(dijkstra.reached(to))
    1.64 -	    {
    1.65 -	      Node n=to;
    1.66 -	      int length=0;
    1.67 -	      while (n!=INVALID && n!=from)
    1.68 -		{
    1.69 -		  Edge e=dijkstra.predEdge(n);
    1.70 -		  (*outputmap)[e]=1;
    1.71 -		  n=dijkstra.predNode(n);
    1.72 -		  length++;
    1.73 -		}
    1.74 -	      o << "Result: " << length << " long path, with cost " << dijkstra.dist(to);
    1.75 -	    }
    1.76 -	  else
    1.77 -	    {
    1.78 -	      o << "Result: failed to find shortest path between ";
    1.79 -	      o << source.get_active_text() << " and " << target.get_active_text();
    1.80 -	    }
    1.81 -	  resultlabel.set_text(o.str());
    1.82 -	  
    1.83 -	  mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
    1.84 -	  //   mapstorage->changeActiveMap(true, E_COLOR,
    1.85 -	  // 			      (edgemapcbts[OUTPUT])->get_active_text());
    1.86 -	  //   mapstorage->changeActiveMap(true, E_TEXT,
    1.87 -	  // 			      (edgemapcbts[INPUT])->get_active_text());
    1.88 -	}
    1.89 +      if(dijkstra.reached(to))
    1.90 +      {
    1.91 +        Node n=to;
    1.92 +        int length=0;
    1.93 +        while (n!=INVALID && n!=from)
    1.94 +        {
    1.95 +          Edge e=dijkstra.predEdge(n);
    1.96 +          outputmap[e]=1;
    1.97 +          n=dijkstra.predNode(n);
    1.98 +          length++;
    1.99 +        }
   1.100 +        o << "Result: " << length << " long path, with cost " << dijkstra.dist(to);
   1.101 +      }
   1.102 +      else
   1.103 +      {
   1.104 +        o << "Result: failed to find shortest path between ";
   1.105 +        o << source.get_active_text() << " and " << target.get_active_text();
   1.106 +      }
   1.107 +      resultlabel.set_text(o.str());
   1.108 +
   1.109 +      mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
   1.110 +      //   mapstorage->changeActiveMap(true, E_COLOR,
   1.111 +      // 			      (edgemapcbts[OUTPUT])->get_active_text());
   1.112 +      //   mapstorage->changeActiveMap(true, E_TEXT,
   1.113 +      // 			      (edgemapcbts[INPUT])->get_active_text());
   1.114      }
   1.115 +  }
   1.116  }
   1.117  
   1.118  void SuurballeBox::run()
   1.119 @@ -130,18 +131,18 @@
   1.120  
   1.121        if(!(from==to))
   1.122  	{
   1.123 -	  Graph::EdgeMap<double> * inputmap=
   1.124 -	    (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
   1.125 -	  Graph::EdgeMap<double> * outputmap=
   1.126 -	    (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
   1.127 +          MapStorage::NumericEdgeMap& inputmap=
   1.128 +	    mapstorage->getNumericEdgeMap(edgemapcbts[INPUT]->get_active_text());
   1.129 +          MapStorage::NumericEdgeMap& outputmap=
   1.130 +	    mapstorage->getNumericEdgeMap(edgemapcbts[OUTPUT]->get_active_text());
   1.131  
   1.132  	  //zero out output map
   1.133  	  for (EdgeIt i(g); i!=INVALID; ++i)
   1.134  	    {
   1.135 -	      (*outputmap)[i]=0;
   1.136 +	      outputmap[i]=0;
   1.137  	    }
   1.138  	  
   1.139 -	  Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, *inputmap, from, to);
   1.140 +	  Suurballe<Graph, MapStorage::NumericEdgeMap > sb((Graph&)g, inputmap, from, to);
   1.141  	  
   1.142  	  int found=sb.run(num_set->get_value_as_int());
   1.143  	  if(found)
   1.144 @@ -152,7 +153,7 @@
   1.145  		  path=sb.path(j);
   1.146  		  for(int k=0;k<path.length();k++)
   1.147  		    {
   1.148 -		      (*outputmap)[path.nth(k)]=j+1;
   1.149 +		      outputmap[path.nth(k)]=j+1;
   1.150  		    }
   1.151  		}
   1.152  	      o << "Result: found " << found << " paths between ";
   1.153 @@ -180,8 +181,8 @@
   1.154    //this can be done after the maps are loaded into ComboBoxes
   1.155    signal_upon_maplist_updated().connect(sigc::mem_fun(*this, &DijkstraBox::maplists_updated));
   1.156  
   1.157 -  addMapSelector("Cost map: ", true);
   1.158 -  addMapSelector("Edges of path here: ", true);
   1.159 +  addMapSelector("Cost map: ", true, NUM);
   1.160 +  addMapSelector("Edges of path here: ", true, NUM);
   1.161  
   1.162    Gtk::Label * source_label=new Gtk::Label("Source: ");
   1.163    Gtk::Label * target_label=new Gtk::Label("Target: ");
   1.164 @@ -212,7 +213,7 @@
   1.165        for (NodeIt i(g); i!=INVALID; ++i)
   1.166  	{
   1.167  	  std::ostringstream text;
   1.168 -	  text << (*((mapstorage->nodemap_storage)["label"]))[i];
   1.169 +	  text << mapstorage->getLabel(i);
   1.170  	  source.prepend_text(text.str());
   1.171  	  target.prepend_text(text.str());
   1.172  	}
   1.173 @@ -225,7 +226,7 @@
   1.174    for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i)
   1.175      {
   1.176        std::ostringstream text;
   1.177 -      text << (*((mapstorage->nodemap_storage)["label"]))[i];
   1.178 +      text << mapstorage->getLabel(i);
   1.179        if(!(text.str().compare(source.get_active_text())))
   1.180  	{
   1.181  	  from=i;