COIN-OR::LEMON - Graph Library

source: glemon-0.x/mapstorage.cc @ 46:121452cc4096

gui
Last change on this file since 46:121452cc4096 was 46:121452cc4096, checked in by Hegyi Péter, 15 years ago

No maps with the same name can be added.

File size: 1.7 KB
Line 
1#include <mapstorage.h>
2
3MapStorage::MapStorage(Graph & graph):g(graph)
4{
5};
6
7int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
8{
9  if( nodemap_storage.find(name) == nodemap_storage.end() )
10    {
11      nodemap_storage[name]=nodemap;
12      return 0;
13    }
14  return 1;
15}
16
17int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
18{
19  if( edgemap_storage.find(name) == edgemap_storage.end() )
20    {
21      edgemap_storage[name]=edgemap;
22      return 0;
23    }
24  return 1;
25}
26
27double MapStorage::maxOfNodeMap(const std::string & name)
28{
29  double max=0;
30  for (NodeIt j(g); j!=INVALID; ++j)
31  {
32    if( (*nodemap_storage[name])[j]>max )
33    {
34      max=(*nodemap_storage[name])[j];
35    }
36  }
37  return max;
38}
39
40double MapStorage::maxOfEdgeMap(const std::string & name)
41{
42  double max=0;
43  for (EdgeIt j(g); j!=INVALID; ++j)
44  {
45    if( (*edgemap_storage[name])[j]>max )
46    {
47      max=(*edgemap_storage[name])[j];
48    }
49  }
50  return max;
51}
52
53double MapStorage::minOfNodeMap(const std::string & name)
54{
55  NodeIt j(g);
56  double min=(*nodemap_storage[name])[j];
57  for (; j!=INVALID; ++j)
58  {
59    if( (*nodemap_storage[name])[j]<min )
60    {
61      min=(*nodemap_storage[name])[j];
62    }
63  }
64  return min;
65}
66
67double MapStorage::minOfEdgeMap(const std::string & name)
68{
69  EdgeIt j(g);
70  double min=(*edgemap_storage[name])[j];
71  for (EdgeIt j(g); j!=INVALID; ++j)
72  {
73    if( (*edgemap_storage[name])[j]<min )
74    {
75      min=(*edgemap_storage[name])[j];
76    }
77  }
78  return min;
79}
80
81void MapStorage::initMapsForEdge(Graph::Edge e)
82{
83  std::map< std::string,Graph::EdgeMap<double> * >::iterator ems_it;
84  for(ems_it=edgemap_storage.begin();ems_it!=edgemap_storage.end();ems_it++)
85    {
86      (*((*ems_it).second))[e]=5;
87    }
88}
Note: See TracBrowser for help on using the repository browser.