Update of /cvsroot/lprof/lprof/src/solvopt
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27463/solvopt
Added Files:
SConscript apprgrdn.c solvopt.c solvopt.h
Log Message:
Added SolvOpt optimizer.
--- NEW FILE: solvopt.h ---
/*
* $Id: solvopt.h,v 1.1 2007/03/16 21:58:45 gfuer Exp $
*
* SOLVOPT version 1.1 (June, 1997)
* by Alexei Kuntsevich and Franz Kappel
* University of Graz, Austria
*
* http://www.uni-graz.at/imawww/kuntsevich/solvopt
*
* Modified by Gerhard Fuernkranz for use in lprof
*
* With the kind permisson of the authors, SolvOpt is distributed
* as part of lprof under the terms of the GNU GPL.
*
* Lieber Herr Fürnkranz,
* Ihre Frage bezüglich der Nutzung von SolvOpt kann ich mit "ja"
* beantworten. Wir haben den Begriff "freeware" in diesem Sinne
* verstanden.
*
* Mit freundlichen Grüßen,
* F. Kappel
*
* -----Ursprüngliche Nachricht-----
* Von: gfuer@... [mailto:gfuer@...]
* Gesendet: Dienstag, 13. März 2007 23:10
* An: Kappel, Franz (franz.kappel@...)
* Betreff: Frage zur SolvOpt-Nutzung
*
* Sehr geehrter Herr Kappel,
*
* auf der Solvopt-Home-Page schreiben Sie "SolvOpt is a freeware...". Da
* "Freeware" jedoch kein genau definierter, rechtsgültiger Begriff ist,
* und ich auch in den Sourcen keine Copyright-Vermerke und/oder
* Nutzungsbedingungen finde, möchte ich gerne bei Ihnen explizit anfragen,
* ob Sie zustimmen würden, dass der SolvOpt-Quellcode unter den
* Bedingungen der GNU GPL benutzt und weiterverteilt werden darf, sodass
* eine Integration mit anderen freien Softwareprogrammen, die ebenfalls
* der GNU GPL untestellt oder GLP-kompatibel sind, ermöglicht wird.
*
* Mit freundlichen Grüßen,
* Gerhard Fürnkranz
*
* THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL MARTI MARIA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
* This file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __solvopt_H
#define __solvopt_H
typedef double SOLVOPTOPTIONS[13];
extern double
cmsxSolvOpt(unsigned short n, double x[],
double fun(void *, double[]), void grad(void *, double[], double[]),
SOLVOPTOPTIONS options,
double func(void *, double[]), void gradc(void *, double[], double[]),
void *cargo);
extern void
cmsxApprGrdn(void *cargo, unsigned short n,
double g[], double x[], double f,
double fun (void *, double[]),
double deltax[], unsigned obj);
void
cmsxSolvOptInitOptions(SOLVOPTOPTIONS options);
/*
options[0]= H, where sign(H)=-1 resp. sign(H)=+1 means minimize
resp. maximize FUN (valid only for unconstrained problem)
and H itself is a factor for the initial trial step size
(options[0]=-1.e0 by default),
options[1]= relative error for the argument
in terms of the max-norm (1.e-4 by default),
options[2]= relative error for the function value (1.e-6 by default),
options[3]= limit for the number of iterations (15000 by default),
options[4]= control of the display of intermediate results and
error resp. warning messages (default value is 0,
i.e., no intermediate output but error and warning
messages),
options[5]= admissible maximal residual for a set of constraints
(options[5]=1.e-8 by default),
@options[6]= the coefficient of space dilation (2.5 by default),
@options[7]= the lower bound for the stepsize used for the finite
difference approximation of gradients (1.e-11 by default).
(@ ... changes should be done with care)
Returned optional values:
options[8], the number of iterations, options[8]<0 means
an error occured,
options[9], the number of objective function evaluations,
options[10],the number of gradients evaluations,
*/
#endif /* __solvopt_H */
--- NEW FILE: SConscript ---
# $Id: SConscript,v 1.1 2007/03/16 21:58:45 gfuer Exp $
Import('env')
env.StaticLibrary('solvopt', [ 'solvopt.c', 'apprgrdn.c' ])
--- NEW FILE: solvopt.c ---
/*
* $Id: solvopt.c,v 1.1 2007/03/16 21:58:45 gfuer Exp $
*
* SOLVOPT version 1.1 (June, 1997)
* by Alexei Kuntsevich and Franz Kappel
* University of Graz, Austria
*
* http://www.uni-graz.at/imawww/kuntsevich/solvopt
*
* Modified by Gerhard Fuernkranz for use in lprof
*
* The function SOLVOPT performs a modified version of Shor's
* r-algorithm in order to find a local minimum resp. maximum
* of a nonlinear function * defined on the n-dimensional Euclidean
* space or a solution of a nonlinear constrained problem:
*
* min { f(x): g(x) (<)= 0, g(x) in R(m), x in R(n) }
*
* With the kind permisson of the authors, SolvOpt is distributed
[...1301 lines suppressed...]
endrun:
/* deallocate working arrays: */
free (idx);
free (deltax);
free (xx);
free (grec);
free (xrec);
free (xopt);
free (x1);
free (z);
free (gc);
free (gt);
free (g1);
free (g0);
free (g);
free (B);
return (f);
}
--- NEW FILE: apprgrdn.c ---
/*
* $Id: apprgrdn.c,v 1.1 2007/03/16 21:58:45 gfuer Exp $
*
* SOLVOPT version 1.1 (June, 1997)
* by Alexei Kuntsevich and Franz Kappel
* University of Graz, Austria
*
* http://www.uni-graz.at/imawww/kuntsevich/solvopt
*
* Modified by Gerhard Fuernkranz for use in lprof
*
* With the kind permisson of the authors, SolvOpt is distributed
* as part of lprof under the terms of the GNU GPL.
*
* Lieber Herr Fürnkranz,
* Ihre Frage bezüglich der Nutzung von SolvOpt kann ich mit "ja"
* beantworten. Wir haben den Begriff "freeware" in diesem Sinne
* verstanden.
*
* Mit freundlichen Grüßen,
* F. Kappel
*
* -----Ursprüngliche Nachricht-----
* Von: gfuer@... [mailto:gfuer@...]
* Gesendet: Dienstag, 13. März 2007 23:10
* An: Kappel, Franz (franz.kappel@...)
* Betreff: Frage zur SolvOpt-Nutzung
*
* Sehr geehrter Herr Kappel,
*
* auf der Solvopt-Home-Page schreiben Sie "SolvOpt is a freeware...". Da
* "Freeware" jedoch kein genau definierter, rechtsgültiger Begriff ist,
* und ich auch in den Sourcen keine Copyright-Vermerke und/oder
* Nutzungsbedingungen finde, möchte ich gerne bei Ihnen explizit anfragen,
* ob Sie zustimmen würden, dass der SolvOpt-Quellcode unter den
* Bedingungen der GNU GPL benutzt und weiterverteilt werden darf, sodass
* eine Integration mit anderen freien Softwareprogrammen, die ebenfalls
* der GNU GPL untestellt oder GLP-kompatibel sind, ermöglicht wird.
*
* Mit freundlichen Grüßen,
* Gerhard Fürnkranz
*
* THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL MARTI MARIA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
* This file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <math.h>
#include "solvopt.h"
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
void
cmsxApprGrdn(void *cargo, unsigned short n,
double g[], double x[], double f,
double fun (void *, double[]),
double deltax[], unsigned obj)
{
/*
Function APPRGRDN performs the finite difference approximation
of the gradient <g> at a point <x>.
f is the calculated function value at a point <x>,
<fun> is the name of a function that calculates function values,
deltax is an array of the relative stepsizes.
obj is the flag indicating whether the gradient of the objective
function (1) or the constraint function (0) is to be calculated.
*/
double const lowbndobj = 2.0e-10, lowbndcnt = 5.0e-15,
ten = 10.0, half = 0.5;
double d, y, fi;
unsigned short i, j, center = 0;
for (i = 0; i < n; i++) {
y = x[i];
d = max (lowbndcnt, fabs (y));
d *= deltax[i];
if (obj) {
if (fabs (d) < lowbndobj) {
if (deltax[i] < 0.0)
d = -lowbndobj;
else
d = lowbndobj;
center = 1;
}
else
center = 0;
}
else if (fabs (d) < lowbndcnt) {
if (deltax[i] < 0.0)
d = -lowbndcnt;
else
d = lowbndcnt;
}
x[i] = y + d;
fi = fun (cargo, x);
if (obj) {
if (fi == f) {
for (j = 1; j <= 3; j++) {
d *= ten;
x[i] = y + d;
fi = fun (cargo, x);
if (fi != f)
break;
}
}
}
g[i] = (fi - f) / d;
if (obj) {
if (center) {
x[i] = y - d;
fi = fun (cargo, x);
g[i] = half * (g[i] + (f - fi) / d);
}
}
x[i] = y;
}
}
|