【问题标题】:CLIPS & clipsmm: slot of float typeCLIPS & clipsmm: 浮点型槽
【发布时间】:2017-03-27 01:16:04
【问题描述】:

我对浮动类型的插槽有疑问。我的知识库文件中有一个模板:

(deftemplate test
(slot slot1 (type INTEGER) (default 10))
(slot slot2 (type FLOAT) (default 4.0))
)

我使用 clipsmm 将 CLIPS 与 Qt 应用程序集成。我这样断言事实:

CLIPS::Fact::pointer fact;
QString fact_str = "(test (slot1 15) (slot2 4.3))";
fact = env.assert_fact(Std(fact_str)); //Std() translates QString into std::string

这一事实已添加到议程中,但 slot2 的值 = 4.0 而不是 4.3:

<== Activation 0 start:
<== f-0 (initial-fact)
:== ?answer ==> 0 <== 0 //this is global
==> Activation 0 start:
==> f-0 (initial-fact)
Start!
==> f-1 (test (slot1 15) (slot2 4.0))

如果我使用“XCLIPS 专家系统”,一切都很好,并且 slot2 的值 = 4.3。我做错了什么?

UPD。我以这种方式更改了 environment.cpp:

Fact::pointer Environment::assert_fact( const std::string& factstring )
{
  void* clips_fact = EnvAssertString( m_cobj, const_cast<char*>(factstring.c_str()) );

  std::cout << "factstring =" << factstring << std::endl;     //std::cout is added
  if ( clips_fact )
    return Fact::create( *this, clips_fact );
  else
    return Fact::pointer();
}

并且显示正确: "factstring = (test (slot1 15) (slot2 4.3))"

UPD2。我试图以这种方式添加事实:

CLIPS::Template::pointer temp;
temp = env.get_template(Std("test"));
CLIPS::Fact::pointer f1;
f1 = CLIPS::Fact::create(env, temp);
CLIPS::Value v1 = CLIPS::Value(15);
CLIPS::Value v2 = CLIPS::Value(4.3);
f1->set_slot(Std("slot1"), v1);
f1->set_slot(Std("slot2"), v2);
env.assert_fact(f1);

得到了这样的结果:

==> f-2     (test (slot1 15) (slot2 4,3.0))

【问题讨论】:

  • 我在 Linux (OpenSuse 13.2) 中工作,使用 CLIPS 6.30.0-2.6、clipsmm-0.3.4、Qt 4.8.6
  • 你是否在environment.cpp中的clipsmm assert_fact方法中验证了传递给EnvAssertString的转换字符串是有效的?
  • 是的,我更新了问题。转换后的字符串似乎没问题。
  • 您还想检查 factstring.c_str() 的值以验证该转换是否有效。如果它适用于标准剪辑可执行文件但不适用于 clipsmm,则所使用的编译选项可能存在一些差异。
  • 我检查了 factstring.c_str() 的值:也是对的。请告诉我您指的是哪些编译选项以及在哪里查看它们?

标签: c++ clips


【解决方案1】:

我不太明白,但以下帮助:更改操作系统区域设置中的数字格式。默认使用“ru_Ru”,其中“,”用于分隔小数位。我将其更改为“ba_Ru”(仅适用于“详细设置-> 数字”),并且浮点类型的值在我的专家系统中变得正确。但是现在我在打开文件时遇到了一些问题,其中包括西里尔文。我不得不重命名一些文件夹和文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 2014-07-01
    • 1970-01-01
    • 2014-07-09
    • 2020-01-17
    • 2010-11-03
    相关资源
    最近更新 更多