我是prolog的新手,想要从image中给出的下面的prolog代码生成一个显示矩阵。下面的图片是使用tkEclipse(Eclipse for prolog)从给定的prolog代码生成的 以下是prolog的约束满足问题代码
:- lib(ic).
:- lib(ech).
:- local struct(fms(f1, f2, f3, f4)).
:- local struct(fcs(pc1, cc1, hc2, pc2, hc3, pc4, cc4)).
:- local struct(part_family(fms, fcs, fvs, rms, prs)).
:- local struct(rms(rm1, rm2, rm3, rm4, rm5, rm6, rm7)).
:- local struct(fvs(pc1_1, pc1_2, cc1_1, cc1_2, hc2_1, hc2_2, pc2_1, hc3_1,
pc4_1, pc4_2, cc4_1)).
:- local struct(prs(pr1, pr2, pr3, pr4, pr5, pr6)).
:- constraints cc1/3, cc2/4, cc3/4, cc4/4, cc11/3, cc12/4.
cc1(A:L, B:M, Active)<=>memberd(A:L, Active),memberd(B:M, Active)|L $= M.
cc11(A:L, B:M, Active)<=>memberd(A:L, Active)|L $= M.
cc11(A:L, B:M, Active)<=>not memberd(A:L, Active)|M = 0.
cc12(A:L, B:M, C:N, Active)<=>memberd(A:L, Active),memberd(B:M, Active)|N $= (L
and M).
cc12(A:L, B:M, C:N, Active)<=>not memberd(A:L, Active)|N = 0.
cc12(A:L, B:M, C:N,Active)<=>not memberd(B:M, Active)|N = 0.
cc2(A:L, B:M, C:N, Active)<=>memberd(A:L, Active), memberd(B:M, Active),
memberd(C:N, Active)|L $= (M and N).
cc3(A:L, B:M, C:N, Active)<=>memberd(A:L, Active), memberd(B:M, Active),
memberd(C:N, Active)|L $= ((M and N) or (neg M and N)).
cc4(A:L, B:M, C:N, Active)<=>memberd(A:L, Active), memberd(B:M, Active),
memberd(C:N, Active)|L $= ((M and neg N) or (neg M and N)).
solve_dcsp(part_family(fms(f1:F1,f2:F2,f3:F3,f4:F4),
fcs(pc1:PC1,cc1:CC1,hc2:HC2,pc2:PC2,hc3:HC3,pc4:PC4,cc4:CC4),
fvs(pc1_1:PC1_1, pc1_2:PC1_2, cc1_1:CC1_1, cc1_2:CC1_2, hc2_1:HC2_1,
hc2_2:HC2_2, pc2_1:PC2_1, hc3_1:HC3_1, pc4_1:PC4_1, pc4_2:PC4_2,
cc4_1:CC4_1),
rms(rm1:RM1,rm2:RM2,rm3:RM3,rm4:RM4,rm5:RM5,rm6:RM6,rm7:RM7),
prs(pr1:PR1,pr2:PR2,pr3:PR3,pr4:PR4,pr5:PR5,pr6:PR6))):-[F1,F2,F3,F4]::[0,1],
[PC1,CC1,HC2,PC2,HC3,PC4,CC4]::[0,1],
[PC1_1,PC1_2,CC1_1,CC1_2,HC2_1,HC2_2,PC2_1,HC3_1,PC4_1,PC4_2,CC4_1]::[0,1],
[RM1,RM2,RM3,RM4,RM5,RM6,RM7]::[0,1],
[PR1,PR2,PR3,PR4,PR5,PR6]::[0,1],
Active = [f1:F1,f2:F2,f3:F3,f4:F4],
((F1 and F2 and F3 and neg F4) or (F1 and F2 and neg F3 and F4)) $=1,
find_solution(Active),
activate(f1:F1,[pc1:PC1,cc1:CC1],Active,New_active1),
activate(f2:F2,[pc2:PC2,hc2:HC2],New_active1,New_active2),
activate(f3:F3,[hc3:HC3],New_active2,New_active3),
activate(f4:F4,[pc4:PC4,cc4:CC4],New_active3,New_active4),
cc2(f1:F1,pc1:PC1,cc1:CC1,New_active4),
cc3(f2:F2,pc2:PC2,hc2:HC2,New_active4),
cc2(f4:F4,pc4:PC4,cc4:CC4,New_active4),
cc1(f3:F3,hc3:HC3,New_active4),
find_solution(New_active4),
activate(pc1:PC1,[pc1_1:PC1_1,pc1_2:PC1_2],New_active4,New_active5),
activate(cc1:CC1,[cc1_1:CC1_1,cc1_2:CC1_2],New_active5,New_active6),
activate(pc2:PC2,[pc2_1:PC2_1],New_active6,New_active7),
activate(hc2:HC2,[hc2_1:HC2_1,hc2_2:HC2_2],New_active7,New_active8),
activate(hc3:HC3,[hc3_1:HC3_1],New_active8,New_active9),
activate(pc4:PC4,[pc4_1:PC4_1,pc4_2:PC4_2],New_active9,New_active10),
activate(cc4:CC4,[cc4_1:CC4_1],New_active10,New_active11),
cc4(pc1:PC1,pc1_1:PC1_1,pc1_2:PC1_2,New_active11),
cc4(cc1:CC1,cc1_1:CC1_1,cc1_2:CC1_2,New_active11),
cc1(pc2:PC2,pc2_1:PC2_1,New_active11),
cc4(hc2:HC2,hc2_1:HC2_1,hc2_2:HC2_2,New_active11),
cc1(hc3:HC3,hc3_1:HC3_1,New_active11),
cc2(pc4:PC4,pc4_1:PC4_1,pc4_2:PC4_2,New_active11),
cc1(cc4:CC4,cc4_1:CC4_1,New_active11),
cc1(pc1_1:PC1_1,cc1_1:CC1_1,New_active11),
cc1(pc1_2:PC1_2,pc2_1:PC2_1,New_active11),
cc1(pc1_1:PC1_1,hc3_1:HC3_1,New_active11),
cc1(pc1_1:PC1_1,hc2_1:HC2_1,New_active11),
cc1(pc1_2:PC1_2,f4:F4,New_active11),
cc1(pc1_2:PC1_2,pc2:PC2,New_active11),
find_solution(New_active11),
cc11(pc1:PC1,rm1:RM1,New_active11),
cc11(cc1:CC1,rm2:RM2,New_active11),
cc11(pc2:PC2,rm3:RM3,New_active11),
cc11(hc2:HC2,rm4:RM4,New_active11),
cc11(hc3:HC3,rm5:RM5,New_active11),
cc11(pc4:PC4,rm6:RM6,New_active11),
cc11(cc4:CC4,rm7:RM7,New_active11),
cc12(hc2:HC2,pc1:PC1,pr1:PR1,New_active11),
cc12(pc1:PC1,cc1:CC1,pr2:PR2,New_active11),
cc12(hc2:HC2,hc3:HC3,pr3:PR3,New_active11),
cc12(hc2:HC2,pc4:PC4,pr4:PR4,New_active11),
cc12(pc4:PC4,cc4:CC4,pr5:PR5,New_active11),
cc11(pc4:PC2,pr6:PR6,New_active11),
find_solution([rm1:RM1, rm2:RM2, rm3:RM3, rm4:RM4, rm5:RM5, rm6:RM6, rm7:RM7,
pr1:PR1, pr2:PR2, pr3:PR3, pr4:PR4, pr5:PR5, pr6:PR6]),
print_configuration(part_family(fms(f1:F1, f2:F2, f3:F3, f4:F4),
fcs(pc1:PC1, cc1:CC1, hc2:HC2, pc2:PC2, hc3:HC3, pc4:PC4,
cc4:CC4),
fvs(pc1_1:PC1_1, pc1_2:PC1_2, cc1_1:CC1_1, cc1_2:CC1_2,
hc2_1:HC2_1, hc2_2:HC2_2, pc2_1:PC2_1, hc3_1:HC3_1,
pc4_1:PC4_1, pc4_2:PC4_2, cc4_1:CC4_1),
rms(rm1:RM1, rm2:RM2, rm3:RM3, rm4:RM4, rm5:RM5, rm6:RM6,
rm7:RM7),
prs(pr1:PR1, pr2:PR2, pr3:PR3, pr4:PR4, pr5:PR5,
pr6:PR6))).
find_solution([]):- true.
find_solution([_:D|Active1]):-indomain(D),
find_solution(Active1).
memberd(_,[]):-fail.
memberd(X:_,[H:_|_]):-X = H,!.
memberd(M:_,[_:_|Ts]):-memberd(M:_,Ts),!.
activate(_:Head,L2,Active,New_active):-((nonvar(Head),Head =1) -> add(L2,Active,New_active); New_active = Active).
add([],List2,New_list):- New_list=List2.
add([E1|Es],List2,New_list):-add(Es,[E1|List2],New_list).
print_configuration(part_family(Fms,Fcs,Fvs,Rms,Prs)):-writeln("Find the following configuration result:"),
write(" Function Modules:"),
(foreacharg(Fm,Fms) do write_configuration(Fm)),
nl,
write(" Feature Clusters:"),
(foreacharg(Fc,Fcs) do write_configuration(Fc)),
nl,
write(" Feature Variants:"),
(foreacharg(Fv,Fvs) do write_configuration(Fv)),
nl,
write(" RMOPs:"),
(foreacharg(Rm,Rms) do write_configuration(Rm)),
nl,
write(" Precedence relations:"),
(foreacharg(Pr,Prs) do write_configuration(Pr)),
nl.
write_configuration(A:B):-B==1-> write(A),write(" ");true.
到目前为止,我已经生成了显示矩阵,就像image下面一样。代码很好,问题主要是关于如何使用编译器生成那种显示matrix。