1

I am trying to do something that logically should be possible to do. However, I am not sure how to do this within the realm of linear programming. I am using ZMPL/SCIP, but this should be readable to most.

set I := {1,2,3,4,5};
param u[I] := <1> 10, <2> 20, <3> 30, <4> 40, <5> 50;

var a;
var b;

subto bval:
  b == 2;

subto works:
  a == u[2];

#subto does_not_work:
#  a == u[b];

I am trying to make sure that the variable a is equal to the value at the index b in u. So for example, I ensure that b == 2 and then I try to set the constraint that a == u[b], but that does not work. It complains that I am trying to index with a variable. I am able to just do a == u[2] however, which makes a equal to 20.

Is there a way to easily access u at an index specified by a variable? Thanks for any help/guidance.


EDIT: I think the consensus is that this is not possible because it no longer becomes an LP. In that case, can anyone think of another way to write this so that, depending on the value of b, I can get an associated value from the set u? This would have to avoid directly indexing it.

gnychis
  • 267
  • 1
  • 3
  • 9

1 Answers1

1

In most general programming languages, you would be able to do what you are trying to do. I'm not familiar with the language you mention, but I can see why a language which is specialized for linear programming might not allow this. Linear programming problems are of the form: Here's a set of variables, and here's a set of linear constraints in these variables. The condition a == u[b] is not a linear constraint in b.

It's true that because you have b == 2, then it's equivalent to a == u[2] which is linear in the variables (treating u[2] as a single variable), but the parser probably does not reason that deeply.

Ted
  • 33,788
  • Is there a linear way that you can think of for b to take on the value that I want it to take on? I'm stuck trying to figure out some other way to represent this. – gnychis Jul 21 '13 at 06:34
  • @gynchis What you are trying to do? It seems weird to have a constraint on an array index variable in a linear programming problem. Among other things, the variables in a linear programming problem are real variables, while index variables are restricted to be integral. – Ted Jul 21 '13 at 07:03
  • I guess in my mind what I'm trying to do isn't difficult, but it's difficult in the realm of the LP. I'm really just trying to fetch a specific value based on the value of a variable. I thought I could contain them in a set and index them based on the variable, but I can't. Really looking for any other way to do something similar. – gnychis Jul 21 '13 at 07:05