gpt4 book ai didi

specman - 矛盾软约束的行为

转载 作者:行者123 更新时间:2023-12-01 10:39:01 25 4
gpt4 key购买 nike

我有一个测试用例,其中的行为似乎是错误的。我看到在所有世代中,num_of_red_shoes 都很高,而我希望分布更均匀。这种行为的原因是什么?如何解决?

<'
struct closet {
kind:[SMALL,BIG];

num_of_shoes:uint;
num_of_red_shoes:uint;
num_of_black_shoes:uint;
num_of_yellow_shoes:uint;

keep soft num_of_red_shoes < 10;
keep soft num_of_black_shoes < 10;
keep soft num_of_yellow_shoes < 10;

keep num_of_yellow_shoes + num_of_black_shoes + num_of_red_shoes == num_of_shoes;

when BIG closet {
keep num_of_shoes in [50..100];
};
};

extend sys {
closets[100]:list of BIG closet;
};
'>

生成结果:

item   type        kind        num_of_sh*  num_of_re*  num_of_bl*  num_of_ye* 
---------------------------------------------------------------------------
0. BIG closet BIG 78 73 1 4
1. BIG closet BIG 67 50 8 9
2. BIG closet BIG 73 68 0 5
3. BIG closet BIG 73 66 3 4
4. BIG closet BIG 51 50 0 1
5. BIG closet BIG 78 76 1 1
6. BIG closet BIG 55 43 7 5
7. BIG closet BIG 88 87 1 0
8. BIG closet BIG 99 84 6 9
9. BIG closet BIG 92 92 0 0
10. BIG closet BIG 63 55 3 5
11. BIG closet BIG 59 50 9 0
12. BIG closet BIG 51 44 2 5
13. BIG closet BIG 82 76 1 5
14. BIG closet BIG 81 74 2 5
15. BIG closet BIG 97 93 2 2
16. BIG closet BIG 54 41 8 5
17. BIG closet BIG 55 44 5 6
18. BIG closet BIG 70 55 9 6
19. BIG closet BIG 63 57 1 5

最佳答案

当存在相互矛盾的软约束时,Specman 不会随机化强制执行的软约束,而是优先考虑最后写入的约束。由于 soft on red shoes 在测试中排在第一位,因此它总是被覆盖。

如果已知软件是相互排斥的(这里不是这种情况),您可以使用一个简单的标志来随机选择应该保留哪个软件。例如代码看起来像这样:

flag:uint[0..2];

keep soft read_only(flag==0) => num_of_red_shoes < 10;
keep soft read_only(flag==1) => num_of_black_shoes < 10;
keep soft read_only(flag==2) => num_of_yellow_shoes < 10;

但是,由于这里事先并不知道有多少个软件需要保存(并且有可能满足两个或所有三个),因此应该制定更复杂的解决方案。这是执行此随机化的代码:

struct closet {
kind:[SMALL,BIG];

num_of_shoes:uint;
num_of_red_shoes:uint;
num_of_black_shoes:uint;
num_of_yellow_shoes:uint;

//replaces the original soft constraints (if a flag is true the correlating
//right-side implication will be enforced
soft_flags[3]:list of bool;
keep for each in soft_flags {
soft it == TRUE;
};

//this list is used to shuffle the flags so their enforcement will be done
//with even distribution
soft_indices:list of uint;
keep soft_indices.is_a_permutation({0;1;2});

keep soft_flags[soft_indices[0]] => num_of_red_shoes < 10;
keep soft_flags[soft_indices[1]] => num_of_black_shoes < 10;
keep soft_flags[soft_indices[2]] => num_of_yellow_shoes < 10;

keep num_of_yellow_shoes + num_of_black_shoes + num_of_red_shoes == num_of_shoes;
};

关于specman - 矛盾软约束的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31558580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com