Topic
  • 6 replies
  • Latest Post - ‏2013-01-21T11:02:21Z by SystemAdmin
SystemAdmin
SystemAdmin
623 Posts

Pinned topic How to run an incremental counter within "subject to"

‏2013-01-18T11:10:26Z |
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..(NoOfRows-1)) {
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.
Updated on 2013-01-21T11:02:21Z at 2013-01-21T11:02:21Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    623 Posts

    Re: How to run an incremental counter within "subject to"

    ‏2013-01-18T13:24:53Z  
    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) + t-w
    


    I hope it helps, Petr
  • GGR
    GGR
    70 Posts

    Re: How to run an incremental counter within "subject to"

    ‏2013-01-18T13:36:00Z  
    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
  • GGR
    GGR
    70 Posts

    Re: How to run an incremental counter within "subject to"

    ‏2013-01-18T13:42:00Z  
    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; 
    }
    
  • SystemAdmin
    SystemAdmin
    623 Posts

    Re: How to run an incremental counter within "subject to"

    ‏2013-01-19T07: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..(NoOfRows-1)) {
    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,t-3, 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.
  • SystemAdmin
    SystemAdmin
    623 Posts

    Re: How to run an incremental counter within "subject to"

    ‏2013-01-21T10:31:21Z  
    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..(NoOfRows-1)) {
    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,t-3, 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.
    I see, I made a mistake in the expression. The right expression should be:
    
    ((2*noOfRows - w) * (w-1)) div 2 + t - w
    


    Petr
  • SystemAdmin
    SystemAdmin
    623 Posts

    Re: How to run an incremental counter within "subject to"

    ‏2013-01-21T11:02:21Z  
    I see, I made a mistake in the expression. The right expression should be:
    <pre class="jive-pre"> ((2*noOfRows - w) * (w-1)) div 2 + t - w </pre>

    Petr
    Ok. Got it to work.
    Thank you Petr.