Generating N Graph edges

Hello All,

I'm trying to solve a problem which seems very complex but im having a feeling that it has a simple solution. I'm reading graph edges from a text file along with their weights and storing it in a 2d array;
1
2
3
4
5
6
7
FILE *fin = fopen("somefile.txt", "r");

    for (int i = 0; i <=edges; i++) {
    fscanf(fin, "%d%d%d", &u, &v, &w);
            graph[u][v]=w;
    }
    fclose(fin);


The test file contains edges in the following format;
1
2
3
4
5
1 2 10
1 3 10
1 4 10
3 5 10
4 3 10


Now I would like to generate N possible graph edges. I dont care whether its a valid combination or not at the moment. So if N=2, possible combination is;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1 2 10
1 3 10

1 2 10
1 4 10

1 2 10
3 5 10

1 2 10
4 3 10

1 3 10
1 2 10 

....

If N=3..you can all guess what that means. We can clearly see that we have some duplicates but I will check for duplicates later. My question, how can I accomplish this as i thought lot about it but nothing makes sense. :(
i totally have no clue wath you mean with N possible graph edges :s could you explain that ?
Welll...i gave the example of having N=2 graph edges. If N=3, then the combinations would be (depending upon the 2d array),
1
2
3
4
5
6
7
8
9

1 2 10
1 3 10
1 4 10

1 2 10
1 3 10
3 5 10


If N=4, one of the possible combination is;

1
2
3
4
1 2 10
1 4 10
3 5 10
4 3 10


Any more confusion? :)
There are two main ways of storing a graph
1. a list of edges
2. an adjacency matrix

for your problem a list of edges storage form would be easiest to use

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct edge
{
  int oneend;
  int otherend;
  int weight;
  edge(int setoneend,int setotherend,int setweigth)
    : oneend(setoneend), otherened(setotherened), weight(setweight) { }
};

edge graph[numedges];

for (int i = 0; i <=numedges; i++) {
    fscanf(fin, "%d%d%d", &u, &v, &w);
            graph[i]=edge(u,v,w);
    }
    fclose(fin)


from here you can extract subsets of edges easily
Thanks for your reply! although, im still having problem that how can i create subsets with this approach. Can you help me out a 'bit' further,please?
Topic archived. No new replies allowed.