├── .codecov.yml ├── .gitignore ├── .gitmodules ├── .mailmap ├── .travis.yml ├── AUTHORS ├── CMakeLists.txt ├── CONTRIBUTING.md ├── COPYING ├── COPYING.LESSER ├── NEWS ├── README.md ├── THANKS ├── TODO ├── appveyor.yml ├── doc ├── Doxyfile.extra.in ├── getting-started.html └── operators-decorators.html ├── include └── roboptim │ ├── core.hh │ └── core │ ├── alloc.hh │ ├── cache.hh │ ├── cache.hxx │ ├── callback │ ├── multiplexer.hh │ ├── multiplexer.hxx │ ├── wrapper.hh │ └── wrapper.hxx │ ├── debug.hh │ ├── decorator │ ├── cached-function.hh │ ├── cached-function.hxx │ ├── finite-difference-gradient.hh │ └── finite-difference-gradient.hxx │ ├── derivable-function.hh │ ├── derivable-parametrized-function.hh │ ├── derivative-size.hh │ ├── detail │ ├── autopromote.hh │ ├── structured-input.hh │ ├── structured-input.hxx │ └── utility.hh │ ├── differentiable-function.hh │ ├── differentiable-function.hxx │ ├── finite-difference-gradient.hh │ ├── function-pool.hh │ ├── function-pool.hxx │ ├── function.hh │ ├── function.hxx │ ├── function │ ├── constant.hh │ ├── cos.hh │ ├── identity.hh │ ├── polynomial.hh │ ├── polynomial.hxx │ └── sin.hh │ ├── fwd.hh │ ├── generic-solver.hh │ ├── indent.hh │ ├── io.hh │ ├── linear-function.hh │ ├── linear-function.hxx │ ├── n-times-derivable-function.hh │ ├── n-times-derivable-function.hxx │ ├── numeric-linear-function.hh │ ├── numeric-linear-function.hxx │ ├── numeric-quadratic-function.hh │ ├── numeric-quadratic-function.hxx │ ├── operator │ ├── bind.hh │ ├── bind.hxx │ ├── chain.hh │ ├── chain.hxx │ ├── concatenate.hh │ ├── concatenate.hxx │ ├── derivative.hh │ ├── map.hh │ ├── map.hxx │ ├── minus.hh │ ├── minus.hxx │ ├── plus.hh │ ├── plus.hxx │ ├── product.hh │ ├── product.hxx │ ├── scalar.hh │ ├── scalar.hxx │ ├── selection-by-id.hh │ ├── selection-by-id.hxx │ ├── selection.hh │ ├── selection.hxx │ ├── split.hh │ └── split.hxx │ ├── optimization-logger.hh │ ├── optimization-logger.hxx │ ├── parametrized-function.hh │ ├── parametrized-function.hxx │ ├── plugin │ ├── dummy-laststate.hh │ ├── dummy-laststate.hxx │ ├── dummy-td.hh │ ├── dummy.hh │ └── dummy.hxx │ ├── portability.hh │ ├── problem.hh │ ├── problem.hxx │ ├── quadratic-function.hh │ ├── quadratic-function.hxx │ ├── result-analyzer.hh │ ├── result-analyzer.hxx │ ├── result-with-warnings.hh │ ├── result.hh │ ├── scaling-helper.hh │ ├── scaling-helper.hxx │ ├── solver-callback.hh │ ├── solver-callback.hxx │ ├── solver-error.hh │ ├── solver-factory.hh │ ├── solver-factory.hxx │ ├── solver-state.hh │ ├── solver-state.hxx │ ├── solver-warning.hh │ ├── solver.hh │ ├── solver.hxx │ ├── sum-of-c1-squares.hh │ ├── sum-of-c1-squares.hxx │ ├── sys.hh │ ├── terminal-color.hh │ ├── twice-derivable-function.hh │ ├── twice-differentiable-function.hh │ ├── twice-differentiable-function.hxx │ ├── util.hh │ ├── util.hxx │ └── visualization │ ├── fwd.hh │ ├── gnuplot-commands.hh │ ├── gnuplot-differentiable-function.hh │ ├── gnuplot-function.hh │ ├── gnuplot-matrix.hh │ ├── gnuplot.hh │ ├── matplotlib-commands.hh │ ├── matplotlib-function.hh │ ├── matplotlib-matrix.hh │ └── matplotlib.hh ├── package.xml ├── src ├── CMakeLists.txt ├── alloc.cc ├── debug.cc ├── debug.hh ├── doc.hh ├── dummy-d-sparse-laststate.cc ├── dummy-laststate.cc ├── dummy-sparse.cc ├── dummy-td.cc ├── dummy.cc ├── finite-difference-gradient.cc ├── generic-solver.cc ├── indent.cc ├── result-with-warnings.cc ├── result.cc ├── roboptim-core-precompile.cc ├── solver-error.cc ├── solver-warning.cc ├── solver.cc ├── util.cc └── visualization │ ├── gnuplot-commands.cc │ ├── gnuplot-differentiable-function.cc │ ├── gnuplot-matrix.cc │ ├── gnuplot.cc │ ├── matplotlib-commands.cc │ ├── matplotlib-matrix.cc │ └── matplotlib.cc └── tests ├── CMakeLists.txt ├── cache.cc ├── cache.stdout ├── decorator-cached-function.cc ├── decorator-cached-function.stdout ├── decorator-finite-difference-gradient.cc ├── decorator-finite-difference-gradient.stdout ├── decorator-finite-difference-jacobian.cc ├── decorator-finite-difference-jacobian.stdout ├── derivable-function-sparse.stdout ├── derivable-function.cc ├── derivable-function.stdout ├── derivable-parametrized-function.cc ├── derivable-parametrized-function.stdout ├── detail-autopromote.cc ├── detail-structured-input.cc ├── detail-utility.cc ├── example.cc ├── example.stdout ├── function-constant.cc ├── function-constant.stdout ├── function-cos.cc ├── function-identity.cc ├── function-identity.stdout ├── function-polynomial.cc ├── function-pool.cc ├── function-pool.stdout ├── function-sin.cc ├── function-typing.cc ├── function.cc ├── function.stdout ├── indent.cc ├── indent.stdout ├── interval.cc ├── interval.stdout ├── linear-function.cc ├── linear-function.stdout ├── multiplexer.cc ├── multiplexer.stdout ├── n-times-derivable-function.cc ├── n-times-derivable-function.stdout ├── numeric-linear-function.cc ├── numeric-linear-function.stdout ├── numeric-quadratic-function.cc ├── numeric-quadratic-function.stdout ├── operator-bind.cc ├── operator-bind.stdout ├── operator-chain.cc ├── operator-concatenate.cc ├── operator-derivative.cc ├── operator-map.cc ├── operator-minus.cc ├── operator-plus.cc ├── operator-product.cc ├── operator-product.stdout ├── operator-scalar.cc ├── operator-scalar.stdout ├── operator-selection-by-id.cc ├── operator-selection.cc ├── operator-split.cc ├── operator-split.stdout ├── optimization-logger.cc ├── optimization-logger.stdout ├── parametrized-function.cc ├── parametrized-function.stdout ├── plugin-laststate.cc ├── plugin-laststate.stdout ├── plugin.cc ├── plugin.stdout ├── problem-cc.cc ├── problem-cc.stdout ├── problem.cc ├── problem.stdout ├── quadratic-function.cc ├── quadratic-function.stdout ├── ref.cc ├── ref.stdout ├── result-analyzer.cc ├── result-analyzer.stdout ├── result-with-warnings.cc ├── result-with-warnings.stdout ├── result.cc ├── result.stdout ├── scaling-helper.cc ├── scaling-helper.stdout ├── simple.cc ├── simple.stdout ├── solver-error.cc ├── solver-error.stdout ├── solver-factory.cc ├── solver-factory.stdout ├── solver-state.cc ├── solver-state.stdout ├── solver.cc ├── solver.stdout ├── storage-order.cc ├── storage-order.stdout ├── sum-of-c1-squares.cc ├── sum-of-c1-squares.stdout ├── terminal-color-normal.stdout ├── terminal-color-tty.stdout ├── terminal-color.cc ├── twice-derivable-function.cc ├── twice-derivable-function.stdout ├── util.cc ├── util.stdout ├── visualization-gnuplot-differentiable-function.cc ├── visualization-gnuplot-differentiable-function.stdout ├── visualization-gnuplot-function.cc ├── visualization-gnuplot-function.stdout ├── visualization-gnuplot-simple.cc ├── visualization-gnuplot-simple.stdout ├── visualization-matplotlib-function.cc ├── visualization-matplotlib-function.stdout ├── visualization-matplotlib-matrix.cc ├── visualization-matplotlib-matrix.stdout ├── visualization-matplotlib-multiplot.cc ├── visualization-matplotlib-multiplot.stdout ├── visualization-matplotlib-simple.cc ├── visualization-matplotlib-simple.stdout └── visualization-util.stdout /.codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | max_report_age: off 3 | 4 | coverage: 5 | range: 60..90 6 | round: down 7 | precision: 2 8 | 9 | status: 10 | project: 11 | default: 12 | threshold: null 13 | if_not_found: success 14 | patch: 15 | default: 16 | enabled: yes 17 | threshold: null 18 | if_not_found: success 19 | changes: 20 | default: 21 | enabled: yes 22 | threshold: null 23 | if_not_found: success 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build* 2 | _build* 3 | _travis* 4 | .version 5 | .tarball-version 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tests/shared-tests"] 2 | path = tests/shared-tests 3 | url = git://github.com/roboptim/roboptim-shared-tests.git 4 | [submodule "cmake"] 5 | path = cmake 6 | url = https://github.com/jrl-umi3218/jrl-cmakemodules 7 | [submodule ".travis"] 8 | path = .travis 9 | url = git://github.com/jrl-umi3218/jrl-travis.git 10 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Antonio El Khoury 2 | Florent Lamiraux 3 | Thomas Moulard 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | This package was written by and with the assistance of 2 | 3 | * Ko Ayusawa k.ayusawa@aist.go.jp 4 | - Windows (Intel compiler) portage 5 | 6 | * Stanislas Brossette stanislas.brossette@gmail.com 7 | - Polynomial function. 8 | 9 | * Benjamin Chrétien chretien@lirmm.fr 10 | - Package maintainer. 11 | - Solver error reporting enhancement. 12 | - Callback system. 13 | - Eigen::Ref support. 14 | - NLopt bridge implementation. 15 | - PaGMO bridge implementation. 16 | - Python bindings implementation. 17 | - Analysis scripts. 18 | 19 | * Félix Darricau felix.darricau@gmail.com 20 | - Manifold support. 21 | 22 | * Grégoire Duchemin greg.duchemin@gmail.com 23 | - Manifold support. 24 | 25 | * Antonio El Khoury antonio.elkhoury@gmail.com 26 | - Non-scalar constraints support. 27 | 28 | * Florent Lamiraux florent@laas.fr 29 | - Interface design. 30 | - Eigen3 support. 31 | 32 | * François Keith francois.keith@gmail.com 33 | - Microsoft Windows / Microsoft Visual Studio support. 34 | - Non-scalar constraints support. 35 | 36 | * Thomas Moulard thomas.moulard@gmail.com 37 | - Package creation. 38 | - Interface implementation. 39 | - CFSQP bridge implementation. 40 | - Ipopt bridge implementation. 41 | - NAG bridge implementation. 42 | - KNITRO bridge implementation. 43 | - Tutorials. 44 | - Homebrew repository. 45 | 46 | * Olivier Stasse olivier.stasse@aist.go.jp 47 | - Interface design. 48 | 49 | * Pierre-Brice Wieber pierre-brice.wieber@inrialpes.fr 50 | - Interface design. 51 | - CFSQP integration. 52 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute # 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | a just a few small guidelines you need to follow. 5 | 6 | 7 | ## Contributor License Agreement ## 8 | 9 | Contributions to RobOptim must be accompanied by a Contributor License 10 | Agreement. This is not a copyright **assignment**, it simply gives 11 | us permission to use and redistribute your contributions as part 12 | of the project. 13 | 14 | * If you are an individual writing original source code and you're sure you 15 | own the intellectual property, then you'll need to sign an [individual 16 | CLA][]. 17 | 18 | * If you work for a company that wants to allow you to contribute your work, 19 | then you'll need to sign a [corporate CLA][]. 20 | 21 | You generally only need to submit a CLA once, so if you've already submitted 22 | one (even if it was for a different project), you probably don't need to do it 23 | again. 24 | 25 | [individual CLA]: https://secure.echosign.com/public/hostedForm?formid=6E36JIE2DS4J23 26 | [corporate CLA]: https://secure.echosign.com/public/hostedForm?formid=6E36JH542R7X4V 27 | 28 | 29 | ## Submitting a patch ## 30 | 31 | 1. It's generally best to start by opening a new issue describing the bug or 32 | feature you're intending to fix. Even if you think it's relatively minor, 33 | it's helpful to know what people are working on. Mention in the initial 34 | issue that you are planning to work on that bug or feature so that it can 35 | be assigned to you. 36 | 37 | 1. Follow the normal process of [forking][] the project, and setup a new 38 | branch to work in. It's important that each group of changes be done in 39 | separate branches in order to ensure that a pull request only includes the 40 | commits related to that bug or feature. 41 | 42 | 1. Carefully check your commits by compiling and running the test 43 | suite on your machine. You should not break the API, if you have 44 | to, detail why in your commit message. 45 | 46 | 1. Any significant changes should almost always be accompanied by tests. 47 | 48 | 1. Do your best to have [well-formed commit messages][] for each change. 49 | This provides consistency throughout the project, and ensures that commit 50 | messages are able to be formatted properly by various git tools. 51 | 52 | 1. Finally, push the commits to your fork and submit a [pull request][]. 53 | 54 | [forking]: https://help.github.com/articles/fork-a-repo 55 | [well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html 56 | [squash]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits 57 | [pull request]: https://help.github.com/articles/creating-a-pull-request 58 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | -*- outline -*- 2 | 3 | * EPITA/LRDE Tiger's project for indentation handling in C++ streams. 4 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | -*- outline -*- 2 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 3.2-{branch}-{build} 2 | branches: 3 | only: 4 | - master 5 | - dev 6 | 7 | configuration: 8 | - Debug 9 | 10 | platform: 11 | - x64 12 | 13 | os: Visual Studio 2015 14 | clone_folder: C:\devel-src\roboptim-core 15 | environment: 16 | CI_OS_NAME: win32 17 | CI_TOOL: appveyor 18 | # Dependencies should be a list of dependencies separated by spaces 19 | CHOCO_DEPENDENCIES: "doxygen.portable" 20 | GIT_DEPENDENCIES: "gergondet/ltdl-win32" 21 | # Should be the same as clone_folder 22 | PROJECT_SOURCE_DIR: C:\devel-src\roboptim-core 23 | # Do not tinker with the variables below unless you know what you are doing 24 | SOURCE_FOLDER: C:\devel-src 25 | CMAKE_INSTALL_PREFIX: C:/devel 26 | PATH: C:/devel/bin;C:\Libraries\boost_1_60_0\lib64-msvc-14.0;C:\msys64\mingw64\bin;%PATH% 27 | PKG_CONFIG_PATH: C:/devel/lib/pkgconfig 28 | BOOST_ROOT: C:\Libraries\boost_1_60_0 29 | BOOST_LIBRARYDIR: C:\Libraries\boost_1_60_0\lib64-msvc-14.0 30 | MINGW_GFORTRAN: C:\msys64\mingw64\bin\gfortran.exe 31 | # N.B: empty lines here and in test_script are VERY important 32 | build_script: 33 | - ps: >- 34 | Set-PSDebug -Trace 2 35 | 36 | iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aescande/testAppveyor/master/installAsAppveyorDependency.ps1')) 37 | 38 | git submodule update --init --recursive 39 | 40 | . ./.travis/functions.ps1 41 | 42 | setup_build 43 | 44 | ./.travis/dependencies/eigen-3.2.ps1 45 | 46 | install_dependencies 47 | 48 | build_project 49 | test_script: 50 | - cmd: >- 51 | cd %PROJECT_SOURCE_DIR%/build 52 | 53 | ctest --build-config %CONFIGURATION% --exclude-regex example 54 | -------------------------------------------------------------------------------- /doc/Doxyfile.extra.in: -------------------------------------------------------------------------------- 1 | EXAMPLE_PATH+=@CMAKE_SOURCE_DIR@/doc 2 | 3 | ENABLE_PREPROCESSING = YES 4 | MACRO_EXPANSION = YES 5 | EXPAND_ONLY_PREDEF = YES 6 | PREDEFINED = ROBOPTIM_CORE_DEPRECATED 7 | -------------------------------------------------------------------------------- /include/roboptim/core/alloc.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 by Félix Darricau, AIST, CNRS, EPITA 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_ALLOC_HH 19 | # define ROBOPTIM_CORE_ALLOC_HH 20 | 21 | # if defined(EIGEN_RUNTIME_NO_MALLOC) && !defined(ROBOPTIM_DO_NOT_CHECK_ALLOCATION) 22 | # define ROBOPTIM_CHECK_ALLOCATION 23 | # endif //! defined(EIGEN_RUNTIME_NO_MALLOC) && !defined(ROBOPTIM_DO_NOT_CHECK_ALLOCATION) 24 | 25 | // Include only relevant if we check allocations 26 | # ifdef ROBOPTIM_CHECK_ALLOCATION 27 | # include 28 | # endif //! ROBOPTIM_CHECK_ALLOCATION 29 | 30 | # include 31 | 32 | namespace roboptim 33 | { 34 | /// \brief Update the static variable used for Eigen::set_is_malloc_allowed. 35 | ROBOPTIM_CORE_DLLAPI 36 | bool is_malloc_allowed_update (bool update = false, bool new_value = false); 37 | 38 | /// \brief Manage the calls to Eigen::set_is_malloc_allowed. 39 | /// \param allow whether to allow dynamic allocations. 40 | inline bool set_is_malloc_allowed (bool allow) 41 | { 42 | is_malloc_allowed_update (true, allow); 43 | 44 | # ifdef ROBOPTIM_CHECK_ALLOCATION 45 | return Eigen::internal::set_is_malloc_allowed (allow); 46 | # else 47 | return true; 48 | # endif //! ROBOPTIM_CHECK_ALLOCATION 49 | } 50 | 51 | /// \brief Whether dynamic allocation is allowed. 52 | inline bool is_malloc_allowed () 53 | { 54 | return is_malloc_allowed_update (false); 55 | } 56 | } 57 | 58 | # ifdef ROBOPTIM_CHECK_ALLOCATION 59 | # undef ROBOPTIM_CHECK_ALLOCATION 60 | # endif //! ROBOPTIM_CHECK_ALLOCATION 61 | 62 | #endif //! ROBOPTIM_CORE_ALLOC_HH 63 | -------------------------------------------------------------------------------- /include/roboptim/core/callback/wrapper.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 by Benjamin Chrétien, CNRS-LIRMM. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_CALLBACK_WRAPPER_HH 19 | # define ROBOPTIM_CORE_CALLBACK_WRAPPER_HH 20 | 21 | # include 22 | # include 23 | 24 | namespace roboptim 25 | { 26 | namespace callback 27 | { 28 | /// \brief Raw callback wrapper. 29 | /// \tparam S solver type. 30 | template 31 | class Wrapper : public SolverCallback 32 | { 33 | public: 34 | /// \brief Parent type. 35 | typedef SolverCallback parent_t; 36 | 37 | /// \brief Type of the solver. 38 | typedef S solver_t; 39 | 40 | /// \brief Callback function type. 41 | typedef typename solver_t::callback_t callback_t; 42 | 43 | /// \brief Problem type. 44 | typedef typename solver_t::problem_t problem_t; 45 | 46 | /// \brief Type of the state of the solver. 47 | typedef SolverState solverState_t; 48 | 49 | /// \brief Default constructor. 50 | /// \param c raw callback function. 51 | /// \param name optional name. 52 | Wrapper (callback_t c, const std::string& name = "wrapped callback"); 53 | 54 | /// \brief Virtual destructor. 55 | virtual ~Wrapper (); 56 | 57 | protected: 58 | 59 | /// \brief Meta-callback calling multiple callbacks. 60 | /// Unsafe version that can throw exceptions. 61 | /// 62 | /// \param pb problem. 63 | /// \param state solver state. 64 | virtual void perIterationCallbackUnsafe 65 | (const problem_t& pb, solverState_t& state); 66 | 67 | private: 68 | /// \brief Callback function. 69 | callback_t callback_; 70 | }; 71 | } // end of namespace callback 72 | } // end of namespace roboptim 73 | 74 | # include 75 | 76 | #endif //! ROBOPTIM_CORE_CALLBACK_WRAPPER_HH 77 | -------------------------------------------------------------------------------- /include/roboptim/core/callback/wrapper.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 by Benjamin Chrétien, CNRS-LIRMM. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_CALLBACK_WRAPPER_HXX 19 | # define ROBOPTIM_CORE_CALLBACK_WRAPPER_HXX 20 | 21 | # include 22 | # include 23 | # include 24 | # include 25 | 26 | namespace roboptim 27 | { 28 | namespace callback 29 | { 30 | template 31 | Wrapper::Wrapper (callback_t c, const std::string& name) 32 | : parent_t (name), 33 | callback_ (c) 34 | { 35 | } 36 | 37 | template 38 | Wrapper::~Wrapper () 39 | {} 40 | 41 | template 42 | void Wrapper::perIterationCallbackUnsafe 43 | (const problem_t& pb, solverState_t& state) 44 | { 45 | (callback_) (pb, state); 46 | } 47 | 48 | // Explicit template instantiations for dense and sparse matrices. 49 | # ifdef ROBOPTIM_PRECOMPILED_DENSE_SPARSE 50 | extern template class ROBOPTIM_CORE_DLLAPI Wrapper >; 51 | extern template class ROBOPTIM_CORE_DLLAPI Wrapper >; 52 | # endif //! ROBOPTIM_PRECOMPILED_DENSE_SPARSE 53 | 54 | } // end of namespace callback 55 | } // end of namespace roboptim 56 | 57 | #endif //! ROBOPTIM_CORE_CALLBACK_WRAPPER_HXX 58 | -------------------------------------------------------------------------------- /include/roboptim/core/derivable-function.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_DERIVABLE_FUNCTION_HH 19 | # define ROBOPTIM_CORE_DERIVABLE_FUNCTION_HH 20 | // Legacy header. 21 | # include 22 | 23 | namespace roboptim 24 | { 25 | /// \brief Legacy name of TwiceDifferentiableFunction. 26 | typedef DifferentiableFunction DerivableFunction; 27 | 28 | /// \brief Legacy name of TwiceDifferentiableSparseFunction. 29 | typedef DifferentiableSparseFunction DerivableSparseFunction; 30 | 31 | } // end of namespace roboptim. 32 | 33 | #endif //! ROBOPTIM_CORE_DERIVABLE_FUNCTION_HH 34 | -------------------------------------------------------------------------------- /include/roboptim/core/derivative-size.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_DERIVATIVE_SIZE_HH 19 | # define ROBOPTIM_CORE_DERIVATIVE_SIZE_HH 20 | # include 21 | 22 | namespace roboptim 23 | { 24 | template 25 | struct derivativeSize< GenericFunction > 26 | { 27 | static const unsigned int value = 0; 28 | }; 29 | 30 | template 31 | struct derivativeSize< GenericDifferentiableFunction > 32 | { 33 | static const unsigned int value = 1; 34 | }; 35 | 36 | template 37 | struct derivativeSize< GenericTwiceDifferentiableFunction > 38 | { 39 | static const unsigned int value = 2; 40 | }; 41 | 42 | template 43 | struct derivativeSize > 44 | { 45 | static const unsigned int value = N; 46 | }; 47 | } // end of namespace roboptim 48 | 49 | #endif //! ROBOPTIM_CORE_DERIVATIVE_SIZE_HH 50 | -------------------------------------------------------------------------------- /include/roboptim/core/finite-difference-gradient.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 by Benjamin Chrétien, CNRS-LIRMM. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_FINITE_DIFFERENCE_GRADIENT_HH 19 | # define ROBOPTIM_CORE_FINITE_DIFFERENCE_GRADIENT_HH 20 | 21 | # pragma message "Using deprecated include. Please use " \ 22 | "roboptim/core/decorator/finite-difference-gradient.hh instead." 23 | 24 | # include 25 | 26 | #endif //! ROBOPTIM_CORE_FINITE_DIFFERENCE_GRADIENT_HH 27 | -------------------------------------------------------------------------------- /include/roboptim/core/indent.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_INDENT_HH 19 | # define ROBOPTIM_CORE_INDENT_HH 20 | # include 21 | # include 22 | 23 | # include 24 | 25 | namespace roboptim 26 | { 27 | /// \brief The current indentation level for \a o. 28 | ROBOPTIM_CORE_DLLAPI long int& indent (std::ostream& o); 29 | 30 | /// \brief Increment the indentation. 31 | ROBOPTIM_CORE_DLLAPI std::ostream& incindent (std::ostream& o); 32 | 33 | /// \brief Decrement the indentation. 34 | ROBOPTIM_CORE_DLLAPI std::ostream& decindent (std::ostream& o); 35 | 36 | /// \brief Reset the indentation. 37 | ROBOPTIM_CORE_DLLAPI std::ostream& resetindent (std::ostream& o); 38 | 39 | /// \brief Print an end of line, then set the indentation. 40 | ROBOPTIM_CORE_DLLAPI std::ostream& iendl (std::ostream& o); 41 | 42 | /// \brief Increment the indentation, print an end of line, 43 | /// and set the indentation. 44 | ROBOPTIM_CORE_DLLAPI std::ostream& incendl (std::ostream& o); 45 | 46 | /// \brief Decrement the indentation, print an end of line, 47 | /// and set the indentation. 48 | ROBOPTIM_CORE_DLLAPI std::ostream& decendl (std::ostream& o); 49 | } 50 | 51 | #endif //! ROBOPTIM_CORE_INDENT_HH 52 | -------------------------------------------------------------------------------- /include/roboptim/core/io.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_IO_HH 19 | # define ROBOPTIM_CORE_IO_HH 20 | # include 21 | # include 22 | 23 | # include 24 | # include 25 | 26 | #endif //! ROBOPTIM_CORE_IO_HH 27 | -------------------------------------------------------------------------------- /include/roboptim/core/linear-function.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_LINEAR_FUNCTION_HH 19 | # define ROBOPTIM_CORE_LINEAR_FUNCTION_HH 20 | # include 21 | 22 | # include 23 | # include 24 | 25 | namespace roboptim 26 | { 27 | /// \addtogroup roboptim_meta_function 28 | /// @{ 29 | 30 | /// \brief Define an abstract linear function. 31 | /// 32 | /// Inherit from this class when implementing linear functions. 33 | template 34 | class GenericLinearFunction : public GenericQuadraticFunction 35 | { 36 | public: 37 | ROBOPTIM_TWICE_DIFFERENTIABLE_FUNCTION_FWD_TYPEDEFS_ 38 | (GenericQuadraticFunction); 39 | ROBOPTIM_ADD_FLAG(ROBOPTIM_IS_LINEAR); 40 | 41 | /// \brief Concrete class constructor should call this constructor. 42 | /// 43 | /// \param inputSize function arity 44 | /// \param outputSize result size 45 | /// \param name function's name 46 | GenericLinearFunction (size_type inputSize, 47 | size_type outputSize = 1, 48 | std::string name = std::string ()); 49 | 50 | /// \brief Display the function on the specified output stream. 51 | /// 52 | /// \param o output stream used for display 53 | /// \return output stream 54 | virtual std::ostream& print (std::ostream&) const; 55 | protected: 56 | void impl_hessian (hessian_ref hessian, 57 | const_argument_ref argument, 58 | size_type functionId = 0) const; 59 | }; 60 | 61 | /// @} 62 | 63 | } // end of namespace roboptim 64 | 65 | # include 66 | #endif //! ROBOPTIM_CORE_LINEAR_FUNCTION_HH 67 | -------------------------------------------------------------------------------- /include/roboptim/core/linear-function.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_LINEAR_FUNCTION_HXX 19 | # define ROBOPTIM_CORE_LINEAR_FUNCTION_HXX 20 | # include 21 | # include 22 | 23 | namespace roboptim 24 | { 25 | template 26 | GenericLinearFunction::GenericLinearFunction (size_type inputSize, 27 | size_type outputSize, 28 | std::string name) 29 | : GenericQuadraticFunction (inputSize, outputSize, name) 30 | {} 31 | 32 | template 33 | void 34 | GenericLinearFunction::impl_hessian (hessian_ref hessian, 35 | const_argument_ref, 36 | size_type) const 37 | { 38 | this->setZero (hessian); 39 | } 40 | 41 | template 42 | std::ostream& 43 | GenericLinearFunction::print (std::ostream& o) const 44 | { 45 | if (this->getName ().empty ()) 46 | return o << "Linear function"; 47 | else 48 | return o << this->getName () << " (linear function)"; 49 | } 50 | 51 | // Explicit template instantiations for dense and sparse matrices. 52 | # ifdef ROBOPTIM_PRECOMPILED_DENSE_SPARSE 53 | ROBOPTIM_ALLOW_ATTRIBUTES_ON 54 | extern template class ROBOPTIM_CORE_DLLAPI GenericLinearFunction; 55 | extern template class ROBOPTIM_CORE_DLLAPI GenericLinearFunction; 56 | ROBOPTIM_ALLOW_ATTRIBUTES_OFF 57 | # endif 58 | 59 | } // end of namespace roboptim 60 | 61 | #endif //! ROBOPTIM_CORE_LINEAR_FUNCTION_HXX 62 | -------------------------------------------------------------------------------- /include/roboptim/core/n-times-derivable-function.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_N_TIMES_DERIVABLE_HXX 19 | # define ROBOPTIM_CORE_N_TIMES_DERIVABLE_HXX 20 | 21 | namespace roboptim 22 | { 23 | template 24 | NTimesDerivableFunction::~NTimesDerivableFunction () 25 | { 26 | } 27 | 28 | template 29 | std::ostream& 30 | NTimesDerivableFunction::print (std::ostream& o) const 31 | { 32 | o << derivabilityOrder << "-time differentiable function."; 33 | return o; 34 | } 35 | } 36 | #endif //! ROBOPTIM_CORE_N_TIMES_DERIVABLE_HXX 37 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/chain.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_CHAIN_HXX 19 | # define ROBOPTIM_CORE_OPERATOR_CHAIN_HXX 20 | # include 21 | 22 | namespace roboptim 23 | { 24 | template 25 | Chain::Chain 26 | (boost::shared_ptr left, boost::shared_ptr right) 27 | : detail::PromoteTrait::T_promote 28 | (right->inputSize (), 29 | left->outputSize (), 30 | (boost::format ("%1%(%2%)") 31 | % left->getName () 32 | % right->getName ()).str ()), 33 | left_ (left), 34 | right_ (right), 35 | rightResult_ (right->outputSize ()), 36 | gradientLeft_ (left->inputSize ()), 37 | gradientRight_ (right->inputSize ()), 38 | jacobianLeft_ (left->outputSize (), 39 | left->inputSize ()), 40 | jacobianRight_ (right->outputSize (), 41 | right->inputSize ()) 42 | { 43 | if (left->inputSize () != right->outputSize ()) 44 | throw std::runtime_error 45 | ("left input size and right output size mismatch"); 46 | 47 | rightResult_.setZero (); 48 | gradientLeft_.setZero (); 49 | gradientRight_.setZero (); 50 | jacobianLeft_.setZero (); 51 | jacobianRight_.setZero (); 52 | } 53 | 54 | template 55 | Chain::~Chain () 56 | {} 57 | 58 | template 59 | void 60 | Chain::impl_compute 61 | (result_ref result, const_argument_ref x) 62 | const 63 | { 64 | (*right_) (rightResult_, x); 65 | (*left_) (result, rightResult_); 66 | } 67 | 68 | template 69 | void 70 | Chain::impl_gradient (gradient_ref gradient, 71 | const_argument_ref x, 72 | size_type functionId) 73 | const 74 | { 75 | (*right_) (rightResult_, x); 76 | left_->gradient (gradientLeft_, rightResult_, functionId); 77 | right_->jacobian (jacobianRight_, x); 78 | gradient.noalias () = gradientLeft_.adjoint () * jacobianRight_; 79 | } 80 | 81 | template 82 | void 83 | Chain::impl_jacobian (jacobian_ref jacobian, 84 | const_argument_ref x) 85 | const 86 | { 87 | (*right_) (rightResult_, x); 88 | left_->jacobian (jacobianLeft_, rightResult_); 89 | right_->jacobian (jacobianRight_, x); 90 | 91 | jacobian.noalias () = jacobianLeft_ * jacobianRight_; 92 | } 93 | 94 | } // end of namespace roboptim. 95 | 96 | #endif //! ROBOPTIM_CORE_OPERATOR_CHAIN_HXX 97 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/map.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_MAP_HH 19 | # define ROBOPTIM_CORE_OPERATOR_MAP_HH 20 | # include 21 | # include 22 | 23 | # include 24 | # include 25 | 26 | 27 | namespace roboptim 28 | { 29 | /// \addtogroup roboptim_operator 30 | /// @{ 31 | 32 | /// \brief Apply a function several times to an input vector. 33 | /// 34 | /// Input: 35 | /// [x_0^0 x_1^0 ... x_N^0 ... x_0^M x_1^M ... x_N^M] 36 | /// 37 | /// Output: 38 | /// [f(x_0^0 x_1^0 ... x_N^0) ... f(x_0^M x_1^M ... x_N^M)] 39 | /// 40 | /// \tparam U input function type. 41 | template 42 | class Map : public detail::AutopromoteTrait::T_type 43 | { 44 | public: 45 | typedef typename detail::AutopromoteTrait::T_type parentType_t; 46 | ROBOPTIM_DIFFERENTIABLE_FUNCTION_FWD_TYPEDEFS_ (parentType_t); 47 | 48 | typedef boost::shared_ptr MapShPtr_t; 49 | 50 | /// \brief Map operator constructor. 51 | /// \param origin input function. 52 | /// \param repeat number of times to repeat the function. 53 | explicit Map (boost::shared_ptr origin, size_type repeat); 54 | ~Map (); 55 | 56 | const boost::shared_ptr& origin () const 57 | { 58 | return origin_; 59 | } 60 | 61 | boost::shared_ptr& origin () 62 | { 63 | return origin_; 64 | } 65 | 66 | void impl_compute (result_ref result, const_argument_ref x) 67 | const ; 68 | 69 | void impl_gradient (gradient_ref gradient, 70 | const_argument_ref argument, 71 | size_type functionId = 0) 72 | const ; 73 | void impl_jacobian (jacobian_ref jacobian, 74 | const_argument_ref arg) 75 | const ; 76 | private: 77 | boost::shared_ptr origin_; 78 | size_type repeat_; 79 | 80 | mutable argument_t x_; 81 | mutable result_t result_; 82 | mutable gradient_t gradient_; 83 | mutable jacobian_t jacobian_; 84 | }; 85 | 86 | template 87 | boost::shared_ptr > 88 | map (boost::shared_ptr origin, typename U::size_type repeat) 89 | { 90 | return boost::make_shared > (origin, repeat); 91 | } 92 | 93 | /// @} 94 | 95 | } // end of namespace roboptim. 96 | 97 | # include 98 | #endif //! ROBOPTIM_CORE_OPERATOR_MAP_HH 99 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/minus.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_MINUS_HXX 19 | # define ROBOPTIM_CORE_OPERATOR_MINUS_HXX 20 | # include 21 | 22 | namespace roboptim 23 | { 24 | template 25 | Minus::Minus 26 | (boost::shared_ptr left, boost::shared_ptr right) 27 | : detail::PromoteTrait::T_promote 28 | (left->inputSize (), 29 | left->outputSize (), 30 | (boost::format ("%1% - %2%") 31 | % left->getName () 32 | % right->getName ()).str ()), 33 | left_ (left), 34 | right_ (right), 35 | result_ (left->outputSize ()), 36 | gradient_ (left->inputSize ()), 37 | jacobian_ (left->outputSize (), 38 | left->inputSize ()) 39 | { 40 | if (left->inputSize () != right->inputSize () 41 | || left->outputSize () != right->outputSize ()) 42 | throw std::runtime_error ("left and right size mismatch"); 43 | result_.setZero (); 44 | gradient_.setZero (); 45 | jacobian_.setZero (); 46 | } 47 | 48 | template 49 | Minus::~Minus () 50 | {} 51 | 52 | template 53 | void 54 | Minus::impl_compute 55 | (result_ref result, const_argument_ref x) 56 | const 57 | { 58 | result.setZero (); 59 | (*left_) (result, x); 60 | (*right_) (result_, x); 61 | result -= result_; 62 | } 63 | 64 | template 65 | void 66 | Minus::impl_gradient (gradient_ref gradient, 67 | const_argument_ref argument, 68 | size_type functionId) 69 | const 70 | { 71 | left_->gradient (gradient, argument, functionId); 72 | right_->gradient (gradient_, argument, functionId); 73 | gradient -= gradient_; 74 | } 75 | 76 | template 77 | void 78 | Minus::impl_jacobian (jacobian_ref jacobian, 79 | const_argument_ref argument) 80 | const 81 | { 82 | left_->jacobian (jacobian, argument); 83 | right_->jacobian (jacobian_, argument); 84 | jacobian -= jacobian_; 85 | } 86 | } // end of namespace roboptim. 87 | 88 | #endif //! ROBOPTIM_CORE_OPERATOR_MINUS_HXX 89 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/plus.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_PLUS_HXX 19 | # define ROBOPTIM_CORE_OPERATOR_PLUS_HXX 20 | # include 21 | 22 | namespace roboptim 23 | { 24 | template 25 | Plus::Plus 26 | (boost::shared_ptr left, boost::shared_ptr right) 27 | : detail::PromoteTrait::T_promote 28 | (left->inputSize (), 29 | left->outputSize (), 30 | (boost::format ("%1% + %2%") 31 | % left->getName () 32 | % right->getName ()).str ()), 33 | left_ (left), 34 | right_ (right), 35 | result_ (left->outputSize ()), 36 | gradient_ (left->inputSize ()), 37 | jacobian_ (left->outputSize (), 38 | left->inputSize ()) 39 | { 40 | if (left->inputSize () != right->inputSize () 41 | || left->outputSize () != right->outputSize ()) 42 | throw std::runtime_error ("left and right size mismatch"); 43 | result_.setZero (); 44 | gradient_.setZero (); 45 | jacobian_.setZero (); 46 | } 47 | 48 | template 49 | Plus::~Plus () 50 | {} 51 | 52 | template 53 | void 54 | Plus::impl_compute 55 | (result_ref result, const_argument_ref x) 56 | const 57 | { 58 | result.setZero (); 59 | (*left_) (result, x); 60 | (*right_) (result_, x); 61 | result += result_; 62 | } 63 | 64 | template 65 | void 66 | Plus::impl_gradient (gradient_ref gradient, 67 | const_argument_ref argument, 68 | size_type functionId) 69 | const 70 | { 71 | left_->gradient (gradient, argument, functionId); 72 | right_->gradient (gradient_, argument, functionId); 73 | gradient += gradient_; 74 | } 75 | 76 | template 77 | void 78 | Plus::impl_jacobian (jacobian_ref jacobian, 79 | const_argument_ref argument) 80 | const 81 | { 82 | left_->jacobian (jacobian, argument); 83 | right_->jacobian (jacobian_, argument); 84 | jacobian += jacobian_; 85 | } 86 | } // end of namespace roboptim. 87 | 88 | #endif //! ROBOPTIM_CORE_OPERATOR_PLUS_HXX 89 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/scalar.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_SCALAR_HXX 19 | # define ROBOPTIM_CORE_OPERATOR_SCALAR_HXX 20 | # include 21 | 22 | namespace roboptim 23 | { 24 | template 25 | Scalar::Scalar 26 | (boost::shared_ptr origin, 27 | value_type scalar) 28 | : detail::AutopromoteTrait::T_type 29 | (origin->inputSize (), 30 | origin->outputSize (), 31 | (boost::format ("%1% * (%2%)") 32 | % scalar 33 | % (origin->getName ().empty ()? "f" : origin->getName ())).str ()), 34 | origin_ (origin), 35 | scalar_ (scalar) 36 | {} 37 | 38 | template 39 | Scalar::~Scalar () 40 | {} 41 | 42 | template 43 | void 44 | Scalar::impl_compute 45 | (result_ref result, const_argument_ref x) 46 | const 47 | { 48 | origin_->operator () (result, x); 49 | result *= scalar_; 50 | } 51 | 52 | template 53 | void 54 | Scalar::impl_gradient (gradient_ref gradient, 55 | const_argument_ref argument, 56 | size_type functionId) 57 | const 58 | { 59 | origin_->gradient (gradient, argument, functionId); 60 | gradient *= scalar_; 61 | } 62 | 63 | template 64 | void 65 | Scalar::impl_jacobian (jacobian_ref jacobian, 66 | const_argument_ref argument) 67 | const 68 | { 69 | origin_->jacobian (jacobian, argument); 70 | jacobian *= scalar_; 71 | } 72 | 73 | template 74 | void 75 | Scalar::impl_hessian (hessian_ref hessian, 76 | const_argument_ref argument, 77 | size_type functionId) 78 | const 79 | { 80 | origin_->hessian (hessian, argument, functionId); 81 | hessian *= scalar_; 82 | } 83 | 84 | template 85 | std::ostream& Scalar::print (std::ostream& o) const 86 | { 87 | o << this->getName () << ":" << incindent 88 | << iendl << "Sub-function: " << *origin_ 89 | << decindent; 90 | 91 | return o; 92 | } 93 | 94 | } // end of namespace roboptim. 95 | 96 | #endif //! ROBOPTIM_CORE_OPERATOR_SCALAR_HXX 97 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/selection-by-id.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_SELECTION_BY_ID_HH 19 | # define ROBOPTIM_CORE_OPERATOR_SELECTION_BY_ID_HH 20 | # include 21 | # include 22 | # include 23 | 24 | # include 25 | # include 26 | 27 | 28 | namespace roboptim 29 | { 30 | /// \addtogroup roboptim_operator 31 | /// @{ 32 | 33 | /// \brief Select part of a function. 34 | /// \tparam U input function type. 35 | template 36 | class SelectionById : public detail::AutopromoteTrait::T_type 37 | { 38 | public: 39 | typedef typename detail::AutopromoteTrait::T_type parentType_t; 40 | ROBOPTIM_DIFFERENTIABLE_FUNCTION_FWD_TYPEDEFS_ (parentType_t); 41 | 42 | typedef boost::shared_ptr SelectionByIdShPtr_t; 43 | 44 | explicit SelectionById (boost::shared_ptr origin, 45 | std::vector selector); 46 | ~SelectionById (); 47 | 48 | const boost::shared_ptr& origin () const 49 | { 50 | return origin_; 51 | } 52 | 53 | boost::shared_ptr& origin () 54 | { 55 | return origin_; 56 | } 57 | 58 | void impl_compute (result_ref result, const_argument_ref x) 59 | const; 60 | 61 | void impl_gradient (gradient_ref gradient, 62 | const_argument_ref argument, 63 | size_type functionId = 0) 64 | const; 65 | void impl_jacobian (jacobian_ref jacobian, 66 | const_argument_ref arg) 67 | const; 68 | private: 69 | boost::shared_ptr origin_; 70 | std::vector selector_; 71 | 72 | mutable result_t result_; 73 | mutable gradient_t gradient_; 74 | }; 75 | 76 | template 77 | boost::shared_ptr > 78 | selectionById (boost::shared_ptr origin, 79 | std::vector selector) 80 | { 81 | return boost::make_shared > (origin, selector); 82 | } 83 | 84 | /// @} 85 | 86 | } // end of namespace roboptim. 87 | 88 | # include 89 | #endif //! ROBOPTIM_CORE_OPERATOR_SELECTION_BY_ID_HH 90 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/selection.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_SELECTION_HH 19 | # define ROBOPTIM_CORE_OPERATOR_SELECTION_HH 20 | # include 21 | # include 22 | # include 23 | 24 | # include 25 | # include 26 | 27 | 28 | namespace roboptim 29 | { 30 | /// \addtogroup roboptim_operator 31 | /// @{ 32 | 33 | /// \brief Select a block of a function's output. 34 | /// The selected block is a range given by a start and a size. 35 | /// \tparam U input function type. 36 | template 37 | class Selection : public detail::AutopromoteTrait::T_type 38 | { 39 | public: 40 | typedef typename detail::AutopromoteTrait::T_type parentType_t; 41 | ROBOPTIM_DIFFERENTIABLE_FUNCTION_FWD_TYPEDEFS_ (parentType_t); 42 | 43 | typedef boost::shared_ptr SelectionShPtr_t; 44 | 45 | /// \brief Create a selection given an input function and a block. 46 | /// \param fct input function. 47 | /// \param start start of the range. 48 | /// \param size size of the range. 49 | explicit Selection (boost::shared_ptr fct, 50 | size_type start, size_type size); 51 | ~Selection (); 52 | 53 | const boost::shared_ptr& origin () const 54 | { 55 | return origin_; 56 | } 57 | 58 | boost::shared_ptr& origin () 59 | { 60 | return origin_; 61 | } 62 | 63 | void impl_compute (result_ref result, const_argument_ref x) 64 | const; 65 | 66 | void impl_gradient (gradient_ref gradient, 67 | const_argument_ref argument, 68 | size_type functionId = 0) 69 | const; 70 | void impl_jacobian (jacobian_ref jacobian, 71 | const_argument_ref arg) 72 | const; 73 | private: 74 | boost::shared_ptr origin_; 75 | 76 | size_type start_; 77 | size_type size_; 78 | 79 | mutable result_t result_; 80 | mutable gradient_t gradient_; 81 | mutable jacobian_t jacobian_; 82 | }; 83 | 84 | template 85 | boost::shared_ptr > 86 | selection (boost::shared_ptr origin, 87 | typename Selection::size_type start = 0, 88 | typename Selection::size_type size = 1) 89 | { 90 | return boost::make_shared > (origin, start, size); 91 | } 92 | 93 | /// @} 94 | 95 | } // end of namespace roboptim. 96 | 97 | # include 98 | #endif //! ROBOPTIM_CORE_OPERATOR_SELECTION_HH 99 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/selection.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_SELECTION_HXX 19 | # define ROBOPTIM_CORE_OPERATOR_SELECTION_HXX 20 | # include 21 | 22 | namespace roboptim 23 | { 24 | template 25 | Selection::Selection 26 | (boost::shared_ptr origin, 27 | size_type start, 28 | size_type size) 29 | : detail::AutopromoteTrait::T_type 30 | (origin->inputSize (), 31 | size, 32 | (boost::format ("selection(%1%)") 33 | % origin->getName ()).str ()), 34 | origin_ (origin), 35 | start_ (start), 36 | size_ (size), 37 | result_ (origin->outputSize ()), 38 | jacobian_ (origin->outputSize (), 39 | origin->inputSize ()) 40 | { 41 | if (start + size > origin->inputSize ()) 42 | throw std::runtime_error ("invalid start/size"); 43 | 44 | result_.setZero (); 45 | gradient_.setZero (); 46 | jacobian_.setZero (); 47 | } 48 | 49 | template 50 | Selection::~Selection () 51 | {} 52 | 53 | template 54 | void 55 | Selection::impl_compute 56 | (result_ref result, const_argument_ref x) 57 | const 58 | { 59 | origin_->operator () (result_, x); 60 | result = result_.segment (start_, size_); 61 | } 62 | 63 | template 64 | void 65 | Selection::impl_gradient (gradient_ref gradient, 66 | const_argument_ref argument, 67 | size_type functionId) 68 | const 69 | { 70 | origin_->gradient (gradient, argument, functionId); 71 | } 72 | 73 | template 74 | void 75 | Selection::impl_jacobian (jacobian_ref jacobian, 76 | const_argument_ref argument) 77 | const 78 | { 79 | origin_->jacobian (jacobian_, argument); 80 | jacobian = jacobian_.block (start_, 0, size_, jacobian_.cols ()); 81 | } 82 | 83 | } // end of namespace roboptim. 84 | 85 | #endif //! ROBOPTIM_CORE_OPERATOR_SELECTION_HXX 86 | -------------------------------------------------------------------------------- /include/roboptim/core/operator/split.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_OPERATOR_SPLIT_HH 19 | # define ROBOPTIM_CORE_OPERATOR_SPLIT_HH 20 | # include 21 | # include 22 | 23 | # include 24 | 25 | namespace roboptim 26 | { 27 | /// \addtogroup roboptim_operator 28 | /// @{ 29 | 30 | /// \brief Select an element of a function's output. 31 | /// \tparam T input function type. 32 | template 33 | class Split : public T 34 | { 35 | public: 36 | /// \brief Import traits type. 37 | typedef typename T::traits_t traits_t; 38 | 39 | ROBOPTIM_TWICE_DIFFERENTIABLE_FUNCTION_FWD_TYPEDEFS_ 40 | (GenericTwiceDifferentiableFunction); 41 | 42 | /// \brief Import interval type. 43 | typedef typename DifferentiableFunction::interval_t interval_t; 44 | 45 | /// \brief Split operator constructor. 46 | /// \param fct input function. 47 | /// \param functionId index of the output to select. 48 | explicit Split (boost::shared_ptr fct, 49 | size_type functionId); 50 | ~Split (); 51 | 52 | protected: 53 | virtual void impl_compute (result_ref result, const_argument_ref argument) 54 | const; 55 | 56 | 57 | virtual void impl_gradient (gradient_ref gradient, 58 | const_argument_ref argument, 59 | size_type functionId = 0) 60 | const; 61 | 62 | virtual void impl_hessian (hessian_ref hessian, 63 | const_argument_ref argument, 64 | size_type functionId = 0) const; 65 | 66 | virtual void impl_derivative (gradient_ref derivative, 67 | value_type argument, 68 | size_type order = 1) const; 69 | 70 | private: 71 | boost::shared_ptr function_; 72 | size_type functionId_; 73 | mutable result_t res_; 74 | }; 75 | 76 | template 77 | void addNonScalarConstraint 78 | (P& problem, 79 | boost::shared_ptr constraint, 80 | std::vector interval, 81 | std::vector scale 82 | = std::vector ()); 83 | 84 | /// @} 85 | 86 | } // end of namespace roboptim 87 | 88 | # include 89 | #endif //! ROBOPTIM_CORE_OPERATOR_SPLIT_HH 90 | -------------------------------------------------------------------------------- /include/roboptim/core/parametrized-function.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_PARAMETRIZED_FUNCTION_HXX 19 | # define ROBOPTIM_CORE_PARAMETRIZED_FUNCTION_HXX 20 | 21 | namespace roboptim 22 | { 23 | template 24 | ParametrizedFunction::ParametrizedFunction (size_type inputSize, 25 | size_type functionInputSize, 26 | size_type functionOutputSize) 27 | : inputSize_ (inputSize), 28 | functionInputSize_ (functionInputSize), 29 | functionOutputSize_ (functionOutputSize) 30 | { 31 | } 32 | 33 | template 34 | typename ParametrizedFunction::result_t 35 | ParametrizedFunction::operator () (const_argument_ref argument) 36 | const 37 | { 38 | assert (argument.size () == inputSize ()); 39 | return impl_compute (argument); 40 | } 41 | 42 | template 43 | typename ParametrizedFunction::size_type 44 | ParametrizedFunction::inputSize () const 45 | { 46 | return inputSize_; 47 | } 48 | 49 | template 50 | typename ParametrizedFunction::size_type 51 | ParametrizedFunction::functionInputSize () const 52 | { 53 | return functionInputSize_; 54 | } 55 | 56 | 57 | template 58 | typename ParametrizedFunction::size_type 59 | ParametrizedFunction::functionOutputSize () const 60 | { 61 | return functionOutputSize_; 62 | } 63 | 64 | template 65 | std::ostream& 66 | ParametrizedFunction::print (std::ostream& o) const 67 | { 68 | o << "Parametrized function"; 69 | return o; 70 | } 71 | 72 | 73 | template 74 | std::ostream& operator<< (std::ostream& o, const ParametrizedFunction& f) 75 | { 76 | return f.print (o); 77 | } 78 | 79 | } // end of namespace roboptim 80 | 81 | #endif //! ROBOPTIM_CORE_PARAMETRIZED_FUNCTION_HXX 82 | -------------------------------------------------------------------------------- /include/roboptim/core/plugin/dummy-laststate.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // Copyright (C) 2014 by Benjamin Chretien, CNRS-LIRMM. 3 | // 4 | // This file is part of the roboptim. 5 | // 6 | // roboptim is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU Lesser General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // roboptim is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU Lesser General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public License 17 | // along with roboptim. If not, see . 18 | 19 | namespace roboptim 20 | { 21 | 22 | template 23 | GenericDummySolverLastState::GenericDummySolverLastState 24 | (const problem_t& pb) 25 | : parent_t (pb), 26 | callback_ (), 27 | solverState_ (pb) 28 | { 29 | parent_t::parameters_["dummy-parameter"].description = "dummy parameter"; 30 | parent_t::parameters_["dummy-parameter"].value = 42.; 31 | 32 | parent_t::parameters_["dummy-parameter2"].description = "yet another dummy parameter"; 33 | parent_t::parameters_["dummy-parameter2"].value = 3; 34 | 35 | parent_t::parameters_["dummy-parameter3"].description = "just a dummy key"; 36 | parent_t::parameters_["dummy-parameter3"].value = std::string ("...and a dummy value!"); 37 | 38 | Parameter::vector_t v (4); 39 | v << 1., 2., 3., 4.; 40 | parent_t::parameters_["dummy-parameter4"].value = v; 41 | 42 | parent_t::parameters_["dummy-parameter5"].description = "dummy boolean"; 43 | parent_t::parameters_["dummy-parameter5"].value = false; 44 | } 45 | 46 | template 47 | GenericDummySolverLastState::~GenericDummySolverLastState () 48 | { 49 | } 50 | 51 | template 52 | void GenericDummySolverLastState::solve () 53 | { 54 | // Set some dummy values for the last state of the solver 55 | Result res (parent_t::problem ().function ().inputSize (), 56 | parent_t::problem ().function ().outputSize ()); 57 | res.x.fill (1337); 58 | res.constraints.fill (0); 59 | res.lambda.fill (0); 60 | res.value.fill (42); 61 | 62 | // Also fill solver state (for logger testing) 63 | solverState_.x () = res.x; 64 | solverState_.cost () = res.value[0]; 65 | solverState_.constraintViolation () = 42; 66 | 67 | // call user-defined callback 68 | if (callback_) 69 | callback_ (parent_t::problem (), solverState_); 70 | 71 | // Add these values to SolverError 72 | parent_t::result_ = SolverError ("The dummy solver always fail.", res); 73 | } 74 | 75 | } // end of namespace roboptim 76 | -------------------------------------------------------------------------------- /include/roboptim/core/plugin/dummy-td.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Benjamin Chretien. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | 19 | #ifndef ROBOPTIM_CORE_DUMMY_TD_HH 20 | # define ROBOPTIM_CORE_DUMMY_TD_HH 21 | # include 22 | 23 | # include 24 | 25 | namespace roboptim 26 | { 27 | /// \brief Dummy solver which always fails. 28 | /// 29 | /// This solver always fails but is always available 30 | /// as it does not rely on the plug-in mechanism. 31 | /// 32 | /// It is also a good starting point for users that 33 | /// want to develop their own solver. 34 | class DummySolverTd : public Solver 35 | { 36 | public: 37 | /// \brief Define parent's type. 38 | typedef Solver parent_t; 39 | 40 | /// \brief Build a solver from a problem. 41 | /// \param problem problem that will be solved 42 | explicit DummySolverTd (const problem_t& problem); 43 | 44 | virtual ~DummySolverTd (); 45 | 46 | /// \brief Implement the solve algorithm. 47 | /// 48 | /// Implement the solve method as required by the 49 | /// #GenericSolver class. 50 | virtual void solve (); 51 | }; 52 | 53 | } // end of namespace roboptim 54 | 55 | #endif //! ROBOPTIM_CORE_DUMMY_TD_HH 56 | -------------------------------------------------------------------------------- /include/roboptim/core/plugin/dummy.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | 19 | #ifndef ROBOPTIM_CORE_DUMMY_HH 20 | # define ROBOPTIM_CORE_DUMMY_HH 21 | # include 22 | 23 | # include 24 | 25 | namespace roboptim 26 | { 27 | /// \brief Dummy solver which always fails. 28 | /// 29 | /// This solver always fails but is always available 30 | /// as it does not rely on the plug-in mechanism. 31 | /// 32 | /// It is also a good starting point for users that 33 | /// want to develop their own solver. 34 | /// 35 | /// \tparam T matrix traits. 36 | template 37 | class GenericDummySolver : public Solver 38 | { 39 | public: 40 | /// \brief Define parent's type. 41 | typedef Solver parent_t; 42 | 43 | /// \brief Problem type. 44 | typedef typename parent_t::problem_t problem_t; 45 | 46 | /// \brief Build a solver from a problem. 47 | /// \param problem problem that will be solved 48 | explicit GenericDummySolver (const problem_t& problem); 49 | 50 | virtual ~GenericDummySolver (); 51 | 52 | /// \brief Implement the solve algorithm. 53 | /// 54 | /// Implement the solve method as required by the 55 | /// #GenericSolver class. 56 | virtual void solve (); 57 | }; 58 | 59 | } // end of namespace roboptim 60 | 61 | # include 62 | 63 | #endif //! ROBOPTIM_CORE_DUMMY_HH 64 | -------------------------------------------------------------------------------- /include/roboptim/core/plugin/dummy.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 by Benjamin Chrétien, CNRS-AIST JRL. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_PLUGIN_DUMMY_HXX 19 | # define ROBOPTIM_CORE_PLUGIN_DUMMY_HXX 20 | 21 | namespace roboptim 22 | { 23 | template 24 | GenericDummySolver::GenericDummySolver (const problem_t& pb) 25 | : parent_t (pb) 26 | { 27 | this->parameters_["dummy-parameter"].description = "dummy parameter"; 28 | this->parameters_["dummy-parameter"].value = 42.; 29 | 30 | this->parameters_["dummy-parameter2"].description = "yet another dummy parameter"; 31 | this->parameters_["dummy-parameter2"].value = 3; 32 | 33 | this->parameters_["dummy-parameter3"].description = "just a dummy key"; 34 | this->parameters_["dummy-parameter3"].value = std::string ("...and a dummy value!"); 35 | 36 | Parameter::vector_t v (4); 37 | v << 1., 2., 3., 4.; 38 | this->parameters_["dummy-parameter4"].value = v; 39 | 40 | this->parameters_["dummy-parameter5"].description = "dummy boolean"; 41 | this->parameters_["dummy-parameter5"].value = false; 42 | } 43 | 44 | template 45 | GenericDummySolver::~GenericDummySolver () 46 | { 47 | } 48 | 49 | template 50 | void GenericDummySolver::solve () 51 | { 52 | this->result_ = SolverError ("The dummy solver always fail."); 53 | } 54 | } // end of namespace roboptim 55 | 56 | #endif //! ROBOPTIM_CORE_PLUGIN_DUMMY_HXX 57 | -------------------------------------------------------------------------------- /include/roboptim/core/quadratic-function.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_QUADRATIC_FUNCTION_HH 19 | # define ROBOPTIM_CORE_QUADRATIC_FUNCTION_HH 20 | # include 21 | 22 | # include 23 | # include 24 | 25 | namespace roboptim 26 | { 27 | /// \addtogroup roboptim_meta_function 28 | /// @{ 29 | 30 | /// \brief Define an abstract quadratic function. 31 | /// 32 | /// Inherit from this class when implementing quadratic functions. 33 | template 34 | class GenericQuadraticFunction : public GenericTwiceDifferentiableFunction 35 | { 36 | public: 37 | typedef GenericTwiceDifferentiableFunction parent_t; 38 | typedef typename parent_t::size_type size_type; 39 | ROBOPTIM_ADD_FLAG(ROBOPTIM_IS_QUADRATIC); 40 | 41 | /// \brief Concrete class constructor should call this constructor. 42 | /// 43 | /// \param inputSize function arity 44 | /// \param outputSize result size 45 | /// \param name function's name 46 | GenericQuadraticFunction (size_type inputSize, 47 | size_type outputSize = 1, 48 | std::string name = std::string ()); 49 | 50 | /// \brief Display the function on the specified output stream. 51 | /// 52 | /// \param o output stream used for display 53 | /// \return output stream 54 | virtual std::ostream& print (std::ostream&) const; 55 | }; 56 | 57 | /// @} 58 | 59 | } // end of namespace roboptim 60 | 61 | # include 62 | #endif //! ROBOPTIM_CORE_QUADRATIC_FUNCTION_HH 63 | -------------------------------------------------------------------------------- /include/roboptim/core/quadratic-function.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_QUADRATIC_FUNCTION_HXX 19 | # define ROBOPTIM_CORE_QUADRATIC_FUNCTION_HXX 20 | 21 | # include 22 | 23 | namespace roboptim 24 | { 25 | template 26 | GenericQuadraticFunction::GenericQuadraticFunction (size_type inputSize, 27 | size_type outputSize, 28 | std::string name) 29 | : GenericTwiceDifferentiableFunction (inputSize, outputSize, name) 30 | {} 31 | 32 | template 33 | std::ostream& 34 | GenericQuadraticFunction::print (std::ostream& o) const 35 | { 36 | if (this->getName ().empty ()) 37 | return o << "Quadratic function"; 38 | else 39 | return o << this->getName () << " (quadratic function)"; 40 | } 41 | 42 | // Explicit template instantiations for dense and sparse matrices. 43 | # ifdef ROBOPTIM_PRECOMPILED_DENSE_SPARSE 44 | ROBOPTIM_ALLOW_ATTRIBUTES_ON 45 | extern template class ROBOPTIM_CORE_DLLAPI GenericQuadraticFunction; 46 | extern template class ROBOPTIM_CORE_DLLAPI GenericQuadraticFunction; 47 | ROBOPTIM_ALLOW_ATTRIBUTES_OFF 48 | # endif 49 | 50 | } // end of namespace roboptim 51 | 52 | #endif //! ROBOPTIM_CORE_QUADRATIC_FUNCTION_HXX 53 | -------------------------------------------------------------------------------- /include/roboptim/core/result-with-warnings.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_RESULT_WITH_WARNINGS_HH 19 | # define ROBOPTIM_CORE_RESULT_WITH_WARNINGS_HH 20 | 21 | # include 22 | # include 23 | # include 24 | 25 | namespace roboptim 26 | { 27 | /// \addtogroup roboptim_problem 28 | /// @{ 29 | 30 | /// \brief Warnings have been merged to Result to simplify the API. 31 | /// To prevent issues with existing visitors, we cannot use a simple 32 | /// typedef such as: 33 | // ROBOPTIM_CORE_DEPRECATED typedef Result ResultWithWarnings; 34 | /// 35 | /// \deprecated Deprecated since version 3.3. Use Result instead. 36 | class ROBOPTIM_CORE_DEPRECATED ROBOPTIM_CORE_DLLAPI ResultWithWarnings : public Result 37 | { 38 | public: 39 | /// \brief Import size type from Result class. 40 | typedef Result::size_type size_type; 41 | 42 | explicit ResultWithWarnings (const size_type inputSize, 43 | const size_type outputSize = 1); 44 | ~ResultWithWarnings (); 45 | }; 46 | /// @} 47 | 48 | } // end of namespace roboptim 49 | 50 | #endif //! ROBOPTIM_CORE_RESULT_WITH_WARNINGS_HH 51 | -------------------------------------------------------------------------------- /include/roboptim/core/solver-callback.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 by Benjamin Chrétien, CNRS-LIRMM. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_SOLVER_CALLBACK_HXX 19 | # define ROBOPTIM_CORE_SOLVER_CALLBACK_HXX 20 | 21 | # include 22 | 23 | # include 24 | 25 | namespace roboptim 26 | { 27 | template 28 | SolverCallback::SolverCallback (const std::string& name) 29 | : name_ (name) 30 | {} 31 | 32 | template 33 | SolverCallback::~SolverCallback () 34 | {} 35 | 36 | template 37 | const std::string& SolverCallback::name () const 38 | { 39 | return name_; 40 | } 41 | 42 | template 43 | typename SolverCallback::callback_t 44 | SolverCallback::callback () 45 | { 46 | return boost::bind (&SolverCallback::perIterationCallback, 47 | this, boost::placeholders::_1, boost::placeholders::_2); 48 | } 49 | 50 | 51 | template 52 | void SolverCallback::operator () (const problem_t& pb, 53 | solverState_t& state) 54 | { 55 | (callback ()) (pb, state); 56 | } 57 | 58 | template 59 | void SolverCallback::perIterationCallback 60 | (const problem_t& pb, solverState_t& state) 61 | { 62 | try 63 | { 64 | perIterationCallbackUnsafe (pb, state); 65 | } 66 | catch (std::exception& e) 67 | { 68 | std::cerr << e.what () << std::endl; 69 | } 70 | catch (...) 71 | { 72 | std::cerr << "unknown exception" << std::endl; 73 | } 74 | } 75 | 76 | template 77 | std::ostream& 78 | SolverCallback::print (std::ostream& o) const 79 | { 80 | o << name_; 81 | 82 | return o; 83 | } 84 | 85 | template 86 | std::ostream& 87 | operator<< (std::ostream& o, const SolverCallback& c) 88 | { 89 | return c.print (o); 90 | } 91 | 92 | // Explicit template instantiations for dense and sparse matrices. 93 | # ifdef ROBOPTIM_PRECOMPILED_DENSE_SPARSE 94 | extern template class ROBOPTIM_CORE_DLLAPI SolverCallback >; 95 | extern template class ROBOPTIM_CORE_DLLAPI SolverCallback >; 96 | # endif //! ROBOPTIM_PRECOMPILED_DENSE_SPARSE 97 | 98 | } // end of namespace roboptim 99 | 100 | #endif //! ROBOPTIM_CORE_SOLVER_CALLBACK_HXX 101 | -------------------------------------------------------------------------------- /include/roboptim/core/solver-warning.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_SOLVER_WARNING_HH 19 | # define ROBOPTIM_CORE_SOLVER_WARNING_HH 20 | 21 | # include 22 | # include 23 | # include 24 | 25 | # include 26 | # include 27 | 28 | namespace roboptim 29 | { 30 | /// \addtogroup roboptim_problem 31 | /// @{ 32 | 33 | /// \brief Exception used for non-critical errors during optimization. 34 | /// 35 | /// This class is mainly used to populate the warning vector of the 36 | /// ResultWithWarnings class. 37 | class ROBOPTIM_CORE_DLLAPI SolverWarning : public std::runtime_error 38 | { 39 | public: 40 | /// \brief Instantiate the class with a message. 41 | /// \param arg message 42 | explicit SolverWarning (const std::string& arg); 43 | 44 | /// \brief Display the problem on the specified output stream. 45 | /// 46 | /// \param o output stream used for display 47 | /// \return output stream 48 | virtual std::ostream& print (std::ostream&) const; 49 | }; 50 | 51 | /// \brief Override operator<< to handle warning display. 52 | /// 53 | /// \param o output stream used for display 54 | /// \param w warning to be displayed 55 | /// \return output stream 56 | ROBOPTIM_CORE_DLLAPI std::ostream& operator<< (std::ostream& o, 57 | const SolverWarning& w); 58 | 59 | /// @} 60 | } // end of namespace roboptim 61 | 62 | #endif //! ROBOPTIM_CORE_SOLVER_ERROR_HH 63 | -------------------------------------------------------------------------------- /include/roboptim/core/sys.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | -------------------------------------------------------------------------------- /include/roboptim/core/twice-derivable-function.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_TWICE_DERIVABLE_FUNCTION_HH 19 | # define ROBOPTIM_CORE_TWICE_DERIVABLE_FUNCTION_HH 20 | // Legacy header. 21 | # include 22 | 23 | namespace roboptim 24 | { 25 | /// \brief Legacy name of DifferentiableFunction. 26 | typedef TwiceDifferentiableFunction TwiceDerivableFunction; 27 | } // end of namespace roboptim 28 | #endif //! ROBOPTIM_CORE_TWICE_DERIVABLE_FUNCTION_HH 29 | -------------------------------------------------------------------------------- /include/roboptim/core/twice-differentiable-function.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_TWICE_DIFFERENTIABLE_FUNCTION_HXX 19 | # define ROBOPTIM_CORE_TWICE_DIFFERENTIABLE_FUNCTION_HXX 20 | # include 21 | 22 | # include 23 | # include 24 | # include 25 | 26 | namespace roboptim 27 | { 28 | template 29 | GenericTwiceDifferentiableFunction::GenericTwiceDifferentiableFunction 30 | (size_type inputSize, 31 | size_type outputSize, 32 | std::string name) 33 | : GenericDifferentiableFunction (inputSize, outputSize, name) 34 | { 35 | } 36 | 37 | template 38 | std::ostream& 39 | GenericTwiceDifferentiableFunction::print (std::ostream& o) const 40 | { 41 | if (this->getName ().empty ()) 42 | return o << "Twice differentiable function"; 43 | 44 | std::stringstream ss; 45 | ss << std::endl; 46 | char fill = o.fill (' '); 47 | ss << std::setw ((int)indent (o)) 48 | << "" 49 | << std::setfill (fill); 50 | std::string name = this->getName (); 51 | boost::algorithm::replace_all (name, "\n", ss.str ()); 52 | 53 | return o << name << " (twice differentiable function)"; 54 | } 55 | 56 | // Explicit template instantiations for dense and sparse matrices. 57 | # ifdef ROBOPTIM_PRECOMPILED_DENSE_SPARSE 58 | ROBOPTIM_ALLOW_ATTRIBUTES_ON 59 | extern template class ROBOPTIM_CORE_DLLAPI GenericTwiceDifferentiableFunction; 60 | extern template class ROBOPTIM_CORE_DLLAPI GenericTwiceDifferentiableFunction; 61 | ROBOPTIM_ALLOW_ATTRIBUTES_OFF 62 | # endif 63 | 64 | } // end of namespace roboptim 65 | 66 | #endif //! ROBOPTIM_CORE_TWICE_DIFFERENTIABLE_FUNCTION_HXX 67 | -------------------------------------------------------------------------------- /include/roboptim/core/visualization/fwd.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_VISUALIZATION_FWD_HH 19 | # define ROBOPTIM_CORE_VISUALIZATION_FWD_HH 20 | # include 21 | # include 22 | 23 | namespace roboptim 24 | { 25 | namespace visualization 26 | { 27 | class Gnuplot; 28 | 29 | namespace gnuplot 30 | { 31 | class Command; 32 | 33 | class clear; 34 | class pwd; 35 | class quit; 36 | class replot; 37 | class reread; 38 | class reset; 39 | class set; 40 | class unset; 41 | 42 | class cd; 43 | class help; 44 | 45 | } // end of namespace gnuplot. 46 | 47 | class Matplotlib; 48 | 49 | namespace matplotlib 50 | { 51 | class Import; 52 | class Command; 53 | 54 | class figure; 55 | class set; 56 | class show; 57 | 58 | } // end of namespace matplotlib. 59 | 60 | } // end of namespace visualization. 61 | } // end of namespace roboptim. 62 | 63 | #endif //! ROBOPTIM_CORE_VISUALIZATION_FWD_HH 64 | -------------------------------------------------------------------------------- /include/roboptim/core/visualization/gnuplot-matrix.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Benjamin Chretien, AIST, CNRS. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef ROBOPTIM_CORE_VISUALIZATION_GNUPLOT_MATRIX_HH 19 | # define ROBOPTIM_CORE_VISUALIZATION_GNUPLOT_MATRIX_HH 20 | # include 21 | # include 22 | # include 23 | 24 | # include 25 | 26 | namespace roboptim 27 | { 28 | namespace visualization 29 | { 30 | namespace gnuplot 31 | { 32 | /// \addtogroup roboptim_visualization 33 | /// @{ 34 | 35 | /// \brief Plot the structure of a matrix with Gnuplot. 36 | /// 37 | /// Plot the structure of a matrix with Gnuplot. Nonzero values will be 38 | /// displayed in blue, zeros in white. 39 | /// 40 | /// When dealing with a dense matrix, the actual values are printed and 41 | /// exact zeros will be displayed in white. 42 | /// 43 | /// When dealing with a sparse matrix, inserted zeros will also be treated 44 | /// as nonzero values, thus returning the real structure of the sparse 45 | /// matrix. In this case, the values returned are 1 for sparse elements, 46 | /// and 0 for actual zeros. 47 | /// 48 | /// \param mat matrix to plot. 49 | /// \return Gnuplot command. 50 | 51 | ROBOPTIM_CORE_DLLAPI 52 | Command plot_mat 53 | (GenericFunctionTraits::const_matrix_ref mat); 54 | 55 | ROBOPTIM_CORE_DLLAPI 56 | Command plot_mat 57 | (GenericFunctionTraits::const_matrix_ref mat); 58 | 59 | template 60 | Command plot_mat 61 | (typename GenericFunctionTraits::const_matrix_ref) 62 | { 63 | BOOST_MPL_ASSERT_MSG (false, NOT_IMPLEMENTED, ()); 64 | return Command (""); 65 | } 66 | 67 | /// @} 68 | } // end of namespace gnuplot. 69 | } // end of namespace visualization. 70 | } // end of namespace roboptim. 71 | 72 | #endif //! ROBOPTIM_CORE_VISUALIZATION_GNUPLOT_MATRIX_HH 73 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | roboptim-core 4 | 3.2 5 | This plus provides the core librairie to do optimization in robotics. 6 | 7 | Guilhem Saurel 8 | 9 | GPL3 10 | 11 | ament_cmake 12 | 13 | rclcpp 14 | libboost-dev 15 | libboost-date-time-dev 16 | libboost-system-dev 17 | libboost-filesystem-dev 18 | libboost-test-dev 19 | libeigen3-dev 20 | liblapack-dev 21 | libblas-dev 22 | libltdl-dev 23 | 24 | rclcpp 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/alloc.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 by Félix Darricau, AIST, CNRS, EPITA 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "roboptim/core/alloc.hh" 19 | 20 | namespace roboptim 21 | { 22 | bool is_malloc_allowed_update (bool update, bool new_value) 23 | { 24 | static bool value = true; 25 | if (update) 26 | value = new_value; 27 | return value; 28 | } 29 | } // end of namespace roboptim. 30 | -------------------------------------------------------------------------------- /src/debug.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 by Benjamin Chrétien, CNRS-AIST JRL. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | #include 20 | 21 | #include "roboptim/core/debug.hh" 22 | #include "roboptim/core/terminal-color.hh" 23 | 24 | namespace roboptim 25 | { 26 | void assertion_failed(char const *expr, char const *function, 27 | char const *file, long line) 28 | { 29 | std::cerr << fg::bold << "Assertion" << fg::reset 30 | << ": `" << fg::fail << fg::bold << expr << fg::reset 31 | << "` failed in " << file << ":" << line 32 | << ": " << function << std::endl; 33 | std::abort(); 34 | } 35 | 36 | void assertion_failed_msg(char const *expr, char const *msg, 37 | char const *function, char const *file, long line) 38 | { 39 | std::cerr << fg::bold << "Assertion" << fg::reset 40 | << ": `" << fg::fail << fg::bold << expr << fg::reset 41 | << "` failed in " << fg::bold << file << ":" << line << fg::reset 42 | << ": " << function << ": " 43 | << fg::warn << fg::bold << msg << fg::reset << std::endl; 44 | std::abort(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/debug.hh: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #ifndef DEBUG_HH 19 | # define DEBUG_HH 20 | # include 21 | 22 | # ifndef CWDEBUG 23 | # include 24 | # include 25 | 26 | # define AllocTag1(p) 27 | # define AllocTag2(p, desc) 28 | # define AllocTag_dynamic_description(p, data) 29 | # define AllocTag(p, data) 30 | # define Debug(STATEMENT) 31 | # define Dout(cntrl, data) 32 | # define DoutFatal(cntrl, data) LibcwDoutFatal(, , cntrl, data) 33 | # define ForAllDebugChannels(STATEMENT) 34 | # define ForAllDebugObjects(STATEMENT) 35 | # define LibcwDebug(dc_namespace, STATEMENT) 36 | # define LibcwDout(dc_namespace, d, cntrl, data) 37 | # define LibcwDoutFatal(dc_namespace, d, cntrl, data) \ 38 | do { ::std::cerr << data << ::std::endl; ::std::exit(EXIT_FAILURE); } while(1) 39 | # define LibcwdForAllDebugChannels(dc_namespace, STATEMENT) 40 | # define LibcwdForAllDebugObjects(dc_namespace, STATEMENT) 41 | # define NEW(x) new x 42 | # define CWDEBUG_ALLOC 0 43 | # define CWDEBUG_MAGIC 0 44 | # define CWDEBUG_LOCATION 0 45 | # define CWDEBUG_LIBBFD 0 46 | # define CWDEBUG_DEBUG 0 47 | # define CWDEBUG_DEBUGOUTPUT 0 48 | # define CWDEBUG_DEBUGM 0 49 | # define CWDEBUG_DEBUGT 0 50 | # define CWDEBUG_MARKER 0 51 | 52 | # endif // CWDEBUG 53 | 54 | # define ROBOPTIM_CORE_INTERNAL 55 | # include 56 | # define DEBUGCHANNELS roboptim::debug::channels 57 | # ifdef CWDEBUG 58 | # include 59 | # endif 60 | 61 | #endif // !DEBUG_HH 62 | -------------------------------------------------------------------------------- /src/dummy-d-sparse-laststate.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2014 by Benjamin Chretien, CNRS-LIRMM. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include 21 | 22 | #include "roboptim/core/function.hh" 23 | #include "roboptim/core/problem.hh" 24 | #include "roboptim/core/plugin/dummy-laststate.hh" 25 | 26 | extern "C" 27 | { 28 | using namespace roboptim; 29 | typedef DummyDifferentiableSparseSolverLastState::parent_t solver_t; 30 | 31 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem (); 32 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList (); 33 | ROBOPTIM_CORE_DLLEXPORT solver_t* create 34 | (const DummyDifferentiableSparseSolverLastState::problem_t& pb); 35 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p); 36 | 37 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem () 38 | { 39 | return sizeof (solver_t::problem_t); 40 | } 41 | 42 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList () 43 | { 44 | return typeid (solver_t::problem_t::constraintsList_t).name (); 45 | } 46 | 47 | ROBOPTIM_CORE_DLLEXPORT solver_t* create 48 | (const DummyDifferentiableSparseSolverLastState::problem_t& pb) 49 | { 50 | return new DummyDifferentiableSparseSolverLastState (pb); 51 | } 52 | 53 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p) 54 | { 55 | delete p; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/dummy-laststate.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include 21 | 22 | #include "roboptim/core/function.hh" 23 | #include "roboptim/core/problem.hh" 24 | #include "roboptim/core/plugin/dummy-laststate.hh" 25 | 26 | extern "C" 27 | { 28 | using namespace roboptim; 29 | typedef DummySolverLastState::parent_t solver_t; 30 | 31 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem (); 32 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList (); 33 | ROBOPTIM_CORE_DLLEXPORT solver_t* create 34 | (const DummySolverLastState::problem_t& pb); 35 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p); 36 | 37 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem () 38 | { 39 | return sizeof (solver_t::problem_t); 40 | } 41 | 42 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList () 43 | { 44 | return typeid (solver_t::problem_t::constraintsList_t).name (); 45 | } 46 | 47 | ROBOPTIM_CORE_DLLEXPORT solver_t* create 48 | (const DummySolverLastState::problem_t& pb) 49 | { 50 | return new DummySolverLastState (pb); 51 | } 52 | 53 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p) 54 | { 55 | delete p; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/dummy-sparse.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 by Benjamin Chrétien, CNRS-AIST JRL. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include 21 | 22 | #include "roboptim/core/function.hh" 23 | #include "roboptim/core/plugin/dummy.hh" 24 | 25 | extern "C" 26 | { 27 | typedef roboptim::GenericDummySolver DummySparseSolver; 28 | typedef DummySparseSolver::parent_t solver_t; 29 | 30 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem (); 31 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList (); 32 | ROBOPTIM_CORE_DLLEXPORT solver_t* create (const DummySparseSolver::problem_t& pb); 33 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p); 34 | 35 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem () 36 | { 37 | return sizeof (solver_t::problem_t); 38 | } 39 | 40 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList () 41 | { 42 | return typeid (solver_t::problem_t::constraintsList_t).name (); 43 | } 44 | 45 | ROBOPTIM_CORE_DLLEXPORT solver_t* create (const DummySparseSolver::problem_t& pb) 46 | { 47 | return new DummySparseSolver (pb); 48 | } 49 | 50 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p) 51 | { 52 | delete p; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/dummy-td.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Benjamin Chretien, CNRS. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include 21 | 22 | #include "roboptim/core/function.hh" 23 | #include "roboptim/core/problem.hh" 24 | #include "roboptim/core/plugin/dummy-td.hh" 25 | 26 | namespace roboptim 27 | { 28 | DummySolverTd::DummySolverTd (const problem_t& pb) 29 | : parent_t (pb) 30 | { 31 | parameters_["dummy-parameter"].description = "dummy parameter"; 32 | parameters_["dummy-parameter"].value = 42.; 33 | 34 | parameters_["dummy-parameter2"].description = "yet another dummy parameter"; 35 | parameters_["dummy-parameter2"].value = 3; 36 | 37 | parameters_["dummy-parameter3"].description = "just a dummy key"; 38 | parameters_["dummy-parameter3"].value = std::string ("...and a dummy value!"); 39 | 40 | Parameter::vector_t v (4); 41 | v << 1., 2., 3., 4.; 42 | parameters_["dummy-parameter4"].value = v; 43 | 44 | parameters_["dummy-parameter5"].description = "dummy boolean"; 45 | parameters_["dummy-parameter5"].value = false; 46 | } 47 | 48 | DummySolverTd::~DummySolverTd () 49 | { 50 | } 51 | 52 | void 53 | DummySolverTd::solve () 54 | { 55 | result_ = SolverError ("The dummy solver always fail."); 56 | } 57 | 58 | } // end of namespace roboptim 59 | 60 | extern "C" 61 | { 62 | using namespace roboptim; 63 | typedef DummySolverTd::parent_t solver_t; 64 | 65 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem (); 66 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList (); 67 | ROBOPTIM_CORE_DLLEXPORT solver_t* create (const DummySolverTd::problem_t& pb); 68 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p); 69 | 70 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem () 71 | { 72 | return sizeof (solver_t::problem_t); 73 | } 74 | 75 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList () 76 | { 77 | return typeid (solver_t::problem_t::constraintsList_t).name (); 78 | } 79 | 80 | ROBOPTIM_CORE_DLLEXPORT solver_t* create (const DummySolverTd::problem_t& pb) 81 | { 82 | return new DummySolverTd (pb); 83 | } 84 | 85 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p) 86 | { 87 | delete p; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/dummy.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include 21 | 22 | #include "roboptim/core/function.hh" 23 | #include "roboptim/core/plugin/dummy.hh" 24 | 25 | extern "C" 26 | { 27 | typedef roboptim::GenericDummySolver DummySolver; 28 | typedef DummySolver::parent_t solver_t; 29 | 30 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem (); 31 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList (); 32 | ROBOPTIM_CORE_DLLEXPORT solver_t* create (const DummySolver::problem_t& pb); 33 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p); 34 | 35 | ROBOPTIM_CORE_DLLEXPORT std::size_t getSizeOfProblem () 36 | { 37 | return sizeof (solver_t::problem_t); 38 | } 39 | 40 | ROBOPTIM_CORE_DLLEXPORT const char* getTypeIdOfConstraintsList () 41 | { 42 | return typeid (solver_t::problem_t::constraintsList_t).name (); 43 | } 44 | 45 | ROBOPTIM_CORE_DLLEXPORT solver_t* create (const DummySolver::problem_t& pb) 46 | { 47 | return new DummySolver (pb); 48 | } 49 | 50 | ROBOPTIM_CORE_DLLEXPORT void destroy (solver_t* p) 51 | { 52 | delete p; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/finite-difference-gradient.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | -------------------------------------------------------------------------------- /src/generic-solver.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include 21 | #include "roboptim/core/generic-solver.hh" 22 | 23 | namespace roboptim 24 | { 25 | GenericSolver::GenericSolver () 26 | : boost::noncopyable (), 27 | result_ (NoSolution ()) 28 | { 29 | } 30 | 31 | GenericSolver::GenericSolver (const GenericSolver& solver) 32 | : boost::noncopyable (), 33 | result_ (solver.result_) 34 | { 35 | } 36 | 37 | GenericSolver::~GenericSolver () 38 | { 39 | } 40 | 41 | void 42 | GenericSolver::reset () 43 | { 44 | result_ = NoSolution (); 45 | } 46 | 47 | const GenericSolver::result_t& 48 | GenericSolver::minimum () 49 | { 50 | if (result_.which () != SOLVER_NO_SOLUTION) 51 | return result_; 52 | solve (); 53 | assert (result_.which () != SOLVER_NO_SOLUTION); 54 | 55 | return result_; 56 | } 57 | 58 | std::ostream& 59 | GenericSolver::print (std::ostream& o) const 60 | { 61 | o << "Generic Solver"; 62 | return o; 63 | } 64 | 65 | std::ostream& 66 | operator<< (std::ostream& o, const GenericSolver& gs) 67 | { 68 | return gs.print (o); 69 | } 70 | 71 | std::ostream& 72 | operator<< (std::ostream& o, const NoSolution&) 73 | { 74 | return o << "no solution"; 75 | } 76 | } // end of namespace roboptim 77 | -------------------------------------------------------------------------------- /src/indent.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "roboptim/core/indent.hh" 25 | 26 | namespace roboptim 27 | { 28 | long int& indent (std::ostream& o) 29 | { 30 | // The slot to store the current indentation level. 31 | static const int indent_index = std::ios::xalloc (); 32 | return o.iword (indent_index); 33 | } 34 | 35 | std::ostream& incindent (std::ostream& o) 36 | { 37 | indent (o) += 2; 38 | return o; 39 | } 40 | 41 | std::ostream& decindent (std::ostream& o) 42 | { 43 | assert (indent (o)); 44 | indent (o) -= 2; 45 | return o; 46 | } 47 | 48 | std::ostream& resetindent (std::ostream& o) 49 | { 50 | indent (o) = 0; 51 | return o; 52 | } 53 | 54 | std::ostream& iendl (std::ostream& o) 55 | { 56 | o << std::endl; 57 | // Be sure to be able to restore the stream flags. 58 | char fill = o.fill (' '); 59 | return o << std::setw ((int)indent (o)) 60 | << "" 61 | << std::setfill (fill); 62 | } 63 | 64 | std::ostream& incendl (std::ostream& o) 65 | { 66 | return o << incindent << iendl; 67 | } 68 | 69 | std::ostream& decendl (std::ostream& o) 70 | { 71 | return o << decindent << iendl; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/result-with-warnings.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 by Benjamin Chrétien, CNRS-AIST JRL. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | namespace roboptim 21 | { 22 | ResultWithWarnings::ResultWithWarnings (const size_type inputSize, 23 | const size_type outputSize) 24 | : Result (inputSize, outputSize) 25 | {} 26 | 27 | ResultWithWarnings::~ResultWithWarnings () 28 | {} 29 | } // end of namespace roboptim 30 | -------------------------------------------------------------------------------- /src/result.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace roboptim 29 | { 30 | Result::Result (const size_type inputSize_, 31 | const size_type outputSize_) 32 | : inputSize (inputSize_), 33 | outputSize (outputSize_), 34 | x (inputSize), 35 | value (outputSize), 36 | constraints (), 37 | constraint_violation (Function::infinity ()), 38 | lambda (), 39 | warnings () 40 | { 41 | x.setZero (); 42 | value.setZero (); 43 | constraints.setZero (); 44 | lambda.setZero (); 45 | } 46 | 47 | Result::~Result () 48 | { 49 | } 50 | 51 | std::ostream& 52 | Result::print (std::ostream& o) const 53 | { 54 | o << "Result:" << incindent 55 | << iendl << "Size (input, output): " << inputSize << ", " << outputSize 56 | << iendl << "X: " << x 57 | << iendl << "Value: " << value; 58 | if (constraints.size () > 0) 59 | o << iendl << "Constraints values: " << constraints; 60 | if (constraint_violation < Function::infinity ()) 61 | o << iendl << "Constraint violation: " << constraint_violation; 62 | if (lambda.size () > 0) 63 | o << iendl << "Lambda: " << lambda; 64 | if (!warnings.empty ()) 65 | o << iendl << "Warnings: " << warnings; 66 | 67 | return o << decindent; 68 | } 69 | 70 | std::ostream& operator<< (std::ostream& o, const Result& r) 71 | { 72 | return r.print (o); 73 | } 74 | 75 | } // end of namespace roboptim 76 | -------------------------------------------------------------------------------- /src/solver-error.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "debug.hh" 23 | 24 | #include "roboptim/core/solver-error.hh" 25 | #include "roboptim/core/util.hh" 26 | #include "roboptim/core/terminal-color.hh" 27 | 28 | namespace roboptim 29 | { 30 | SolverError::SolverError (const std::string& msg) 31 | : std::runtime_error (msg) 32 | { 33 | } 34 | 35 | SolverError::SolverError (const std::string& msg, 36 | const Result& res) 37 | : std::runtime_error (msg), 38 | lastState_(res) 39 | { 40 | } 41 | 42 | SolverError::SolverError (const SolverError& error) 43 | : std::runtime_error (error.what()), 44 | lastState_(error.lastState_) 45 | { 46 | } 47 | 48 | SolverError::~SolverError () throw () 49 | { 50 | } 51 | 52 | std::ostream& 53 | SolverError::print (std::ostream& o) const 54 | { 55 | o << fg::fail << "Solver error"; 56 | 57 | // If the error message is not empty 58 | std::string msg (what ()); 59 | if (!msg.empty ()) 60 | { 61 | o << ":"; 62 | 63 | // Split string on newlines, and insert indenting 64 | std::vector errors = split (msg, '\n'); 65 | if (errors.size () == 1) 66 | { 67 | o << " " << errors[0]; 68 | } 69 | else 70 | { 71 | o << incindent; 72 | for (std::vector::const_iterator 73 | s = errors.begin (); s != errors.end (); ++s) 74 | { 75 | o << iendl << *s; 76 | } 77 | o << decindent; 78 | } 79 | } 80 | o << fg::reset; 81 | 82 | return o; 83 | } 84 | 85 | const boost::optional& SolverError::lastState () const 86 | { 87 | return lastState_; 88 | } 89 | 90 | boost::optional& SolverError::lastState () 91 | { 92 | return lastState_; 93 | } 94 | 95 | std::ostream& operator<< (std::ostream& o, const SolverError& s) 96 | { 97 | return s.print (o); 98 | } 99 | 100 | } // end of namespace roboptim 101 | -------------------------------------------------------------------------------- /src/solver-warning.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "debug.hh" 19 | 20 | #include "roboptim/core/solver-warning.hh" 21 | 22 | namespace roboptim 23 | { 24 | SolverWarning::SolverWarning (const std::string& msg) 25 | : std::runtime_error (msg) 26 | { 27 | } 28 | 29 | std::ostream& SolverWarning::print (std::ostream& o) const 30 | { 31 | return o << what (); 32 | } 33 | 34 | std::ostream& operator<< (std::ostream& o, const SolverWarning& w) 35 | { 36 | return w.print (o); 37 | } 38 | } // end of namespace roboptim 39 | -------------------------------------------------------------------------------- /src/solver.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | #include 20 | 21 | #include "debug.hh" 22 | #include "roboptim/core/solver.hh" 23 | 24 | namespace roboptim 25 | { 26 | namespace detail 27 | { 28 | struct PrintSolverParameter : public boost::static_visitor 29 | { 30 | PrintSolverParameter (std::ostream& o) : o_ (o) 31 | {} 32 | 33 | template 34 | std::ostream& operator () (const T& val) 35 | { 36 | o_ << val; 37 | return o_; 38 | } 39 | 40 | std::ostream& operator () (const bool& val) 41 | { 42 | o_ << (val? "true" : "false"); 43 | return o_; 44 | } 45 | 46 | private: 47 | std::ostream& o_; 48 | }; 49 | } // end of namespace detail 50 | 51 | Parameter::Parameter () 52 | : description (""), 53 | value () 54 | {} 55 | 56 | std::ostream& operator<< (std::ostream& o, 57 | const Parameter& parameter) 58 | { 59 | detail::PrintSolverParameter psp (o); 60 | 61 | if (!parameter.description.empty ()) 62 | o << " (" << parameter.description << ")"; 63 | o << ": "; 64 | 65 | boost::apply_visitor (psp, parameter.value); 66 | 67 | return o; 68 | } 69 | } // end of namespace roboptim 70 | -------------------------------------------------------------------------------- /src/visualization/gnuplot-differentiable-function.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | # include 24 | # include 25 | 26 | namespace roboptim 27 | { 28 | namespace visualization 29 | { 30 | namespace gnuplot 31 | { 32 | namespace detail 33 | { 34 | 35 | std::string dense_jacobian_to_gnuplot 36 | (DifferentiableFunction::const_jacobian_ref jac, 37 | const std::string& name) 38 | { 39 | std::string str = "set title 'Dense Jacobian (" + name + ")'\n"; 40 | str += plot_mat (jac).command (); 41 | 42 | return str; 43 | } 44 | 45 | 46 | std::string sparse_jacobian_to_gnuplot 47 | (DifferentiableSparseFunction::const_jacobian_ref jac, 48 | const std::string& name) 49 | { 50 | std::string str = "set title 'Sparse Jacobian (" + name + ")'\n"; 51 | str += plot_mat (jac).command (); 52 | 53 | return str; 54 | } 55 | 56 | } // end of namespace detail. 57 | 58 | template <> 59 | Command plot_jac (const DifferentiableFunction& f, 60 | DifferentiableFunction::const_argument_ref arg) 61 | { 62 | DifferentiableFunction::jacobian_t jac = f.jacobian(arg); 63 | 64 | return Command (detail::dense_jacobian_to_gnuplot 65 | (jac, f.getName())); 66 | } 67 | 68 | 69 | template <> 70 | Command plot_jac (const DifferentiableSparseFunction& f, 71 | DifferentiableSparseFunction::const_argument_ref arg) 72 | { 73 | DifferentiableSparseFunction::jacobian_t jac = f.jacobian(arg); 74 | 75 | return Command (detail::sparse_jacobian_to_gnuplot 76 | (jac, f.getName())); 77 | } 78 | 79 | } // end of namespace gnuplot. 80 | } // end of namespace visualization. 81 | } // end of namespace roboptim 82 | -------------------------------------------------------------------------------- /src/visualization/gnuplot.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "roboptim/core/config.hh" 19 | #include "config.h" 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace roboptim 28 | { 29 | namespace visualization 30 | { 31 | Gnuplot::Gnuplot (bool with_header) 32 | { 33 | using namespace gnuplot; 34 | push_command (Command ("#!/usr/bin/gnuplot")); 35 | if (with_header) push_command (comment ("Generated by " PACKAGE_NAME)); 36 | } 37 | 38 | Gnuplot::~Gnuplot () 39 | { 40 | } 41 | 42 | void 43 | Gnuplot::push_command (gnuplot::Command cmd) 44 | { 45 | commands_.push_back (cmd); 46 | } 47 | 48 | std::ostream& 49 | Gnuplot::print (std::ostream& o) const 50 | { 51 | typedef std::vector::const_iterator citer_t; 52 | 53 | for (citer_t it = commands_.begin (); it != commands_.end (); ++it) 54 | o << it->command () << std::endl; 55 | return o; 56 | } 57 | 58 | Gnuplot& 59 | Gnuplot::operator << (gnuplot::Command cmd) 60 | { 61 | push_command (cmd); 62 | return *this; 63 | } 64 | 65 | std::ostream& 66 | operator<< (std::ostream& o, const Gnuplot& gp) 67 | { 68 | return gp.print (o); 69 | } 70 | 71 | void 72 | Gnuplot::clear () 73 | { 74 | commands_.clear (); 75 | } 76 | } // end of namespace visualization. 77 | } // end of namespace roboptim. 78 | -------------------------------------------------------------------------------- /tests/cache.stdout: -------------------------------------------------------------------------------- 1 | {} 2 | {42} 3 | x₀ = 0 4 | x₂ = 2 5 | x₃ = 3 6 | x₄ = 4 7 | x₅ = 5 8 | x₁ = 0 9 | {} 10 | {37} 11 | -------------------------------------------------------------------------------- /tests/derivable-function-sparse.stdout: -------------------------------------------------------------------------------- 1 | null function (differentiable function) 2 | Differentiable function 3 | 1 4 | 1 5 | 1 6 | 1 7 | null function 8 | 9 | 1 10 | 1 11 | [1](0) 12 | [1](0) 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 1 22 | 1 23 | (1, 1) 24 | (1, 1) 25 | 1 26 | 1 27 | 1 28 | 1 29 | -------------------------------------------------------------------------------- /tests/derivable-function.stdout: -------------------------------------------------------------------------------- 1 | null function (differentiable function) 2 | Differentiable function 3 | 1 4 | 1 5 | 1 6 | 1 7 | null function 8 | 9 | 1 10 | 1 11 | [1](0) 12 | [1](0) 13 | [1](0) 14 | [1](0) 15 | [1](0) 16 | [1](0) 17 | 1 18 | 1 19 | (1, 1) 20 | (1, 1) 21 | 1 22 | 1 23 | 1 24 | 1 25 | -------------------------------------------------------------------------------- /tests/derivable-parametrized-function.stdout: -------------------------------------------------------------------------------- 1 | Parameter is 0 2 | Identity function 3 | offset = [1](0) 4 | Evaluate: 5 | [1](31) 6 | Gradient: 7 | [1](1) 8 | Jacobian: 9 | [1](1) 10 | Derivative w.r.t params: 11 | [1](1) 12 | 13 | Parameter is 3.14 14 | Identity function 15 | offset = [1](3.14) 16 | Evaluate: 17 | [1](34.14) 18 | Gradient: 19 | [1](1) 20 | Jacobian: 21 | [1](1) 22 | Derivative w.r.t params: 23 | [1](1) 24 | 25 | Parameter is 42 26 | Identity function 27 | offset = [1](42) 28 | Evaluate: 29 | [1](73) 30 | Gradient: 31 | [1](1) 32 | Jacobian: 33 | [1](1) 34 | Derivative w.r.t params: 35 | [1](1) 36 | 37 | Derivable parametrized function 38 | Evaluate: 39 | Identity function 40 | offset = [1](256) 41 | Gradient (order = 0): 42 | [1](1) 43 | Gradient (order = 1): 44 | [1](0) 45 | Jacobian (order = 0): 46 | [1](1) 47 | Jacobian (order = 1): 48 | [1](0) 49 | -------------------------------------------------------------------------------- /tests/example.stdout: -------------------------------------------------------------------------------- 1 | Solver: 2 | Plugin: dummy-td 3 | Problem: 4 | x₀ * x₃ * (x₀ + x₁ + x₂) + x₃ (twice differentiable function) 5 | Objective scaling: 1 6 | Arguments bounds: (1, 5), (1, 5), (1, 5), (1, 5) 7 | Arguments scaling: 1, 1, 1, 1 8 | Arguments names: x₀, x₁, x₂, x₃ 9 | Number of constraints: 2 10 | Constraint 0 11 | x₀ * x₁ * x₂ * x₃ (twice differentiable function) 12 | Bounds: (25, inf) 13 | Scaling: 1 14 | Constraint 1 15 | x₀² + x₁² + x₂² + x₃² (twice differentiable function) 16 | Bounds: (40, 40) 17 | Scaling: 1 18 | No starting point. 19 | Infinity value (for all functions): inf 20 | Result: 21 | Solver error: The dummy solver always fail. 22 | Parameters: 23 | dummy-parameter (dummy parameter): 42 24 | dummy-parameter2 (yet another dummy parameter): 3 25 | dummy-parameter3 (just a dummy key): ...and a dummy value! 26 | dummy-parameter4: [4](1,2,3,4) 27 | dummy-parameter5 (dummy boolean): false 28 | 29 | A solution has not been found. As expected... 30 | The dummy solver always fail. 31 | -------------------------------------------------------------------------------- /tests/function-constant.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | using namespace roboptim; 26 | 27 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 28 | ::roboptim::EigenMatrixSparse> functionTypes_t; 29 | 30 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 31 | 32 | BOOST_AUTO_TEST_CASE_TEMPLATE (constant_function, T, functionTypes_t) 33 | { 34 | typename GenericConstantFunction::vector_t offset (4); 35 | offset[0] = 12.; 36 | offset[1] = 46.; 37 | offset[2] = 2.; 38 | offset[3] = -9.; 39 | 40 | GenericConstantFunction cst (offset); 41 | 42 | typename GenericConstantFunction::vector_t x (4); 43 | x.setZero (); 44 | 45 | std::cout 46 | << cst << std::endl 47 | << "Evaluate:" << std::endl 48 | << cst (x) << std::endl 49 | << "Gradient:" << std::endl 50 | << cst.gradient (x) << std::endl 51 | << "Jacobian:" << std::endl 52 | << cst.jacobian (x) << std::endl 53 | << "Hessian:" << std::endl 54 | << cst.hessian (x) << std::endl; 55 | 56 | typename GenericConstantFunction::vector_t result = cst (x); 57 | BOOST_CHECK (allclose (offset, result)); 58 | } 59 | 60 | BOOST_AUTO_TEST_SUITE_END () 61 | -------------------------------------------------------------------------------- /tests/function-constant.stdout: -------------------------------------------------------------------------------- 1 | Constant function 2 | offset = [4](12,46,2,-9) 3 | 4 | Evaluate: 5 | [4](12,46,2,-9) 6 | Gradient: 7 | [4](0,0,0,0) 8 | Jacobian: 9 | [4,4]((0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0)) 10 | -------------------------------------------------------------------------------- /tests/function-cos.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | using namespace roboptim; 30 | 31 | 32 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 33 | ::roboptim::EigenMatrixSparse> functionTypes_t; 34 | 35 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 36 | 37 | BOOST_AUTO_TEST_CASE_TEMPLATE (cos_test, T, functionTypes_t) 38 | { 39 | boost::shared_ptr > fct = 40 | boost::make_shared > (); 41 | 42 | typename Cos::argument_t x (1); 43 | x.setZero (); 44 | 45 | std::cout 46 | << (*fct) << std::endl 47 | << "Evaluate:" << std::endl 48 | << (*fct) (x) << std::endl 49 | << "Gradient:" << std::endl 50 | << fct->gradient (x, 0) << std::endl 51 | << "Jacobian:" << std::endl 52 | << fct->jacobian (x) << std::endl 53 | << "Hessian:" << std::endl 54 | << fct->hessian (x) << std::endl; 55 | } 56 | 57 | BOOST_AUTO_TEST_SUITE_END () 58 | -------------------------------------------------------------------------------- /tests/function-identity.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | using namespace roboptim; 26 | 27 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 28 | ::roboptim::EigenMatrixSparse> functionTypes_t; 29 | 30 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 31 | 32 | BOOST_AUTO_TEST_CASE_TEMPLATE (identity_function, T, functionTypes_t) 33 | { 34 | typename GenericIdentityFunction::vector_t offset (4); 35 | offset[0] = 12.; 36 | offset[1] = 46.; 37 | offset[2] = 2.; 38 | offset[3] = -9.; 39 | 40 | GenericIdentityFunction id (offset); 41 | 42 | typename GenericIdentityFunction::vector_t x (4); 43 | x.setZero (); 44 | 45 | std::cout 46 | << id << std::endl 47 | << "Evaluate:" << std::endl 48 | << id (x) << std::endl 49 | << "Gradient:" << std::endl 50 | << id.gradient (x) << std::endl 51 | << "Jacobian:" << std::endl 52 | << id.jacobian (x) << std::endl 53 | << "Hessian:" << std::endl 54 | << id.hessian (x) << std::endl; 55 | } 56 | 57 | BOOST_AUTO_TEST_SUITE_END () 58 | -------------------------------------------------------------------------------- /tests/function-identity.stdout: -------------------------------------------------------------------------------- 1 | Identity function 2 | offset = [4](12,46,2,-9) 3 | 4 | Evaluate: 5 | [4](12,46,2,-9) 6 | Gradient: 7 | [4](1,0,0,0) 8 | Jacobian: 9 | [4,4]((1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1)) 10 | -------------------------------------------------------------------------------- /tests/function-pool.stdout: -------------------------------------------------------------------------------- 1 | Engine: calling compute 2 | Engine: calling jacobian 3 | Engine: calling compute 4 | Engine: calling compute 5 | Engine: calling compute 6 | Engine: calling compute 7 | Engine: calling compute 8 | x = [3](0.785398,-0.785398,1.5708) 9 | Joint position pool (differentiable function): 10 | Position of joint 0 (differentiable function) 11 | Position of joint 1 (differentiable function) 12 | Position of joint 2 (differentiable function) 13 | [6](0.707107,0.707107,1.70711,0.707107,1.70711,1.70711) 14 | [6,3]((-0.707107,0,0), (0.707107,0,0), (-0.707107,0,0), (1.70711,1,0), (-1.70711,-1,-1), (1.70711,1,0)) 15 | Position of joint 0 (differentiable function) 16 | [2](0.707107,0.707107) 17 | [2,3]((-0.707107,0,0), (0.707107,0,0)) 18 | Position of joint 1 (differentiable function) 19 | [2](1.70711,0.707107) 20 | [2,3]((-0.707107,0,0), (1.70711,1,0)) 21 | Position of joint 2 (differentiable function) 22 | [2](1.70711,1.70711) 23 | [2,3]((-1.70711,-1,-1), (1.70711,1,0)) 24 | [6,3]((-0.707107,0,0), (0.707107,0,0), (-0.707107,0,0), (1.70711,1,0), (-1.70711,-1,-1), (1.70711,1,0)) 25 | -------------------------------------------------------------------------------- /tests/function-sin.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | using namespace roboptim; 30 | 31 | 32 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 33 | ::roboptim::EigenMatrixSparse> functionTypes_t; 34 | 35 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 36 | 37 | BOOST_AUTO_TEST_CASE_TEMPLATE (sin_test, T, functionTypes_t) 38 | { 39 | boost::shared_ptr > fct = 40 | boost::make_shared > (); 41 | 42 | typename Sin::argument_t x (1); 43 | x.setZero (); 44 | std::cout 45 | << (*fct) << std::endl 46 | << "Evaluate:" << std::endl 47 | << (*fct) (x) << std::endl 48 | << "Gradient:" << std::endl 49 | << fct->gradient (x, 0) << std::endl 50 | << "Jacobian:" << std::endl 51 | << fct->jacobian (x) << std::endl 52 | << "Hessian:" << std::endl 53 | << fct->hessian (x) << std::endl; 54 | } 55 | 56 | BOOST_AUTO_TEST_SUITE_END () 57 | -------------------------------------------------------------------------------- /tests/function.stdout: -------------------------------------------------------------------------------- 1 | null function (not differentiable) 2 | Function 3 | 1 4 | 1 5 | 1 6 | 1 7 | null function 8 | 9 | 1 10 | 1 11 | [1](0) 12 | [1](0) 13 | [1](0) 14 | [1](0) 15 | -------------------------------------------------------------------------------- /tests/indent.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2014 by Benjamin Chrétien, CNRS. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | using namespace roboptim; 26 | 27 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 28 | 29 | BOOST_AUTO_TEST_CASE (indent) 30 | { 31 | boost::shared_ptr 32 | output = retrievePattern ("indent"); 33 | 34 | (*output) << "Test 1" << incindent; 35 | (*output) << iendl << "Dummy 1"; 36 | (*output) << iendl << "Dummy 2"; 37 | (*output) << incindent; 38 | (*output) << iendl << "Foo"; 39 | (*output) << iendl << "Bar"; 40 | (*output) << decindent; 41 | (*output) << iendl << "Dummy 3"; 42 | (*output) << resetindent << iendl << "Test 2"; 43 | (*output) << incendl << "Dummy 4"; 44 | (*output) << decendl << "Test 3"; 45 | 46 | std::cout << output->str () << std::endl; 47 | BOOST_CHECK (output->match_pattern ()); 48 | } 49 | 50 | BOOST_AUTO_TEST_SUITE_END () 51 | -------------------------------------------------------------------------------- /tests/indent.stdout: -------------------------------------------------------------------------------- 1 | Test 1 2 | Dummy 1 3 | Dummy 2 4 | Foo 5 | Bar 6 | Dummy 3 7 | Test 2 8 | Dummy 4 9 | Test 3 10 | -------------------------------------------------------------------------------- /tests/interval.stdout: -------------------------------------------------------------------------------- 1 | (0, 5) 2 | (-inf, inf) 3 | (42, inf) 4 | (-inf, 42) 5 | (0 5 1) 6 | (-inf inf 0.1) 7 | (1 4 0.1) 8 | 0 9 | 1 10 | 2 11 | 3 12 | 4 13 | 5 14 | -------------------------------------------------------------------------------- /tests/linear-function.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | using namespace roboptim; 26 | 27 | struct Null : public LinearFunction 28 | { 29 | Null () : LinearFunction (1, 1, "null function") 30 | {} 31 | 32 | void impl_compute (result_ref res, const_argument_ref) const 33 | { 34 | res.setZero (); 35 | } 36 | 37 | void impl_gradient (gradient_ref grad, const_argument_ref, 38 | size_type) const 39 | { 40 | grad.setZero (); 41 | } 42 | }; 43 | 44 | struct NoTitle : public LinearFunction 45 | { 46 | NoTitle () : LinearFunction (1, 1) 47 | {} 48 | 49 | void impl_compute (result_ref res, const_argument_ref) const 50 | { 51 | res.setZero (); 52 | } 53 | 54 | void impl_gradient (gradient_ref grad, const_argument_ref, 55 | size_type) const 56 | { 57 | grad.setZero (); 58 | } 59 | }; 60 | 61 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 62 | 63 | BOOST_AUTO_TEST_CASE (linear_function) 64 | { 65 | boost::shared_ptr 66 | output = retrievePattern ("linear-function"); 67 | 68 | Null null; 69 | NoTitle notitle; 70 | 71 | (*output) << null << std::endl 72 | << notitle << std::endl; 73 | 74 | Null::vector_t x (1); 75 | x[0] = 42.; 76 | 77 | (*output) << null.gradient (x) << std::endl 78 | << notitle.gradient (x) << std::endl; 79 | 80 | (*output) << null.hessian (x) << std::endl 81 | << notitle.hessian (x) << std::endl; 82 | 83 | std::cout << output->str () << std::endl; 84 | BOOST_CHECK (output->match_pattern ()); 85 | } 86 | 87 | BOOST_AUTO_TEST_SUITE_END () 88 | -------------------------------------------------------------------------------- /tests/linear-function.stdout: -------------------------------------------------------------------------------- 1 | null function (linear function) 2 | Linear function 3 | [1](0) 4 | [1](0) 5 | [1](0) 6 | [1](0) 7 | -------------------------------------------------------------------------------- /tests/multiplexer.stdout: -------------------------------------------------------------------------------- 1 | Multiplexer callbacks: 2 | - wrapped callback 3 | - bar 4 | - Optimization logger: 5 | Log directory: /tmp/roboptim-core-tests/multiplexer-logger 6 | Foo 7 | Bar 8 | Multiplexer callbacks: 9 | - foo 10 | Foo 11 | -------------------------------------------------------------------------------- /tests/n-times-derivable-function.stdout: -------------------------------------------------------------------------------- 1 | 2-time differentiable function. 2 | Evaluate: 3 | [4](0,0,0,0) 4 | Gradient: 5 | [1](0) 6 | Jacobian: 7 | [4](0,0,0,0) 8 | Max derivability order: 2 9 | 10 | 10-time differentiable function. 11 | Evaluate: 12 | [4](0,0,0,0) 13 | Gradient: 14 | [1](0) 15 | Jacobian: 16 | [4](0,0,0,0) 17 | Max derivability order: 10 18 | -------------------------------------------------------------------------------- /tests/numeric-linear-function.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace roboptim; 27 | 28 | typedef DummySolver solver_t; 29 | 30 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 31 | ::roboptim::EigenMatrixSparse> functionTypes_t; 32 | 33 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 34 | 35 | BOOST_AUTO_TEST_CASE_TEMPLATE (numeric_linear_function, T, functionTypes_t) 36 | { 37 | boost::shared_ptr 38 | output = retrievePattern ("numeric-linear-function"); 39 | 40 | typename GenericNumericLinearFunction::matrix_t a (1, 5); 41 | typename GenericNumericLinearFunction::vector_t b (1); 42 | typename GenericNumericLinearFunction::vector_t x (5); 43 | 44 | a.setZero (); 45 | b.setZero (); 46 | x.setZero (); 47 | 48 | a.coeffRef (0, 0) = 1.2; 49 | a.coeffRef (0, 1) = 3.4; 50 | a.coeffRef (0, 2) = 5.6; 51 | a.coeffRef (0, 3) = 7.8; 52 | 53 | b[0] = 1.; 54 | 55 | GenericNumericLinearFunction f (a, b, "Dummy"); 56 | 57 | (*output) << f << std::endl; 58 | 59 | x[0] = 0.1; 60 | x[1] = 1.2; 61 | x[2] = 2.3; 62 | x[3] = 3.4; 63 | x[4] = 4.5; 64 | 65 | (*output) << "f(x) = " << f (x) << std::endl; 66 | (*output) << "G(x) = " << toDense (f.gradient (x, 0)) << std::endl; 67 | (*output) << "J(x) = " << toDense (f.jacobian (x)) << std::endl; 68 | (*output) << "H(x) = " << toDense (f.hessian (x)) << std::endl; 69 | 70 | GenericNumericLinearFunction numericLinearFunction (a, b); 71 | GenericLinearFunction* linearFunction = &numericLinearFunction; 72 | 73 | GenericNumericLinearFunction numericLinearFunctionRebuilt (*linearFunction); 74 | 75 | BOOST_CHECK (allclose (numericLinearFunction.A (), 76 | numericLinearFunctionRebuilt.A ())); 77 | BOOST_CHECK_EQUAL (numericLinearFunction.b (), numericLinearFunctionRebuilt.b ()); 78 | 79 | std::cout << output->str () << std::endl; 80 | BOOST_CHECK (output->match_pattern ()); 81 | } 82 | 83 | BOOST_AUTO_TEST_SUITE_END () 84 | -------------------------------------------------------------------------------- /tests/numeric-linear-function.stdout: -------------------------------------------------------------------------------- 1 | Dummy (numeric linear function): 2 | A = [5](1.2,3.4,5.6,7.8,0) 3 | B = [1](1) 4 | f(x) = [1](44.6) 5 | G(x) = [5](1.2,3.4,5.6,7.8,0) 6 | J(x) = [5](1.2,3.4,5.6,7.8,0) 7 | H(x) = [5,5]((0,0,0,0,0), (0,0,0,0,0), (0,0,0,0,0), (0,0,0,0,0), (0,0,0,0,0)) 8 | -------------------------------------------------------------------------------- /tests/numeric-quadratic-function.stdout: -------------------------------------------------------------------------------- 1 | Dummy (numeric quadratic function): 2 | A = [5,5]((1,0,0,0,0), (0,1,0,0,0), (0,0,1,0,0), (0,0,0,1,0), (0,0,0,0,1)) 3 | B = [5](0,0,0,0,0) 4 | c = [1](0) 5 | x = [5](0,1,2,3,4) 6 | f(x) = [1](30) 7 | J(x) = [5](0,2,4,6,8) 8 | G(x) = [5](0,2,4,6,8) 9 | H(x) = [5,5]((2,0,0,0,0), (0,2,0,0,0), (0,0,2,0,0), (0,0,0,2,0), (0,0,0,0,2)) 10 | -------------------------------------------------------------------------------- /tests/operator-bind.stdout: -------------------------------------------------------------------------------- 1 | x: [5](0,0,0,0,0) 2 | fct: Bind(identity): 3 | Bound values: [0]{} 4 | fct(x): [5](0,0,0,0,0) 5 | gradient(x): [5](1,0,0,0,0) 6 | jacobian(x): [5,5]((1,0,0,0,0), (0,1,0,0,0), (0,0,1,0,0), (0,0,0,1,0), (0,0,0,0,1)) 7 | x: [4](0,0,0,0) 8 | fct: Bind(identity): 9 | Bound values: [1]{0: 42} 10 | fct(x): [5](42,0,0,0,0) 11 | gradient(x): [4](0,0,0,0) 12 | jacobian(x): [5,4]((0,0,0,0), (1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1)) 13 | x: [3](1,1,1) 14 | fct: Bind(f(x) = Σx_i²): 15 | Bound values: [2]{1: 12, 3: -2} 16 | fct(x): [1](151) 17 | gradient(x): [3](2,2,2) 18 | jacobian(x): [3](2,2,2) 19 | -------------------------------------------------------------------------------- /tests/operator-concatenate.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace roboptim; 34 | 35 | 36 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 37 | ::roboptim::EigenMatrixSparse> functionTypes_t; 38 | 39 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 40 | 41 | BOOST_AUTO_TEST_CASE_TEMPLATE (concatenate_test, T, functionTypes_t) 42 | { 43 | boost::shared_ptr > cosinus = boost::make_shared > (); 44 | boost::shared_ptr > sinus = boost::make_shared > (); 45 | 46 | boost::shared_ptr > 47 | fct = concatenate (cosinus, sinus); 48 | 49 | BOOST_CHECK (fct->outputSize () == 1 + 1); 50 | 51 | typename GenericDifferentiableFunction::vector_t x (1); 52 | x.setZero (); 53 | std::cout 54 | << (*fct) (x) << "\n" 55 | << fct->gradient (x, 0) << "\n" 56 | << fct->gradient (x, 1) << "\n" 57 | << fct->jacobian (x) << std::endl; 58 | 59 | typename GenericConstantFunction::result_t offset1 (2); 60 | offset1.setZero (); 61 | typename GenericConstantFunction::result_t offset2 (4); 62 | offset2.setZero (); 63 | boost::shared_ptr > constant1 = 64 | boost::make_shared > (offset1); 65 | boost::shared_ptr > constant2 = 66 | boost::make_shared > (offset2); 67 | BOOST_CHECK_THROW (fct = concatenate (constant1, constant2), 68 | std::runtime_error); 69 | } 70 | 71 | BOOST_AUTO_TEST_SUITE_END () 72 | -------------------------------------------------------------------------------- /tests/operator-map.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | using namespace roboptim; 32 | 33 | 34 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 35 | ::roboptim::EigenMatrixSparse> functionTypes_t; 36 | 37 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 38 | 39 | BOOST_AUTO_TEST_CASE_TEMPLATE (map_test, T, functionTypes_t) 40 | { 41 | boost::shared_ptr > cosinus = 42 | boost::make_shared > (); 43 | 44 | boost::shared_ptr > 45 | fct = map (cosinus, 10); 46 | 47 | BOOST_CHECK (fct->inputSize () == 10); 48 | BOOST_CHECK (fct->outputSize () == 10); 49 | 50 | typename Cos::vector_t x (10); 51 | x.setZero (); 52 | std::cout 53 | << (*fct) (x) << "\n" 54 | << fct->gradient (x, 0) << "\n" 55 | << fct->jacobian (x) << std::endl; 56 | } 57 | 58 | BOOST_AUTO_TEST_SUITE_END () 59 | -------------------------------------------------------------------------------- /tests/operator-minus.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | using namespace roboptim; 33 | 34 | 35 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 36 | ::roboptim::EigenMatrixSparse> functionTypes_t; 37 | 38 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 39 | 40 | BOOST_AUTO_TEST_CASE_TEMPLATE (minus_test, T, functionTypes_t) 41 | { 42 | typename GenericIdentityFunction::result_t offset (5); 43 | offset.setZero (); 44 | 45 | boost::shared_ptr > identity = 46 | boost::make_shared > (offset); 47 | boost::shared_ptr > constant = 48 | boost::make_shared > (offset); 49 | 50 | boost::shared_ptr > 51 | fct = identity - constant - constant; 52 | 53 | typename GenericIdentityFunction::vector_t x (5); 54 | x.setZero (); 55 | std::cout 56 | << (*fct) (x) << "\n" 57 | << fct->gradient (x, 0) << "\n" 58 | << fct->gradient (x, 1) << "\n" 59 | << fct->gradient (x, 2) << "\n" 60 | << fct->gradient (x, 3) << "\n" 61 | << fct->gradient (x, 4) << "\n" 62 | << fct->jacobian (x) << std::endl; 63 | 64 | typename GenericIdentityFunction::result_t offset_throw (6); 65 | offset_throw.setZero (); 66 | boost::shared_ptr > constant_throw = 67 | boost::make_shared > (offset_throw); 68 | BOOST_CHECK_THROW (fct = identity - constant_throw, std::runtime_error); 69 | } 70 | 71 | BOOST_AUTO_TEST_SUITE_END () 72 | -------------------------------------------------------------------------------- /tests/operator-plus.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | using namespace roboptim; 33 | 34 | 35 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 36 | ::roboptim::EigenMatrixSparse> functionTypes_t; 37 | 38 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 39 | 40 | BOOST_AUTO_TEST_CASE_TEMPLATE (plus_test, T, functionTypes_t) 41 | { 42 | typename GenericIdentityFunction::result_t offset (5); 43 | offset.setZero (); 44 | 45 | boost::shared_ptr > identity = 46 | boost::make_shared > (offset); 47 | boost::shared_ptr > constant = 48 | boost::make_shared > (offset); 49 | 50 | boost::shared_ptr > 51 | fct = identity + constant + constant; 52 | 53 | typename GenericIdentityFunction::vector_t x (5); 54 | x.setZero (); 55 | std::cout 56 | << (*fct) (x) << "\n" 57 | << fct->gradient (x, 0) << "\n" 58 | << fct->gradient (x, 1) << "\n" 59 | << fct->gradient (x, 2) << "\n" 60 | << fct->gradient (x, 3) << "\n" 61 | << fct->gradient (x, 4) << "\n" 62 | << fct->jacobian (x) << std::endl; 63 | 64 | typename GenericIdentityFunction::result_t offset_throw (6); 65 | offset_throw.setZero (); 66 | boost::shared_ptr > constant_throw = 67 | boost::make_shared > (offset_throw); 68 | BOOST_CHECK_THROW (fct = identity + constant_throw, std::runtime_error); 69 | } 70 | 71 | BOOST_AUTO_TEST_SUITE_END () 72 | -------------------------------------------------------------------------------- /tests/operator-product.stdout: -------------------------------------------------------------------------------- 1 | x = [5](0,1,2,3,4) 2 | U(x) = x = [5](0,1,2,3,4) 3 | V(x) = 2 = [5](2,2,2,2,2) 4 | U(x) * V(x) = 2x = [5](0,2,4,6,8) 5 | [5](2,0,0,0,0) 6 | [5](0,2,0,0,0) 7 | [5](0,0,2,0,0) 8 | [5](0,0,0,2,0) 9 | [5](0,0,0,0,2) 10 | [5,5]((2,0,0,0,0), (0,2,0,0,0), (0,0,2,0,0), (0,0,0,2,0), (0,0,0,0,2)) 11 | 12 | x = [5](0,1,2,3,4) 13 | U(x) = 2x = [5](0,2,4,6,8) 14 | V(x) = 2x = [5](0,2,4,6,8) 15 | U(x) * V(x) = 4x² = [5](0,4,16,36,64) 16 | [5](0,0,0,0,0) 17 | [5](0,8,0,0,0) 18 | [5](0,0,16,0,0) 19 | [5](0,0,0,24,0) 20 | [5](0,0,0,0,32) 21 | [5,5]((0,0,0,0,0), (0,8,0,0,0), (0,0,16,0,0), (0,0,0,24,0), (0,0,0,0,32)) 22 | -------------------------------------------------------------------------------- /tests/operator-scalar.stdout: -------------------------------------------------------------------------------- 1 | [1](1) 2 | 1 + x² (differentiable function) 3 | [1](2) 4 | [1](2) 5 | [1](2) 6 | 2 * (1 + x²): 7 | Sub-function: 1 + x² (differentiable function) 8 | [1](4) 9 | [1](4) 10 | [1](4) 11 | [4](1,1,1,1) 12 | Numeric quadratic function: 13 | A = [4,4]((1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1)) 14 | B = [4](0,0,0,0) 15 | c = [1](0) 16 | [1](4) 17 | [4](2,2,2,2) 18 | [4](2,2,2,2) 19 | 2 * (f): 20 | Sub-function: Numeric quadratic function: 21 | A = [4,4]((1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1)) 22 | B = [4](0,0,0,0) 23 | c = [1](0) 24 | [1](8) 25 | [4](4,4,4,4) 26 | [4](4,4,4,4) 27 | [4,4]((4,0,0,0), (0,4,0,0), (0,0,4,0), (0,0,0,4)) 28 | -------------------------------------------------------------------------------- /tests/operator-selection-by-id.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | using namespace roboptim; 33 | 34 | 35 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 36 | ::roboptim::EigenMatrixSparse> functionTypes_t; 37 | 38 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 39 | 40 | BOOST_AUTO_TEST_CASE_TEMPLATE (chain_test, T, functionTypes_t) 41 | { 42 | typename GenericIdentityFunction::result_t offset (5); 43 | offset.setZero (); 44 | 45 | boost::shared_ptr > identity = 46 | boost::make_shared > (offset); 47 | 48 | std::vector selector (5, false); 49 | selector[2] = true; 50 | boost::shared_ptr > 51 | fct = selectionById (identity, selector); 52 | 53 | BOOST_CHECK (fct->outputSize () == 1); 54 | 55 | typename GenericIdentityFunction::vector_t x (5); 56 | x.setZero (); 57 | std::cout 58 | << (*fct) (x) << "\n" 59 | << fct->gradient (x, 0) << "\n" 60 | << fct->jacobian (x) << std::endl; 61 | 62 | typename GenericIdentityFunction::result_t offset_throw (6); 63 | offset_throw.setZero (); 64 | boost::shared_ptr > identity_throw = 65 | boost::make_shared > (offset_throw); 66 | BOOST_CHECK_THROW (fct = selectionById (identity_throw, selector), 67 | std::runtime_error); 68 | } 69 | 70 | BOOST_AUTO_TEST_SUITE_END () 71 | -------------------------------------------------------------------------------- /tests/operator-selection.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | using namespace roboptim; 33 | 34 | 35 | typedef boost::mpl::list< ::roboptim::EigenMatrixDense, 36 | ::roboptim::EigenMatrixSparse> functionTypes_t; 37 | 38 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 39 | 40 | BOOST_AUTO_TEST_CASE_TEMPLATE (chain_test, T, functionTypes_t) 41 | { 42 | typename GenericIdentityFunction::result_t offset (5); 43 | offset.setZero (); 44 | 45 | boost::shared_ptr > identity = 46 | boost::make_shared > (offset); 47 | 48 | boost::shared_ptr > 49 | fct = selection (identity, 0, 1); 50 | 51 | BOOST_CHECK (fct->outputSize () == 1); 52 | 53 | typename GenericIdentityFunction::vector_t x (5); 54 | x.setZero (); 55 | std::cout 56 | << (*fct) (x) << "\n" 57 | << fct->gradient (x, 0) << "\n" 58 | << fct->jacobian (x) << std::endl; 59 | 60 | BOOST_CHECK_THROW (fct = selection (identity, 0, 10), std::runtime_error); 61 | } 62 | 63 | BOOST_AUTO_TEST_SUITE_END () 64 | -------------------------------------------------------------------------------- /tests/operator-split.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #undef NDEBUG 19 | 20 | #include "shared-tests/fixture.hh" 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace roboptim; 30 | 31 | struct F : public DifferentiableFunction 32 | { 33 | F () : DifferentiableFunction (1, 10, "f_n (x) = n * x") 34 | {} 35 | 36 | void impl_compute (result_ref res, const_argument_ref argument) const 37 | { 38 | res.setZero (); 39 | for (size_type i = 0; i < outputSize (); ++i) 40 | res[i] = (value_type)i * argument[0]; 41 | } 42 | 43 | void impl_gradient (gradient_ref grad, const_argument_ref, 44 | size_type functionId) const 45 | { 46 | grad.setZero (); 47 | grad[0] = (value_type)functionId; 48 | } 49 | }; 50 | 51 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 52 | 53 | BOOST_AUTO_TEST_CASE (split) 54 | { 55 | boost::shared_ptr 56 | output = retrievePattern ("operator-split"); 57 | 58 | boost::shared_ptr f (new F ()); 59 | 60 | for (DifferentiableFunction::vector_t::Index id = 0; id < 10; ++id) 61 | { 62 | Split splitF (f, id); 63 | 64 | (*output) << splitF << ":" << std::endl 65 | << std::endl; 66 | 67 | Function::vector_t x (1); 68 | for (double i = 0.; i < 10.; i += 0.5) 69 | { 70 | x[0] = i; 71 | (*output) << "x = " << x[0] << std::endl; 72 | (*output) << splitF (x) << std::endl; 73 | (*output) << splitF.gradient (x) << std::endl; 74 | (*output) << std::endl; 75 | } 76 | } 77 | 78 | std::cout << output->str () << std::endl; 79 | BOOST_CHECK (output->match_pattern ()); 80 | } 81 | 82 | BOOST_AUTO_TEST_SUITE_END () 83 | -------------------------------------------------------------------------------- /tests/parametrized-function.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace roboptim; 27 | 28 | // Define a simple function. 29 | struct ParametrizedF : public ParametrizedFunction 30 | { 31 | ParametrizedF () : ParametrizedFunction (1, 1, 1) 32 | {} 33 | 34 | result_t impl_compute (const_argument_ref argument) const 35 | { 36 | return result_t (argument); 37 | } 38 | }; 39 | 40 | #define CHECKME(PVALUE) \ 41 | { \ 42 | (*output) << "Parameter is " << PVALUE << std::endl; \ 43 | parameter[0] = (PVALUE); \ 44 | ConstantFunction cst = pf (parameter); \ 45 | \ 46 | ConstantFunction::vector_t x (1); \ 47 | x[0] = 31.; \ 48 | (*output) \ 49 | << cst << std::endl \ 50 | << "Evaluate:" << std::endl \ 51 | << cst (x) << std::endl \ 52 | << "Gradient:" << std::endl \ 53 | << cst.gradient (x) << std::endl \ 54 | << "Jacobian:" << std::endl \ 55 | << cst.jacobian (x) << std::endl \ 56 | << "Hessian:" << std::endl \ 57 | << cst.hessian (x) << std::endl \ 58 | << std::endl; \ 59 | } \ 60 | 61 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 62 | 63 | BOOST_AUTO_TEST_CASE (parametrized_function) 64 | { 65 | boost::shared_ptr 66 | output = retrievePattern ("parametrized-function"); 67 | 68 | ParametrizedF pf; 69 | 70 | ParametrizedF::argument_t parameter (1); 71 | parameter.setZero (); 72 | 73 | CHECKME (0.); 74 | CHECKME (3.14); 75 | CHECKME (42.); 76 | 77 | { 78 | parameter[0] = 128.; 79 | ConstantFunction::vector_t x (1); 80 | x[0] = 256.; 81 | 82 | // Natural evaluation in one line. 83 | ConstantFunction::result_t res = pf (parameter) (x); 84 | 85 | (*output) << pf << std::endl; 86 | 87 | BOOST_CHECK_EQUAL (res[0], 128.); 88 | BOOST_CHECK (pf.functionInputSize () == 1); 89 | BOOST_CHECK (pf.functionOutputSize () == 1); 90 | } 91 | 92 | std::cout << output->str () << std::endl; 93 | BOOST_CHECK (output->match_pattern ()); 94 | } 95 | 96 | BOOST_AUTO_TEST_SUITE_END () 97 | -------------------------------------------------------------------------------- /tests/parametrized-function.stdout: -------------------------------------------------------------------------------- 1 | Parameter is 0 2 | Constant function 3 | offset = [1](0) 4 | Evaluate: 5 | [1](0) 6 | Gradient: 7 | [1](0) 8 | Jacobian: 9 | [1](0) 10 | Hessian: 11 | [1](0) 12 | 13 | Parameter is 3.14 14 | Constant function 15 | offset = [1](3.14) 16 | Evaluate: 17 | [1](3.14) 18 | Gradient: 19 | [1](0) 20 | Jacobian: 21 | [1](0) 22 | Hessian: 23 | [1](0) 24 | 25 | Parameter is 42 26 | Constant function 27 | offset = [1](42) 28 | Evaluate: 29 | [1](42) 30 | Gradient: 31 | [1](0) 32 | Jacobian: 33 | [1](0) 34 | Hessian: 35 | [1](0) 36 | 37 | Parametrized function 38 | -------------------------------------------------------------------------------- /tests/plugin-laststate.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | using namespace roboptim; 29 | 30 | // Specify the solver that will be used. 31 | typedef Solver solver_t; 32 | 33 | // Define a simple function. 34 | struct F : public Function 35 | { 36 | F () : Function (4, 1, "a * d * (a + b + c) + d") 37 | {} 38 | 39 | void impl_compute (result_ref result, const_argument_ref argument) 40 | const 41 | { 42 | result (0) = argument[0] * argument[3] 43 | * (argument[0] + argument[1] + argument[2]) + argument[3]; 44 | } 45 | 46 | // No gradient, hessian. 47 | }; 48 | 49 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 50 | 51 | BOOST_AUTO_TEST_CASE (plugin) 52 | { 53 | boost::shared_ptr 54 | output = retrievePattern ("plugin-laststate"); 55 | 56 | // Instantiate the function and the problem. 57 | boost::shared_ptr f = boost::make_shared (); 58 | solver_t::problem_t pb (f); 59 | 60 | // Instantiate the factory using the dummy solver. 61 | SolverFactory factory ("dummy-laststate", pb); 62 | 63 | // Retrieve a solver instance from the factory. 64 | solver_t& solver = factory (); 65 | 66 | // Get the Boost.Variant minimum. 67 | solver_t::result_t res = solver.minimum (); 68 | 69 | // Get the "real" minimum. 70 | solver.getMinimum (); 71 | 72 | // Display problem and solver. 73 | (*output) << pb << std::endl 74 | << "---" << std::endl 75 | << solver << std::endl << std::endl; 76 | 77 | // Display the solver's last state (x, objective etc.) 78 | SolverError& err = boost::get (res); 79 | const boost::optional& lastState = err.lastState(); 80 | if(lastState) 81 | { 82 | (*output) << "Last dummy x: " << lastState->x 83 | << std::endl; 84 | (*output) << "Last dummy value: " << lastState->value 85 | << std::endl << std::endl; 86 | } 87 | 88 | // Try to get the minimum from a GenericSolver*. 89 | GenericSolver* gs = &solver; 90 | (*output) << gs->getMinimum ().what () 91 | << std::endl; 92 | 93 | std::cout << output->str () << std::endl; 94 | BOOST_CHECK (output->match_pattern ()); 95 | } 96 | 97 | BOOST_AUTO_TEST_SUITE_END () 98 | -------------------------------------------------------------------------------- /tests/plugin-laststate.stdout: -------------------------------------------------------------------------------- 1 | Problem: 2 | a * d * (a + b + c) + d (not differentiable) 3 | Objective scaling: 1 4 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 5 | Arguments scaling: 1, 1, 1, 1 6 | No constraints. 7 | No starting point. 8 | Infinity value (for all functions): inf 9 | --- 10 | Solver: 11 | Plugin: dummy-laststate 12 | Problem: 13 | a * d * (a + b + c) + d (not differentiable) 14 | Objective scaling: 1 15 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 16 | Arguments scaling: 1, 1, 1, 1 17 | No constraints. 18 | No starting point. 19 | Infinity value (for all functions): inf 20 | Result: 21 | Solver error: The dummy solver always fail. 22 | Parameters: 23 | dummy-parameter (dummy parameter): 42 24 | dummy-parameter2 (yet another dummy parameter): 3 25 | dummy-parameter3 (just a dummy key): ...and a dummy value! 26 | dummy-parameter4: [4](1,2,3,4) 27 | dummy-parameter5 (dummy boolean): false 28 | 29 | Last dummy x: [4](1337,1337,1337,1337) 30 | Last dummy value: [1](42) 31 | 32 | The dummy solver always fail. 33 | -------------------------------------------------------------------------------- /tests/plugin.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | using namespace roboptim; 29 | 30 | // Specify the solver that will be used. 31 | typedef Solver solver_t; 32 | 33 | // Define a simple function. 34 | struct F : public Function 35 | { 36 | F () : Function (4, 1, "a * d * (a + b + c) + d") 37 | {} 38 | 39 | void impl_compute (result_ref result, const_argument_ref argument) 40 | const 41 | { 42 | result (0) = argument[0] * argument[3] 43 | * (argument[0] + argument[1] + argument[2]) + argument[3]; 44 | } 45 | 46 | // No gradient, hessian. 47 | }; 48 | 49 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 50 | 51 | BOOST_AUTO_TEST_CASE (plugin) 52 | { 53 | boost::shared_ptr 54 | output = retrievePattern ("plugin"); 55 | 56 | // Instantiate the function and the problem. 57 | boost::shared_ptr f = boost::make_shared (); 58 | solver_t::problem_t pb (f); 59 | 60 | // Instantiate the factory using the dummy solver. 61 | SolverFactory factory ("dummy", pb); 62 | 63 | // Retrieve a solver instance from the factory. 64 | solver_t& solver = factory (); 65 | 66 | // Get the Boost.Variant minimum. 67 | solver_t::result_t res = solver.minimum (); 68 | 69 | // Get the "real" minimum. 70 | solver.getMinimum (); 71 | 72 | // Display problem and solver. 73 | (*output) << pb << std::endl 74 | << "---" << std::endl 75 | << solver << std::endl << std::endl; 76 | 77 | std::cout << pb << std::endl 78 | << "---" << std::endl 79 | << solver << std::endl << std::endl; 80 | 81 | // Try to get the minimum from a GenericSolver*. 82 | GenericSolver* gs = &solver; 83 | (*output) << gs->getMinimum ().what () 84 | << std::endl; 85 | 86 | std::cout << output->str () << std::endl; 87 | BOOST_CHECK (output->match_pattern ()); 88 | } 89 | 90 | BOOST_AUTO_TEST_SUITE_END () 91 | -------------------------------------------------------------------------------- /tests/plugin.stdout: -------------------------------------------------------------------------------- 1 | Problem: 2 | a * d * (a + b + c) + d (not differentiable) 3 | Objective scaling: 1 4 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 5 | Arguments scaling: 1, 1, 1, 1 6 | No constraints. 7 | No starting point. 8 | Infinity value (for all functions): inf 9 | --- 10 | Solver: 11 | Plugin: dummy 12 | Problem: 13 | a * d * (a + b + c) + d (not differentiable) 14 | Objective scaling: 1 15 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 16 | Arguments scaling: 1, 1, 1, 1 17 | No constraints. 18 | No starting point. 19 | Infinity value (for all functions): inf 20 | Result: 21 | Solver error: The dummy solver always fail. 22 | Parameters: 23 | dummy-parameter (dummy parameter): 42 24 | dummy-parameter2 (yet another dummy parameter): 3 25 | dummy-parameter3 (just a dummy key): ...and a dummy value! 26 | dummy-parameter4: [4](1,2,3,4) 27 | dummy-parameter5 (dummy boolean): false 28 | 29 | The dummy solver always fail. 30 | -------------------------------------------------------------------------------- /tests/problem-cc.stdout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roboptim/roboptim-core/da505d4fc8e50c849370d84a9838773d3a91fdbe/tests/problem-cc.stdout -------------------------------------------------------------------------------- /tests/quadratic-function.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | using namespace roboptim; 26 | 27 | struct Null : public QuadraticFunction 28 | { 29 | Null () : QuadraticFunction (1, 1, "null function") 30 | {} 31 | 32 | void impl_compute (result_ref res, const_argument_ref) const throw () 33 | { 34 | res.setZero (); 35 | } 36 | 37 | void impl_gradient (gradient_ref grad, const_argument_ref, 38 | size_type) const 39 | { 40 | grad.setZero (); 41 | } 42 | 43 | void impl_hessian (hessian_ref h, const_argument_ref, 44 | size_type) const 45 | { 46 | h.setZero (); 47 | } 48 | }; 49 | 50 | struct NoTitle : public QuadraticFunction 51 | { 52 | NoTitle () : QuadraticFunction (1, 1) 53 | {} 54 | 55 | void impl_compute (result_ref res, const_argument_ref) const throw () 56 | { 57 | res.setZero (); 58 | } 59 | 60 | void impl_gradient (gradient_ref grad, const_argument_ref, 61 | size_type) const 62 | { 63 | grad.setZero (); 64 | } 65 | 66 | void impl_hessian (hessian_ref h, const_argument_ref, size_type) 67 | const 68 | { 69 | h.setZero (); 70 | } 71 | }; 72 | 73 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 74 | 75 | BOOST_AUTO_TEST_CASE (quadratic_function) 76 | { 77 | boost::shared_ptr 78 | output = retrievePattern ("quadratic-function"); 79 | 80 | Null null; 81 | NoTitle notitle; 82 | 83 | (*output) << null << std::endl 84 | << notitle << std::endl; 85 | 86 | Null::vector_t x (1); 87 | x[0] = 42.; 88 | 89 | (*output) << null.gradient (x) << std::endl 90 | << notitle.gradient (x) << std::endl; 91 | 92 | (*output) << null.hessian (x) << std::endl 93 | << notitle.hessian (x) << std::endl; 94 | 95 | std::cout << output->str () << std::endl; 96 | BOOST_CHECK (output->match_pattern ()); 97 | } 98 | 99 | BOOST_AUTO_TEST_SUITE_END () 100 | -------------------------------------------------------------------------------- /tests/quadratic-function.stdout: -------------------------------------------------------------------------------- 1 | null function (quadratic function) 2 | Quadratic function 3 | [1](0) 4 | [1](0) 5 | [1](0) 6 | [1](0) 7 | -------------------------------------------------------------------------------- /tests/ref.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2014 by Benjamin Chrétien, CNRS-LIRMM. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | using namespace roboptim; 26 | 27 | boost::shared_ptr output; 28 | 29 | struct F : public DifferentiableFunction 30 | { 31 | F () : DifferentiableFunction (4, 2, 32 | "x₀ * x₃ * (x₀ + x₁ + x₂) + x₃, " 33 | "x₀²") 34 | { 35 | } 36 | 37 | void 38 | impl_compute (result_ref result, const_argument_ref x) const 39 | { 40 | result (0) = x[0] * x[3] * (x[0] + x[1] + x[2]) + x[3]; 41 | result (1) = x[0] * x[0]; 42 | } 43 | 44 | void 45 | impl_gradient (gradient_ref grad, const_argument_ref x, 46 | size_type functionId) const 47 | { 48 | switch (functionId) 49 | { 50 | case 0: 51 | { 52 | grad[0] = x[0] * x[3] + x[3] * (x[0] + x[1] + x[2]); 53 | grad[1] = x[0] * x[3]; 54 | grad[2] = x[0] * x[3] + 1; 55 | grad[3] = x[0] * (x[0] + x[1] + x[2]); 56 | } 57 | break; 58 | 59 | case 1: 60 | { 61 | grad[0] = 2. * x[0]; 62 | } 63 | break; 64 | 65 | default: 66 | abort (); 67 | } 68 | } 69 | }; 70 | 71 | 72 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 73 | 74 | BOOST_AUTO_TEST_CASE (ref) 75 | { 76 | output = retrievePattern ("ref"); 77 | 78 | // Instantiate the function and the problem. 79 | F f; 80 | 81 | F::value_type x[8] = {0., 1., 0., 1., 0., 1., 0., 1. }; 82 | F::jacobian_t jac (2,4); 83 | jac.setZero (); 84 | 85 | Eigen::Map > 86 | map_x (x, 4, Eigen::Stride<1,2> ()); 87 | 88 | F::jacobian_ref jac_ref (jac); 89 | F::const_argument_ref x_ref (map_x); 90 | 91 | set_is_malloc_allowed (false); 92 | f.jacobian (jac_ref, x_ref); 93 | set_is_malloc_allowed (true); 94 | 95 | (*output) << map_x << std::endl; 96 | (*output) << f << std::endl; 97 | (*output) << f (map_x) << std::endl; 98 | (*output) << f.jacobian (map_x) << std::endl; 99 | 100 | std::cout << output->str () << std::endl; 101 | BOOST_CHECK (output->match_pattern ()); 102 | } 103 | 104 | BOOST_AUTO_TEST_SUITE_END () 105 | -------------------------------------------------------------------------------- /tests/ref.stdout: -------------------------------------------------------------------------------- 1 | [4](0,0,0,0) 2 | x₀ * x₃ * (x₀ + x₁ + x₂) + x₃, x₀² (differentiable function) 3 | [2](0,0) 4 | [2,4]((0,0,1,0), (0,0,0,0)) 5 | -------------------------------------------------------------------------------- /tests/result-analyzer.stdout: -------------------------------------------------------------------------------- 1 | x = [2](0,0) 2 | λ = [4](0,0,0,1) 3 | LICQ conditions: not satisfied 4 | rank: 0 5 | max_rank: 1 6 | KKT conditions: satisfied 7 | ∇L(x*,λ*) = [2](0,0) 8 | λ = [4](0,0,0,1) 9 | Constraint violation: 0 10 | Complementary slackness: 0 11 | Dual feasible: true 12 | Null gradient condition: not satisfied 13 | - Constraint: x * x (differentiable function) 14 | Null gradient indices: 0 15 | x = [2](0,3) 16 | λ = [4](1,1,-1,1) 17 | LICQ conditions: not satisfied 18 | rank: 1 19 | max_rank: 2 20 | KKT conditions: not satisfied 21 | ∇L(x*,λ*) = [2](1,1) 22 | λ = [4](1,1,-1,1) 23 | Constraint violation: 0 24 | Complementary slackness: 0 25 | Dual feasible: true 26 | Null gradient condition: satisfied 27 | x = [2](-1,1) 28 | λ = [4](1,1,-1,1) 29 | LICQ conditions: satisfied 30 | rank: 1 31 | max_rank: 1 32 | KKT conditions: not satisfied 33 | ∇L(x*,λ*) = [2](1,1) 34 | λ = [4](1,1,-1,1) 35 | Constraint violation: 0 36 | Complementary slackness: 0 37 | Dual feasible: true 38 | Null gradient condition: satisfied 39 | Problem: 40 | x * x (differentiable function) 41 | Objective scaling: 1 42 | Arguments bounds: (-1, 3), (-1, 3) 43 | Arguments scaling: 1, 1 44 | Arguments names: x₀, x₁ 45 | Number of constraints: 1 46 | Constraint 0 47 | x * x (differentiable function) 48 | Bounds: (0, 9) 49 | Scaling: 1 50 | Initial value: [1](0) 51 | Starting point: [2](0,0) 52 | Starting value: [1](0) 53 | Infinity value (for all functions): inf 54 | -------------------------------------------------------------------------------- /tests/result-with-warnings.stdout: -------------------------------------------------------------------------------- 1 | solve () 2 | Result: 3 | Size (input, output): 1, 1 4 | X: [1](0) 5 | Value: [1](0) 6 | Warnings: Dummy warning message. 7 | -------------------------------------------------------------------------------- /tests/result.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace roboptim; 27 | 28 | // Define a simple function. 29 | struct F : public Function 30 | { 31 | F () : Function (1, 1, "x") 32 | {} 33 | 34 | void impl_compute (result_ref res, 35 | const_argument_ref x) const 36 | { 37 | res (0) = x[0]; 38 | } 39 | 40 | // No gradient, hessian. 41 | }; 42 | 43 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 44 | 45 | BOOST_AUTO_TEST_CASE (result) 46 | { 47 | boost::shared_ptr 48 | output = retrievePattern ("result"); 49 | 50 | // Instantiate some results. 51 | Result result (3, 8); 52 | F f; 53 | F::size_type c_size = 4; 54 | result.constraints.resize (c_size); 55 | result.constraints.setZero (); 56 | result.lambda.resize (c_size); 57 | result.lambda.setZero (); 58 | result.constraint_violation = 0.; 59 | 60 | assert (result.x.size () == 3); 61 | assert (result.value.size () == 8); 62 | assert (result.lambda.size () == c_size); 63 | 64 | Result result2 (result); 65 | Result result3 = result; 66 | 67 | (*output) << result << std::endl; 68 | 69 | std::cout << output->str () << std::endl; 70 | BOOST_CHECK (output->match_pattern ()); 71 | } 72 | 73 | BOOST_AUTO_TEST_SUITE_END () 74 | -------------------------------------------------------------------------------- /tests/result.stdout: -------------------------------------------------------------------------------- 1 | Result: 2 | Size (input, output): 3, 8 3 | X: [3](0,0,0) 4 | Value: [8](0,0,0,0,0,0,0,0) 5 | Constraints values: [4](0,0,0,0) 6 | Constraint violation: 0 7 | Lambda: [4](0,0,0,0) 8 | -------------------------------------------------------------------------------- /tests/scaling-helper.stdout: -------------------------------------------------------------------------------- 1 | Constant function 2 | offset = [2](1,2) 3 | Problem: 4 | Constant function 5 | offset = [2](1,2) 6 | Objective scaling: 1, 1 7 | Arguments bounds: (-inf, inf), (-inf, inf) 8 | Arguments scaling: 1, 1 9 | No constraints. 10 | No starting point. 11 | Infinity value (for all functions): inf 12 | [2](2,1) 13 | [2](100,-200) 14 | No suggested scaling parameters 15 | Problem: 16 | Constant function 17 | offset = [2](1,2) 18 | Objective scaling: 1, 1 19 | Arguments bounds: (-inf, inf), (-inf, inf) 20 | Arguments scaling: 1, 1 21 | Number of constraints: 3 22 | Constraint 0 23 | Numeric linear function: 24 | A = [2,2]((300,0), (0,10)) 25 | B = [2](200,300) 26 | Bounds: (0, inf), (0, inf) 27 | Scaling: 1, 1 28 | Constraint 1 29 | Numeric quadratic function: 30 | A = [2,2]((300,0), (0,10)) 31 | B = [2](200,300) 32 | c = [1](0) 33 | Bounds: (0, inf) 34 | Scaling: 1 35 | Constraint 2 36 | Numeric quadratic function: 37 | A = [2,2]((0.0003,0), (0,1e-05)) 38 | B = [2](0.0002,0.0003) 39 | c = [1](0) 40 | Bounds: (0, inf) 41 | Scaling: 1 42 | No starting point. 43 | Infinity value (for all functions): inf 44 | [4,2]((300,0), (0,10), (1400,320), (0.0014,0.00032)) 45 | [4,2]((300,0), (0,10), (60200,-3700), (0.0602,-0.0037)) 46 | Suggested scaling parameters: 47 | Constraint 0: 48 | Numeric linear function: 49 | A = [2,2]((300,0), (0,10)) 50 | B = [2](200,300) 51 | Scaling: 1, 1 52 | Constraint 1: 53 | Numeric quadratic function: 54 | A = [2,2]((300,0), (0,10)) 55 | B = [2](200,300) 56 | c = [1](0) 57 | Scaling: 1 58 | Constraint 2: 59 | Numeric quadratic function: 60 | A = [2,2]((0.0003,0), (0,1e-05)) 61 | B = [2](0.0002,0.0003) 62 | c = [1](0) 63 | Scaling: 1 64 | Suggested scaling parameters: 65 | Constraint 0: 66 | Numeric linear function: 67 | A = [2,2]((300,0), (0,10)) 68 | B = [2](200,300) 69 | Scaling: 0.333333, 1 70 | Constraint 1: 71 | Numeric quadratic function: 72 | A = [2,2]((300,0), (0,10)) 73 | B = [2](200,300) 74 | c = [1](0) 75 | Scaling: 0.00166113 76 | Constraint 2: 77 | Numeric quadratic function: 78 | A = [2,2]((0.0003,0), (0,1e-05)) 79 | B = [2](0.0002,0.0003) 80 | c = [1](0) 81 | Scaling: 71.4286 82 | 83 | -------------------------------------------------------------------------------- /tests/simple.stdout: -------------------------------------------------------------------------------- 1 | Problem: 2 | a * d * (a + b + c) + d (not differentiable) 3 | Objective scaling: 1 4 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 5 | Arguments scaling: 1, 1, 1, 1 6 | No constraints. 7 | No starting point. 8 | Infinity value (for all functions): inf 9 | Problem: 10 | a * d * (a + b + c) + d (not differentiable) 11 | Objective scaling: 1 12 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 13 | Arguments scaling: 1, 1, 1, 1 14 | Number of constraints: 1 15 | Constraint 0 16 | a * d * (a + b + c) + d (not differentiable) 17 | Bounds: (0, 5) 18 | Scaling: 3.5 19 | Initial value: [1](0) 20 | Starting point: [4](0,0,0,0) 21 | Starting value: [1](0) 22 | Infinity value (for all functions): inf 23 | --- 24 | Solver: 25 | Problem: 26 | a * d * (a + b + c) + d (not differentiable) 27 | Objective scaling: 1 28 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 29 | Arguments scaling: 1, 1, 1, 1 30 | Number of constraints: 1 31 | Constraint 0 32 | a * d * (a + b + c) + d (not differentiable) 33 | Bounds: (0, 5) 34 | Scaling: 3.5 35 | Initial value: [1](0) 36 | Starting point: [4](0,0,0,0) 37 | Starting value: [1](0) 38 | Infinity value (for all functions): inf 39 | Result: 40 | Solver error: The dummy solver always fail. 41 | Parameters: 42 | dummy-parameter (dummy parameter): 42 43 | dummy-parameter2 (yet another dummy parameter): 3 44 | dummy-parameter3 (just a dummy key): ...and a dummy value! 45 | dummy-parameter4: [4](1,2,3,4) 46 | dummy-parameter5 (dummy boolean): false 47 | The dummy solver always fail. 48 | Discrete point: 2.3 (cnt: 1) 49 | Discrete point: 2.8 (cnt: 2) 50 | 51 | Discrete point: 2 (cnt: 1) 52 | Discrete point: 2.1 (cnt: 2) 53 | Discrete point: 2.2 (cnt: 3) 54 | Discrete point: 2.3 (cnt: 4) 55 | Discrete point: 2.4 (cnt: 5) 56 | Discrete point: 2.5 (cnt: 6) 57 | Discrete point: 2.6 (cnt: 7) 58 | Discrete point: 2.7 (cnt: 8) 59 | Discrete point: 2.8 (cnt: 9) 60 | Discrete point: 2.9 (cnt: 10) 61 | Discrete point: 3 (cnt: 11) 62 | 63 | Discrete point: 0.8 (cnt: 1) 64 | Discrete point: 1.8 (cnt: 2) 65 | Discrete point: 2.8 (cnt: 3) 66 | Discrete point: 3.8 (cnt: 4) 67 | Discrete point: 4.8 (cnt: 5) 68 | Discrete point: 5.8 (cnt: 6) 69 | Discrete point: 6.8 (cnt: 7) 70 | Discrete point: 7.8 (cnt: 8) 71 | Discrete point: 8.8 (cnt: 9) 72 | Discrete point: 9.8 (cnt: 10) 73 | Discrete point: 10.8 (cnt: 11) 74 | 75 | -------------------------------------------------------------------------------- /tests/solver-error.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 by Benjamin Chrétien, CNRS-AIST JRL. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace roboptim; 30 | 31 | boost::shared_ptr output; 32 | 33 | // Define a simple function. 34 | struct F1 : public Function 35 | { 36 | F1 () : Function (4, 1, "a + b + c + d") 37 | {} 38 | 39 | void impl_compute (result_ref res, 40 | const_argument_ref x) const 41 | { 42 | res (0) = x[0] + x[1] + x[2] + x[3]; 43 | } 44 | 45 | // No gradient, hessian. 46 | }; 47 | 48 | class DummyErrorSolver : public Solver 49 | { 50 | public: 51 | /// Define parent's type. 52 | typedef Solver parent_t; 53 | typedef parent_t::solverState_t solverState_t; 54 | typedef parent_t::callback_t callback_t; 55 | 56 | DummyErrorSolver (const problem_t& pb) 57 | : parent_t (pb) 58 | { 59 | } 60 | 61 | ~DummyErrorSolver () 62 | { 63 | } 64 | 65 | void solve () 66 | { 67 | (*output) << "solve ()" << std::endl; 68 | 69 | result_ = SolverError ("The dummy solver always fail.\n" 70 | "It also prints a dummy multiline error message."); 71 | } 72 | }; 73 | 74 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 75 | 76 | BOOST_AUTO_TEST_CASE (solver_error) 77 | { 78 | output = retrievePattern ("solver-error"); 79 | 80 | typedef DummyErrorSolver solver_t; 81 | boost::shared_ptr f = boost::make_shared (); 82 | solver_t::problem_t pb (f); 83 | 84 | boost::shared_ptr solver (new solver_t (pb)); 85 | solver->solve (); 86 | 87 | (*output) << *solver << std::endl; 88 | 89 | std::cout << output->str () << std::endl; 90 | BOOST_CHECK (output->match_pattern ()); 91 | } 92 | 93 | BOOST_AUTO_TEST_SUITE_END () 94 | -------------------------------------------------------------------------------- /tests/solver-error.stdout: -------------------------------------------------------------------------------- 1 | solve () 2 | Solver: 3 | Problem: 4 | a + b + c + d (not differentiable) 5 | Objective scaling: 1 6 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 7 | Arguments scaling: 1, 1, 1, 1 8 | No constraints. 9 | No starting point. 10 | Infinity value (for all functions): inf 11 | Result: 12 | Solver error: 13 | The dummy solver always fail. 14 | It also prints a dummy multiline error message. 15 | 16 | -------------------------------------------------------------------------------- /tests/solver-factory.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2014 by Benjamin Chrétien, CNRS. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace roboptim; 29 | 30 | // Specify the solver that will be used. 31 | typedef Solver solver_t; 32 | 33 | // Output stream 34 | boost::shared_ptr output; 35 | 36 | struct F : public TwiceDifferentiableFunction 37 | { 38 | F () : TwiceDifferentiableFunction (1, 1, "0") 39 | { 40 | } 41 | 42 | void 43 | impl_compute (result_ref, const_argument_ref) const 44 | { 45 | } 46 | 47 | void 48 | impl_gradient (gradient_ref, const_argument_ref, size_type) const 49 | { 50 | } 51 | 52 | void 53 | impl_hessian (hessian_ref, const_argument_ref, size_type) const 54 | { 55 | } 56 | }; 57 | 58 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 59 | 60 | BOOST_AUTO_TEST_CASE (solver_factory) 61 | { 62 | boost::shared_ptr 63 | output = retrievePattern ("solver-factory"); 64 | 65 | // Create cost function. 66 | boost::shared_ptr f = boost::make_shared (); 67 | 68 | // Create problem. 69 | solver_t::problem_t pb (f); 70 | 71 | // Set bounds for all optimization parameters. 72 | for (std::size_t i = 0; 73 | static_cast (i) < pb.function ().inputSize (); ++i) 74 | pb.argumentBounds ()[i] = Function::makeInterval (0., 1.); 75 | 76 | // Set the starting point. 77 | Function::vector_t start (pb.function ().inputSize ()); 78 | start.setZero (); 79 | 80 | // Initialize solver. 81 | SolverFactory factory ("dummy-td", pb); 82 | solver_t& solver = factory (); 83 | (*output) << solver << std::endl; 84 | 85 | BOOST_CHECK_THROW (SolverFactory factory_plugin ("dummy-foo", pb); 86 | solver_t& solver_plugin = factory_plugin (); 87 | (*output) << solver_plugin << std::endl, 88 | std::runtime_error); 89 | 90 | std::cout << output->str () << std::endl; 91 | BOOST_CHECK (output->match_pattern ()); 92 | } 93 | 94 | BOOST_AUTO_TEST_SUITE_END () 95 | -------------------------------------------------------------------------------- /tests/solver-factory.stdout: -------------------------------------------------------------------------------- 1 | Solver: 2 | Plugin: dummy-td 3 | Problem: 4 | 0 (twice differentiable function) 5 | Objective scaling: 1 6 | Arguments bounds: (0, 1) 7 | Arguments scaling: 1 8 | No constraints. 9 | No starting point. 10 | Infinity value (for all functions): inf 11 | Parameters: 12 | dummy-parameter (dummy parameter): 42 13 | dummy-parameter2 (yet another dummy parameter): 3 14 | dummy-parameter3 (just a dummy key): ...and a dummy value! 15 | dummy-parameter4: [4](1,2,3,4) 16 | dummy-parameter5 (dummy boolean): false 17 | 18 | -------------------------------------------------------------------------------- /tests/solver-state.stdout: -------------------------------------------------------------------------------- 1 | Solver: 2 | Problem: 3 | a + b + c + d (not differentiable) 4 | Objective scaling: 1 5 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 6 | Arguments scaling: 1, 1, 1, 1 7 | No constraints. 8 | No starting point. 9 | Infinity value (for all functions): inf 10 | 11 | solver_t.solve () 12 | Solver state: 13 | x: [4](0,0,0,0) 14 | Cost: 0 15 | Parameters: 16 | data.bool (dummy bool): true 17 | data.double (dummy double): 42 18 | data.int (dummy integer): 10 19 | data.string (dummy string): "dummy data" 20 | data.vector (dummy vector): [4](0,0,0,0) 21 | solver_t.setIterationCallback () 22 | solver_t.solve () 23 | callback_t.callback () 24 | Solver state: 25 | x: [4](5,5,5,5) 26 | Cost: 42 27 | Parameters: 28 | data.bool (dummy bool): true 29 | data.double (dummy double): 42 30 | data.int (dummy integer): 10 31 | data.string (dummy string): "dummy data" 32 | data.vector (dummy vector): [4](0,0,0,0) 33 | solver_t.solve () 34 | callback_t.callback () 35 | Solver state: 36 | x: [4](2,2,2,2) 37 | Cost: 42 38 | Parameters: 39 | data.bool (dummy bool): true 40 | data.double (dummy double): 42 41 | data.int (dummy integer): 10 42 | data.string (dummy string): "dummy data" 43 | data.vector (dummy vector): [4](0,0,0,0) 44 | solver_t.setIterationCallback () 45 | solver_t.solve () 46 | 47 | ******************************************************************************** 48 | 49 | Solver: 50 | Problem: 51 | a + b + c + d + e, a * b * c * d * e (not differentiable) 52 | Objective scaling: 1, 1 53 | Arguments bounds: (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf), (-inf, inf) 54 | Arguments scaling: 1, 1, 1, 1, 1 55 | No constraints. 56 | No starting point. 57 | Infinity value (for all functions): inf 58 | 59 | solver_t.solve () 60 | Solver state: 61 | x: [5](0,0,0,0,0) 62 | Cost: 0 63 | Parameters: 64 | data.bool (dummy bool): true 65 | data.double (dummy double): 42 66 | data.int (dummy integer): 10 67 | data.string (dummy string): "dummy data" 68 | data.vector (dummy vector): [5](0,0,0,0,0) 69 | solver_t.setIterationCallback () 70 | solver_t.solve () 71 | callback_t.callback () 72 | Solver state: 73 | x: [5](5,5,5,5,5) 74 | Cost: 42 75 | Parameters: 76 | data.bool (dummy bool): true 77 | data.double (dummy double): 42 78 | data.int (dummy integer): 10 79 | data.string (dummy string): "dummy data" 80 | data.vector (dummy vector): [5](0,0,0,0,0) 81 | solver_t.solve () 82 | callback_t.callback () 83 | Solver state: 84 | x: [5](2,2,2,2,2) 85 | Cost: 42 86 | Parameters: 87 | data.bool (dummy bool): true 88 | data.double (dummy double): 42 89 | data.int (dummy integer): 10 90 | data.string (dummy string): "dummy data" 91 | data.vector (dummy vector): [5](0,0,0,0,0) 92 | solver_t.setIterationCallback () 93 | solver_t.solve () 94 | 95 | -------------------------------------------------------------------------------- /tests/storage-order.stdout: -------------------------------------------------------------------------------- 1 | [2,2]((1,2), (3,4)) 2 | [2](2,4) 3 | -------------------------------------------------------------------------------- /tests/sum-of-c1-squares.stdout: -------------------------------------------------------------------------------- 1 | null (differentiable function) 2 | [4](204,40,60,80) 3 | [4](204,40,60,80) 4 | 4 5 | 1 6 | -------------------------------------------------------------------------------- /tests/terminal-color-normal.stdout: -------------------------------------------------------------------------------- 1 | normal text 2 | red text 3 | green text 4 | yellow text 5 | blue text 6 | orange text 7 | bold text 8 | bold red text 9 | bold green text 10 | bold yellow text 11 | bold blue text 12 | bold orange text 13 | italic text 14 | italic red text 15 | italic green text 16 | italic yellow text 17 | italic blue text 18 | italic orange text 19 | ok text 20 | warn text 21 | fail text 22 | 23 | -------------------------------------------------------------------------------- /tests/terminal-color-tty.stdout: -------------------------------------------------------------------------------- 1 | normal text 2 | red text 3 | green text 4 | yellow text 5 | blue text 6 | orange text 7 | bold text 8 | bold red text 9 | bold green text 10 | bold yellow text 11 | bold blue text 12 | bold orange text 13 | italic text 14 | italic red text 15 | italic green text 16 | italic yellow text 17 | italic blue text 18 | italic orange text 19 | ok text 20 | warn text 21 | fail text 22 | 23 | -------------------------------------------------------------------------------- /tests/twice-derivable-function.stdout: -------------------------------------------------------------------------------- 1 | null function (twice differentiable function) 2 | Twice differentiable function 3 | 1 4 | 1 5 | 1 6 | 1 7 | null function 8 | 9 | 1 10 | 1 11 | [1](0) 12 | [1](0) 13 | [1](0) 14 | [1](0) 15 | [1](0) 16 | [1](0) 17 | 1 18 | 1 19 | (1, 1) 20 | (1, 1) 21 | 1 22 | 1 23 | 1 24 | 1 25 | [1](0) 26 | [1](0) 27 | [1](0) 28 | [1](0) 29 | (1, 1) 30 | (1, 1) 31 | 1 32 | 1 33 | -------------------------------------------------------------------------------- /tests/util.stdout: -------------------------------------------------------------------------------- 1 | empty vector 2 | 1 3 | (42, foo) 4 | {} 5 | {bar: 1337, foo: 42} 6 | int 7 | [5,5]((0,0,0,0,0), (0,1,2,3,4), (0,2,4,6,8), (0,3,6,9,12), (0,4,8,12,16)) 8 | [5,5]((0,0,0,0,0), (0,1,2,3,4), (0,2,4,6,8), (0,3,6,9,12), (0,4,8,12,16)) 9 | [4](1,2,3,4) 10 | [4](1,2,3,4) 11 | [5,5]((0,3,0,0,0), (0,0,0,0,0), (0,12,0,42,0), (0,0,0,1,0), (0,0,0,0,0)) 12 | [5,5]((0,3,0,0,0), (0,0,0,0,0), (0,4,0,5,0), (0,0,0,6,0), (0,0,0,0,0)) 13 | [3,3]((12,0,42), (0,0,1), (0,0,0)) 14 | [5,5]((0,3,0,0,0), (0,0,0,0,0), (0,12,0,42,0), (0,0,0,1,0), (0,0,0,0,0)) 15 | [5,5]((0,6,0,0,0), (0,0,0,0,0), (0,24,0,84,0), (0,0,0,2,0), (0,0,0,0,0)) 16 | [5,5]((0,12,0,0,0), (0,0,0,0,0), (0,48,0,168,0), (0,0,0,4,0), (0,0,0,0,0)) 17 | [10](1,0.1,0.01,0.001,0.0001,1e-05,1e-06,1e-07,1e-08,1e-09) 18 | [10](1,0.1,0.01,0.001,0.0001,1e-05,1e-06,1e-07,1e-08,0) 19 | [4,4]((1,0.1,0.01,0.001), (0.0001,1e-05,1e-06,1e-07), (1e-08,1e-09,1e-10,1e-11), (1e-12,1e-13,1e-14,1e-15)) 20 | [4,4]((1,0.1,0.01,0.001), (0.0001,1e-05,1e-06,1e-07), (1e-08,0,0,0), (0,0,0,0)) 21 | "aaa" split with 'a': , , 22 | "ababa" split with 'b': a, a, a 23 | "this is a test" split with ' ': this, is, a, test 24 | "" split with '\n': empty vector 25 | "an awesome 26 | multiline test 27 | with 3 lines!" split with '\n': an awesome, multiline test, with 3 lines! 28 | Not expecting a FPE... done! 29 | -------------------------------------------------------------------------------- /tests/visualization-gnuplot-differentiable-function.stdout: -------------------------------------------------------------------------------- 1 | #!/usr/bin/gnuplot 2 | # Generated by roboptim-core 3 | set terminal wxt persist 4 | set multiplot layout 2,1 5 | # Dense matrix 6 | set title 'Dense Jacobian (The Answer)' 7 | set palette defined(0 "white",1 "blue") 8 | set grid front 9 | set xrange [0:7] 10 | set yrange [0:7] reverse 11 | set size ratio -1 12 | unset colorbox 13 | plot '-' using ($1+0.5):($2+0.5):($3 == 0 ? 0 : 1) matrix with image notitle 14 | 1.00000000 0.00000000 0.00000000 0.00000000 1.00000000 1.00000000 0.00000000 15 | 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 0.00000000 1.00000000 16 | 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 0.00000000 1.00000000 17 | 1.00000000 1.00000000 1.00000000 0.00000000 0.00000000 1.00000000 0.00000000 18 | 0.00000000 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 19 | 0.00000000 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 20 | 0.00000000 0.00000000 1.00000000 0.00000000 1.00000000 1.00000000 1.00000000 21 | e 22 | e 23 | 24 | # Sparse matrix 25 | set title 'Sparse Jacobian (The Answer)' 26 | set palette defined(0 "white",1 "blue") 27 | set grid front 28 | set xrange [0:7] 29 | set yrange [0:7] reverse 30 | set size ratio -1 31 | unset colorbox 32 | plot '-' using ($1+0.5):($2+0.5):($3 == 0 ? 0 : 1) matrix with image notitle 33 | 1.00000000 0.00000000 0.00000000 0.00000000 1.00000000 1.00000000 0.00000000 34 | 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 0.00000000 1.00000000 35 | 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 0.00000000 1.00000000 36 | 1.00000000 1.00000000 1.00000000 0.00000000 0.00000000 1.00000000 0.00000000 37 | 0.00000000 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 38 | 0.00000000 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 39 | 0.00000000 0.00000000 1.00000000 0.00000000 1.00000000 1.00000000 1.00000000 40 | e 41 | e 42 | 43 | unset multiplot 44 | -------------------------------------------------------------------------------- /tests/visualization-gnuplot-simple.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | using namespace roboptim; 28 | using namespace roboptim::visualization; 29 | 30 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 31 | 32 | BOOST_AUTO_TEST_CASE (visualization_gnuplot_simple) 33 | { 34 | boost::shared_ptr 35 | output = retrievePattern ("visualization-gnuplot-simple"); 36 | 37 | using namespace roboptim::visualization::gnuplot; 38 | Gnuplot gnuplot = Gnuplot::make_gnuplot (); 39 | 40 | // Display nothing, generate just some valid Gnuplot commands. 41 | (*output) 42 | << (gnuplot 43 | << set ("term", "x11 enhanced persist") 44 | << comment ("Hello, world!\nThis is a three-line comment!\nAmazing!") 45 | << cd ("/tmp") 46 | << help ("pwd") 47 | << show ("foo") 48 | << replot 49 | << pwd 50 | << reread 51 | << clear 52 | << reset 53 | << quit 54 | ); 55 | 56 | // Test clear function 57 | gnuplot.clear (); 58 | (*output) << gnuplot; 59 | 60 | std::cout << output->str () << std::endl; 61 | BOOST_CHECK (output->match_pattern ()); 62 | } 63 | 64 | BOOST_AUTO_TEST_SUITE_END () 65 | -------------------------------------------------------------------------------- /tests/visualization-gnuplot-simple.stdout: -------------------------------------------------------------------------------- 1 | #!/usr/bin/gnuplot 2 | # Generated by roboptim-core 3 | set term x11 enhanced persist 4 | # Hello, world! 5 | # This is a three-line comment! 6 | # Amazing! 7 | cd '/tmp' 8 | help 'pwd' 9 | show foo 10 | replot 11 | pwd 12 | reread 13 | clear 14 | reset 15 | quit 16 | -------------------------------------------------------------------------------- /tests/visualization-matplotlib-simple.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2014 by Benjamin Chrétien, CNRS-LIRMM. 2 | // 3 | // This file is part of the roboptim. 4 | // 5 | // roboptim is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // roboptim is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with roboptim. If not, see . 17 | 18 | #include "shared-tests/fixture.hh" 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | using namespace roboptim; 28 | using namespace roboptim::visualization; 29 | 30 | BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration) 31 | 32 | BOOST_AUTO_TEST_CASE (visualization_matplotlib_simple) 33 | { 34 | boost::shared_ptr 35 | output = retrievePattern ("visualization-matplotlib-simple"); 36 | 37 | using namespace roboptim::visualization::matplotlib; 38 | Matplotlib matplotlib = Matplotlib::make_matplotlib (std::make_pair(1, 1), false); 39 | 40 | // Display nothing, generate just some valid matplotlib commands. 41 | (*output) 42 | << (matplotlib 43 | << set ("foo", "42") 44 | << comment ("Hello, world!\nThis is a three-line comment!\nAmazing!") 45 | << import ("foo") 46 | << import ("foo", "bar") 47 | << figure () 48 | << show () 49 | ); 50 | 51 | // Test clear function. 52 | matplotlib.clear (); 53 | // Enable header. 54 | matplotlib.withHeader () = true; 55 | BOOST_CHECK (matplotlib.withHeader () == true); 56 | (*output) << std::endl << matplotlib; 57 | 58 | // Test some throws. 59 | BOOST_CHECK_THROW ((*output) << (matplotlib << set ("bar", 0)), 60 | std::runtime_error); 61 | 62 | std::cout << output->str () << std::endl; 63 | BOOST_CHECK (output->match_pattern ()); 64 | } 65 | 66 | BOOST_AUTO_TEST_SUITE_END () 67 | -------------------------------------------------------------------------------- /tests/visualization-matplotlib-simple.stdout: -------------------------------------------------------------------------------- 1 | foo = 42 2 | # Hello, world! 3 | # This is a three-line comment! 4 | # Amazing! 5 | fig = plt.figure() 6 | plt.show() 7 | 8 | 9 | #!/usr/bin/env python 10 | # Generated by roboptim-core 11 | import matplotlib 12 | import matplotlib.pyplot as plt 13 | import numpy as np 14 | 15 | fig = plt.figure() 16 | ax = plt.subplot(111) 17 | 18 | 19 | box = ax.get_position() 20 | ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) 21 | ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) 22 | fig.tight_layout() 23 | plt.show() 24 | -------------------------------------------------------------------------------- /tests/visualization-util.stdout: -------------------------------------------------------------------------------- 1 | [10](1,0.1,0.01,0.001,0.0001,1e-05,1e-06,1e-07,1e-08,1e-09) 2 | [10](1,0.1,0.01,0.001,0.0001,1e-05,1e-06,1e-07,1e-08,0) 3 | [4,4]((1,0.1,0.01,0.001), (0.0001,1e-05,1e-06,1e-07), (1e-08,1e-09,1e-10,1e-11), (1e-12,1e-13,1e-14,1e-15)) 4 | [4,4]((1,0.1,0.01,0.001), (0.0001,1e-05,1e-06,1e-07), (1e-08,0,0,0), (0,0,0,0)) 5 | --------------------------------------------------------------------------------