Home > utilities > penlabtestfeeder.m

penlabtestfeeder

PURPOSE ^

PENLABTESTFEEDER sets up one test to be run at a time.

SYNOPSIS ^

function [status,name,prob,res] = penlabtestfeeder(no,testset)

DESCRIPTION ^

 PENLABTESTFEEDER sets up one test to be run at a time.

 INPUT:
   no - number of the test problem, 1..length(testset)
   testset - (optional) is a list of all tests, their type
        and the location of the datafile; if not set
        the default selection of tests is used.

 OUTPUT:
   status - 0  = test is set up;
            <0 = problem with initialization of the requested test;
            1  = wrong test number (maximal no of tests reached?)
   name - name of the problem, this is used to show with the result
   prob - if status==0, penlab structure with the test, otherwise []
   res - expected result (objective function at the solution) or []

 Description of the testset: TODO (see to the default one below at the moment)

 See also penlabstresstest

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [status,name,prob,res] = penlabtestfeeder(no,testset)
0002 % PENLABTESTFEEDER sets up one test to be run at a time.
0003 %
0004 % INPUT:
0005 %   no - number of the test problem, 1..length(testset)
0006 %   testset - (optional) is a list of all tests, their type
0007 %        and the location of the datafile; if not set
0008 %        the default selection of tests is used.
0009 %
0010 % OUTPUT:
0011 %   status - 0  = test is set up;
0012 %            <0 = problem with initialization of the requested test;
0013 %            1  = wrong test number (maximal no of tests reached?)
0014 %   name - name of the problem, this is used to show with the result
0015 %   prob - if status==0, penlab structure with the test, otherwise []
0016 %   res - expected result (objective function at the solution) or []
0017 %
0018 % Description of the testset: TODO (see to the default one below at the moment)
0019 %
0020 % See also penlabstresstest
0021 %
0022 
0023 % This file is a part of PENLAB package distributed under GPLv3 license
0024 % Copyright (c) 2013 by  J. Fiala, M. Kocvara, M. Stingl
0025 % Last Modified: 3/12/2013
0026 
0027   if (nargin<1)
0028     no = 0;
0029   end
0030 
0031   if (nargin<2)
0032     % create the default testset
0033     % TODO later expand with (optional) expected result (e.g., the objective)
0034     testset = { ...
0035       { 'sdpa', 'datafiles/control1.dat-s', 1.778463e+01 }, ...
0036       { 'sdpa', 'datafiles/control2.dat-s', 8.300000e+00 }, ...
0037       { 'sdpa', 'datafiles/theta1.dat-s', 2.300000e+01 }, ...
0038       { 'sdpa', 'datafiles/theta2.dat-s', 3.287917e+01 }, ...
0039       { 'sdpa', 'datafiles/truss1.dat-s', -8.999996e+00 }, ...
0040       { 'sdpa', 'datafiles/arch0.dat-s', 5.66517e-01 }, ...
0041       { 'sdpa', 'datafiles/mcp100.dat-s', 2.261574e+02 }, ...
0042       { 'ampl', 'datafiles/camshape100.nl' }, ...
0043       { 'ampl', 'datafiles/chain100.nl' }, ...
0044       { 'ampl', 'datafiles/cosine.nl' }, ...
0045       { 'ampl', 'datafiles/israel.nl' }, ...
0046       { 'ampl', 'datafiles/polygon25.nl' }, ...
0047       { 'ampl', 'datafiles/seba.nl' }, ...
0048       { 'bmi', 'datafiles/bmi_example.mat' }, ...
0049       { 'bmi', 'datafiles/bmi_f4e.mat' }, ...
0050       { 'bmi', 'datafiles/bmi_interval1_0.mat' }, ...
0051       { 'bmi', 'datafiles/bmi_interval1_1.mat' }, ...
0052       { 'bmi', 'datafiles/bmi_interval2_0.mat' }, ...
0053       { 'bmi', 'datafiles/bmi_interval2_1.mat' }, ...
0054       { 'bmi', 'datafiles/bmi_jia.mat' }, ...
0055       { 'bmi', 'datafiles/bmi_patel5.mat' }, ...
0056       { 'bmi', 'datafiles/bmi_toy2.mat' }, ...
0057       { 'pmi', 'datafiles/pmi_example.mat' }, ...
0058       { 'pmi', 'datafiles/pmi_AC1.mat' }, ...
0059       { 'pmi', 'datafiles/pmi_NN4.mat' }, ...
0060     };
0061     % { 'bmi', 'datafiles/bmi_helicopter.mat' }, ...
0062     % { 'sdpa', 'datafiles/maxG11.dat-s' }, ...
0063     % { 'bmi', 'datafiles/bmi_toy1.mat' }, ...
0064   end
0065 
0066   ntests = length(testset);
0067   if (no<1 || no>ntests)
0068     status = 1;
0069     name = 'NONEXISTENT';
0070     prob = [];
0071     res = [];
0072     return;
0073   end
0074 
0075   test = testset{no};
0076   if (length(test)>=3)
0077     res = test{3};
0078   else
0079     res = [];
0080   end
0081   if (strcmpi(test{1},'sdpa'))
0082     [status,name,prob] = sdpa_feeder(test{2});
0083   elseif (strcmpi(test{1},'bmi'))
0084     [status,name,prob] = bmi_feeder(test{2});
0085   elseif (strcmpi(test{1},'pmi'))
0086     [status,name,prob] = pmi_feeder(test{2});
0087   elseif (strcmpi(test{1},'ampl'))
0088     [status,name,prob] = ampl_feeder(test{2});
0089   else
0090     % unknown test type
0091     status = -10;
0092     name = 'unknowntype';
0093     prob = [];
0094     res = [];
0095     return;
0096   end
0097 
0098 end
0099 
0100 function [status,name,prob] = sdpa_feeder(sdpafile)
0101 % SDPA_FEEDER reads Linear SDP problem from a SDPA file into penlab object.
0102 % Returns
0103 %   status~=0 if the file doesn't exist or there is a formating error,
0104 %     or any other error with initialization, otherwise 0 if all OK
0105 %   name name of the problem (basename of the SDPA data file)
0106 %   prob penlab object
0107 %
0108 
0109   if (isempty(sdpafile) || ~ischar(sdpafile))
0110     status = -2;
0111     name = 'EMPTY';
0112     prob = [];
0113     return;
0114   end
0115 
0116   [path,name,ext] = fileparts(sdpafile);
0117 
0118   try 
0119     sdpdata = readsdpa(sdpafile);
0120   catch
0121     status = -1;
0122     prob = [];
0123     return;
0124   end
0125 
0126   try
0127     penm = sdp_define(sdpdata);
0128     prob = penlab(penm);
0129     status = 0;
0130   catch
0131     status = -3;
0132     prob = [];
0133   end
0134 
0135 end
0136 
0137 function [status,name,prob] = bmi_feeder(bmifile)
0138 % BMI_FEEDER loads bmidata from Matlab mat-file into penlab object.
0139 % Returns
0140 %   status~=0 if the file doesn't exist or there is a formating error,
0141 %     or any other error with initialization, otherwise 0 if all OK
0142 %   name name of the problem (basename of the data file)
0143 %   prob penlab object
0144 %
0145 
0146   if (isempty(bmifile) || ~ischar(bmifile))
0147     status = -2;
0148     name = 'EMPTY';
0149     prob = [];
0150     return;
0151   end
0152 
0153   [path,name,ext] = fileparts(bmifile);
0154 
0155   try 
0156     % this mat-file should store bmidata struct
0157     load(bmifile);
0158   catch
0159     status = -1;
0160     prob = [];
0161     return;
0162   end
0163 
0164   try
0165     penm = bmi_define(bmidata);
0166     prob = penlab(penm);
0167     status = 0;
0168   catch
0169     status = -3;
0170     prob = [];
0171   end
0172 
0173 end
0174 
0175 function [status,name,prob] = pmi_feeder(pmifile)
0176 % PMI_FEEDER loads pmidata from Matlab mat-file into penlab object.
0177 % Returns
0178 %   status~=0 if the file doesn't exist or there is a formating error,
0179 %     or any other error with initialization, otherwise 0 if all OK
0180 %   name name of the problem (basename of the data file)
0181 %   prob penlab object
0182 %
0183 
0184   if (isempty(pmifile) || ~ischar(pmifile))
0185     status = -2;
0186     name = 'EMPTY';
0187     prob = [];
0188     return;
0189   end
0190 
0191   [path,name,ext] = fileparts(pmifile);
0192 
0193   try 
0194     % this mat-file should store pmidata struct
0195     load(pmifile);
0196   catch
0197     status = -1;
0198     prob = [];
0199     return;
0200   end
0201 
0202   try
0203     penm = pmi_define(pmidata);
0204     prob = penlab(penm);
0205     status = 0;
0206   catch
0207     status = -3;
0208     prob = [];
0209   end
0210 
0211 end
0212 
0213 function [status,name,prob] = ampl_feeder(amplfile)
0214 % AMPL_FEEDER reads AMPL nl file and sets up a penlab object.
0215 % Returns
0216 %   status~=0 if the file doesn't exist or there is a formating error,
0217 %     or any other error with initialization, otherwise 0 if all OK
0218 %   name name of the problem (basename of the data file)
0219 %   prob penlab object
0220 %
0221 
0222   if (isempty(amplfile) || ~ischar(amplfile))
0223     status = -2;
0224     name = 'EMPTY';
0225     prob = [];
0226     return;
0227   end
0228 
0229   [path,name,ext] = fileparts(amplfile);
0230 
0231   try 
0232     penm = nlp_define(amplfile);
0233   catch
0234     status = -1;
0235     prob = [];
0236     return;
0237   end
0238 
0239   try
0240     prob = penlab(penm);
0241     status = 0;
0242   catch
0243     status = -3;
0244     prob = [];
0245   end
0246 
0247 end
0248

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