Marcin
Marcin

Reputation: 1

How to introduce into optimization algorithm a linear constraint which involves calculated variables which depend on decision variables

An optimization problem consists of an objective function which should be minimized, 10 decision variables (from x(1) to x(10)) and some constraints.

In the objective function some additional variables are calculated, i.e.

Variable1=5*x(5)+x(1)*10-25
Variable2=x(1)=5*x(2)+50*x(10)

etc.

The problem is that I want to put both above calculated variables (Variable1 and Variable2) which are functions of decision variables into the constraints function. For example:

Variable1>=100
Variable2<50

To do this I am trying to put these conditions into the constraint function:

function [c,ceq] = constraints(x)
c = [-Variable1+100;
Variable2-50;];

ceq = [];

I know that these constraints are linear, but it is impossible to put them as linear constraints =>A*X<b, because linear constraints can contain only decision variables.

In this form the fmincon algorithm does not take into account the above conditions. How can I add these constraints anyway?

Upvotes: 0

Views: 135

Answers (1)

Adam
Adam

Reputation: 2777

Variable1 = 5*x(5) + x(1)*10 -25

Write Variable1 including all the decision variables, the missing ones have 0 as coefficient

Variable1 = 10*x(1) + 0*x(2) + 0*x(3) + 0*x(4) + 5*x(5) + ...
            0*x(6) + 0*x(7) + 0*x(8) + 0*x(9) + 0*x(10) -25

Variable1 >=100

10*x(1) + 0*x(2) + 0*x(3) + 0*x(4) + 5*x(5) + ...
0*x(6) + 0*x(7) + 0*x(8) + 0*x(9) + 0*x(10) -25 >= 100

left hand side should contain only decision variables
remove -25 from left side by adding +25 to both sides

10*x(1) + 0*x(2) + 0*x(3) + 0*x(4) + 5*x(5) + ...
0*x(6) + 0*x(7) + 0*x(8) + 0*x(9) + 0*x(10)  >= 100 + 25

change >= to <= by multiplying both sides by -1

-10*x(1) - 0*x(2) - 0*x(3) - 0*x(4) - 5*x(5) - ...
0*x(6) - 0*x(7) - 0*x(8) - 0*x(9) - 0*x(10)  <= -100 - 25
  • A first row: copy left hand side decision variable coefficients
A(1, :) = [-10, -0, -0, -0, -5, -0, -0, -0, -0, -0]
  • b first row: copy right hand side value
b(1, :) = -100-25;

Same logic for Variable2

Variable2 = x(1) + 5*x(2)+50*x(10)
Variable2 = x(1) + 5*x(2) + 0*x(3) + 0*x(4) + 0*x(5) + ...
            0*x(6) + 0*x(7) + 0*x(8) + 0*x(9) + 50*x(10)

Variable2 < 50

1*x(1) + 5*x(2) + 0*x(3) + 0*x(4) + 0*x(5) + ...
0*x(6) + 0*x(7) + 0*x(8) + 0*x(9) + 50*x(10) < 50
  • A second row
A(2, :) = [+1, +5, +0, +0, +0, +0, +0, +0, +0, +50]
  • b second row
b(2, :) = +50

Overall A and b

A = [-10, 0, 0, 0, -5, 0, 0, 0, 0, 0; 
     1, 5, 0, 0,  0,  0, 0, 0, 0, 50 ]  
b = [-125; 50]  

Upvotes: 1

Related Questions