了解 Donald B. Johnson 算法中的伪代码

发布于 2024-09-03 07:16:07 字数 868 浏览 6 评论 0原文

有谁知道 Donald B. Johnson 算法,它枚举了所有基本电路(循环) )在有向图中?

我有他 1975 年发表的论文,但我看不懂伪代码。

我的目标是用 Java 实现这个算法。

例如,我有一些问题,它所指的矩阵 Ak 是什么。在伪代码中,它提到

Ak:=adjacency structure of strong component K with least 
    vertex in subgraph of G induced by {s,s+1,....n};

这是否意味着我必须实现另一个算法来查找 Ak 矩阵?

还有一个问题就是下面这句话是什么意思?

begin logical f; 

“逻辑过程 CIRCUIT (整数值 v);”行是否也意味着电路过程返回一个逻辑变量?在伪代码中还有一行“CIRCUIT := f;”。这意味着什么?

如果有人可以将这个 1970 年代的伪代码翻译成更现代类型的伪代码,这样我就可以理解它,那就太好了。

如果您有兴趣提供帮助,但找不到这篇论文,请给我发电子邮件 [电子邮件受保护],我会将论文发送给您。

Does anyone know the Donald B. Johnson's algorithm, which enumerates all the elementary circuits (cycles) in a directed graph?

I have the paper he had published in 1975, but I cannot understand the pseudocode.

My goal is to implement this algorithm in Java.

Some questions I have, for example, is what is the matrix Ak it refers to. In the pseudocode, it mentions that

Ak:=adjacency structure of strong component K with least 
    vertex in subgraph of G induced by {s,s+1,....n};

Does that mean I have to implement another algorithm that finds the Ak matrix?

Another question is what the following means?

begin logical f; 

Does also the line "logical procedure CIRCUIT (integer value v);" mean that the circuit procedure returns a logical variable? In the pseudocode also has the line "CIRCUIT := f;". What does this mean?

It would be great if someone could translate this 1970's pseudocode to a more modern type of pseudocode so I can understand it

In case you are interested to help but you cannot find the paper please email me at [email protected] and I will send you the paper.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪少女 2024-09-10 07:16:07

伪代码让人想起 Algol、Pascal 或 Ada。

这是否意味着我必须实现另一种算法来查找 Ak 矩阵?

Ak 似乎是具有指定属性的输入值数组的列表。它可能与相应的邻接矩阵有关,但我不清楚。我猜是这样的:

int[][] a = new int[k][n];
int[][] b = new int[k][n];
boolean[] blocked = new boolean[n];
int s;

逻辑f是什么意思?

这声明了一个代表 truefalse 值的局部变量,类似于 Java 的 boolean

逻辑过程CIRCUIT(整数值v);

这声明了一个名为 CIRCUIT 的子程序,它具有按值传递的单个整数参数 v。子程序返回 truefalse逻辑结果,并且 CIRCUIT := f 分配 f< /code> 作为结果。在Java中,

boolean circuit(int v) {
    boolean f;
    ...
    f = false;
    ...
    return f;
}

关键字beginend界定了可以嵌套的块作用域,因此CIRCUIT嵌套在主块中,UNBLOCK 嵌套在 CIRCUIT 内部。 := 是赋值; Ø不是ε 是元素; 为空; !=stackunstack建议pushpop

这只是一个开始,但我希望它有所帮助。

附录:根据反思,AB 必须是同构的。

这是一个非常字面的大纲。我对 ABA 的了解还不够。 V 选择比数组更好的数据结构。

import java.util.Stack;

public final class CircuitFinding {
    static int k, n;
    int[][] a = new int[k][n];
    int[][] b = new int[k][n];
    boolean[] blocked = new boolean[n];
    int[] v = new int[k];
    int s = 1;
    Stack<Integer> stack = new Stack<Integer>();

    private void unblock(int u) {
        blocked[u] = false;
        for (int w : b[u]) {
            //delete w from B(u)
            if (blocked[w]) {
                unblock(w);
            }
        }
    }

