【问题标题】:Prolog Combine RuleProlog 合并规则
【发布时间】:2010-07-21 19:06:10
【问题描述】:

我需要编写一个由子规则组成的规则。

知道如何实现这一目标吗?

isloanaccept(Name, LoanAmount, LoanTenure) 
:-  customer(Name, bank(_),customertype(_),
    citizen(malaysian),age(Age),credit(C),
    income(I),property(car|house)), 
    Age >= 18,
    C > 500, 
    I > (LoanAmount / LoanTenure) / 12.
lowerinterest(Senior) :- isseniorcitizen(Senior).

例如,我需要检查客户类型。 如果客户类型是 VIP,则利息较低。 如果年龄在 60 岁以上,利息会降低。

请帮忙。

谢谢。

【问题讨论】:

    标签: prolog rule


    【解决方案1】:

    isloanaccept 添加一个额外的参数可能是最简单的方法。

    isloanaccept(Name, LoanAmount, LoanTenure, Interest) :-
        customer(Name, bank(_), customertype(Type), citizen(malaysian), age(Age),
                 credit(C), income(I), property(car|house)), 
        Age >= 18,
        C > 500,
        I > (LoanAmount / LoanTenure) / 12,
        interest(Age, Interest).
    
    % Interest depending on age and customertype; add parameters, or pass in a list,
    % to have interest determined by other factors
    interest(Age,Type,Interest) :-
        (senior_citizen(Age) ->
            Interest = 0.05
        ; Type = vip ->
            Interest = 0.07
        ;
            Interest = 0.10
        ).
    

    PS.:请尝试以这种方式格式化 Prolog 代码,这样更容易阅读。

    【讨论】:

      【解决方案2】:

      这就是我会做的:

      % usage: isInterestOk(+CustomerType, +Interest)
      isInterestOk('VIP', Interest) :-
          Interest =< 1000.
      isInterestOk('normal', Interest) :-
          Interest =< 500.
      

      【讨论】:

      • 让我重新表述我的问题。我需要创建一个函数来评估贷款,如果贷款被接受,那么我需要检查它是否向该人提供了较低的利息。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多