Weighted Graph?

Hi,
How do I create a C++ weighted Graph where each vertex in the graph has a weight (some integer value)?

You can download my graph project here:

http://rapidshare.com/files/317273914/Graphs.rar.html

Here is the function to create a graph from graph data stored in a text file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
void GraphType::createGraph()
{
        ifstream infile;
        char fileName[50];

        int index;
        int vertex;
        int adjacentVertex;

        if(gSize != 0)
            clearGraph();

        cout << "Enter input file name: ";
        cin >> fileName;
        cout << endl;

        infile.open(fileName);

        if(!infile)
        {
                cout << "Cannot open input file." << endl;
                return;
        }

        infile >> gSize;

        graph = new UnorderedLinkList[gSize];

        for(index = 0; index < gSize; index++)
        {
                infile >> vertex;
                infile >> adjacentVertex;

                while(adjacentVertex != -999)
                {
                    graph[ vertex ].insertLast(adjacentVertex);
                    infile >> adjacentVertex;
                }
        }
        infile.close();
}


And here is the Graph data (number of vertices = 10, vertex 0 to 9 and adjacent vertices) input from text file "Network2.txt":

10

0 1 2 9 -999

1 0 2 -999

2 0 1 9 8 3 -999

3 2 8 5 -999

4 3 8 6 5 -999

5 4 6 7 -999

6 4 7 8 -999

7 8 6 5 -999

8 9 2 3 4 6 7 -999

9 0 2 8 -999

My question is, how do i assign a unique value or weight to vertices 0 to 9? Any assistance will be really appreciated. Thanks in advance!
That will depend on how you want to provide the weight value. Do you want to calculate it based on some formula (like, for example, the number of adjacent vertices)? Do you want to specify it manually, as in prompting the user to enter the value? Read it in from some other source?

The answer to your question, basically, depends on how you wish to implement it.
Thanks jRaskell for replying. I would like to implement the weight for each node by simply assigning a random value to them.
Topic archived. No new replies allowed.