Code Monkey home page Code Monkey logo

psopt's Introduction

PSOPT

Copyright (C) 2009-2022 Victor M. Becerra

Introduction

This is the PSOPT library, a software tool for computational optimal control

PSOPT is an open source optimal control package written in C++ that uses direct collocation methods. These methods solve optimal control problems by approximating the time-dependent variables using global or local polynomials. This allows to discretize the differential equations and continuous constraints over a grid of nodes, and to compute any integrals associated with the problem using well known quadrature formulas. Nonlinear programming then is used to find local optimal solutions. PSOPT is able to deal with problems with the following characteristics:

  • Single or multiphase problems
  • Continuous time nonlinear dynamics
  • General endpoint constraints
  • Nonlinear path constraints (equalities or inequalities) on states and/or control variables
  • Integral constraints
  • Interior point constraints
  • Bounds on controls and state variables
  • General cost function with Lagrange and Mayer terms.
  • Free or fixed initial and final conditions
  • Linear or nonlinear linkages between phases
  • Fixed or free initial time
  • Fixed or free final time
  • Optimisation of static parameters
  • Parameter estimation problems with sampled measurements • Differential equations with delayed variables.

The implementation has the following features:

  • Choice between Legendre, Chebyshev, trapezoidal, or Hermite-Simpson based collocation
  • Automatic scaling
  • Automatic first and second derivatives using the ADOL-C library
  • Numerical differentiation by using sparse finite differences
  • Automatic mesh refinement
  • Automatic identification of the Jacobian and Hessian sparsity.
  • DAE formulation, so that differential and algebraic constraints can be implemented in the same C++ function.

The PSOPT interface uses both Eigen3 (a linear algebra template library) and ADOL-C (an automatic differentiation library).

The first release of PSOPT was published in 2009. This is release 5 of PSOPT.

The PSOPT website is http://www.psopt.net.

License

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA, or visit http://www.gnu.org/licenses/

Author: Professor Victor M. Becerra

Address:

       University of Portsmouth

       School of Energy and Electronic Engineering
       
       Portsmouth PO1 3DJ
       
       United Kingdom

e-mail: [email protected]

Getting started

Please consult the detailed installation instructions in the PSOPT PDF documentation. In the following, we only summarize some main points.

Dependencies

PSOPT requires the following libraries:

  1. IPOPT
  2. ADOL-C
  3. EIGEN3

Optionally, the user may wish to employ the following software

  1. SNOPT
  2. GNUplot

Moreover, PSOPT is built using CMake. CMake is an open-source, cross-platform family of tools designed to build, test and package software. The build process also requires the pkg-config tool.

Build

Please note that the minimum version of CMake that is required by the build process is 3.12. Earlier versions of CMake are not suitable.

If you use Ubuntu 20.04, all dependencies plus GNUplot can simply be installed as follows:

  1. sudo apt-get install git
  2. sudo apt-get install cmake
  3. sudo apt-get install gfortran
  4. sudo apt-get install g++
  5. sudo apt-get install libboost-dev
  6. sudo apt-get install libboost-system-dev
  7. sudo apt-get install coinor-libipopt-dev
  8. sudo apt-get install libcolpack-dev
  9. sudo apt-get install libadolc-dev
  10. sudo apt-get install gnuplot
  11. sudo apt-get install libeigen3-dev
  12. sudo apt-get install libblas-dev
  13. sudo apt-get install liblapack-dev

Please note that a runtime error related to the adolc library is currently reported when executing PSOPT under Ubuntu 22.04 if the above instructions are followed. To avoid this, you can follow the special instructions given here for Ubuntu 22.04.

If you use Debian 11.4.0, all dependencies plus GNUplot can simply be installed as follows:

  1. su
  2. apt-get install git
  3. apt-get install cmake
  4. apt-get install gfortran
  5. apt-get install g++
  6. apt-get install libboost-dev
  7. apt-get install libboost-system-dev
  8. apt-get install coinor-libipopt-dev
  9. apt-get install libcolpack-dev
  10. apt-get install libadolc-dev
  11. apt-get install gnuplot
  12. apt-get install libeigen3-dev
  13. apt-get install libblas-dev
  14. apt-get install liblapack-dev

If you use OpenSuse Leap 15.4, all dependencies plus GNUplot can be installed as follows:

  1. sudo zypper install git
  2. sudo zypper install gnuplot
  3. sudo zypper install libboost_system1_66_0-devel
  4. sudo zypper install eigen3-devel
  5. sudo zypper install ColPack-devel
  6. sudo zypper install adolc-devel
  7. sudo zypper install blas-devel
  8. sudo zypper install lapack-devel
  9. sudo zypper ar -f https://download.opensuse.org/repositories/science/15.4/ science
  10. sudo zypper install Ipopt-devel
  11. sudo zypper install cmake
  12. sudo zypper install gcc-c++

