Home > utilities > alselftest.m

alselftest

PURPOSE ^

ALSELFTEST is a self test of evaluation of the Augmented Lagrangian and its

SYNOPSIS ^

function [prob]=alselftest(testID)

DESCRIPTION ^

 ALSELFTEST is a self test of evaluation of the Augmented Lagrangian and its
 derivatives. It uses precomputed data from PenSDP and Pennon/Pennlp stored
 in data container file (DCF) in directory ./datafiles/
 Argument 'testID' is optional and if it is not present, it runs all the
 tests otherwise only these listed in vector 'testID'. Returns the last 
 loaded problem.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [prob]=alselftest(testID)
0002 % ALSELFTEST is a self test of evaluation of the Augmented Lagrangian and its
0003 % derivatives. It uses precomputed data from PenSDP and Pennon/Pennlp stored
0004 % in data container file (DCF) in directory ./datafiles/
0005 % Argument 'testID' is optional and if it is not present, it runs all the
0006 % tests otherwise only these listed in vector 'testID'. Returns the last
0007 % loaded problem.
0008 
0009 % This file is a part of PENLAB package distributed under GPLv3 license
0010 % Copyright (c) 2013 by  J. Fiala, M. Kocvara, M. Stingl
0011 % Last Modified: 27 Nov 2013
0012   
0013   prob = [];
0014 
0015   % hardcoded data - type, input1, input2, comment where input 1 and 2 will
0016   % be typically problem definition and matching DCF.
0017   tests = [
0018     {'pennlp','../../problems/ampl-nl/cosine.nl', 'datafiles/pennlp_cosine.dcf', 'big & unconstrained'}
0019     {'pennlp', '../../problems/ampl-nl/chain100.nl', 'datafiles/pennlp_chain100_a.dcf', '100 LIN eq + 1 NLN eq, no box (==> no penalties)'}
0020     {'pennlp', '../../problems/ampl-nl/israel.nl', 'datafiles/pennlp_israel_a.dcf', 'box + LIN ineq only (no equal)'}
0021     {'pennlp', '../../problems/ampl-nl/seba.nl', 'datafiles/pennlp_seba.dcf', 'box + LIN ineq & eq'}
0022     {'pennlp', '../../problems/ampl-nl/camshape100.nl', 'datafiles/pennlp_camshape100_a.dcf', 'NLN ineq + LIN eq + BOX'}
0023 
0024     {'pensdp', 'datafiles/truss1.dat-s', 'datafiles/pensdpa_truss1.dcf', 'very small matrices, no inequalities'} 
0025     {'pensdp', 'datafiles/theta1.dat-s', 'datafiles/pensdpa_theta1.dcf', 'one bigger matrix, no inequalitites'}
0026     {'pensdp', 'datafiles/control1.dat-s', 'datafiles/pensdpa_control1.dcf', 'two bigger matrices'}
0027     {'pensdp', 'datafiles/arch0.dat-s', 'datafiles/pensdpa_arch0.dcf', 'one matrix & set of inequalitites'}
0028     {'pensdp', 'datafiles/truss1b.dat-s', 'datafiles/pensdpa_truss1b.dcf', 'very small matrices, one inequality'} 
0029     ];
0030 
0031   testno=size(tests,1);
0032 
0033   if (nargin==0)
0034     testID=[1:testno];
0035   else
0036     testID=intersect(testID,[1:testno]);
0037   end
0038 
0039   for i=testID
0040     prob = runtest(i,tests{i,:});
0041   end
0042 end
0043     
0044 % run one test and return the object
0045 function [prob] = runtest(ID, type, input1, input2, comment)
0046 
0047   [fdir,fname,fext] = fileparts(input1);
0048   disp(sprintf('* Test %2i - %s: %s, %s',ID,type,fname,comment));
0049 
0050   if (strcmpi(type,'pennlp') || strcmpi(type,'nlp'))
0051 
0052     penm=nlp_define(input1);
0053     prob=penlab(penm);
0054     [alx,aldx,alddx] = setuptestpoint(prob,input2,type);
0055 
0056   elseif (strcmpi(type,'pensdp') || strcmpi(type,'sdp'))
0057 
0058     sdpdata=readsdpa(input1);
0059     penm=sdp_define(sdpdata);
0060     prob=penlab(penm);
0061     [alx,aldx,alddx] = setuptestpoint(prob,input2,type);
0062 
0063   else
0064     disp('Unknown type of the test.');
0065     prob = [];
0066   end
0067 
0068   if (~isempty(prob))
0069 
0070     prob.eval_alx(); 
0071     prob.eval_aldx(); 
0072     prob.eval_alddx();
0073 
0074     prndiff('ALx', prob.ALx, alx);
0075     prndiff('ALdx', prob.ALdx, aldx);
0076     if (prob.Neq>0)
0077       prndiff('ALddx', prob.ALddx, alddx(1:prob.Nx,1:prob.Nx));
0078       prndiff('eqdx', prob.eqdx, alddx(1:prob.Nx,prob.Nx+1:end));
0079     else
0080       prndiff('ALddx', prob.ALddx, alddx);
0081     end
0082 
0083   end
0084 
0085 end
0086 
0087 % print differences (errors) absolute and relative
0088 function prndiff(text,my,ref)
0089   diff=norm(my-ref,inf);
0090   nrm=norm(ref,inf);
0091   if (nrm==0)
0092     nrm=1;
0093   end
0094 
0095   if (diff/nrm>1e-10)
0096     wrn='   WARNING !!!';
0097   else
0098     wrn='';
0099   end
0100   disp(sprintf('  %-20s:   %e   %e  (abs|rel) %s',text,diff,diff/nrm,wrn));
0101   %if (diff/nrm>1e-10)
0102   %  disp('  !!!         WARNING         WARNING         WARNING         !!!');
0103   %end
0104 
0105 end
0106

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