我试图做出约束,以检查图中是否存在从顶点A到顶点B的路径。我已经做了一个约束,返回了路径本身,但是我还需要一个函数,该函数返回一个布尔值,指示路径是否存在。
我已经花了很多时间,但是我的尝试都没有成功...
有谁知道我该怎么办?
这是我制作的返回路径本身的函数,其中graph是一个邻接矩阵,source和target是顶点A和B:
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)