Skip to content

Commit

Permalink
fixed bug in test_bench, added test for HS268, which seems to lead to…
Browse files Browse the repository at this point in the history
… different solutions on different platforms
  • Loading branch information
jferreau committed Dec 18, 2014
1 parent 0b91be3 commit 76a6e81
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ testing/cpp/test_example7.cpp -text
testing/cpp/test_exampleLP.cpp -text
testing/cpp/test_gradientShift.cpp -text
testing/cpp/test_guessedWS1.cpp -text
testing/cpp/test_hs268.cpp -text
testing/cpp/test_indexlist.cpp -text
testing/cpp/test_janick1.cpp -text
testing/cpp/test_janick2.cpp -text
Expand Down
5 changes: 5 additions & 0 deletions testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ QPOASES_TEST_EXES = \
${BINDIR}/test_example7${EXE} \
${BINDIR}/test_exampleLP${EXE} \
${BINDIR}/test_qrecipe${EXE} \
${BINDIR}/test_hs268${EXE} \
${BINDIR}/test_gradientShift${EXE} \
${BINDIR}/test_runAllOqpExamples${EXE} \
${BINDIR}/test_sebastien1${EXE} \
Expand Down Expand Up @@ -139,6 +140,10 @@ ${BINDIR}/test_qrecipe${EXE}: ./cpp/test_qrecipe.${OBJEXT} ./cpp/test_qrecipe_da
@${ECHO} "Creating" $@
@${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES}

${BINDIR}/test_hs268${EXE}: ./cpp/test_hs268.${OBJEXT}
@${ECHO} "Creating" $@
@${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES}

${BINDIR}/test_gradientShift${EXE}: ./cpp/test_gradientShift.${OBJEXT} ${LINK_DEPENDS}
@${ECHO} "Creating" $@
@${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES}
Expand Down
80 changes: 40 additions & 40 deletions testing/cpp/test_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ int main( int argc, char *argv[] )
returnValue returnvalue;

int expectedNumSolvedProblems = 44;
real_t expectedAvgStationarity = TOL;
real_t expectedAvgavgFeasibility = TOL;
real_t expectedAvgFeasibility = TOL;
real_t expectedAvgStationarity = TOL;
real_t expectedAvgFeasibility = TOL;
real_t expectedAvgComplementarity = TOL;


if ( argv[argc-1][0] == 'O' )
Expand All @@ -116,17 +116,17 @@ int main( int argc, char *argv[] )
options.setToDefault();
if ( argv[argc-1][2] == 's' )
{
expectedNumSolvedProblems = 44;
expectedAvgStationarity = 1e-7;
expectedAvgavgFeasibility = 1e-10;
expectedAvgFeasibility = 5e-7;
expectedNumSolvedProblems = 44;
expectedAvgStationarity = 2e-10;
expectedAvgFeasibility = 2e-10;
expectedAvgComplementarity = 5e-7;
}
else
{
expectedNumSolvedProblems = 44;
expectedAvgStationarity = 1e-7;
expectedAvgavgFeasibility = 5e-10;
expectedAvgFeasibility = 5e-8;
expectedNumSolvedProblems = 44;
expectedAvgStationarity = 5e-10;
expectedAvgFeasibility = 5e-10;
expectedAvgComplementarity = 5e-8;
}
break;

Expand All @@ -135,17 +135,17 @@ int main( int argc, char *argv[] )
options.setToReliable();
if ( argv[argc-1][2] == 's' )
{
expectedNumSolvedProblems = 44;
expectedAvgStationarity = 1e-9;
expectedAvgavgFeasibility = 2e-11;
expectedAvgFeasibility = 2e-9;
expectedNumSolvedProblems = 44;
expectedAvgStationarity = 2e-9;
expectedAvgFeasibility = 2e-11;
expectedAvgComplementarity = 3e-9;
}
else
{
expectedNumSolvedProblems = 44;
expectedAvgStationarity = 2e-9;
expectedAvgavgFeasibility = 1e-9;
expectedAvgFeasibility = 2e-7;
expectedNumSolvedProblems = 44;
expectedAvgStationarity = 2e-9;
expectedAvgFeasibility = 2e-9;
expectedAvgComplementarity = 3e-7;
}
break;

Expand All @@ -154,17 +154,17 @@ int main( int argc, char *argv[] )
options.setToMPC();
if ( argv[argc-1][2] == 's' )
{
expectedNumSolvedProblems = 42;
expectedAvgStationarity = 2e-8;
expectedAvgavgFeasibility = 1e-8;
expectedAvgFeasibility = 1e-7;
expectedNumSolvedProblems = 42;
expectedAvgStationarity = 2e-8;
expectedAvgFeasibility = 1e-8;
expectedAvgComplementarity = 2e-7;
}
else
{
expectedNumSolvedProblems = 42;
expectedAvgStationarity = 2e-8;
expectedAvgavgFeasibility = 1e-8;
expectedAvgFeasibility = 5e-8;
expectedNumSolvedProblems = 42;
expectedAvgStationarity = 3e-8;
expectedAvgFeasibility = 1e-8;
expectedAvgComplementarity = 5e-8;
}
break;

