# HG changeset patch # User jwe # Date 812872280 0 # Node ID 26411f9c7603c498d6d5697263ffe401e14bdd2b # Parent 5f3f07b6db89afcd055d2170da0bc035ba6af15f [project @ 1995-10-05 05:41:26 by jwe] diff --git a/liboctave/DAE.h b/liboctave/DAE.h --- a/liboctave/DAE.h +++ b/liboctave/DAE.h @@ -32,10 +32,6 @@ #include "ODE.h" #include "DAEFunc.h" -#ifndef Vector -#define Vector ColumnVector -#endif - class DAE : public ODE, public DAEFunc { public: @@ -44,29 +40,31 @@ DAE (int); - DAE (const Vector& x, double time, DAEFunc& f); + DAE (const ColumnVector& x, double time, DAEFunc& f); - DAE (const Vector& x, const Vector& xdot, double time, DAEFunc& f); + DAE (const ColumnVector& x, const ColumnVector& xdot, + double time, DAEFunc& f); ~DAE (void); - Vector deriv (void); + ColumnVector deriv (void); - virtual void initialize (const Vector& x, double t); - virtual void initialize (const Vector& x, const Vector& xdot, double t); + virtual void initialize (const ColumnVector& x, double t); + virtual void initialize (const ColumnVector& x, + const ColumnVector& xdot, double t); - Vector integrate (double t); + ColumnVector integrate (double t); - Matrix integrate (const Vector& tout, Matrix& xdot_out); - Matrix integrate (const Vector& tout, Matrix& xdot_out, - const Vector& tcrit); + Matrix integrate (const ColumnVector& tout, Matrix& xdot_out); + Matrix integrate (const ColumnVector& tout, Matrix& xdot_out, + const ColumnVector& tcrit); protected: // Some of this is probably too closely related to DASSL, but hey, // this is just a first attempt... - Vector xdot; + ColumnVector xdot; private: diff --git a/liboctave/FSQP.h b/liboctave/FSQP.h --- a/liboctave/FSQP.h +++ b/liboctave/FSQP.h @@ -32,10 +32,6 @@ #include "NLP.h" -#ifndef Vector -#define Vector ColumnVector -#endif - class FSQP : public NLP { public: diff --git a/liboctave/LP.h b/liboctave/LP.h --- a/liboctave/LP.h +++ b/liboctave/LP.h @@ -24,10 +24,6 @@ #if !defined (octave_LP_h) #define octave_LP_h 1 -#if defined (__GNUG__) -#pragma interface -#endif - #include "dColVector.h" #include "Bounds.h" #include "LinConst.h" diff --git a/liboctave/LinConst.h b/liboctave/LinConst.h --- a/liboctave/LinConst.h +++ b/liboctave/LinConst.h @@ -37,10 +37,6 @@ #include "dMatrix.h" #include "Bounds.h" -#ifndef Vector -#define Vector ColumnVector -#endif - class LinConst : public Bounds { public: @@ -51,15 +47,15 @@ LinConst (int eq, int ineq, int n) : Bounds (eq+ineq), A (nb, n) {} - LinConst (const Vector& l, const Matrix& amat, const Vector& u) + LinConst (const ColumnVector& l, const Matrix& amat, const ColumnVector& u) : Bounds (l, u), A (amat) { if (nb != amat.rows ()) error ("inconsistent sizes for constraint matrix and bounds vectors"); } - LinConst (const Matrix& A_eq, const Vector& b_eq, - const Matrix& A_ineq, const Vector& b_ineq); + LinConst (const Matrix& A_eq, const ColumnVector& b_eq, + const Matrix& A_ineq, const ColumnVector& b_ineq); LinConst (const LinConst& a) : Bounds (a.lb, a.ub), A (a.constraint_matrix ()) {} @@ -91,8 +87,8 @@ Matrix eq_constraint_matrix (void) const; Matrix ineq_constraint_matrix (void) const; - Vector eq_constraint_vector (void) const; - Vector ineq_constraint_vector (void) const; + ColumnVector eq_constraint_vector (void) const; + ColumnVector ineq_constraint_vector (void) const; friend ostream& operator << (ostream& os, const LinConst& b); diff --git a/liboctave/Makefile.in b/liboctave/Makefile.in --- a/liboctave/Makefile.in +++ b/liboctave/Makefile.in @@ -44,8 +44,8 @@ dbleLU.cc dbleQR.cc dbleQRP.cc dbleSCHUR.cc dbleSVD.cc SOURCES = Bounds.cc CollocWt.cc DAE.cc FEGrid.cc FSQP.cc LinConst.cc \ - LPsolve.cc NLEqn.cc NPSOL.cc Objective.cc ODE.cc QLD.cc \ - QPSOL.cc Quad.cc Range.cc lo-error.cc sun-utils.cc \ + LPsolve.cc NLEqn.cc NPSOL.cc ODE.cc QLD.cc QPSOL.cc Quad.cc \ + Range.cc lo-error.cc sun-utils.cc \ $(TEMPLATE_SRC) \ $(TI_SRC) \ $(MATRIX_SRC) diff --git a/liboctave/NLEqn.cc b/liboctave/NLEqn.cc --- a/liboctave/NLEqn.cc +++ b/liboctave/NLEqn.cc @@ -29,9 +29,6 @@ #include #endif -#include -#include - #include "NLEqn.h" #include "dMatrix.h" #include "f77-uscore.h" @@ -51,8 +48,8 @@ double*, const int&); } -static nonlinear_fcn user_fun; -static jacobian_fcn user_jac; +static NLFunc::nonlinear_fcn user_fun; +static NLFunc::jacobian_fcn user_jac; // error handling @@ -62,51 +59,8 @@ (*current_liboctave_error_handler) ("fatal NLEqn error: %s", msg); } -// Constructors - -NLEqn::NLEqn (void) : NLFunc (), n (0), x () { } - -NLEqn::NLEqn (const Vector& xvec, const NLFunc f) - : NLFunc (f), n (xvec.capacity ()), x (xvec) { } - -NLEqn::NLEqn (const NLEqn& a) : NLFunc (a.fun, a.jac), n (a.n), x (a.x) { } - void -NLEqn::resize (int nn) -{ - if (n != nn) - { - n = nn; - x.resize (n); - } -} - -int -NLEqn::size (void) const -{ - return n; -} - -// Assignment - -NLEqn& -NLEqn::operator = (const NLEqn& a) -{ - fun = a.fun; - jac = a.jac; - x = a.n; - - return *this; -} - -Vector -NLEqn::states (void) const -{ - return x; -} - -void -NLEqn::set_states (const Vector& xvec) +NLEqn::set_states (const ColumnVector& xvec) { if (xvec.capacity () != n) { @@ -119,34 +73,12 @@ // Other operations -Vector -NLEqn::solve (const Vector& xvec) -{ - set_states (xvec); - int info; - return solve (info); -} - -Vector -NLEqn::solve (const Vector& xvec, int& info) -{ - set_states (xvec); - return solve (info); -} - -Vector -NLEqn::solve (void) -{ - int info; - return solve (info); -} - int hybrd1_fcn (int *n, double *x, double *fvec, int *iflag) { int nn = *n; - Vector tmp_f (nn); - Vector tmp_x (nn); + ColumnVector tmp_f (nn); + ColumnVector tmp_x (nn); for (int i = 0; i < nn; i++) tmp_x.elem (i) = x[i]; @@ -169,7 +101,7 @@ int *ldfjac, int *iflag) { int nn = *n; - Vector tmp_x (nn); + ColumnVector tmp_x (nn); for (int i = 0; i < nn; i++) tmp_x.elem (i) = x[i]; @@ -177,7 +109,7 @@ int flag = *iflag; if (flag == 1) { - Vector tmp_f (nn); + ColumnVector tmp_f (nn); tmp_f = (*user_fun) (tmp_x); @@ -209,13 +141,15 @@ return 0; } -Vector +ColumnVector NLEqn::solve (int& info) { + ColumnVector retval; + if (n == 0) { error ("equation set not initialized"); - return Vector (); + return retval; } double tol = tolerance (); @@ -251,8 +185,6 @@ delete [] wa; } - Vector retval; - if (info >= 0) { retval.resize (n); @@ -267,60 +199,6 @@ return retval; } -NLEqn_options::NLEqn_options (void) -{ - init (); -} - -NLEqn_options::NLEqn_options (const NLEqn_options& opt) -{ - copy (opt); -} - -NLEqn_options& -NLEqn_options::operator = (const NLEqn_options& opt) -{ - if (this != &opt) - copy (opt); - - return *this; -} - -NLEqn_options::~NLEqn_options (void) -{ -} - -void -NLEqn_options::init (void) -{ - double sqrt_eps = sqrt (DBL_EPSILON); - x_tolerance = sqrt_eps; -} - -void -NLEqn_options::copy (const NLEqn_options& opt) -{ - x_tolerance = opt.x_tolerance; -} - -void -NLEqn_options::set_default_options (void) -{ - init (); -} - -void -NLEqn_options::set_tolerance (double val) -{ - x_tolerance = (val > 0.0) ? val : sqrt (DBL_EPSILON); -} - -double -NLEqn_options::tolerance (void) -{ - return x_tolerance; -} - /* ;;; Local Variables: *** ;;; mode: C++ *** diff --git a/liboctave/NLFunc.h b/liboctave/NLFunc.h --- a/liboctave/NLFunc.h +++ b/liboctave/NLFunc.h @@ -24,20 +24,16 @@ #if !defined (octave_NLFunc_h) #define octave_NLFunc_h 1 -#if defined (__GNUG__) -#pragma interface -#endif - class ColumnVector; class Matrix; -typedef ColumnVector (*nonlinear_fcn) (const ColumnVector&); -typedef Matrix (*jacobian_fcn) (const ColumnVector&); - class NLFunc { public: + typedef ColumnVector (*nonlinear_fcn) (const ColumnVector&); + typedef Matrix (*jacobian_fcn) (const ColumnVector&); + NLFunc (void) { fun = 0; diff --git a/liboctave/NPSOL.cc b/liboctave/NPSOL.cc --- a/liboctave/NPSOL.cc +++ b/liboctave/NPSOL.cc @@ -64,10 +64,10 @@ // function, and the user wants us to quit. int npsol_objective_error = 0; -static objective_fcn user_phi; -static gradient_fcn user_grad; -static nonlinear_fcn user_g; -static jacobian_fcn user_jac; +static Objective::objective_fcn user_phi; +static Objective::gradient_fcn user_grad; +static NLFunc::nonlinear_fcn user_g; +static NLFunc::jacobian_fcn user_jac; int npsol_objfun (int& mode, const int& n, double *xx, double *objf, diff --git a/liboctave/ODEFunc.h b/liboctave/ODEFunc.h --- a/liboctave/ODEFunc.h +++ b/liboctave/ODEFunc.h @@ -24,39 +24,63 @@ #if !defined (octave_ODEFunc_h) #define octave_ODEFunc_h 1 -#if defined (__GNUG__) -#pragma interface -#endif - class Matrix; class ColumnVector; -#ifndef Vector -#define Vector ColumnVector -#endif - class ODEFunc { public: - typedef Vector (*ODERHSFunc) (const Vector&, double); - typedef Matrix (*ODEJacFunc) (const Vector&, double); + typedef ColumnVector (*ODERHSFunc) (const ColumnVector&, double); + typedef Matrix (*ODEJacFunc) (const ColumnVector&, double); + + ODEFunc (void) + { + fun = 0; + jac = 0; + } - ODEFunc (void); - ODEFunc (ODERHSFunc f); - ODEFunc (ODERHSFunc f, ODEJacFunc j); + ODEFunc (ODERHSFunc f) + { + fun = f; + jac = 0; + } - ODEFunc (const ODEFunc& a); + ODEFunc (ODERHSFunc f, ODEJacFunc j) + { + fun = f; + jac = j; + } - ODEFunc& operator = (const ODEFunc& a); + ODEFunc (const ODEFunc& a) + { + fun = a.function (); + jac = a.jacobian_function (); + } - ODERHSFunc function (void) const; + ODEFunc& operator = (const ODEFunc& a) + { + fun = a.function (); + jac = a.jacobian_function (); + + return *this; + } - ODEFunc& set_function (ODERHSFunc f); + ODERHSFunc function (void) const { return fun; } + + ODEFunc& set_function (ODERHSFunc f) + { + fun = f; + return *this; + } - ODEJacFunc jacobian_function (void) const; + ODEJacFunc jacobian_function (void) const { return jac; } - ODEFunc& set_jacobian_function (ODEJacFunc j); + ODEFunc& set_jacobian_function (ODEJacFunc j) + { + jac = j; + return *this; + } protected: diff --git a/liboctave/Objective.h b/liboctave/Objective.h --- a/liboctave/Objective.h +++ b/liboctave/Objective.h @@ -24,38 +24,62 @@ #if !defined (octave_Objective_h) #define octave_Objective_h 1 -#if defined (__GNUG__) -#pragma interface -#endif - #include "dColVector.h" -#ifndef Vector -#define Vector ColumnVector -#endif - -typedef double (*objective_fcn) (const Vector&); -typedef Vector (*gradient_fcn) (const Vector&); - class Objective { public: - Objective (void); - Objective (const objective_fcn); - Objective (const objective_fcn, const gradient_fcn); + typedef double (*objective_fcn) (const ColumnVector&); + typedef ColumnVector (*gradient_fcn) (const ColumnVector&); + + Objective (void) + { + phi = 0; + grad = 0; + } - Objective (const Objective& a); + Objective (const objective_fcn obj) + { + phi = obj; + grad = 0; + } - Objective& operator = (const Objective& a); + Objective (const objective_fcn obj, const gradient_fcn g) + { + phi = obj; + grad = g; + } - objective_fcn objective_function (void) const; + Objective (const Objective& a) + { + phi = a.phi; + grad = a.grad; + } - Objective& set_objective_function (const objective_fcn); + Objective& operator = (const Objective& a) + { + phi = a.phi; + grad = a.grad; + + return *this; + } - gradient_fcn gradient_function (void) const; + objective_fcn objective_function (void) const { return phi; } + + Objective& set_objective_function (const objective_fcn obj) + { + phi = obj; + return *this; + } - Objective& set_gradient_function (const gradient_fcn); + gradient_fcn gradient_function (void) const { return grad; } + + Objective& set_gradient_function (const gradient_fcn g) + { + grad = g; + return *this; + } private: diff --git a/liboctave/QLD.h b/liboctave/QLD.h --- a/liboctave/QLD.h +++ b/liboctave/QLD.h @@ -33,10 +33,6 @@ #include "QP.h" -#ifndef Vector -#define Vector ColumnVector -#endif - class QLD : public QP { public: diff --git a/liboctave/QPSOL.h b/liboctave/QPSOL.h --- a/liboctave/QPSOL.h +++ b/liboctave/QPSOL.h @@ -34,10 +34,6 @@ #include "dColVector.h" #include "QP.h" -#ifndef Vector -#define Vector ColumnVector -#endif - class QPSOL_options { public: diff --git a/liboctave/Quad.h b/liboctave/Quad.h --- a/liboctave/Quad.h +++ b/liboctave/Quad.h @@ -28,6 +28,9 @@ #pragma interface #endif +#include +#include + #include "dColVector.h" #if !defined (octave_Quad_typedefs) diff --git a/liboctave/base-min.h b/liboctave/base-min.h --- a/liboctave/base-min.h +++ b/liboctave/base-min.h @@ -58,20 +58,20 @@ { double objf; int inform; - Vector lambda; + ColumnVector lambda; return do_minimize (objf, inform, lambda); } virtual ColumnVector minimize (double& objf) { int inform; - Vector lambda; + ColumnVector lambda; return do_minimize (objf, inform, lambda); } virtual ColumnVector minimize (double& objf, int& inform) { - Vector lambda; + ColumnVector lambda; return do_minimize (objf, inform, lambda); } @@ -86,7 +86,7 @@ x = x0; double objf; int inform; - Vector lambda; + ColumnVector lambda; return do_minimize (objf, inform, lambda); } @@ -94,7 +94,7 @@ { x = x0; int inform; - Vector lambda; + ColumnVector lambda; return do_minimize (objf, inform, lambda); } @@ -102,7 +102,7 @@ int& inform) { x = x0; - Vector lambda; + ColumnVector lambda; return do_minimize (objf, inform, lambda); }