我有以下形式的数据:
:-use_module(library(clpb)).
%inputs are ids that will have an associated boolean value.
input(i1).
input(i2).
input(i3).
input(i4).
input(i5).
input(i6).
input(i7).
input(i8).
input(i9).
input(i10).
input(i11).
input(i12).
input(i13).
input(i14).
input(i15).
input(i16).
input(i17).
input(i18).
input(i19).
input(i20).
input(i21).
input(i22).
input(i23).
%and_gate(Id,ListOfInputs) the list of inputs can include other AND and/or OR gates
and_gate(and1,[i1,i2,i3]).
and_gate(and2,[i4,i5,i6]).
and_gate(and3,[and1,and2,or1,or2,i7,i8]).
and_gate(and4,[or3,i9]).
and_gate(and5,[i15,i16,i17]).
%or_gate(Id,ListOfInputs) the list of inputs can include inputs as well as AND and/or OR gates
or_gate(or1,[i10,i11]).
or_gate(or2,[i12,i13]).
or_gate(or3,[or2,i14]).
or_gate(or4,[and5,i18,i19,i20]).
%device(ID,ListOfInputs) the list of inputs can include inputs as well as AND and/or OR gates
device(d1, [and3,and4,or3,or4]).
device(d2,[i21,i22,i23]).
图:https ://docs.google.com/drawings/d/10wBpmFxxbDqrlpPVqpkVo_r8I-qcalWAz7Lro9myjMs/edit?usp=sharing
设备的输入也类似于与门,但它们始终是电路树的“顶层”。我想实现一个谓词,它会导致类似:
?- device_structure(D,OnOFF,Sat,Inputs).
D=d1,
Sat = sat(OnOff =:= *([*([*([V1,V2,V3]),
*([V4,V5,V6]),V7,V8,+[V10,V11],+[V12,V13]
]),
*([V9,+[V14,+[V12,V13]]]),
+[V14,+[V12,V13]],
+[*([V15,V16,V17]),V18,V19,V20]])),
Inputs = [
input(i1,V1),
input(i2,V2),
input(i3,V3),
input(i4,V4),
input(i5,V5),
input(i6,V6),
input(i7,V7),
input(i8,V8),
input(i9,V9),
input(i10,V10),
input(i11,V11),
input(i12,V12),
input(i13,V13),
input(i14,V14),
input(i15,V15),
input(i16,V16),
input(i17,V17),
input(i18,V18),
input(i19,V19),
input(i20,V20)
]).
然后当然是更简单的结构d2
。
这将允许我使用 clpb 库来提供输入的实例化以了解哪些设备处于打开或关闭状态,或者找到需要打开设备才能打开的输入。
然而,尽管进行了多次尝试,我仍然无法正确构建这些结构。
V 变量不需要这样命名,但重要的是 sat 语句中的变量与正确的输入变量匹配。