对一组事实进行排序 CLIPS

2024-02-07

我正在尝试根据基于两个字段的比较器对 CLIPS 中的事实集合进行排序...... 不幸的是,我无法理解为什么如果传递的两个事实中第一个字段相同,则比较器(显然是正确的)会打印 2。

我的比较器:

(deffunction MAIN::rating-sort (?f1 ?f2)
   (printout t ?f1 crlf)
   (printout t ?f2 crlf)
   (printout t "f1-SC " (fact-slot-value ?f1 sum-certainties) crlf)
   (printout t "f2-SC " (fact-slot-value ?f2 sum-certainties) crlf)
   (printout t "f1-TP " (fact-slot-value ?f1 total-price) crlf)
   (printout t "f2-TP " (fact-slot-value ?f2 total-price) crlf)
   (if (< (fact-slot-value ?f1 sum-certainties) (fact-slot-value ?f2 sum-certainties)) then (printout t "1" crlf) return TRUE
   else (if (> (fact-slot-value ?f1 sum-certainties) (fact-slot-value ?f2 sum-certainties)) then (printout t "2" crlf) return FALSE
        else (if (> (fact-slot-value ?f1 total-price) (fact-slot-value ?f2 total-price)) then (printout t "3" crlf) return TRUE
             else (if (< (fact-slot-value ?f1 total-price) (fact-slot-value ?f2 total-price)) then (printout t "4" crlf) return FALSE
                  else (printout t "5" crlf) return FALSE)))))

WM 的事实:

f-64    (alternative (hotels hotel4 hotel3 hotel2 hotel1) (times 1 0 0 0) (total-price 75.0) (certainty 14.0 -0.001 -0.001 -0.001) (sum-certainties 13.997) (flag TRUE))
f-66    (alternative (hotels hotel4 hotel3 hotel2 hotel1) (times 0 1 0 0) (total-price 100.0) (certainty -0.001 14.0 -0.001 -0.001) (sum-certainties 13.997) (flag TRUE))
f-68    (alternative (hotels hotel4 hotel3 hotel2 hotel1) (times 0 0 1 0) (total-price 75.0) (certainty -0.001 -0.001 14.0 -0.001) (sum-certainties 13.997) (flag TRUE))
f-70    (alternative (hotels hotel4 hotel3 hotel2 hotel1) (times 0 0 0 1) (total-price 100.0) (certainty -0.001 -0.001 -0.001 14.0) (sum-certainties 13.997) (flag TRUE))

我的比较器输出:

<Fact-64>
<Fact-66>
f1-SC 13.997
f2-SC 13.997
f1-TP 75.0
f2-TP 100.0
4
<Fact-68>
<Fact-70>
f1-SC 13.997
f2-SC 13.997
f1-TP 75.0
f2-TP 100.0
4
<Fact-64>
<Fact-68>
f1-SC 13.997
f2-SC 13.997
f1-TP 75.0
f2-TP 75.0
2
<Fact-66>
<Fact-68>
f1-SC 13.997
f2-SC 13.997
f1-TP 100.0
f2-TP 75.0
2

我不明白 13.997 怎么会大于 13.997。 谢谢大家。


你需要使用(返回真) and (返回假)在你的功能中而不是返回真 and 返回假,但即使进行此更改,代码也能正常工作。比较器从不打印 2。

         CLIPS (6.31 6/12/19)
CLIPS> 
(deffunction rating-sort (?f1 ?f2)
   (printout t ?f1 crlf)
   (printout t ?f2 crlf)
   (printout t "f1-SC " (fact-slot-value ?f1 sum-certainties) crlf)
   (printout t "f2-SC " (fact-slot-value ?f2 sum-certainties) crlf)
   (printout t "f1-TP " (fact-slot-value ?f1 total-price) crlf)
   (printout t "f2-TP " (fact-slot-value ?f2 total-price) crlf)
   (if (< (fact-slot-value ?f1 sum-certainties) (fact-slot-value ?f2 sum-certainties)) 
      then 
      (printout t "1" crlf) return TRUE
      else 
      (if (> (fact-slot-value ?f1 sum-certainties) (fact-slot-value ?f2 sum-certainties)) 
          then (printout t "2" crlf) return FALSE
          else 
          (if (> (fact-slot-value ?f1 total-price) (fact-slot-value ?f2 total-price)) 
              then (printout t "3" crlf) return TRUE
              else 
              (if (< (fact-slot-value ?f1 total-price) (fact-slot-value ?f2 total-price)) 
                  then (printout t "4" crlf) return FALSE
                  else (printout t "5" crlf) return FALSE)))))
