C++ read file into adjacency matrix


Hi guys,
I want to apply the shortest path method (Dijkstra algortihm) to the following file:

PROCESS1,-3.88,Start,A
PROCESS2,-5.2,Start,B
PROCESS3,-7.97,Start,C
PROCESS4,-0.43,A,D
PROCESS5,-2.2,B,D
PROCESS6,-1.2,C,G
PROCESS7,-3.18,D,G
PROCESS8,-0.42,E,D
PROCESS9,-0.69,H,G
PROCESS10,-0.94,H,J
PROCESS11,-1.64,H,I
PROCESS12,-1.49,J,I
PROCESS13,-2.4,I,F
PROCESS14,-0.58,E,F
PROCESS15,-1.22,End,I
PROCESS16,-1.24,End,F

There are 16 processes, which all consume a certain amount of paint. The goal of the project is to go from 'Start' to 'End', while maximizing the remaining amount of paint. Process 1 (to go from start to A )consumes 3,88 units of paint. As this is an undirected graph, A-D consumes the same amount of paint as D-A.

But before I can apply the dijkstra algorithm, I need to read the following file into an adjacency matrix. The matrix has to be 12x12 (Start, A, B, C, D, ... =12). The first row of the matrix (index 0) has to represent 'start', the second row (index 1) has to represent A, and so on.

For example: As start is connected to A , Matrix[0][1]=-3,88 and Matrix[1][0]=-3,88 (because it is an undirected graph)
As A is connected to D, Matrix[1][5]=-0,43 and Matrix[5][1]=-0,43

Can someone help me to read this file into the adjacency matrix?

What does your code look like so far? If you post a genuine attempt at solving the problem on you're own, you're much more likely to get help.

-Albatross
1
2
std::string field;
std::getline(std::cin, field, ',');
that will read until a comma is found (the comma is then discarded)
Topic archived. No new replies allowed.