0

Good evening,

I need to a little helping seeing something through. Here is the situation:

I have a matrix of elements, for example:

enter image description here

Where each entry can be viewed as a node (the nodes don't have associated IDs, I just labeled them for simplicity in explaining). Then element "6" can be accessed as matrix[1][2], etc.

Now, I convert this into the follow bipartite graph structure:

enter image description here

Now, in adding edge from the left to right side, I have the following nested loop:

for (int i = 1; i <= 8; i++) {
    for (int j = 1; j <= 8; j++) {
        capacityGraph[i][j + 8] = 1; //First layer to second layer
    }
}

Now, my question is:

Is there a way to access the matrix element from the bipartite traversal (doesn't have to be in the same loop)? I think the solution should be simple, I'm just not able to think it through completely. But, for example, if i=6, then I know I'm looking at the 10th node. How do I translate this to matrix[2][2]? And likewise for the jth indexing.

I've looked at few references, and I really think the answer is here:

How to map the indexes of a matrix to a 1-dimensional array (C++)?

but I'm not able to connected the dots completely for whatever reason. Any help is greatly appreciated! Thanks.

1 Answers1

0

Ok, I think I figured it out actually.

I know that the left side consists of all even nodes and the right side consists of all odd nodes. Then I can get the associated node value by either 2(i-1) or 2(j-1) + 1 for the left and right side respectively.

Now, given the node value/position, K, I think I can convert this to the XY coordinates such that the column is K%n for an (nxn matrix). And the row is floor(K/n).

Then the matrix is accessed by Matrix[ K/n ][ K%n ] It seems to work for this example, but I'll update if I figure out anything new.