CLIPS> 

(deftemplate alternative
   (multislot hotels)
   (multislot times)
   (slot total-price)
   (multislot certainty)
   (slot sum-certainties)
   (slot flag))            
CLIPS> 
(deffacts alternatives
   (alternative (hotels hotel4 hotel3 hotel2 hotel1) (times 1 0 0 0) 
                (total-price 75.0) (certainty 14.0 -0.001 -0.001 -0.001) 
                (sum-certainties 13.997) (flag TRUE))
   (alternative (hotels hotel4 hotel3 hotel2 hotel1) (times 0 1 0 0) 
                (total-price 100.0) (certainty -0.001 14.0 -0.001 -0.001) 
                (sum-certainties 13.997) (flag TRUE))
   (alternative (hotels hotel4 hotel3 hotel2 hotel1) (times 0 0 1 0) 
                (total-price 75.0) (certainty -0.001 -0.001 14.0 -0.001) 
                (sum-certainties 13.997) (flag TRUE))
   (alternative (hotels hotel4 hotel3 hotel2 hotel1) (times 0 0 0 1) 
                (total-price 100.0) (certainty -0.001 -0.001 -0.001 14.0) 
                (sum-certainties 13.997) (flag TRUE)))
CLIPS> (reset)
CLIPS> (sort rating-sort (find-all-facts ((?f alternative)) TRUE))
<Fact-1>
<Fact-2>
f1-SC 13.997
f2-SC 13.997
f1-TP 75.0
f2-TP 100.0
4
<Fact-3>
<Fact-4>
f1-SC 13.997
f2-SC 13.997
f1-TP 75.0
f2-TP 100.0
4
<Fact-1>
<Fact-3>
f1-SC 13.997
f2-SC 13.997
f1-TP 75.0
f2-TP 75.0
5
<Fact-2>
<Fact-3>
f1-SC 13.997
f2-SC 13.997
f1-TP 100.0
f2-TP 75.0
3
<Fact-2>
<Fact-4>
f1-SC 13.997
f2-SC 13.997
f1-TP 100.0
f2-TP 100.0
5
(<Fact-1> <Fact-3> <Fact-2> <Fact-4>)
CLIPS>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

