Package minimise :: Module constraint_linear
[hide private]
[frames] | no frames]

Source Code for Module minimise.constraint_linear

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2003 Edward d'Auvergne                                        # 
 4  #                                                                             # 
 5  # This file is part of the program relax.                                     # 
 6  #                                                                             # 
 7  # relax is free software; you can redistribute it and/or modify               # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation; either version 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax is distributed in the hope that it will be useful,                    # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23   
24  from Numeric import dot, matrixmultiply 
25   
26   
27 -class Constraint_linear:
28 - def __init__(self, A=None, b=None):
29 """Class for the creation of linear inequality constraint functions and gradients. 30 31 The constraints are in the form: 32 33 A.x >= b 34 35 where: 36 A is an m*n matrix where the rows are the transposed vectors, ai, of length 37 n. The elements of ai are the coefficients of the model parameters. 38 39 x is the vector of model parameters of dimension n. 40 41 b is the vector of scalars of dimension m. 42 43 m is the number of constraints. 44 45 n is the number of model parameters. 46 47 48 eg if 0 <= q <= 1, q >= 1 - 2r, and 0 <= r, then: 49 50 | 1 0 | | 0 | 51 | | | | 52 |-1 0 | | q | | -1 | 53 | | . | | >= | | 54 | 1 2 | | r | | 1 | 55 | | | | 56 | 0 1 | | 2 | 57 """ 58 59 # Initialise arguments. 60 self.A = A 61 self.b = b
62 63
64 - def func(self, x):
65 """The constraint function. 66 67 A vector containing the constraint values is returned. 68 """ 69 70 return dot(self.A, x) - self.b
71 72
73 - def dfunc(self, x):
74 """The constraint gradient. 75 76 As the inequality constraints are linear, the gradient matrix is constant and equal to the 77 coefficient matrix A. Therefore this function simply returns the matrix. 78 """ 79 80 return self.A
81