I want to use Gurobi solver in Matlab, but I don't know how to calculate the required matrices (qrow and qcol).

For your reference I am copying the example provided in documentation.

0.5 x^2 - xy + y^2 - 2x - 6y
subject to
x + y <= 2
-x + 2y <= 2 2x + y <= 3 x >= 0, y >= 0

c = [-2 -6]; objective linear term

objtype = 1; minimization

A = sparse([1 1; -1 2; 2 1]); % constraint coefficients

b = [2; 2; 3]; % constraint right-hand side

lb = []; [ ] means 0 lower bound

ub = []; [ ] means inf upper bound

contypes = '$<<

vtypes = [ ]; [ ] means all variables are continuous

QP.qrow = int32([0 0 1]); indices of x, x, y as in (0.5 x^2 - xy + y^2); use int64 if sizeof(int) is 8 for you system

QP.qcol = int32([0 1 1]); indices of x, y, y as in (0.5 x^2 - xy + y^2); use int64 if sizeof(int) is 8 for you system

QP.qval = [0.5 -1 1]; coefficients of (0.5 x^2 - xy + y^2)

Does it mean that if I have 4 decision varaibles than i should use 0,1,2,3 as indices for my decision variables x_1, x_2, x_3, x_4.?

Thanks

Note: I tried to use mathurl.com but I don't get how to write in proper format show that it will appear as latex text. Sorry for the notation.

asked 11 Mar '11, 23:35

Shailesh's gravatar image

Shailesh
111
accept rate: 0%


I'm not sure this is the right forum to ask questions about usage of a particular piece of software i.e. Gurobi; try this mailing list instead: http://groups.google.com/group/gurobi

That said, it seems to me that qrow and qcol are interchangeable. The quadratic expression is obtained through a element-wise multiplication of qrow, qcol and qval.

For instance, suppose we have the following expression (where the variables are x0, x1, x2 and x3):

2*x0^2 + 0.2*x0*x3 + 0.1*x0*x2 + x2^2 + 3x1*x3 + 5*x3^2

From the instructions given, I would write the coefficients in qval:

qval = [ 2 0.2 0.1 1 3 5 ]

And qrow, qcol would simply be:

qrow = [ 0 0 0 2 1 3 ]
qcol = [ 0 3 2 2 3 3 ]

If I would assume then that the quadratic part of the objective is then reconstructed as follows:

Quads = sum(qval .* x(qrow) .* x(qcol));

where x is some vector with 0...n indexing (n being the number of terms minus 1).

link

answered 12 Mar '11, 04:10

Gilead's gravatar image

Gilead ♦
2.3k513
accept rate: 15%

Nothing wrong with questions on particular software, though I agree that a gurobi specific group might work better.

(12 Mar '11, 09:09) Michael Trick ♦♦

Thank you very much for the detailed explanation.

(12 Mar '11, 20:39) Shailesh
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×190

Asked: 11 Mar '11, 23:35

Seen: 2,505 times

Last updated: 12 Mar '11, 04:10

OR-Exchange! Your site for questions, answers, and announcements about operations research.