对一组事实进行排序 CLIPS 的相关文章

  • JAXB 不接受 CustomEscapeHandler

    我正在开发一个执行大量 XML 操作的应用程序 因此我尝试让 JAXB 在其中工作 我有以下 CustomEscapeHandler 类 导入 com sun xml bind marshaller CharacterEscapeHandl
  • 续集,语句(where)中的语句(where)

    我正在尝试花 2 个小时来解决一个不是一个的小问题 我正在使用生成的 yeoman Angular fullstack 应用程序 我想用sequelize编写这段代码 SELECT FROM demand WHERE city id NOT
  • MockService 仍然导致错误:无法读取未定义的属性“订阅”

    我是 Angular 测试的新手 所以 我正在关注这个多元视野课程 https app pluralsight com library courses unit testing angular table of contents 我不断收到
  • 如何在 Django 中动态隐藏表单字段?

    我正在 Django 中制作个人资料表单 有很多可选的额外配置文件字段 但我只想一次显示两个 如何隐藏或删除不想动态显示的字段 这是我到目前为止所拥有的 class UserProfileForm forms ModelForm extra
  • 证书结构

    大多数签名证书占用空间都是 20 字节长 Windows 证书管理器中的 占用空间 字段 这怎么可能是发证 认证 机构签署的值呢 具体来说 证书的签名应该是由私钥签名的证书字段的散列值 因此至少具有颁发者私钥的 RSA 模数长度 在 RSA
  • 构造函数作为函数 try 块 - 异常中止程序

    我不确定这是编译器的问题还是我做错了什么 我正在使用 Visual Studio 2013 编译器 我有一个类 我需要在构造函数初始值设定项列表中获取大量资源 其中大部分资源可能会引发异常 我将成员初始值设定项列表包装在函数 try 块中
  • Jquery DataTable中的滚动问题

    我不确定我是否在重复这个问题 如果是的话 指导到正确的地方 我正在使用数据表并尝试实现水平滚动并找到此链接 http www datatables net examples basic init scroll x html http www
  • onnx图,如何获取输出维度?

    如何获取onnx神经网络输出层的维度 我可以得到 onnx 图 但没有输出维度 onnx tensorrt third party onnx onnx tools net drawer py input weights tiny 3l v5
  • 在弹出窗口中显示要删除的项目

    我正在使用 Odoo 10e 我想要一个简单的功能 每当我想从列表视图或仅从特定列表视图中删除一个或多个项目时 我想显示所有选择删除的项目 以在弹出窗口中显示其名称 以便用户可以快速查看他要删除的内容 我知道用户可以在列表视图中查看详细信息
  • 分割时间频率到行

    我试图将具有开始时间 结束时间 频率和持续时间的时间频率拆分为单独的行 以下是一些示例数据 Name Start Time End Time Frequency Hours Duration Mins A 08 00 00 18 00 00
  • 以编程方式更改列表视图项中的文本颜色

    我想做这样的事情 textLabel inCell TextColor Color Black 但 Visual Studio 显示错误 textLabel inCell 在当前上下文中不存在 如何以编程方式更改 listView 项的文本
  • 使用 .NET 控制台应用程序通过芯片选择写入 HID

    您好 我正在编写一个简单的控制台应用程序 需要将字节写入MCP2210 USB to SPI Master我发现这个图书馆here https www zer7 com software hidsharp 似乎在连接设备和读取元数据方面做得
  • 如何在没有应用程序上下文的情况下使用 spring-security 过滤器?

    我想直接从 java 代码使用 spring security web filters 而不需要 spring 应用程序上下文 或 spring 容器 这可能吗 我可以直接调用不同的 spring 生命周期方法吗 如果可以 是否有一个如何执
  • 如何在 Swift 中声明 volatile 变量

    我想从 Objective C 代码转换为 Swift 如下所示 int sum 0 x 1 for int i 0 i lt 100 i sum x x 可以从其他线程访问 因此 x 被声明为 volatile 变量 volatile i