If you use Arch Linux 2022.08.05 or Manjaro 21.3.7, all dependencies plus GNUplot can be installed as follows:

  1. sudo pacman -Syu
  2. sudo pacman -S git base-devel
  3. sudo pacman -S cmake
  4. sudo pacman -S gnuplot
  5. sudo pacman -S eigen
  6. sudo pacman -S boost
  7. sudo pacman -S blas
  8. sudo pacman -S lapack
  9. sudo pacman -S yay
  10. yay -S coin-or-ipopt
  11. yay -S colpack
  12. yay -S adol-c

After installation of dependencies, a typical PSOPT build and installation on a suitable version of Linux (such as Ubuntu 20.04, Debian 11.4.0 or OpenSUSE Leap 15.4, Arch Linux 2022.08.05 or Manjaro 21.3.7), or other Unix-like operating system, follows the steps given below (please see the PDF documentation for futher details):

  1. git clone https://github.com/PSOPT/psopt.git
  2. cd psopt; mkdir build; cd build
  3. cmake -DBUILD_EXAMPLES=ON ..
  4. make
  5. sudo make install

Note that the executable code for the examples is built inside the folder psopt/build/examples. For example, you can run the 'launch' example, by entering the following commands, after the installation.

  1. cd ./examples/launch
  2. ./launch

Getting help

  • PSOPT Documentation with installation instructions, background theory, examples and much more
  • Issue tracking system: If you believe you found a bug in the code, please use the issue tracking system. Please include as much information as possible, and if possible some example code so that we can reproduce the error.
  • Mailing list: subscribe to receive notifications about updates and to post questions and comments about PSOPT.

Please acknowledge this work

This software is provided for free in the hope that it may be useful to others, and we would very much like to hear about your experience with it. If you find PSOPT helpful for your work or research, please emai the author at [email protected] to incorporate a feature on the PSOPT web page.

Given that a great deal of time and effort has gone into PSOPT's development, please cite the following publication if you are using PSOPT for your own research:

BibTex entry:

        @INPROCEEDINGS{5612676,  
        author={V. M. Becerra},  
        booktitle={2010 IEEE International Symposium on Computer-Aided Control System Design},          
        title={Solving complex optimal control problems at no cost with PSOPT},   
        year={2010},    
        pages={1391-1396},  
        doi={10.1109/CACSD.2010.5612676}}

psopt's People

Contributors

aleramos119 avatar chrisdembia avatar ecbrown avatar sauermann avatar schulz0r avatar vmbecerra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

psopt's Issues

f2c library

In my recent installation I found out that you need to use -lf2c to include the library. It's installation on Ubuntu 16.04.

ADOL-C error: function sparse_jac...

Dear professor Becerra,
today I compiled PSOPT package and installed on my Debian (sid) machine according instructions. Everything went well, the package compiled without any error as well as the examples. However, when I tried to run the "alpine" example, the program terminated with the following runtime error:

ADOL-C error: function sparse_jac can only be used if linked with ColPack terminate called after throwing an instance of 'FatalError' what(): errorcode=-1 function=sparse_jac file=sparsedrivers.cpp line=438 what= Aborted

All the other exmples behaved the same way.
Please, help me to solve my problem.

Best regards and thank you in advance, J. Kordik

Workspace for rk4_propagate

I want to pass user data to the callbacks, especially 'dae'. I found in the documentation that you could set user_data in the problem somewhere in the setup of the problem and then access the problem and the user_data through the workspace. However, I'm calling rk4_propagate outside of a callback and I need a workspace to pass to it. In the example code the workspace is set to NULL. I tried instantiating a workspace and passing that but the program crashed when the workspace was destroyed.
What is the best way to pass user data to the rk4_propagate function?

psopt.h defines variable inf, which interferes with other libraries

Hello,
As the title says, psopt.h defines a variable which is a class in the geometry library CGAL. That's why programs which make use of both dependencies cannot compile. I suggest that you use std::numeric_limits<T>::infinity from the header limits so that you don't need to define your own infinity.
Edit: Since there are no tests, I cannot simply commit the proposed solution. After all, I am changing a variable. I still need to fix this issue as soon as possible, so I will go the safe route and put inf into a namespace and fix all compile errors. I guess this won't break anything.

Best regards

Philipp

ubuntu 15.10: example problems all segfault

