【问题标题】:Listing all constraints in Eclipse CLP in a readable form以可读的形式列出 Eclipse CLP 中的所有约束
【发布时间】:2017-02-09 17:19:27
【问题描述】:

我有一个 ECLiPSe 脚本,其目标是将我的问题编码为一组算术约束。在 REPL 中,我最终得到一个延迟目标列表,如下所示:

-(_2941{4 .. 7})   + _2900{1 .. 4} #=< 0
_2941{4 .. 7}      - _2900{1 .. 4} #= 3
-(_3393{7 .. 21})  + _3352{4 .. 18} #=< 0
_3393{7 .. 21}     - _3352{4 .. 18} #= 3
_3845{14 .. 17}    - _3804{4 .. 7} #= 10
_4297{18 .. 21}    - _4256{14 .. 17} #= 4
-(_4749{19 .. 22}) + _4708{18 .. 21} #=< 0
_4749{19 .. 22}    - _4708{18 .. 21} #= 1
...

是否有一个谓词可以在约束存储中为我提供类似的可读约束列表?

delayed_goals 给出了一些特定于库的约束(比如prop_ic_con(ic_con(... &lt;some special characters&gt; etc )),而不是上面清单中的干净输出。我需要将它从 shell 脚本输出到文件,而不是从隐藏延迟目标的交互式循环中输出默认情况下。

【问题讨论】:

    标签: constraint-programming eclipse-clp


    【解决方案1】:

    从内部目标到可读目标的转换是由一个 目标-portray-转换。输出谓词 printfwrite_term 可以选择调用这个翻译,例如

    ?- 3*X+6*Y #> 9, delayed_goals([G]), printf("%Gmw", [G]), nl.
    6 * Y{-1.0Inf .. 1.0Inf} + 3 * X{-1.0Inf .. 1.0Inf} #> 9
    
    ?- 3*X+6*Y #> 9, delayed_goals([G]), write_term(G, [as(goal)]), nl.
    6 * Y{-1.0Inf .. 1.0Inf} + 3 * X{-1.0Inf .. 1.0Inf} #> 9
    

    您也可以使用portray_term/3 显式调用翻译:

    ?- 3*X+6*Y #> 9, delayed_goals([G]), portray_term(G, P, goal).
    G = prop_ic_con(ic_con(...))
    P = (6 * Y{-1.0Inf .. 1.0Inf} + 3 * X{-1.0Inf .. 1.0Inf} #> 9)
    

    【讨论】:

    • 感谢一百万 @jschimpf!有很多方法可以满足我的需要!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多