forum.alglib.net
http://forum.alglib.net/

Matrix constraints
http://forum.alglib.net/viewtopic.php?f=2&t=4473
Page 1 of 1

Author:  dzuniman [ Wed Aug 24, 2022 8:15 am ]
Post subject:  Matrix constraints

I have a quadratic programming problem in C#.
I am solving for 4 variables X = [x1,x2,x3,x4] subject to a constraint with -1 < (X*R - Y)T < 1. R is a 4x6 matrix, Y is a vector of 6 values and T is a vector of 6 values.
Can you please assist me how I can archive this. I believe the constraint is linear but not sure how to represent it. Please assist.
X is transposed.

Author:  Sergey.Bochkanov [ Thu Aug 25, 2022 9:30 pm ]
Post subject:  Re: Matrix constraints

Hi!

If the only unknown in your problem is X (i.e. Y is known and fixed), then you should simply pass R^T to the minqpsetlc2() function. If Y is also unknown, i.e. you solve for both X and Y, then you should augment R^T with minus identity matrix -I, i.e. append it (not add!) to R^T.

Sergey

Author:  dzuniman [ Fri Aug 26, 2022 9:43 am ]
Post subject:  Re: Matrix constraints

X = [x1, x2, x3, x4]
R = {[R11, R12, R13, R14, R15, R16],
[R21, R22, R23, R24, R25, R26],
[R31, R32, R33, R34, R35, R36],
[R41, R42, R43, R44, R45, R46]}
L = [L1, L2, L3, L4, L5, L6]
T = [T1, T2, T3, T4, T5, T6]

Constraint = (X * R - L)*T = 0

X is what I am trying to solve with the given constraint. R, L and T are fixed.
Below is a snap of my code. Please give me an example code how I can include the constraint.

public double[] Optimize()
{
double[] x = new double[] { 0, 0, 0, 0 };
double[] s = new double[] { 1, 1, 1, 1 };
double[] lb = new double[] { 0, 0, 0, 0};
double[] ub = new double[] { double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity };
double epsx = 0.0000000001;
int maxits = 0;

alglib.minlmstate state;
alglib.minlmreport rep;

alglib.minlmcreatev(4, x, 0.0001, out state);
alglib.minlmsetbc(state, lb, ub);
alglib.minlmsetcond(state, epsx, maxits);
alglib.minlmsetscale(state, s);

alglib.minlmoptimize(state, Objective, null, null);

alglib.minlmresults(state, out x, out rep);

return x;
}

Author:  Sergey.Bochkanov [ Fri Aug 26, 2022 4:38 pm ]
Post subject:  Re: Matrix constraints

Hi!

The answer depends on whether multiplication by T in (X * R - L)*T is a scalar product or a component-wise product.

In the former case your formula reduces to just one linear equality: dot_product(X,R*T) = dot_product(L,T). You have to precompute transposed matrix-vector product transp(R*T) - it will be a left part of your single-row linear constraint matrix. And you have to compute a product of L and T - it will be its constant right part. Then call minlmsetlc(), with both values packed into its parameter C.

In the latter case (component-wise product) you have 6 equality constraints (as many as you have components in T).

Author:  dzuniman [ Mon Aug 29, 2022 7:29 am ]
Post subject:  Re: Matrix constraints

Thanks a lot! This did the trick.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/