While I had PSOPT smoothly working on Ubuntu 14.04, the same cannot be said in Ubuntu 15.10: when the example problems are run (any of them) a segfault results. On my own examples (which were previously running) this segfault occurs when 'psopt_level2_setup(problem, algorithm);' is called. Before I completely reinstalled PSOPT, I tried the old binaries that I had compiled in Ubuntu 14.04 ... and they worked without a problem.

Duplicate file

In the directory psopt/dmatrix/doc/latex/ there are two files in the repository:
DMatrix_Class_Reference.pdf
DMatrix_class_reference.pdf
which differ only in the case of the "C".

This causes problems on filesystems like Windows where filenames are caseinsensitive.
I want to suggest to remove one of them. However I can't be sure which one should be kept.

additional design variables

i want to implement psopt for launch vehicle trajectory optimization. the launch vehicle configuration is with strapons. i have to optimize strapon ignition time and strapon separation time using psopt. Also i dont want to add additional phases for this problem. Is it possible to give additional design variables in addition to states and controls in PSOPT. if so kindly provide the detials.

Cannot build individual examples

Greatings,

Following the instructions for the Ubuntu 22.04 it generates binaries for all examples ( in the psopt/build/examples folder ) but when I try to build the examples in the folder psopt/examples/ using cmake . I receive the error message

-- Configuring done
CMake Error at CMakeLists.txt:4 (add_executable):
  Target "goddard" links to target "PkgConfig::ipopt" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?


CMake Error at CMakeLists.txt:4 (add_executable):
  Target "goddard" links to target "Eigen3::Eigen" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?


CMake Error at CMakeLists.txt:5 (add_dependencies):
  The dependency target "PSOPT" of target "goddard" does not exist.

Use CMAKE_CURRENT_SOURCE_DIR instead of CMAKE_SOURCE_DIR

At line 46 in top level CMakeLists.txt file, CMAKE_SOURCE_DIR is used as the source path when installing include directory.

install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/" DESTINATION "include/${PROJECT_NAME}")

However, this may cause error if this package is used as a submodule of another CMake project, such as

- Other Prj
  - TOP CMakeLists.txt
  - PSOPT
    - CMakeLists.txt for PSOPT

In that case, CMAKE_SOURCE_DIR would be <Other Prj> instead of <Other Prj>/PSOPT.

Use CMAKE_CURRENT_SOURCE_DIR instead of CMAKE_SOURCE_DIR could be one way to fix this.

gradient and jacobian

How gradient and jacobian is computed in PSOPT to supply for IPOPT. I have gone through the example code, garadient of jacobian computation are not computed.

psopt.org domain is offline

Hi,
the psopt.org domain is offline and it is noted on the webpage, that the domain is for sale.
As the URL is still in the ReadMe, I wanted to notify you about this issue.

Tag for v5.0.2

I believe there is a typo in the tag for 5.0.2, instead being 5.02. Since psopt is getting packaged, it would be good to have the format fixed to keep the order unambiguously increasing. Thanks!

PSOPT 5.0 MacOS Installation - target_compile_features no known features for CXX compiler

Greetings,

I am unable to install PSOPT in MacOS because of the following error. Please recommend!

(base) ARSLA18090409:build urbanair1$ cmake -DBUILD_EXAMPLES=ON -DCXX=g++-10 -DCC=gcc-10 ..
-- AdolC has not been installed on this system and will be automatically added to this project.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/urbanair1/PSOPT/build/adolc-download
[100%] Built target adolc
CMake Error at CMakeLists.txt:30 (target_compile_features):
target_compile_features no known features for CXX compiler

"AppleClang"

version 10.0.1.10010046.

-- Configuring incomplete, errors occurred!
See also "/Users/urbanair1/PSOPT/build/CMakeFiles/CMakeOutput.log".

Problems to build executable from my own files

I already installed PSOPT and the examples were compiled and they execute well. However, when I try to compile my own files using the instructions included in the PDF manual:

$ cd psopt/build/examples/user
$ make

I get the following message make: *** No targets specified and no makefile found. Stop. I was wondering, where can I find the required makefile?

Invalid number in NLP function or derivative detected.

I'm trying a thrust vector problem. I've modified launch.cxx for a single phase with constant force and constant mass. When I run psopt the IPOPT fails with the message:
EXIT: Invalid number in NLP function or derivative detected.
I've included a link to user.cxx on Google Drive.

user.cxx

Failing to install on ubuntu 16.04 depending on OS language

I found out that the installation script "install-ubuntu-16.04.sh" fails for non-english OS, where the "Downloads" folder does not exist (e.g., it has been renamed as "Scaricamenti" in italian).

The problem can be fixed by creating a "Downloads" folder in the $HOME path.

Compilation fails with IpoptAppplication not being found

Dear Victor,

I am having a compilation error while trying to build PSOPT with the provided installation script. The error:

