Interior-point-optimisation  1.0-1
Interior-pointoptimisationlibrary
PhaseIBoundedVariableFunctionAndDerivatives.cc
Go to the documentation of this file.
1 /*
2  * $Id: PhaseIBoundedVariableFunctionAndDerivatives.cc 236 2014-11-30 14:09:06Z jdl3 $
3  * Copyright (C) 2013–14 John D Lamb
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 # include<config.h>
22 #endif
23 
25 
26 using namespace ipo_function::detail;
27 
30  bool const upperBound )
31  : FunctionBase { 2 }, function( function ), b { b },
33 {
34  functionGradient = gsl::vector( 2 );
35  if( upperBound ) functionGradient[0] = 1.0;
36  else functionGradient[0] = -1.0;
37  functionGradient[1] = -1.0;
38  functionHessian = gsl::matrix { 2, 2 };
39  functionHessian.set_all( 0.0 );
40 }
41 
42 double
44  if( vector.size() < 2 ) return 0; // do something sane
45 
46  double const& x { vector[0] };
47  double const& s { vector[1] };
48  if( upperBound )
49  return x - b - s;
50  else
51  return b - x - s;
52 }
53 
54 gsl::vector
56  return functionGradient;
57 }
58 
59 gsl::matrix
61  return functionHessian;
62 }
63 
64 void
66  if( vector.size() < 2 ){ functionValue = 0; return; } // do something sane
67 
68  double const& x { vector[0] };
69  double const& s { vector[1] };
70  if( upperBound )
71  functionValue = x - b - s;
72  else
73  functionValue = b - x - s;
74 }
double functionValue
The function value.
void setVector(gsl::vector const &vector)
Set a vector and compute function value, gradient and Hessian efficiently.
gsl::vector functionGradient
The gradient value.
double operator()(gsl::vector const &vector)
The function operator: computes or according as is an upper or lower bound.
Namespace for details of ipo_function that are not normally needed to construct and solve a convex op...
virtual gsl::matrix hessian() const
virtual gsl::vector gradient() const
gsl::matrix functionHessian
The Hessian value.
PhaseIBoundedVariableFunctionAndDerivatives(double const b, bool const upperBound)
Construct from a function and bound.
Base class for Function and DerivativesEstimates.
bool const upperBound
A boolean value: true or false according as b is an upper bound or lower.
data upperBound
Definition: Variable.cc:38