1

I get an error in a OPL model when I use that constraint:

forall (j1,j2 in p: row[j1]==row[j2] && j1<j2) 

where row is a variable:

dvar int row [p];

The error is like this:

Decision variable row not allowed. 

I don't know why this is not possible, but how can fix this problem?

Xavier Nodet
  • 5,033
  • 2
  • 37
  • 48
Carl
  • 53
  • 1
  • 7
  • Thanks, for the works – Carl Mar 27 '19 at 12:18
  • Hi @G.S. if this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Xavier Nodet Apr 05 '19 at 00:31

1 Answers1

2

The condition is slicing should be bound and should not contain any decision variable. You should rely on logical constraints:

range p=1..4;

dvar int row[p] in p;

subject to
{
 forall(j1,j2 in p) ((row[j1]==row[j2] ) => (row[j1]>=2));
}

This works fine.

halfer
  • 19,824
  • 17
  • 99
  • 186
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Ok, but this is a linear constraint or not? – Carl Mar 27 '19 at 12:17
  • This is a logical constraint. And this will work fine. – Alex Fleischer Mar 27 '19 at 13:23
  • Yeah I know all work, but I don't know if it is a linear constraint theoretical speaking. Because I need to have all like linear constraint. – Carl Mar 27 '19 at 19:52
  • Strictly speaking, a logical constraint is not really a linear constraint. But as it can easily be transformed into a linear constraint (and CPLEX will do it automatically -- https://www.ibm.com/support/knowledgecenter/en/SSSA5P_12.9.0/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_constraints_types_logical.html), the distinction is usually not done. – Xavier Nodet Apr 05 '19 at 00:28