]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/minimum_degree_ordering.cpp
c096ccf6d1e810f8026c6377712ce7a2c92722bf
2 //=======================================================================
3 // Copyright 1997-2001 University of Notre Dame.
4 // Authors: Lie-Quan Lee
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //=======================================================================
12 This file is to demo how to use minimum_degree_ordering algorithm.
14 Important Note: This implementation requires the BGL graph to be
15 directed. Therefore, nonzero entry (i, j) in a symmetrical matrix
16 A coresponds to two directed edges (i->j and j->i).
18 The bcsstk01.rsa is an example graph in Harwell-Boeing format,
19 and bcsstk01 is the ordering produced by Liu's MMD implementation.
20 Link this file with iohb.c to get the harwell-boeing I/O functions.
21 To run this example, type:
23 ./minimum_degree_ordering bcsstk01.rsa bcsstk01
27 #include <boost/config.hpp>
30 #include "boost/graph/adjacency_list.hpp"
31 #include "boost/graph/graph_utility.hpp"
32 #include "boost/graph/minimum_degree_ordering.hpp"
34 void terminate(const char* msg
)
36 std::cerr
<< msg
<< std::endl
;
40 // copy and modify from mtl harwell boeing stream
43 harwell_boeing(char* filename
)
50 // readHB_info(filename, &M, &N, &nonzeros, &Type, &Nrhs);
51 colptr
= (int*)malloc((N
+ 1) * sizeof(int));
53 terminate("Insufficient memory for colptr.\n");
54 rowind
= (int*)malloc(nonzeros
* sizeof(int));
56 terminate("Insufficient memory for rowind.\n");
61 val
= (double*)malloc(nonzeros
* sizeof(double) * 2);
63 terminate("Insufficient memory for val.\n");
69 val
= (double*)malloc(nonzeros
* sizeof(double));
71 terminate("Insufficient memory for val.\n");
75 // readHB_mat_double(filename, colptr, rowind, val);
89 inline int nrows() const { return M
; }
102 int main(int argc
, char* argv
[])
105 using namespace boost
;
109 cout
<< argv
[0] << " HB file" << endl
;
116 delta
= atoi(argv
[3]);
118 harwell_boeing
hbs(argv
[1]);
120 // must be BGL directed graph now
121 typedef adjacency_list
< vecS
, vecS
, directedS
> Graph
;
125 cout
<< "n is " << n
<< endl
;
131 for (int i
= 0; i
< n
; ++i
)
132 for (int j
= hbs
.colptr
[i
]; j
< hbs
.colptr
[i
+ 1]; ++j
)
133 if ((hbs
.rowind
[j
- 1] - 1) > i
)
135 add_edge(hbs
.rowind
[j
- 1] - 1, i
, G
);
136 add_edge(i
, hbs
.rowind
[j
- 1] - 1, G
);
140 cout
<< "number of off-diagnal elements: " << num_edge
<< endl
;
142 typedef std::vector
< int > Vector
;
144 Vector
inverse_perm(n
, 0);
147 Vector
supernode_sizes(n
, 1); // init has to be 1
149 boost::property_map
< Graph
, vertex_index_t
>::type id
150 = get(vertex_index
, G
);
154 minimum_degree_ordering(G
,
155 make_iterator_property_map(°ree
[0], id
, degree
[0]), &inverse_perm
[0],
157 make_iterator_property_map(&supernode_sizes
[0], id
, supernode_sizes
[0]),
162 ifstream
input(argv
[2]);
165 cout
<< argv
[3] << " is failed to open!. " << endl
;
169 bool is_correct
= true;
171 for (i
= 0; i
< n
; i
++)
174 if (comp
!= inverse_perm
[i
] + 1)
176 cout
<< "at i= " << i
<< ": " << comp
177 << " ***is NOT EQUAL to*** " << inverse_perm
[i
] + 1
182 for (i
= 0; i
< n
; i
++)
185 if (comp
!= perm
[i
] + 1)
187 cout
<< "at i= " << i
<< ": " << comp
188 << " ***is NOT EQUAL to*** " << perm
[i
] + 1 << endl
;
193 cout
<< "Permutation and inverse permutation are correct. " << endl
;
195 cout
<< "WARNING -- Permutation or inverse permutation is not the "
196 << "same ones generated by Liu's " << endl
;