I am trying to implement a flow algorithm with thousands of nodes and edges, therefore I need efficient data structures. Currently I do the following:
Structure Node:
Double Linked Array (Parents) //Edges that enter the node (basicaly a tuple that contains a pointer to the parent node and the weight, current flow of the edge
Double Linked Array (Sons) //Edges that leave the node
The problem is, when I perform a BFS, given a node v I need to look at the edges in the residual graph (basically backwards edges for the edges you send flow on), that leave v. Because I can have parallel edges I need to always know which backwards edge comes from which forward edge.
Currently I am solving the problem by first handling all edges in Sons(v), and then I defined a map that gives me the index of the Parents(w) in the destination node w of all those edges. Therefore I get the backwards edge I stored and can perform my algorithm. However those maps have log(E) access time which slows my algorithm down way too much. How should I approach this problem (the double linked lists are implemented as std::vector)?
The representation I use is something like an edge list but with additional information
I have used global arrays to be able to explain the idea better. I use this for my dinitz algorithm.
Now a bit of explanation. In the array "e" I hold all the edges. In the array first[v] I hold the index of the first edge going out of v in the array e. If an edge is present in index idx in the array e then the reverse edge is stored in the element with index idx^1.
So this representation enables us to both have a neighbours list(strarting from first[v] and following the next index until it becomes -1) and be able to access the reverse edge in constant time.