forum.alglib.net

ALGLIB forum
It is currently Sat Dec 21, 2024 4:14 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Matrix constraints
PostPosted: Wed Aug 24, 2022 8:15 am 
Offline

Joined: Fri Jul 08, 2022 1:16 pm
Posts: 3
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.


Top
 Profile  
 
 Post subject: Re: Matrix constraints
PostPosted: Thu Aug 25, 2022 9:30 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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


Top
 Profile  
 
 Post subject: Re: Matrix constraints
PostPosted: Fri Aug 26, 2022 9:43 am 
Offline

Joined: Fri Jul 08, 2022 1:16 pm
Posts: 3
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;
}


Top
 Profile  
 
 Post subject: Re: Matrix constraints
PostPosted: Fri Aug 26, 2022 4:38 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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).


Top
 Profile  
 
 Post subject: Re: Matrix constraints
PostPosted: Mon Aug 29, 2022 7:29 am 
Offline

Joined: Fri Jul 08, 2022 1:16 pm
Posts: 3
Thanks a lot! This did the trick.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group