Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node needs to be deleted after each iteration #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions CircuitFinder.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
//===----------------------------------------------------------------------===//
//
// Written by Xing Mingjie ([email protected]).
//
// An implementation of the Johnson's circuit finding algorithm [1].
//
// [1] Donald B. Johnson, Finding all the elementary circuits of a directed
// graph, SIAM Journal on Computing, 1975.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCUIT_FINDER_H
#define CIRCUIT_FINDER_H

Expand All @@ -32,9 +21,9 @@ class CircuitFinder
bool circuit(int V);
void output();

public:
CircuitFinder(int Array[N][N])
: AK(N), Blocked(N), B(N) {
public:
CircuitFinder(int Array[N][N])
: AK(N), Blocked(N), B(N) {
for (int I = 0; I < N; ++I) {
for (int J = 0; J < N; ++J) {
if (Array[I][J]) {
Expand Down Expand Up @@ -73,9 +62,9 @@ bool CircuitFinder<N>::circuit(int V)
if (W == S) {
output();
F = true;
} else if (W > S && !Blocked[W - 1]) {
F = circuit(W);
}
} else if (!Blocked[W - 1]) {
if(circuit(W))
F = true; }
}

if (F) {
Expand Down Expand Up @@ -115,6 +104,11 @@ void CircuitFinder<N>::run()
B[I - 1].clear();
}
circuit(S);

// remove this vertex from the graph
for (int I = S+1; I <= N; ++I)
AK[I-1].remove(S);

++S;
}
}
Expand Down
44 changes: 8 additions & 36 deletions Example.cpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
//===----------------------------------------------------------------------===//
//
// Written by Xing Mingjie ([email protected]).
//
// A test program for circuit finding algorithm.
//
//===----------------------------------------------------------------------===//


/*
V5 V3
+-<---o---<---o---<--+
| | |
V1 o ^ o V4
| V2| |
+------>------o--->--+
/ \
| |
+->-+

N = 5

/ 2 0 0 0 0 \
| 2 3 4 0 0 |
AK = | 5 0 0 0 0 |
| 3 0 0 0 0 |
\ 1 0 0 0 0 /
*/

#include "CircuitFinder.h"

int main()
{
int A[5][5] = {
2, 0, 0, 0, 0,
2, 3, 4, 0, 0,
5, 0, 0, 0, 0,
3, 0, 0, 0, 0,
1, 0, 0, 0, 0
int A[6][6] = {
2, 5, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
1, 2, 4, 6, 0, 0,
5, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
4, 0, 0, 0, 0, 0,
};

CircuitFinder<5> CF(A);
CircuitFinder<6> CF(A);
CF.run();
return 0;
}
Binary file added a.out
Binary file not shown.