how to fit a graph inside a grid?

大兔子大兔子 提交于 2019-12-24 20:44:54

问题


My question is if we have graph and each node knows its coordinates. how can we place that graph inside a grid such that each edge knows which grid or grids it passes. and we could compare the proximity of grids.

I think the grid structure should like this:

typedef std::pair<int, int> Point;
class Grid
{
int size;

public:
vector<vector<Point>> grid;

Grid(int size) :size(size), grid(size, vector<Point>(size)) 
{
    for (size_t y = 0; y < grid.size(); y++)
    {
        vector<Point> loc;
        for (size_t x = 0; x < grid[y].size(); x++)
        {
            loc.push_back({ x, y });
        }
        grid[y] = loc;
    }
 }
};

And the graph i have:

class Graph
{
  int V; // No. of vertices’

public:
  int getV() { return V; }


   std::vector<int>* parents;
   std::vector<int>* childs;

   std::map<int, Point> nodes_location;

   Graph(){}

   Graph(int V) // Constructor
   {
        parents = new std::vector<int>[V];
        childs = new std::vector<int>[V];
   }; 

   void Insert_Node(int u, int v)
   {
       childs[u].push_back(v);
       parents[v].push_back(u);
   }

}

Assuming the size the grid is known (i.e. 5*5). is there a way to combine these two?

Any help we be greatly appreciated,Thank you.

Regards.

来源:https://stackoverflow.com/questions/53019748/how-to-fit-a-graph-inside-a-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!