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
This topic has been locked.
6 replies
Latest Post
 20130121T11:02:21Z by SystemAdmin
ACCEPTED ANSWER
Pinned topic How to run an incremental counter within "subject to"
20130118T11:10:26Z

Answered question
This question has been answered.
Unanswered question
This question has not been answered yet.
Updated on 20130121T11:02:21Z at 20130121T11:02:21Z by SystemAdmin

ACCEPTED ANSWER
Re: How to run an incremental counter within "subject to"
20130118T13:24:53Z in response to SystemAdminHello.
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 
ACCEPTED ANSWER
Re: How to run an incremental counter within "subject to"
20130118T13:36:00Z in response to SystemAdminHi
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 
ACCEPTED ANSWER
Re: How to run an incremental counter within "subject to"
20130118T13:42:00Z in response to SystemAdminSorry 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; }

ACCEPTED ANSWER
Re: How to run an incremental counter within "subject to"
20130119T07:24:43Z in response to SystemAdminThanks 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.
ACCEPTED ANSWER
Re: How to run an incremental counter within "subject to"
20130121T10:31:21Z in response to SystemAdminI see, I made a mistake in the expression. The right expression should be:
((2*noOfRows  w) * (w1)) div 2 + t  w
Petr
ACCEPTED ANSWER
Re: How to run an incremental counter within "subject to"
20130121T11:02:21Z in response to SystemAdminOk. Got it to work.
Thank you Petr.

