How to compute a definite sum of a vector as an LP constrain
4 views (last 30 days)
My own model is very large and complex so I will try to explain the problem by a simple example: The vector P is a V:1 vector. Each element of P is a positive real number. The following linear programme problem needs to be solved:
%optimization variable x:
%Objective function f:
If one solves the optimization problem above, the optimization variable outcome x will be a V:1 vector with all elements having a value of -1.
Now I want to put a constrain on the definite sum of each element. i.e. the sum of vector elements should never exceed the boundary -3: . (note that I don't want to constrain the total sum of vector x () but only the sum up to the t-th element.
I tried introducing the following auxiliary variable to compute the constrain:
%create auxiliary variable
When I put in the constraint, and run the solver, the optimal solution is found. However, the constraint is not taken into account by the solver since each element of vector x has a value of -1.. Is there anyone that knows a way to resolve this problem??
Swatantra Mahato on 11 Sep 2020
I am assuming you want
w(t) = sum(x(1:t))
for all values of t from 1 to V. In order to do that you may want to insert the above statement inside the for loop. The loop would change as follows:
MATLAB then compares every element of w with –3.
As an example for V=5 and P= [88.0224, 98.9022, 1.0517, 86.6784, 61.6441]
we get x=[ -1,-1,1,-1,-1]
Hope this helps