SAT求解器中search函数的实参是求解发生冲突的限量值。luby函数可以作为序列生成器,序列元素反映一定规律,这样可以使得重启按照指定冲突序列有计划的进行。

先看一下luby函数:

/*
  Finite subsequences of the Luby-sequence:

  0: 1
  1: 1 1 2
  2: 1 1 2 1 1 2 4
  3: 1 1 2 1 1 2 4 1 1 2 1 1 2 4 8
  ...


 */

static double luby(double y, int x){

    // Find the finite subsequence that contains index 'x', and the
    // size of that subsequence:
    int size, seq;
    for (size = 1, seq = 0; size < x+1; seq++, size = 2*size+1);

    while (size-1 != x){
        size = (size-1)>>1;
        seq--;
        x = x % size;
    }

    return pow(y, seq);
}

  编写如下主函数调用luby函数,程序代码及运行结果如下:

    

 1 #include <cstdlib>
 2 #include <iostream>
 3 #include <cmath>
 4 
 5 using namespace std;
 6 static double luby(double y, int x){
 7  
 8     // Find the finite subsequence that contains index 'x', and the
 9     // size of that subsequence:
10     int size, seq;
11     for (size = 1, seq = 0; size < x+1; seq++, size = 2*size+1);
12  
13     while (size-1 != x){
14         size = (size-1)>>1;
15         seq--;
16         x = x % size;
17     }
18  
19     return pow(y, seq);
20 }
21 
22 int main()
23 {
24     int y1 = 10;
25     int x1 = 0;
26     double result = 0;
27     while(x1 < 20){
28         result = luby(y1,x1);
29         printf("luby(%-3d,%-2d) = %10.4f\n", y1, x1, result);
30         x1++;
31     }
32     system("color f1");
33     system("PAUSE");
34     return 0;
35 }     
posted on 2020-03-27 00:17  海阔凭鱼跃越  阅读(528)  评论(0编辑  收藏  举报