Search code examples
constraint-programmingeclipse-clp

Listing all constraints in Eclipse CLP in a readable form


I have an ECLiPSe script whose goal is to encode my problem into a set of arithmetic constraints. In REPL, I eventually get a list of delayed goals which looks as follows:

-(_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
...

Is there a predicate that would give me a similar readable list of constraints in the constraint store?

delayed_goals gives some library-specific constraints (like prop_ic_con(ic_con(... <some special characters> etc )) rather than the clean output as in the above listing. I need to output it to a file from a shell script, not from the interactive loop which hides delayed goals by default.


Solution

  • The translation from an internal goal to a readable one is performed by a goal-portray-transformation. The output predicates printf and write_term can optionally invoke this translation, e.g.

    ?- 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
    

    You can also invoke the translation explicitly using 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)