Hi Neng-Fa,
My usage is more complex, this was a minimal reproducing example. These situations appear in ASPIC when it translates ASP aggregators, say
#sum{Y:gen(Y),test(Y)}>5.
When in the ASP program there are these as well
gen(1..2).
test(2..3).
the predicate involving the aggregator expression gets translated to Picat as the following constraint expression:
aspic_gt(aspic_sum([ASPIC_OPTCOND3:Y in 1..2,Y in 2..3,ASPIC_OPTCOND1=aspic_conj([gen(Y),test(Y)]),ASPIC_OPTCOND2#=ASPIC_OPTCOND1,ASPIC_AGVAL1= Y, ASPIC_AGVAL2#=ASPIC_AGVAL1,ASPIC_OPTCOND3 #= cond(ASPIC_OPTCOND2,ASPIC_AGVAL2,0)]) ,5)
where gen/1,test/1,aspic_conj/2,aspic_gt/2,aspic_sum/1 are functions returning either 0,1 or constraint variables.
This is the workaround I found to basically use functions into constraints: Var=function_call(Args), Var2#=Var,... then Var2 can be used in further constraints.
"cond" is used to apply the condition in a constraint way. I could replace cond with multiplication Condition*Value, but I doubt multiplication leads to more efficient modelling, and I still need functions in constraints, so I have to use the workaround explained above.
best regards,
CG