随机推荐

  • C++ 比较两个字符串文字

    将一个字符串文字与另一个字符串文字进行比较时 运算符 或 结果是否明确定义 例如 以下内容是否保证成立 assert a a assert a b 请不要说 使用 std string 之类的东西 我只是想知道这个具体案例 a a 这个表达
  • Spring 用非主 bean 覆盖主 bean

    我试图在测试配置中使用 Primary 声明的测试期间覆盖 Spring bean 一个声明位于 src main java 路径中 另一个声明 主声明 位于 src test java 路径中 然而 Spring 有意用非主 bean 替
  • 在 Rails 中将日期格式化为单词

    所以我有一个具有日期时间属性的模型实例 我使用以下方式在我的视图中显示它 但它显示为 2011 09 09 我希望它显示为 2011 年 9 月 9 日 我该怎么做呢 Thanks 这将为您提供 2011 年 9 月 9 日 如果您确实需要
  • xslt、javascript 和未转义的 html 实体

    我对 xslt js 和 html 实体有一个小问题 例如 在模板内
  • Mac 上的 webbrowser.get("firefox") 与 Firefox“无法找到可运行的浏览器”

    我认为我需要知道要运行哪个神奇的命令行或 OSA 脚本程序来启动现有 Firefox 浏览器中的 URL 如果正在运行 或者如果没有运行 也启动 Firefox 在 Mac 上 我正在测试一个 Python 程序 Crunchy Pytho
  • phpmyadmin|如何创建一个事件执行 2 个操作

    我想创建一个可以执行两个操作的事件 但我不知道如何操作 这是查询 CREATE EVENT rate ON SCHEDULE EVERY 24 HOUR STARTS 2011 12 01 20 00 00 DO SET p 1 UPDAT
  • 检查字符是否为换行符

    你好 我有一个简单的程序 它计算给定文本中的字符 直到行为空行 仅包含新行 var znaki array a z of integer 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  • ThreadLocal 和 SimpleDateFormat 数组

    使用与中描述的模式非常相似的模式最近的问题 https stackoverflow com questions 10491135 threadlocal for multithreaded access to simpledateforma
  • 如何使用 DataContractJsonSerializer 序列化/反序列化存储在对象字段内的 DateTime?

    我使用以下类通过两个 ASP NET 服务交换 JSON 数据 DataContract public class Filter DataMember public string Name get set DataMember public
  • 如何使用python检测边缘后将图像裁剪成碎片

    我正在从事一个破损文档重建项目 首先 我尝试检测包含撕裂文档碎片的图像边缘 然后尝试使用示例代码通过检测到的边缘将图像裁剪成碎片 import cv2 import numpy as np img cv2 imread test png i
  • javafx jar 构建正常但无法打开

    所以我创建了一个javafx项目 它有3个包 应用程序 控制器和一个包含我使用的所有图像的图像包 如果我只是编译并运行 程序运行良好 没有错误 但是 当我从中创建一个 jar 时 通过选择 build fxbuild 一切都很顺利 它告诉我
  • 传递给 Delphi 控制台应用程序的命令行参数的最大长度

    传递给 Delphi 控制台应用程序的字符串长度是否有最大限制 我正在考虑传递大量 JSON 数据 我将使用 ParamStr x 函数读取数据 CMD EXE 的最大长度为 8192 个字符 由于 CMD EXE 本身的限制 这将是 De
  • ndb.StringProperty 如何等于 python 字符串?

    我有这个 ndb 模型类 class foo ndb Model abc ndb StringProperty 现在当我使用abc像这样 if foo abc a print I m in 它进入 if 块并打印I m in 这怎么可能 我
  • 是否可以阻止 Google Play 应用程序在安装时创建我的应用程序的快捷方式?

    当您通过 Google Play 安装应用程序时 会在主屏幕上创建该应用程序的快捷方式 用户可以通过禁用 Google Play 应用程序中的 自动添加小部件 设置来防止这种情况发生 从开发人员的角度来看 我想知道是否可以在我自己的应用程序
  • 如何在Swing中画蛇?

    我对 Java Swing 相当陌生 正在为我的大学课程开发一个梯子和蛇形项目 老师告诉我们实现一个游戏 玩家可以准确选择游戏板上有多少条蛇以及蛇的位置 梯子也是如此 所以我不能在游戏中使用一个或多个固定图像 这样玩家就无法再更改它们 我需
  • 具有 @ManyToOne 关系的 QueryDSL 投影

    我将 OpenJPA 与 QueryDSL 一起使用 我尝试通过使用 QueryDSL 的 bean 投影功能来避免操作 Tuple 对象 例如 我有这两个实体 具有 ManyToOne 关系 Entity public class Fol
  • 在临时表列 SQL 中设置排序规则的正确方法

    我有一个临时表 它使用批量插入来插入数据 但是 当我想将临时表中的数据更新到普通表时 它会出现排序规则问题 我知道如何通过使用类似的方法来解决这个问题 UPDATE RegularTable SET r Column1 t ColumnA
  • 在哪里可以找到 Java 语法突出显示库? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在用 Java 编写一个源代码编辑器 用于 Java 源代码 并且我想添加简单的语法突出显示 关键
  • 我试图在 bulma css 上使用汉堡菜单,但它不起作用。怎么了?

    我是 bulma css 新手http bulma io http bulma io 我正在尝试为移动用户使用汉堡菜单 我只是按照此页面上的说明进行操作 http bulma io documentation components nav
  • 对一组事实进行排序 CLIPS

    我正在尝试根据基于两个字段的比较器对 CLIPS 中的事实集合进行排序 不幸的是 我无法理解为什么如果传递的两个事实中第一个字段相同 则比较器 显然是正确的 会打印 2 我的比较器 deffunction MAIN rating sort