Problems with Reverse Cuthill-Mckee?
Hello,
I'm a fairly new Boost user, so please forgive me if I'm completely out
of whack here.
I'm presently using Boost's reverse Cuthill-Mckee ordering to reduce the
bandwidth of some very large symmetric, positive definite sparse
matrices that I'm investigating.
Generally, the cuthill_mckee_ordering() has worked quite well, although
a short while ago, I began noticing that it occasionally gave an invalid
ordering (i.e., the permutations spit out by the algorithm would have
multiple vertexes all the same, which, when used to permute my matrices,
would destroy my problem).
It took me a while to figure out what was going on, but I've finally
distilled a small enough example that exhibits the problem. Consider
the following matrix:
Matrix:
6x6
[
[3.66667,0,-0.5,0,0,0],
[0,2.66667,0,-0.222222,0,0],
[-0.5,0,1.66667,0,0,-0.222222],
[0,-0.222222,0,3.33333,-2.22222,0],
[0,0,0,-2.22222,4.66667,0],
[0,0,-0.222222,0,0,4.66667]
]
Using fairly straightforward code, I loop through the non-zeros, and add
edges to an undirected Boost graph (basically the same as the
cuthill_mckee_ordering.cpp example in the docs). Here is the graph that
gets created for the above problem, in Graphviz format:
graph G {
0;
1;
2;
3;
4;
5;
0--0 ;
0--2 ;
1--1 ;
1--3 ;
2--2 ;
2--5 ;
3--3 ;
3--4 ;
4--4 ;
5--5 ;
}
And, if I run this example using the cuthill_mckee_ordering technique
(or if I modify cuthill_mckee_ordering.cpp to use these vertices and
edges), I get the following permutation (using the pseudo-peripheral
heuristic):
Inv_perm:
0 0 0 0 2 5
You can see, from the Graphviz output, that this graph has two
disconnected sets of vertices, which is where I think the problem lies.
It may be a problem in my understanding of how to setup the Boost graph,
or perhaps a problem in the reordering technique. You'll notice that,
in my example, I've eliminated the duplicate edges (such as 2-5 being
the same as 5-2) -- I've tried adding them in, too, but it hasn't
changed the result.
I've noticed that, if one of my matrices produces a graph in which there
are no disconnected sets of vertices, the RCM ordering works fine. It's
only when the graph is disconnected in this fashion that the ordering
fails. I've also noticed that, when using this kind of disconnected
graph, if I sometimes select a random starting vertex (instead of the
pseudo-peripheral pair heuristic), the cuthill_mckee_ordering segfaults.
I've attached some sample code below that seems to exhibit the problem.
I'm certainly open to the possibility that it's a problem in my
understanding of how to use the library.
Also, my Boost version is: 1.30.2 (Redhat RPM)
Any thoughts would be appreciated.
regards,
Kris
==============================================================
(borrowed and slightly modified from cuthill_mckee_ordering.cpp)
#include
Hello, After more digging into this matter, I'm fairly sure that the problem lies in the fact that disjoint sets of nodes aren't looped over in cuthill_mckee_ordering.hpp. Consequently, the out-edges of the nodes are examined, but if the out-edges never connect to another set of nodes, then only a portion of each disjointed graph is ever considered for reordering. This can be somewhat disastrous, because the ordering results will vary immensely depending on which starting vertex was used (and, by extension, which disjoint set was reordered). This seems equivalent to only scanning through one of the sets of level sets in the RCM algorithm. After a very quick glance at the minimal_degree_ordering.hpp and sloan_ordering.hpp code, I suspect that they also won't work quite right with disjoint graphs. I don't know if this is intended behaviour or not, as the documentation didn't really seem to hint toward how these kinds of graphs should be handled. In the meantime, I started to hack together a solution for my problem, but have found it to be rather "unpretty". (Basically, I use the Boost connected_components function to find disconnected components, then I loop through each disconnected component, find a good pseudo-peripheral starting vertex, and do the reordering just for the vertices in that component. I'm not even really sure that this is the best way to fix the RCM code.) Anyway, given my lack of experience with Boost, my hack is very ugly, but I thought I'd let ppl know where I think the problem lies, just in case they were having similar issues. regards, Kris On Sun, 2004-01-11 at 11:28, Kris Vorwerk wrote:
Generally, the cuthill_mckee_ordering() has worked quite well, although a short while ago, I began noticing that it occasionally gave an invalid ordering (i.e., the permutations spit out by the algorithm would have multiple vertexes all the same, which, when used to permute my matrices, would destroy my problem). [snip]
Hi Kris, I wish I had time to look at your problem and solution... alas I'm swamped with work on iterator adaptor stuff for the C++ standard TR. -Jeremy ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 856-1820 ----------------------------------------------------------------------
I wish I had time to look at your problem and solution... alas I'm swamped with work on iterator adaptor stuff for the C++ standard TR.
No prob -- I totally understand :) (In fact, I'm swamped with trying to
get my grad school stuff working, which is why I've resorted to
hacking together code to make Boost work for me :)
The following is rough and not very elegant, but it seems to work, I
believe. (Well, it sort of works. I will explain what I mean after the
code, below.)
// BEGIN CODE SNIPPET -------------------------------------------
// This is just the code that I changed... (The detail code
// remains the same.)
namespace boost {
// Reverse Cuthill-McKee algorithm with a given starting Vertex.
//
// This algorithm requires user to provide a starting vertex to
// compute RCM ordering.
template
participants (2)
-
Jeremy Siek
-
Kris Vorwerk