    private boolean circuit(int v) {
        boolean f = false;
        stack.push(v);
        blocked[v] = true;
        L1:
        for (int w : a[v]) {
            if (w == s) {
                //output circuit composed of stack followed by s;
                f = true;
            } else if (!blocked[w]) {
                if (circuit(w)) {
                    f = true;
                }
            }
        }
        L2:
        if (f) {
            unblock(v);
        } else {
            for (int w : a[v]) {
                //if (v∉B(w)) put v on B(w);
            }
        }
        v = stack.pop();
        return f;
    }

    public void main() {
        while (s < n) {
            //A:= adjacency structure of strong component K with least
            //vertex in subgraph of G induced by {s, s+ 1, n};
            if (a[k] != null) {
                //s := least vertex in V;
                for (int i : v) {
                    blocked[i] = false;
                    b[i] = null;
                }
                L3:
                circuit(s);
                s++;
            } else {
                s = n;
            }
        }
    }
}

The pseudo-code is reminiscent of Algol, Pascal or Ada.

Does that mean I have to implement another algorithm that finds the Ak matrix?

Ak appears to be a list of arrays of input values having the specified properties. It may be related to the corresponding adjacency matrix, but it's not clear to me. I'm guessing something like this:

int[][] a = new int[k][n];
int[][] b = new int[k][n];
boolean[] blocked = new boolean[n];
int s;

What does logical f mean?

This declares a local variable representing a true or false value, similar to Java's boolean.

logical procedure CIRCUIT (integer value v);

This declares a subprogram named CIRCUIT having a single integer parameter v that is passed by value. The subprogram returns a logical result of true or false, and CIRCUIT := f assigns f as the result. In Java,

boolean circuit(int v) {
    boolean f;
    ...
    f = false;
    ...
    return f;
}

The keywords begin and end delimit a block scope that may be nested, so CIRCUIT is nested in the main block and UNBLOCK is nested inside of CIRCUIT. := is assignment; ¬ is not; is element; is empty; is !=; stack and unstack suggest push and pop.

It's only a start, but I hope it helps.

Addendum: On reflection, A and B must be isomorphic.

Here's a very literal outline. I don't know enough about A, B & V to choose a better data structure than arrays.

import java.util.Stack;

public final class CircuitFinding {
    static int k, n;
    int[][] a = new int[k][n];
    int[][] b = new int[k][n];
    boolean[] blocked = new boolean[n];
    int[] v = new int[k];
    int s = 1;
    Stack<Integer> stack = new Stack<Integer>();

    private void unblock(int u) {
        blocked[u] = false;
        for (int w : b[u]) {
            //delete w from B(u)
            if (blocked[w]) {
                unblock(w);
            }
        }
    }

    private boolean circuit(int v) {
        boolean f = false;
        stack.push(v);
        blocked[v] = true;
        L1:
        for (int w : a[v]) {
            if (w == s) {
                //output circuit composed of stack followed by s;
                f = true;
            } else if (!blocked[w]) {
                if (circuit(w)) {
                    f = true;
                }
            }
        }
        L2:
        if (f) {
            unblock(v);
        } else {
            for (int w : a[v]) {
                //if (v∉B(w)) put v on B(w);
            }
        }
        v = stack.pop();
        return f;
    }

    public void main() {
        while (s < n) {
            //A:= adjacency structure of strong component K with least
            //vertex in subgraph of G induced by {s, s+ 1, n};
            if (a[k] != null) {
                //s := least vertex in V;
                for (int i : v) {
                    blocked[i] = false;
                    b[i] = null;
                }
                L3:
                circuit(s);
                s++;
            } else {
                s = n;
            }
        }
    }
}
枕头说它不想醒 2024-09-10 07:16:07

您可以在 github 上找到该算法的 Java 实现:https://github.com/1123/johnson 。它使用 Jung2 java 图形库。

You can find a Java implementation of this algorithm on github: https://github.com/1123/johnson. It uses the Jung2 java graph library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文