3

This is the equation that is given in the example:

The equation

and the code to replicate it in python is

>>> from cvxopt import matrix, solvers
>>> A = matrix([ [-1.0, -1.0, 0.0, 1.0], [1.0, -1.0, -1.0, -2.0] ])
>>> b = matrix([ 1.0, -2.0, 0.0, 4.0 ])
>>> c = matrix([ 2.0, 1.0 ])
>>> sol=solvers.lp(c,A,b)

Can anyone please explain how are the the data given to variables a, b, c?

Stephen Rauch
  • 1,783
  • 11
  • 21
  • 34
Sourav Roy
  • 141
  • 2

1 Answers1

1

Welcome to the site!

As Media has mentioned values of A,b,c are passed through those matrices. To understand it better I'm naming the constraints from top to bottom i.e., 1st constraint as constraints-1,......constraint-4.

Firstly, lets talk about matrix b which consists of all the values on the right hand side of the constraints i.e., 1,2,0,4. He converted all the constraints to $⩽$ by multiplying with -1 on both sides. So he multiplied with -1 for constraints-2 and 3.

Now the constraints-2 has changed from $x_1 + x_2 ⩾ 2$ to $-x_1 - x_2 ⩽ -2$

Values of Matrix b would be 1,-2,0(-0),4

Now lets go through the constraints i.e.,

  1. $-x_1 + x_2 ⩽ 1 $ for the coefficient of $x_1,x_2$ are -1 and 1. The values of Matrix A row 1 values are -1,1
  2. Similarly for row 2 to row 4 as you have 4 contraints.

Finally our objective function coefficients, are the values of c i.e., 2 and 1.

Do let me know if you have any more doubts.

Toros91
  • 2,352
  • 3
  • 14
  • 31
  • If you need some additional information let me know, or else can you help to accept the answer. Thanks in advance – Toros91 May 15 '18 at 08:10