views:

71

answers:

3

Hello, I have oriented graph. Graph can be strongly connected. Every vertex can have a set of anything, for example letters. The set is user editable.

Every vertex makes intersection of sets in previous vertices (only one step back).

But now, there is problem: When I update set of one vertex, the change should expand to all vertices and uptate their intersection of sets of previous vertices.

How to do every vertex have correct intersection after update of any vertex? Restriction: algorithm must avoid to stick in infinity. ...

Any idea how to solve it?. EDIT:

Example - red vertix changes, and it is needed to spread change of intersecions of all vertices: alt text

+2  A: 

Looks like a BFS would do it:

  1. Memorize the set of the vertex which has changed.
  2. Now start a breadth first search from the changed vertex
  3. For each adjacent vertex change the corresponding set according to the set from (1)
  4. Mark vertex as visited
  5. Repeat 1-4 for each adjacent vertex until no more unvisited vertices exist

Maybe your real problem lies in the intersection of sets. That you would be point (3) here. You should add an example to make the problem clearer.

MicSim
I try to make example in couple of minutes.But problem is that some vertices must be visited more than once to solve it correctly.
joseph
But, I just think that some vertices must be visited more than once, it does not need to be true
joseph
+1 -- this looks like the way to go. Incidentally, to create a breadth-first search, it's often easiest to have a queue holding things that need to be worked on, and when you finish one item, add its unmarked children to the queue. If you can't easily mark the nodes themselves, you can have a hash set of "nodes visited" that you update each time you finish working on a node. The only reason this might not work is if you require several passes for this to work--but this should not be the case for "intersection".
Rex Kerr
+1  A: 

You could split the changes into subtractive and additive changes. Anything subtractive can be removed in one pass using the method MicSim described. Anything additive, however, might propagate all the way through any cycles that you have.

For additive changes, do the updates the same way but ignore any inputs that haven't been updated yet. This will cause you to overpopulate the graph, as you're not computing all the intersections. But then if you go back for a second pass, you'll clean up all the changes. (You might need to keep sweeping through until there are no more changes; I'm not entirely sure.)

I suppose if you don't care to keep track of what was added and what was subtracted--only that there was a change--you just do an initial sweep where update-needing but un-updated nodes don't get intersected, and then keep sweeping through until everything settles down. Since intersection can only remove elements, this is guaranteed to complete.

Rex Kerr
A: 

Do BFS as suggested by MicSim, stop after an iteration that hasn't changed any vertices.

MK
And is quaranted that tha algorithm does not stick to infinity? What if every iteration changes some vertex?
joseph
If every iteration changes some vertex it means that your strings in vertices are either growing out of bounds to infinity or achieved some kind of fluctuating equilibrium. They can't grow to infinity because you have sets and they can't grow without new unique elements being added to them.Now let's consider the fluctuation case. Fluctuation is possible if an item is first added to the vertex and then after some number of steps is removed from the vertex. But a change to a single vertex can't both remove and add the same item. So fluctuation is not possible.It's not a 100% proof, but...
MK
If you use the method I outlined (i.e. initial overpopulation followed by refinement), each additional pass can only _remove_ elements from the sets, and as the sets are finite, this must complete in a finite number of passes.
Rex Kerr