Hi all,
I am running a constraint satisfaction problem with ILOG. For my problem, I would want to run an incremental counter within the "subject to" section. I was wondering if there are anyway for me to do that.
To elaborate more, below is a section of my code:
forall(w in 1..(NoOfRows1)) {
forall(t in (w+1)..NoOfRows) {
forall(i in 1..NoOfColumns) {
(1*Pairwise[j][i]) + Assignment[w][i] + Assignment[t][i] <= 1;
(2*Pairwise[j][i])  Assignment[w][i]  Assignment[t][i] <= 0;
}
j++; < I need an incremental counter here so that the correct decision variable could be assigned.
}
}
I was wondering in ILOG, how can I code in the j++ ?
I apologize if this is a simple problem. I am a very new user of ILOG and I am working on a school project with the software.
Thank you for reading.
Topic

Re: How to run an incremental counter within "subject to"
20130118T13:24:53ZThis is the accepted answer. This is the accepted answer.Hello.
OPL is a declarative language. I.e., like in math, variables cannot change their value. This is allowed only in execute block.
A solution is to replace every occurrence of j by an expression that evaluates to the right value. In your case, I think that the right expression is (if you want to use it inside forall over t):
w*NoOfRows  ((w*(w+1)) div 2) + tw
I hope it helps, Petr 
Re: How to run an incremental counter within "subject to"
20130118T13:36:00ZThis is the accepted answer. This is the accepted answer.Hi
The most pertaining to OPL is to declare a tupleset S of <w, t, j> and used it in the constraint declaration:
forall(s in S) {
forall(i in 1..NoOfColumns) {
(1*Pairwisehttp://s.j[i]) + Assignmenthttp://s.w[i] + Assignmenthttp://s.t[i] <= 1;
(2*Pairwisehttp://s.j[i])  Assignmenthttp://s.w[i]  Assignmenthttp://s.t[i] <= 0;
}
j++; < I need an incremental counter here so that the correct decision variable could be assigned.
}
}
<code>
Hope that helps 
Re: How to run an incremental counter within "subject to"
20130118T13:42:00ZThis is the accepted answer. This is the accepted answer.Sorry for the typos of the last message. The OPL code should look like:
forall(s in S, i in 1..NoOfColumns) { (1*Pairwise[s.j[[i]) + Assignment[s.w][i] + Assignment[s.t][i] <= 1; (2*Pairwise[s.j][i])  Assignment[s.w][i]  Assignment[s.t][i] <= 0; }

Re: How to run an incremental counter within "subject to"
20130119T07:24:43ZThis is the accepted answer. This is the accepted answer.Thanks for all the prompt responses. Appreciate them greatly.
Actually I think I have made a mistake in my previous code.
The basic form of the loop will be as such:
forall(w in 1..(NoOfRows1)) {
forall(t in (w+1)..NoOfRows) {
forall(i in 1..NoOfColumns) {
(1*Pairwise[j][i]) + Assignment[w][i] + Assignment[t][i] <= 1;
(2*Pairwise[j][i])  Assignment[w][i]  Assignment[t][i] <= 0;
}
}
}
The problem comes with assigning j. To reiterate, when w = 1, t = 2, I would need j = 1. Take for example my NoOfRows = 4, so as the loop runs, the j will need to go as follows:
w=1,t=2, j=1
w=1,t=3, j=2
w=1,t=4, j=3
w=2,t3, j=4
w=2,t=4, j=5
w=3,t=4, j=6
Apologize for not being clear enough.
Thank you Petr and GGR for your replies, I will study your replies carefully. 
Re: How to run an incremental counter within "subject to"
20130121T10:31:21ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20130119T07:24:43Z
Thanks for all the prompt responses. Appreciate them greatly.
Actually I think I have made a mistake in my previous code.
The basic form of the loop will be as such:
forall(w in 1..(NoOfRows1)) {
forall(t in (w+1)..NoOfRows) {
forall(i in 1..NoOfColumns) {
(1*Pairwise[j][i]) + Assignment[w][i] + Assignment[t][i] <= 1;
(2*Pairwise[j][i])  Assignment[w][i]  Assignment[t][i] <= 0;
}
}
}
The problem comes with assigning j. To reiterate, when w = 1, t = 2, I would need j = 1. Take for example my NoOfRows = 4, so as the loop runs, the j will need to go as follows:
w=1,t=2, j=1
w=1,t=3, j=2
w=1,t=4, j=3
w=2,t3, j=4
w=2,t=4, j=5
w=3,t=4, j=6
Apologize for not being clear enough.
Thank you Petr and GGR for your replies, I will study your replies carefully.
((2*noOfRows  w) * (w1)) div 2 + t  w
Petr 
Re: How to run an incremental counter within "subject to"
20130121T11:02:21ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20130121T10:31:21Z
I see, I made a mistake in the expression. The right expression should be:
<pre class="jivepre">((2*noOfRows  w) * (w1)) div 2 + t  w
</pre>
Petr
Thank you Petr.