0

I have a small script/code and i want to impose some active constraints. In the code shown below, i have P[I,J] #= E and in the next line Result[I,E] #= J but this is throwing an instantiation error because E is not instantiated.

For these constraints i need to know what value is at P[I,J], so if i write it as E is P[I,J] then offcourse i will not get an instantiation error(incase i suspend next two constraints with suspend, e.g suspend:(P[I,J] #= E) but will it effect the activeness of a constraint because the assignment will not be delayed but only constraint will be delayed. Is there any alternative way to impose this constraint?

multifor([I,J] ,[1,1],[N,N]),param(P,ResultFirst),foreach(E,_) do
            E #:: 1..9,
            P[I,J] #= E,
           (ResultFirst[I,E] #= J),
jschimpf
  • 4,904
  • 11
  • 24
Luai Ghunim
  • 976
  • 7
  • 14
  • why do you need to delay the index assignment? Indeed when you have a suspension, the delayed assignment will happen automatically! – OmG May 25 '19 at 21:38
  • @OmG `suspend` library does not impose active constraints and even using the `suspend` would not solve the problem. – Luai Ghunim May 25 '19 at 21:39
  • I didn't say that using any specific library, I said that you have an extra level that you don't need to solve the problem. – OmG May 25 '19 at 21:43

1 Answers1

1

It would be nice if one could just write it the way you have done, but unfortunately this is currently not supported (assuming you are using ECLiPSe). If the array index E is uninstantiated at constraint setup time, you have to use an element/3 constraint. So, instead of

ResultFirst[I,E] #= J

write

element(E, ResultFirst[I], J)
jschimpf
  • 4,904
  • 11
  • 24
  • Thank you very much. I think that `ResultFirst[i]` will take a one dimensional array out(of 2D array) and then element/3 will be invoked. Is it correct? – Luai Ghunim May 25 '19 at 23:03
  • Is it possible to use this solution for a column? I mean for `ResultFirst[E,J] #= I`? I can't figure out how to get the colum out without row. – Luai Ghunim May 31 '19 at 06:12
  • Ok I used this trick and it seems fine :) ` element(E,ResultFirst[1..N,J],I)` – Luai Ghunim May 31 '19 at 06:20
  • 1
    If you have at least ECLiPSe version 7.0, you can abbreviate the `1..N` with a `*`, i.e. `element(E,ResultFirst[*,J],I)` – jschimpf May 31 '19 at 13:29