#include<stdio.h>
#define N 6
#define M 10
typedef int bool;
#define true 1
#define false 0
unsigned int nondet_uint();
typedef unsigned __CPROVER_bitvector[M] bitvector;
unsigned int zeroTon(unsigned int n) {
unsigned int result = nondet_uint();
__CPROVER_assume(result >=0 && result <=n);
return result ;
};
//Constrine the value between 0 and 1
unsigned int nondet (){
unsigned int num = nondet_uint();
__CPROVER_assume( num>= 0 && num <= 1);
return num;
};
void main() {
unsigned int pos , i, j, k;
unsigned int len = 0;
bool Ch , Ck , C0 ;
bitvector compartment1 , compartment2 , compartment3 , compartment4, compartment5, compartment6;
bitvector nodes[N] = {compartment1, compartment2, compartment3, compartment4, compartment5, compartment6};
// Represent the graph with given topology
unsigned int graph[N][N];
for(i=0;i <N; i++) {
for(j=0;j<N;j++) {
graph[i][j] = nondet();
}
}
unsigned int p[N] ;
unsigned int ticks;
//Make sure that graph is one connected : just find one hamiltonian cycle
//make sure elements are in between node no's and all are distinct
for(i=0; i<N; i++) {
p[i] = zeroTon(5);
}
for(i=0; i <N; i++) {
for(j=0; (j<N) && (j!=i) ; j++) {
if( p[i] != p[j]){
C1 = C1 && 1;
}
else {
C1 = C1 && 0;
}
}
}
//hamiltonian One exists
for(i=0;i<N-1;i++) {
if( graph[p[i]][p[i+1]] == 1) {
Ch = Ch && 1;
}
else {
Ch = Ch && 0;
}
}
len =0;
for(i=0;i<N;i++) {
for(j=0;j<N; j++){
if (graph[i][j] == 1) {
len = len + 1;
}
}
}
//THIS IS GOING IN INFINITE LOOP ?? WHY ??
for(i=0;i<len;i++) {
printf("i'm a disco dancer ");
}
__CPROVER_assert(!(Ch && C1) , "Graph has an ham path");
}
我只是想得到一个具有哈密顿路径的总节点 6 的图表。这适用于上面的代码。但是,当我尝试使用 len 即总边缘数时,我在 cbmc run 中得到了无限展开。
上面的代码运行良好,除非我使用 len 进行迭代。cbmc 运行进入无限展开??谁能解释一下。