changeset 1941:c3ae47c97e53

[project @ 1996-02-13 19:35:44 by jwe]
author jwe
date Tue, 13 Feb 1996 19:35:51 +0000
parents 1b193e313c56
children bb9df7be8227
files liboctave/NPSOL.cc liboctave/NPSOL.h liboctave/QPSOL.cc
diffstat 3 files changed, 51 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/NPSOL.cc	Tue Feb 13 16:28:47 1996 +0000
+++ b/liboctave/NPSOL.cc	Tue Feb 13 19:35:51 1996 +0000
@@ -174,23 +174,23 @@
   // Informative stuff.
 
   int iter;
-  int *istate = new int [n+nclin+ncnln];
+
+  Array<int> aistate (n+nclin+ncnln);
+  int *istate = aistate.fortran_vec ();
 
   // User defined function stuff is defined above in the functions
   // npsol_confun() and npsol_objfun();
 
   // Constraint stuff.
 
-  double *pclin = 0;
-  Matrix clin;
-  if (nclin > 0)
-    {
-      clin = lc.constraint_matrix ();
-      pclin  = clin.fortran_vec ();
-    }
+  Matrix clin = lc.constraint_matrix ();
+  double *pclin = clin.fortran_vec ();
 
-  double *clow = new double [n+nclin+ncnln];
-  double *cup = new double [n+nclin+ncnln];
+  Array<double> aclow (n+nclin+ncnln);
+  double *clow = aclow.fortran_vec ();
+
+  Array<double> acup (n+nclin+ncnln);
+  double *cup = acup.fortran_vec ();
 
   if (bnds.size () > 0)
     {
@@ -222,21 +222,21 @@
       cup[i+n+nclin] = nlc.upper_bound (i);
     }
 
-  double *c = 0;
-  double *cjac = 0;
-  if (ncnln > 0)
-    {
-      c = new double [ncnln];
-      cjac = new double [nrowj*n];
-    }
+  Array<double> ac (ncnln);
+  double *c = ac.fortran_vec ();
+
+  Array<double> acjac (nrowj*n);
+  double *cjac = acjac.fortran_vec ();
 
   // Objective stuff.
 
-  double *objgrd = new double [n];
+  Array<double> aobjgrd (n);
+  double *objgrd = aobjgrd.fortran_vec ();
 
   // Other stuff.
 
-  double *r = new double [n*n];
+  Array<double> ar (n*n);
+  double *r = ar.fortran_vec ();
 
   lambda.resize (n+nclin+ncnln);
   double *pclambda = lambda.fortran_vec ();
@@ -256,8 +256,11 @@
   else
     lenw = 2*n*(n + 10) + nclin*(n + 11) + ncnln*(2*n + 21);
 
-  int *iw = new int [leniw];
-  double *w = new double [lenw];
+  Array<int> aiw (leniw);
+  int *iw = aiw.fortran_vec ();
+
+  Array<double> aw (lenw);
+  double *w = aw.fortran_vec ();
 
   user_phi  = phi.objective_function ();
   user_grad = phi.gradient_function ();
@@ -275,7 +278,7 @@
   else if (user_jac && user_grad)
     F77_FCN (npoptn, NPOPTN) ("Derivative Level 3", 18L);
 
-  int attempt = 0;
+  attempt = 0;
   while (attempt++ < 5)
     {
 
@@ -293,20 +296,6 @@
 	break;
     }
 
-  // Clean up.
-
-  delete [] istate;
-  delete [] clow;
-  delete [] cup;
-  delete [] c;
-  delete [] cjac;
-  delete [] objgrd;
-  delete [] r;
-  delete [] iw;
-  delete [] w;
-
-  // See how it went.
-
   return x;
 }
 
--- a/liboctave/NPSOL.h	Tue Feb 13 16:28:47 1996 +0000
+++ b/liboctave/NPSOL.h	Tue Feb 13 19:35:51 1996 +0000
@@ -280,6 +280,10 @@
   ~NPSOL (void) { }
 
   ColumnVector do_minimize (double& objf, int& inform, ColumnVector& lambda);
+
+private:
+
+  int attempt;
 };
 
 // XXX FIXME XXX -- would be nice to not have to have this global
--- a/liboctave/QPSOL.cc	Tue Feb 13 16:28:47 1996 +0000
+++ b/liboctave/QPSOL.cc	Tue Feb 13 19:35:51 1996 +0000
@@ -95,38 +95,35 @@
       pa = clin.fortran_vec ();
     }
 
-  double *pbl = new double [nctotl];
-  double *pbu = new double [nctotl];
+  ColumnVector bl (n+nclin);
+  ColumnVector bu (n+nclin);
 
   if (bnds.size () > 0)
     {
-      for (int i = 0; i < n; i++)
-	{
-	  pbl[i] = bnds.lower_bound (i);
-	  pbu[i] = bnds.upper_bound (i);
-	}
+      bl.insert (bnds.lower_bounds (), 0);
+      bu.insert (bnds.upper_bounds (), 0);
     }
   else
     {
-      for (int i = 0; i < n; i++)
-	{
-	  pbl[i] = -bigbnd;
-	  pbu[i] = bigbnd;
-	}
+      bl.fill (-bigbnd);
+      bu.fill (bigbnd);
     }
 
-  for (int i = 0; i < nclin; i++)
+  if (nclin > 0)
     {
-      pbl[i+n] = lc.lower_bound (i);
-      pbu[i+n] = lc.upper_bound (i);
+      bl.insert (lc.lower_bounds (), 0);
+      bu.insert (lc.upper_bounds (), 0);
     }
 
+  double *pbl = bl.fortran_vec ();
+  double *pbu = bu.fortran_vec ();
+
   double *pc = c.fortran_vec ();
 
-  double *featol = new double [nctotl];
   double tmp = feasibility_tolerance ();
-  for (int i = 0; i < nctotl; i++)
-    featol[i] = tmp;
+
+  Array<double> afeatol (nctotl, tmp);
+  double *featol = afeatol.fortran_vec ();
 
   double *ph = H.fortran_vec ();
 
@@ -134,7 +131,8 @@
   int lp = 0;
   int orthog = 1;
 
-  int *istate = new int [nctotl];
+  Array<int> aistate (nctotl);
+  int *istate = aistate.fortran_vec ();
 
   double *px = x.fortran_vec ();
 
@@ -151,8 +149,11 @@
   else
     lenw = 2*ncon*(1 + ncon) + 4*n + nclin;
 
-  int *iw = new int [leniw];
-  double *w = new double [lenw];
+  Array<int> aiw (leniw);
+  int *iw = aiw.fortran_vec ();
+
+  Array<double> aw (lenw);
+  double *w = aw.fortran_vec ();
 
   F77_FCN (qpsol, QPSOL) (itmax, msglvl, n, nclin, nctotl, ncon, n,
 			  n, bigbnd, pa, pbl, pbu, pc, featol, ph,
@@ -160,13 +161,6 @@
 			  inform, iter, objf, pclambda, iw, leniw, w,
 			  lenw);
 
-  delete [] pbl;
-  delete [] pbu;
-  delete [] featol;
-  delete [] istate;
-  delete [] iw;
-  delete [] w;
-
   return x;
 }