Math 使用GLPK输出图形的所有可能路径
我试图使用glpk枚举从源节点到目标节点的所有可能路径,但语法有一些问题。以下是我当前的代码(改编自最短路径示例):Math 使用GLPK输出图形的所有可能路径,math,graph,enumeration,linear-programming,glpk,Math,Graph,Enumeration,Linear Programming,Glpk,我试图使用glpk枚举从源节点到目标节点的所有可能路径,但语法有一些问题。以下是我当前的代码(改编自最短路径示例): 问题到底是什么?为什么你需要列举所有可能的路径?我的问题是我不知道怎么做,我需要所有可能的路径来解决一些练习 param n, integer, > 0; /* number of nodes */ set E, within {i in 0..n, j in 0..n}; /* set of edges */ param s, in {0..n}; /* source
问题到底是什么?为什么你需要列举所有可能的路径?我的问题是我不知道怎么做,我需要所有可能的路径来解决一些练习
param n, integer, > 0;
/* number of nodes */
set E, within {i in 0..n, j in 0..n};
/* set of edges */
param s, in {0..n};
/* source node */
param t, in {0..n};
/* target node */
var x{(i,j) in E}, >= 0;
/* x[i,j] = 1 means that edge (i,j) belong to shortest path;
x[i,j] = 0 means that edge (i,j) does not belong to shortest path;
note that variables x[i,j] are binary, however, there is no need to
declare them so due to the totally unimodular constraint matrix */
s.t. r{i in 1..n}: sum{(j,i) in E} x[j,i] + (if i = s then 1) =
sum{(i,j) in E} x[i,j] + (if i = t then 1);
/* conservation conditions for unity flow from s to t; every feasible
solution is a path from s to t */
var test, integer, =0;
minimize Z: sum{(i,j) in E} x[i,j];
/* objective function is the path length to be minimized */
solve;
for {(i,j) in E: x[i,j]>0}{
printf "%d --> %d ", i, j;
}
#printf " tamanho do caminho %d ", count;