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.