im looking at creating an adjacency matrix built with rows r1, and columns c1, with a float value.

i have managed to read the the values from a text file, set out like:
r1,c1,float1
r2,c2,float2
etc...

i am having trouble converting these values into an adjacency matrix.

thanks

Recommended Answers

All 5 Replies

Do you have a matrix class? If not, I'd recommend vnl_matrix from VNL (part of VXL). You can then just do:

yourMatrix(r1,c1) = float1

Dave

Do you have a matrix class? If not, I'd recommend vnl_matrix from VNL (part of VXL). You can then just do:

yourMatrix(r1,c1) = float1

Dave

we haven't studied that yet, so id say no.

If your file structure is consistent to the sample you provided, you could also try:
(In pseudo-code)

{ // Inside your file-reading loop
  Matrix[num][num] = floatnum; // where num = line number
}

Or you could use a class to represent your matrix, as daviddoria suggested, which would be easier to manage, on the whole :)

You don't necessarily need a matrix class. All you need is arrays. Better yet, you
should use std::vector < std::vector<float> >, as a 2d array.
Adjacency matrix are fairly easy to implement with the cost of O(row^2) of space.
What exactly are you having trouble with, in respect to Adjacency matrix.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.