Sometimes, in the context of a mathematical program, someone wants to use a variable xx to index a vector yy, as in z=y[x].z=y[x]. As a starting point, we should assume that xx is an integer variable whose domain equals, or at least is a subset of, the index set of yy. If you try to set z=y[2.71828]z=y[2.71828], or z=y[5]z=y[5] when yy is indexed by 1,…,41,…,4, you should expect Bad Things To Happen.
With that stipulation, z=y[x]z=y[x] poses no problem in a constraint program. It cannot, however, be expressed directly in a mathematical program. If the domain of xx is not too large, it can be implemented somewhat obliquely in a mathematical program using binary variables.
Let's assume that yy is indexed over 1,…,N1,…,N (with NN known at the outset), and that yy is a parameter. (We'll treat the case where yy is a variable in a minute.) Create NN binary variables x1,…,xNx1,…,xN and add the constraint x1+⋯+xN=1,x1+⋯+xN=1, which makes {x1,…,xN}{x1,…,xN} a type 1 special ordered set (SOS1). Then define zz via z=N∑i=1y[i]∗xi.z=N∑i=1y[i]∗xi.
You can do exactly this when yy is a vector of variables, but it adds a nonconvex quadratic constraint to the model, which likely prevents you from finding a guaranteed optimum, and greatly restricts what algorithms/software you can use. If we know a priori lower and upper bounds for yy, say Li≤y[i]≤Ui∀i∈1,…,NLi≤y[i]≤Ui∀i∈1,…,N with LiLi and UiUi parameters, we can add the xixi as above and use the following set of constraints to define zz: y[i]−z≤(Ui−ˆL)(1−xi)∀i∈1,…,Ny[i]−z≥(Li−ˆU)(1−xi)∀i∈1,…,Nwhere ˆL=mini=1,…,NLi and ˆU=maxi=1,…,NUi.
No comments:
Post a Comment
Due to intermittent spamming, comments are being moderated. If this is your first time commenting on the blog, please read the Ground Rules for Comments. In particular, if you want to ask an operations research-related question not relevant to this post, consider asking it on Operations Research Stack Exchange.