/usr/bin/g++ -c -O0 -g -I/home/listov/adolc_base/include -I../../dmatrix/include -I/cppexamples -I../src -DLAPACK -DUNIX -DSPARSE_MATRIX -DUSE_IPOPT -I../../SuiteSparse/CXSparse/Include -I../../SuiteSparse/CXSparse/../SuiteSparse_config -I../../lusol/csrc -I/home/listov/Ipopt-3.12.12/Ipopt/src/Interfaces -I/home/listov/Ipopt-3.12.12/Ipopt/src/Common -I/home/listov/Ipopt-3.12.12/Ipopt/src/LinAlg -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -fPIC -DHAVE_MALLOC -std=c++11 ../src/psopt.cxx -o ../src/psopt.o cc1plus: warning: command line option ‘-Wimplicit’ is valid for C/ObjC but not for C++ In file included from ../src/psopt.cxx:40:0: ../src/psopt.h:1159:10: fatal error: IpIpoptApplication.hpp: No such file or directory #include "IpIpoptApplication.hpp" ^~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated.

locate IpIpoptApplication.hpp however, shows:
/usr/include/coin/IpIpoptApplication.hpp

System: Ubuntu 18.04, gcc v7.3.0

Thanks,
Peter

Constraint functions should be std::function instead of function pointers

Every example in this project has predefined constraint functions (e.g. events) where values do not change during runtime. Since I have a lot of trajectories to plan which can have arbitrary start and endpoints, I need to reset the functions every time I want to plan a new trajectory. Sadly, the problem definition struct uses C-style function pointers, which do not allow for that.

I would like to see std::function to replace the C-style pointers, so it is possible to use lambdas which capture variables (e.g. the start and stop state) from outside the function. I think this change would not even require any changes to the examples because std::functions are pretty backward compatible.
To illustrate what I want to do, see following code. The first block depicts what is possible right now:

Eigen::Matrix<adouble, 6, 1> myFinalState; // fill this vector appropriately
Prob problem;
// you can assign lambdas to function pointers btw
problem.events = [](adouble* some_args) {
    // cannot see myFinalState
    // thus cannot set it
}

With std::function, following will be possible:

Eigen::Matrix<adouble, 6, 1> myFinalState; // fill this vector appropriately
Prob problem;
// std::function allows to capture myFinalState
problem.events = [&myFinalState](adouble* some_args) {
    Eigen::Map<Eigen::Matrix<adouble, 6, 1>> eventVector(e, 6);    // wrap pointer into eigen vector
    eventVector << myFinalState;    // set final state values here
}

eigen update error ?

psopt 5, propagate.cxx, line 138:
for (i=0;i<nparams;i++) param[i-1] = parameters(i);

should probably be modified to:
for (i=0;i<nparams;i++) param[i] = parameters(i);

best,
navot

smooth_linear_interpolation funciton in interpolation.cxx

I noticed that the two smooth_linear_interpolation functions defined in the interpolation.cxx file are slightly different. In the second declaration of the smooth_linear_interpolation: smooth_linear_interpolation(adouble* y, adouble& x, adouble* Xdata, adouble* Ydata, int n), the following lines are commented:

//  Si = smooth_heaviside( (x-(Xdata[0]-100*a)), a ) - smooth_heaviside( (x-Xdata[0]), a );
//  *y+=Si*Ydata[0];
//  Si = smooth_heaviside( (x-Xdata[n-1]), a ) - smooth_heaviside( (x-(Xdata[n-1]+100*a)), a );
//  *y+=Si*Ydata[n-1];

whereas these lines are not commented in the first declaration of the smooth_linear_interpolation (smooth_linear_interpolation(adouble* y, adouble& x, DMatrix& Xdata, DMatrix& Ydata, int n))

Which one is the intended one?

Could Function psopt() use const arguments?

Dear Victor,

I have a problem with the function int psopt(Sol& solution, Prob& problem, Alg& algorithm) which solves the trajectory optimization problem. Is it possible to mark the arguments for the algorithm and problem with const? I looked into the function and it did not seem to me that the optimizer changes anything about the two mentioned structs. Of course, it changes the solution for obvious reasons.
So, for my use case, I would like to change the function declaration to int psopt(Sol& solution, const Prob& problem, const Alg& algorithm).
The reason is that the function where I use PSOPT is marked as const and does not let me use psopt() due to the reason stated above.

Greetings

Philipp

Two link arm example not working

The two link arm example twolinkarm.cxx throws the following error

**** Run time error
**** To trace this error, set up your debugger to break at
**** function 'error_message', then do a backtrace.
**** A diagnostic message is given below:
**** ====> Index error in operator()(long) <====

The error occurs here when called from here.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.