7

我已经用 or 运算符定义了一个规则,但它返回多个真或假。

isloanaccept(Name,Guarantor,LoanType,LoanAmount,LoanTenure) 
:-  customer(Name,bank(_),customertype(_),
 citizen(Ci),age(Age),credit(C),
 income(I),property(_),bankemployee(_)), 
 Ci == 'malaysian',
 Age >= 18,
 C > 500, 
    I > (LoanAmount / LoanTenure) / 12,
 isguarantor(Guarantor,Name), 
 ispersonalloan(LoanType,LoanAmount,LoanTenure);
 ishouseloan(LoanType,LoanAmount,LoanTenure);
 isbusinessloan(LoanType,LoanAmount,LoanTenure);
 iscarloan(LoanType,LoanAmount,LoanTenure).

实际上,我需要检查贷款类型是否满足特定的贷款要求并结合一般规则。

换句话说,我需要像这样定义上面的规则。

Ci == 'malaysian', Age >= 18,C > 500, 
I > (LoanAmount / LoanTenure) / 12,
isguarantor(Guarantor,Name) 
    Or with   (ispersonalloan(LoanType,LoanAmount,LoanTenure);
             ishouseloan(LoanType,LoanAmount,LoanTenure);
             isbusinessloan(LoanType,LoanAmount,LoanTenure);
             iscarloan(LoanType,LoanAmount,LoanTenur)

它应该在命令行中返回 1 个真/假而不是多个语句。

在命令行中检查了规则后,每个 or 规则都返回 1 个我不想要的布尔值。我需要这样(一般规则和(多或规则))。

如何组合返回 1 个布尔值的几个或规则?

请帮忙。

谢谢。

4

2 回答 2

5

只需将您所有的“或”目标都用once.

例如

once(
 ispersonalloan(LoanType,LoanAmount,LoanTenure);
 ishouseloan(LoanType,LoanAmount,LoanTenure);
 isbusinessloan(LoanType,LoanAmount,LoanTenure);
 iscarloan(LoanType,LoanAmount,LoanTenure)
).

现在,“或”的目标要么成功,要么失败。

于 2010-07-28T19:29:09.173 回答
0

首先你应该把你的目标()周围结合起来;。因为目前它把它解释为customer(...),...,isguarantor(Guarantor,Name), ispersonalloan(...), ishouseloan(...), ...,的析取iscarloan(...)。那是因为运营商,;.

实际上;- 意味着真正的“或”,而不是“互斥或”而不是“在其他情况下”。因此,如果“ishouseloan”不能与“ispersonalloan”一起成功,那么您将有几个成功的目标。在这个例子once/1中可能会有所帮助(以及not(not(...))),但您可以尝试让 prolog 更深入地完成您的任务并指定非重复目标,例如(我对重叠做了一些个人假设isXXX):

isloan(LT, Am, T):-
  (ishouseloan(LT,Am,T)
  ;iscarloan(LT,AM,T)
  ;not((ishouseloan(LT,Am,T);iscarloan(LT,AM,T))),
    (ispersonalloan(LT,Am,T)
    ;isbusinessloan(LT,Am,T)
    )
  )

LT在这种情况下,当您的,AmT尚未绑定到特定值并且isXXX可以绑定自由变量时,您应该能够生成所有贷款。

于 2010-08-05T04:52:21.403 回答