Expand Down Expand Up @@ -280,24 +280,24 @@ int main( int argc, char *argv[] )


/* 4) Print results. */
printf("\n\n" );
printf("Testbench results:\n" );
printf("======================\n\n" );
printf("Pass: %3d\n", npass);
printf("Fail: %3d\n", nfail);
printf("Ratio: %5.1f%%\n", 100.0 * (real_t)npass / (real_t)(npass+nfail));
printf("\n" );
printf( "\n\n" );
printf( "Testbench results:\n" );
printf( "======================\n\n" );
printf( "Pass: %3d\n",npass );
printf( "Fail: %3d\n",nfail );
printf( "Ratio: %5.1f%%\n", 100.0 * (real_t)npass / (real_t)(npass+nfail) );
printf( "\n" );

QPOASES_TEST_FOR_TRUE( npass >= expectedNumSolvedProblems );


printf("avg. stat: %e\n", avgStationarity);
printf("avg. feas: %e\n", avgFeasibility);
printf("avg. cmpl: %e\n", avgFeasibility);
printf( "avg. stat: %e\n", avgStationarity );
printf( "avg. feas: %e\n", avgFeasibility );
printf( "avg. cmpl: %e\n", avgComplementarity );

QPOASES_TEST_FOR_TOL( avgStationarity, expectedAvgStationarity );
QPOASES_TEST_FOR_TOL( avgFeasibility, expectedAvgavgFeasibility );
QPOASES_TEST_FOR_TOL( avgComplementarity, expectedAvgFeasibility );
QPOASES_TEST_FOR_TOL( avgStationarity, expectedAvgStationarity );
QPOASES_TEST_FOR_TOL( avgFeasibility, expectedAvgFeasibility );
QPOASES_TEST_FOR_TOL( avgComplementarity, expectedAvgComplementarity );


return 0;
Expand Down
97 changes: 97 additions & 0 deletions testing/cpp/test_hs268.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* This file is part of qpOASES.
*
* qpOASES -- An Implementation of the Online Active Set Strategy.
* Copyright (C) 2007-2014 by Hans Joachim Ferreau, Andreas Potschka,
* Christian Kirches et al. All rights reserved.
*
* qpOASES is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* qpOASES is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with qpOASES; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/


/**
* \file testing/cpp/test_bench.cpp
* \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau
* \version 3.0
* \date 2010-2014
*
* Unit test running all benchmark examples stored in problems directory.
*/



#include <dirent.h>
#include <cstring>
#include <cstdlib>
#include <qpOASES.hpp>
#include <qpOASES/UnitTesting.hpp>


/** Run benchmark examples. */
int main( int argc, char *argv[] )
{
USING_NAMESPACE_QPOASES

/* 1) Define benchmark arguments. */
BooleanType isSparse = BT_FALSE;
//BooleanType isSparse = BT_TRUE;
Options options;
options.setToDefault();
//options.setToMPC();
//options.setToReliable();
//options.printLevel = PL_LOW;
//options.printLevel = PL_MEDIUM;
options.printLevel = PL_TABULAR;


int nWSR;
real_t maxCPUtime; /* seconds */
real_t maxStationarity = 0.0, maxFeasibility = 0.0, maxComplementarity = 0.0;

char OQPproblem[MAX_STRING_LENGTH];
char problem[] = "HS268";
returnValue returnvalue;


/* 3) Run benchmark. */
fprintf(stdFile, "%-10s ", problem);
fflush(stdFile);

snprintf(OQPproblem, MAX_STRING_LENGTH, "../testing/cpp/data/problems/%s/", problem);
maxCPUtime = 100.0;
nWSR = 100;

returnvalue = runOQPbenchmark( OQPproblem, isSparse, options,
nWSR, maxCPUtime, maxStationarity, maxFeasibility, maxComplementarity
);

printf( "\n" );
printf( "stat: %e\n", maxStationarity );
printf( "feas: %e\n", maxFeasibility );
printf( "cmpl: %e\n", maxComplementarity );

QPOASES_TEST_FOR_TOL( maxStationarity, 1e-11 );
QPOASES_TEST_FOR_TOL( maxFeasibility, 1e-14 );
QPOASES_TEST_FOR_TOL( maxComplementarity, 1e-14 );


return 0;
}


/*
* end of file
*/
1 change: 1 addition & 0 deletions testing/runUnitTests
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ runTest $counter ../bin/test_example4;
runTest $counter ../bin/test_example5;
runTest $counter ../bin/test_exampleLP;
runTest $counter ../bin/test_qrecipe;
runTest $counter ../bin/test_hs268;

runTest $counter ../bin/test_example6;
runTest $counter ../bin/test_example7;
Expand Down

0 comments on commit 76a6e81

Please sign in to comment.