我有以下生成随机值:其中约束不和不保持
:-use_module(library(clpfd)).
list_index_value(List,Index,Value):-
nth0(Index,List,Value).
length_conindexes_conrandomvector(Length,Conindexs,Randomvector):-
length(Randomvector,Length),
same_length(Conindexs,Ones),
maplist(=(1),Ones),
maplist(list_index_value(Randomvector),Conindexs,Ones),
term_variables(Randomvector,Vars),
maplist(random_between(0,1),Vars).
length_conindexes_notconrandomvector(Length,Conindexes,Randomvector):-
length(Randomvector,Length),
length(Conindexes,NumberOfCons),
same_length(Conindexes,Values),
sum(Values,#\=,NumberOfCons),
maplist(list_index_value(Randomvector),Conindexes,Values),
term_variables(Randomvector,Vars),
repeat,
maplist(random_between(0,1),Vars).
length_conindexes_conrandomvector/3
被用来产生一和零,其中在conindexes位置的元素中1的一个随机向量。
?-length_conindexes_conrandomvector(4,[0,1],R).
R = [1, 1, 0, 1].
length_conindexes_notconrandomvector/3
被用来产生一个随机向量,其中不是所有的conindexes的是那些。
?- length_conindexes_notconrandomvector(3,[0,1,2],R).
R = [1, 0, 1] ;
R = [0, 1, 1] ;
R = [1, 1, 0]
这个我觉得我已经用'0123'配置了这个repeat
命令。做这个的最好方式是什么?如果我使用标签,那么这些值不会是随机的?如果约束经常被违反,那么搜索将是非常低效的。做这个的最好方式是什么?
要使这种关系有意义,请添加种子参数。 – false
你是什么意思? – user27815
如果您不添加种子,您的定义不是关系。 – false