### complete graph data structure

Hello

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?

Thank you!
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
not sure how it is a complete graph?!
If there is all against all, then there is no need to specify that.
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?

Thanks!

 ``1234567891011121314151617181920212223242526`` ``````struct Node { int nodeNumber; int nodeX; int nodeY; char nodeName [30]; }; int main () { struct Node node; ifstream inFile; ofstream outFile; inFile.open("data.txt"); cout << "Processing data" << endl; while (inFile.good()) inFile >> node.nodeNumber >> node.nodeX >> node.nodeY >> node.nodeName; inFile.close(); return 0; }``````
¿don't you realize that you have just one node? ¿how do you expect that to work?

 ``1234567891011`` ``````struct Node{ int x,y; //no need for prefix std::string name; }; int main(){ std::vector 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 )
Last edited on
Thanks!
here is updated version, I am getting a few errors.

 ``1234567891011121314151617181920212223242526`` ``````struct Node { int X; int Y; string nodeName; }; int main () { struct Node node; vector graph; ifstream inFile; inFile.open("data.txt"); cout << "Processing data" << endl; while (inFile.good()) graph.push_back (node); for (int n=0; n < graph.size(); n++) //error here { cout << graph [n]<< " " << endl; //error here } inFile.close(); return 0 }``````
;
Last edited on
Hi

Can someone give me some hints with building a complete graph from a file?

Thank you!!!
Topic archived. No new replies allowed.