小编Mar*_*lho的帖子

使用MiniZinc检查图中是否有连接两个顶点的路径

我试图做出约束,以检查图中是否存在从顶点A到顶点B的路径。我已经做了一个约束,返回了路径本身,但是我还需要一个函数,该函数返回一个布尔值,指示路径是否存在。

我已经花了很多时间,但是我的尝试都没有成功...

有谁知道我该怎么办?

这是我制作的返回路径本身的函数,其中graph是一个邻接矩阵,sourcetarget是顶点AB

function array [int] of var int: path(array[int,int] of int: graph, int: source, int: target)::promise_total =
let {
    set of int: V = index_set_1of2(graph);
    int: order = card(V);
    set of int: indexes = 1..order;
    array[indexes] of var (V union {-1}): path_array;
    var indexes: path_nodes_count; % the 'size' of the path

    constraint assert(index_set_1of2(graph) = index_set_2of2(graph), "The adjacency matrix is not square", true); …
Run Code Online (Sandbox Code Playgroud)

graph minizinc

5
推荐指数
1
解决办法
385
查看次数

标签 统计

graph ×1

minizinc ×1