Home > utilities > testmexampl.m

testmexampl

PURPOSE ^

TESTMEXAMPL tests that the behaviour of the AMPL-Matlab interface is correct

SYNOPSIS ^

function [status] = testmexampl(verbose,tol)

DESCRIPTION ^

 TESTMEXAMPL tests that the behaviour of the AMPL-Matlab interface is correct

 RETURN
   status ...  0 failed, 1 all ok
 INPUT
   verbose ... 0 print only what failed, 1 print progress,
               optional, default 1
   tol ....... tolerance when comparing the results
               optional, default 1e-8

 See also penlabtest, penlabstresstest

 TODO This needs improving!

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [status] = testmexampl(verbose,tol)
0002 % TESTMEXAMPL tests that the behaviour of the AMPL-Matlab interface is correct
0003 %
0004 % RETURN
0005 %   status ...  0 failed, 1 all ok
0006 % INPUT
0007 %   verbose ... 0 print only what failed, 1 print progress,
0008 %               optional, default 1
0009 %   tol ....... tolerance when comparing the results
0010 %               optional, default 1e-8
0011 %
0012 % See also penlabtest, penlabstresstest
0013 %
0014 % TODO This needs improving!
0015 %
0016 
0017 % This file is a part of PENLAB package distributed under GPLv3 license
0018 % Copyright (c) 2013 by  J. Fiala, M. Kocvara, M. Stingl
0019 % Last Modified: 5 Dec 2013
0020 
0021   if (nargin<2)
0022     tol = 1e-8;
0023   end
0024   if (nargin<1)
0025     verbose = 1;
0026   end
0027   status = 1;
0028 
0029   if (verbose)
0030     disp(' testing functionality of AMPL-mex interface...')
0031   end
0032 
0033   % is it possible to call it?
0034   try
0035      [x0,u0,ps] = amplf('examples/ex1.nl');
0036   catch
0037     disp(' Error: mexampl - cannot call')
0038     status = 0;
0039     return;
0040   end
0041 
0042   %status = status && onenleval(nlfile,x,v);
0043   status = status && onenleval('examples/ex1.nl',[0.1;0.2;-0.4],rand(2,1));
0044   status = status && onenleval('examples/ex3.nl',rand(2,1),rand(2,1));
0045   status = status && onenleval('datafiles/chain100.nl',rand(200,1),rand(101,1));
0046   status = status && onenleval('datafiles/israel.nl',rand(142,1),rand(163,1));
0047 
0048 end
0049 
0050 function [status] = onenleval(nlfile,x,v)
0051 % ONENLEVAL one evaluation of AMPL (NL) problem at the given point
0052 %   nlfile - input translated AMPL file
0053 %   x - point where to evaluate
0054 %   v - lagrangian multipliers for Hessian of the Lagrangian
0055 
0056   status = 1;
0057 
0058   % get the name of the test
0059   [path,name,ext] = fileparts(nlfile);
0060   %disp(name)
0061 
0062   % a crude test - just call everything and let's see
0063   try
0064     [x0, u0, ps] = amplf(nlfile,0);
0065     %length(x0)
0066     %length(u0)
0067     [fx, gx, hx] = amplf(x,0);
0068     [fdx, gdx, hdx] = amplf(x,1);
0069     ddL = amplf(v);
0070   catch
0071     disp([' test ' name ' FAILED'])
0072     status = 0;
0073   end
0074 
0075 end
0076

Generated on Mon 26-Aug-2019 10:22:08 by m2html © 2005