I need help with building a complete graph from a file.
The format in the file is as follows.
[ vertex 1] [ x_coordinate 1] [ y_coordinate 1] [cityname 1]
[ vertex 2] [ x_coordinate 2] [ y_coordinate 2] [cityname 2]
. . .
[ vertex n] [ x_coordinate n] [ y_coordinate n] [cityname n]
What kind of data structure shall I use in order to store date in a complete graph so there is an edge between every pair?
class never fails, struct are simplest or you can just store the points in 2d arrays and store them all in a container such as a vector or another array
is there any special set up to load data into the graph?
I am not really sure how to proceed...below is the code I have so far...
and then... I need to find weight of each edge by the Euclidean distance
metric. Do I need to generate subsets of 2 nodes in order to calculate the edge weight?
¿don't you realize that you have just one node? ¿how do you expect that to work?
1 2 3 4 5 6 7 8 9 10 11
struct Node{
int x,y; //no need for prefix
std::string name;
};
int main(){
std::vector<Node> graph;
Node node;
while(input>>node)
graph.push_back(node);
}
For the weights you could compute as needed, or store them all in a matrix (symmetric, with W_{(KK)} = 0 )