COIN-OR::LEMON - Graph Library

Changeset 201:879e47e5b731 in glemon-0.x for dijkstrabox.cc


Ignore:
Timestamp:
01/02/08 22:03:09 (16 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
Message:

Merge branches/akos to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dijkstrabox.cc

    r194 r201  
    5151   
    5252void 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
     115void SuurballeBox::run()
    53116{
    54117  if(
     
    69132      if(!(from==to))
    70133        {
    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());
    75138
    76139          //zero out output map
    77140          for (EdgeIt i(g); i!=INVALID; ++i)
    78141            {
    79               (*outputmap)[i]=0;
     142              outputmap[i]=0;
    80143            }
    81144         
    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);
    145146         
    146147          int found=sb.run(num_set->get_value_as_int());
     
    153154                  for(int k=0;k<path.length();k++)
    154155                    {
    155                       (*outputmap)[path.nth(k)]=j+1;
     156                      outputmap[path.nth(k)]=j+1;
    156157                    }
    157158                }
     
    181182  signal_upon_maplist_updated().connect(sigc::mem_fun(*this, &DijkstraBox::maplists_updated));
    182183
    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);
    185186
    186187  Gtk::Label * source_label=new Gtk::Label("Source: ");
     
    213214        {
    214215          std::ostringstream text;
    215           text << (*((mapstorage->nodemap_storage)["label"]))[i];
     216          text << mapstorage->getLabel(i);
    216217          source.prepend_text(text.str());
    217218          target.prepend_text(text.str());
     
    226227    {
    227228      std::ostringstream text;
    228       text << (*((mapstorage->nodemap_storage)["label"]))[i];
     229      text << mapstorage->getLabel(i);
    229230      if(!(text.str().compare(source.get_active_text())))
    230231        {
Note: See TracChangeset for help on using the changeset viewer.