I am trying to solve a specific problem using prologs constraint solvers, and I’m stuck 😀
A more general version of my problem requirement is the like this:
:- lib(ic).:- lib(ic).
solve( [A1*X+B1*Y=C1, A2*X+B2*Y=C2] ):-
X::[0..999],
Y::[0..999],
X #\= 0,
Y #\= 0,
A1*X+B1*Y#=C1, % line1
A2*X+B2*Y#=C2. % line2
And this is the query/goal I use:
solve( [2*X+3*Y=5, 3*X+2*Y=5] ).
And the program will compute the values of X and Y (in this case X=1, Y=1 is the solution).
What I am thinking is, what if the number of arguments in the goal/query can vary..in this case, my prolog program needs to have a dynamic suspended goals in place of lines commented with %line1 and %line2..
Question is, how do i make these expressions delayed..? I do not want to hard code these in the problem and think that only two expressions will be passed over through the goal..
Hope the question is clear.
Thanks.
I think you mean something like:
Note that this is ECLiPSe-CLP specific code (the foreach-loop which could be translated to a recursive helper predicate, of course, and the IC library).
Also note that
call(Eq0)and writing justLhs #= Rhsshould have the same effect (afaik). But when the variables inLhs #= Rhsare solver variables, that seems not to the case, at least I encountered such a problem some months ago usinglib(cplex).