32 for (
int i = 0; i<active.
n(); ++i)
33 if (active[i]) nzmax++;
35 int* pr_list =
new int[active.
n()];
36 memset(pr_list,-1,active.
n()*
sizeof(int));
39 for (
int i = 0; i<active.
n(); ++i) {
47 const int* pB = G.
pB();
51 while (!list.
empty()) {
52 int node=list.
front();
54 for (
int j = pB[node]; j<pB[node+1]; ++j) {
57 if (pr_list[node] != pr_list[child]) {
59 const int pr = pr_list[child];
61 pr_list[*it]=pr_list[node];
63 cc[pr_list[node]]->
fusion(*(cc[pr]));
72 for (
int i = 0; i<nzmax; ++i)
if (cc[i]) num_cc++;
73 for (
int i = 0; i<nzmax; ++i)
delete(cc[i]);
83 int* color =
new int[n];
84 memset(color,0,n*
sizeof(
int));
92 bool cycle_detected=
true;
94 while (cycle_detected) {
97 for (
int i = 0; i<n; ++i)
if (color[i] != 2) {
101 current_path.
clear();
102 while (!list.
empty()) {
103 const int node=list.
front();
104 if (color[node] == 0) {
107 for (
int i = pB[node]; i<pB[node+1]; ++i) {
109 const int child = r[i];
110 if (color[child]==1) {
113 current_path.
reverse(reverse_path);
115 const int current_node=reverse_path.
front();
116 if (current_node == child)
break;
127 const int current_node=*it;
129 if (it == reverse_path.
end())
break;
130 for (
int j = pB[current_node]; j<pB[current_node+1]; ++j) {
132 if (min_link > v[j]) {
143 cerr <<
" \r" << cycles_removed;
145 }
else if (color[child]==0) {
150 }
else if (color[node] == 1) {
155 }
else if (color[node] == 2) {
160 int current_remove=0;
161 for (
int i = 0; i<n; ++i) {
162 int old_remove=current_remove;
163 for (
int j = pB[i]; j < pB[i+1]; ++j) {
165 r[j-current_remove]=r[j];
166 v[j-current_remove]=v[j];
173 pB[n]-=current_remove;
178 template <
typename T>
181 T* num_paths =
new T[n];
182 memset(num_paths,0,n*
sizeof(T));
183 const int* pB = G.
pB();
184 const int* r = G.
r();
185 int* color =
new int[n];
186 memset(color,0,n*
sizeof(
int));
188 for (
int i = 0; i<n; ++i)
191 while (!list.
empty()) {
192 const int node=list.
front();
193 if (color[node]==0) {
194 for (
int i = pB[node]; i<pB[node+1]; ++i) {
198 }
else if (color[node]==1) {
199 num_paths[node]=T(1.0);
200 for (
int i = pB[node]; i<pB[node+1]; ++i) {
201 num_paths[node]+=num_paths[r[i]];
204 }
else if (color[node]==2) {
209 T sum=cblas_asum<T>(n,num_paths,1);
T count_paths_dags(const SpMatrix< T > &G)
int pB(const int i) const
returns pB[i]
void reverse(List< T > &list)
ListIterator< T > & begin() const
int n() const
returns the size of the vector
int count_cc_graph(const SpMatrix< T > &G, Vector< T > &active)
T v(const int i) const
returns v[i]
void copy(const SpMatrix< T > &mat)
int r(const int i) const
returns r[i]
int n() const
returns the number of rows
void fusion(const List< T > &list)
void remove_cycles(const SpMatrix< T > &G1, SpMatrix< T > &G2)