5

I'm trying to implement the following in AMPL:

$$ i \in [N], j \in[N] \backslash \{i\}, t \in [T] $$

I have so far written the following:

subject to Con{i in PP,t in TT, j in PP : j != i}:

but it does not feel correct, is it? I also have a question about implementing this: $$ i \neq j,t $$ in a constraint, i'm only getting one to work:

subject to {i in PP,t in TT, j in PP : j != i}:
  • 3
    Load your model and data such that they don't use the solve command. Then do a displayon the set operations that you want to validate. example you could try display {i in PP,t in TT, j in PP : j != i}; to check if you are getting the correct selection from the sets. – prash Feb 01 '20 at 06:24
  • @prash Column 1 newer equals column 3, which is correct. Tried to copy the result in here, but it got messy ;) – Ulrich_Peters Feb 01 '20 at 06:33
  • Your first constraint syntax looks correct to me. Are you getting an error, or you're just second-guessing yourself? For your second question, I am not sure what you are asking. Your constraint looks the same as the first one (except that you are missing a constraint name) – LarrySnyder610 Feb 01 '20 at 14:02

2 Answers2

2

This looks most like the math (and avoids checking for every $(i,j,t)$ a logical condition that depends only on $i$ and $j$):

{i in PP, j in PP diff {i}, t in TT}
RobPratt
  • 32,006
  • 1
  • 44
  • 84
1

Try the following syntax:

subject to cons {i in PP,t in TT, j in PP : j diff i}:

Or

subject to cons {i in PP,t in TT, j in PP : j<>i}:
Oguz Toragay
  • 8,652
  • 2
  • 13
  • 41