OOQP 安装和使用

OOQP 安装和使用

    • 1. 安装
    • 2. 使用

1. 安装

需要先安装 blas 和 ma27

BLAS:

cd my_lib/
wget http://www.netlib.org/blas/blas.tgz
tar zxf blas.tgz
cd BLAS-3.10.0/
gfortran -O3 -std=legacy -m64 -fno-second-underscore -fPIC -c *.f
ar r libfblas.a *.o
ranlib libfblas.a
rm -rf *.o     
export BLAS=~/my_lib/BLAS-3.10.0/libfblas.a 

MA27:

cd my_lib/
git clone git://github.com/HITSZ-LeggedRobotics/ma27.git
cd ma27/
bash ./configure CPPFLAGS="-fPIC" CFLAGS="-fPIC" FFLAGS="-fPIC"
sudo make install

OOQP:
在 ma27/src 中复制 libma27.a 文件到 ooqp 文件夹下

cd my_lib/
git clone git://github.com/emgertz/OOQP.git
cd OOQP/
./configure
sudo make
sudo make install

结果:

seivl@seivl-Default-string:~/my_lib/OOQP$ sudo make install
/usr/bin/install -c -d /usr/local/include/ooqp	
/usr/bin/install -c ./include/*.h /usr/local/include/ooqp
/usr/bin/install -c -d /usr/local/lib
/usr/bin/install -c ./lib/*.a /usr/local/lib
if [ -d doc-src ]; then cd doc-src; fi; make
make[1]: Entering directory '/home/seivl/my_lib/OOQP/doc-src'
cd ooqp-userguide; \
pdflatex  ooqp-userguide; \
bibtex ooqp-userguide; \
pdflatex  ooqp-userguide; \
pdflatex  ooqp-userguide
/bin/sh: 2: pdflatex: not found
/bin/sh: 3: bibtex: not found
/bin/sh: 4: pdflatex: not found
/bin/sh: 5: pdflatex: not found
GNUmakefile:42: recipe for target 'ooqp-userguide/ooqp-userguide.pdf' failed
make[1]: *** [ooqp-userguide/ooqp-userguide.pdf] Error 127
make[1]: Leaving directory '/home/seivl/my_lib/OOQP/doc-src'
GNUmakefile:102: recipe for target 'install_docs' failed
make: *** [install_docs] Error 2

2. 使用

  • 例子

  • 主函数 main.cpp

/* OOQP                                                               *
 * Authors: E. Michael Gertz, Stephen J. Wright                       *
 * (C) 2001 University of Chicago. See Copyright Notification in OOQP */
 
#include "QpGenData.h"
#include "QpGenVars.h"
#include "QpGenResiduals.h"
#include "GondzioSolver.h"
#include "QpGenSparseMa27.h"
 
#include 
#include 
 
using namespace std;
 
const int nx   = 2;
double    c[]  = { 1.5,  -2 };
 
double  xupp[] = { 20,   0 };
char   ixupp[] = {  1,   0 };
 
double  xlow[] = {  0,   0 };
char   ixlow[] = {  1,   1 };
 
const int nnzQ = 3;
int    irowQ[] = {  0,   1,   1 }; 
int    jcolQ[] = {  0,   0,   1 };
double    dQ[] = {  8,   2,  10 };
 
 
int my         = 0;
double * b     = 0;
int nnzA       = 0;
int * irowA    = 0;
int * jcolA    = 0;
double * dA    = 0;
 
const int mz   = 2;
double clow[]  = { 2,   0 };
char  iclow[]  = { 1,   0 };
 
double cupp[]  = { 0,   6 };
char  icupp[]  = { 0,   1 };
 
const int nnzC = 4;
int   irowC[]  = { 0,   0,   1,   1};
int   jcolC[]  = { 0,   1,   0,   1};
double   dC[]  = { 2,   1,  -1,   2};
 
int main( int argc, char * argv[] )
{
  int usage_ok = 1, quiet = 0;
 
  if( argc > 2 ) usage_ok = 0;
  if( argc == 2 ) {
    if( 0 == strcmp( "--quiet", argv[1] ) ) {
      quiet = 1;
    } else {
      usage_ok = 0;
    }
  } 
  if( !usage_ok ) {
    cerr << "Usage: " <<  argv[0] << " [ --quiet ]\n";
    return 1;
  }
    
  QpGenSparseMa27 * qp 
    = new QpGenSparseMa27( nx, my, mz, nnzQ, nnzA, nnzC );
  
  QpGenData      * prob = (QpGenData * ) qp->copyDataFromSparseTriple(
        c,      irowQ,  nnzQ,   jcolQ,  dQ,
        xlow,   ixlow,  xupp,   ixupp,
        irowA,  nnzA,   jcolA,  dA,     b,
        irowC,  nnzC,   jcolC,  dC,
        clow,   iclow,  cupp,   icupp );
 
  QpGenVars      * vars 
    = (QpGenVars *) qp->makeVariables( prob );
  QpGenResiduals * resid 
    = (QpGenResiduals *) qp->makeResiduals( prob );
  
  GondzioSolver  * s     = new GondzioSolver( qp, prob );
  
  if( !quiet ) s->monitorSelf();
  int ierr = s->solve(prob,vars, resid);
  
  if( ierr == 0 ) {
    cout.precision(4);
    cout << "Solution: \n";
    vars->x->writefToStream( cout, "x[%{index}] = %{value}" );
  } else {
    cout << "Could not solve the problem.\n";
  }
  return ierr;
}
  • CMakeLists.txt
cmake_minimum_required(VERSION 2.8.9)

project(astar)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(OpenCV REQUIRED)

set(AS_SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/src/AStar.cpp
)

set(AS_HEADERS
    ${CMAKE_CURRENT_SOURCE_DIR}/include/AStar.h
)
    

include_directories(include 
                    maps
                    "/home/seivl/my_lib/OOQP/include"
)

link_directories("/home/seivl/my_lib/OOQP/lib")

add_executable(main src/main.cpp ${AS_HEADERS} ${AS_SOURCES})

target_link_libraries(main 
                    ${OpenCV_LIBS}
                    ooqpgensparse
                    ooqpsparse
                    ooqpgondzio
                    ooqpbase 
                    blas 
                    ma27 
                    gfortran
)
  • 结果
seivl@seivl-Default-string:~/my_codebase/astar/build$ ./main 

Duality Gap: 24408.2
 *** Iteration 1 *** 
 mu = 1.05983e+06 relative residual norm = 51.3635
 *** sigma = 0.00860914

Duality Gap: 100552
 Number of Corrections = 3 alpha = 0.932017
 *** Iteration 2 *** 
 mu = 91617.7 relative residual norm = 3.49182
 *** sigma = 0.0167391

Duality Gap: 43229
 Number of Corrections = 0 alpha = 1
 *** Iteration 3 *** 
 mu = 8645.81 relative residual norm = 3.49182e-08
 *** sigma = 0.000574057

Duality Gap: 3626.12
 Number of Corrections = 1 alpha = 0.923124
 *** Iteration 4 *** 
 mu = 725.224 relative residual norm = 2.68436e-09
 *** sigma = 0.636176

Duality Gap: 5271.94
 Number of Corrections = 0 alpha = 0.531986
 *** Iteration 5 *** 
 mu = 1054.39 relative residual norm = 1.25632e-09
 *** sigma = 0.00263244

Duality Gap: 691.751
 Number of Corrections = 3 alpha = 0.875319
 *** Iteration 6 *** 
 mu = 138.35 relative residual norm = 1.5664e-10
 *** sigma = 0.619859

Duality Gap: 823.53
 Number of Corrections = 3 alpha = 0.167946
 *** Iteration 7 *** 
 mu = 164.706 relative residual norm = 1.30332e-10
 *** sigma = 0.000274768

Duality Gap: 21.3443
 Number of Corrections = 1 alpha = 0.99906
 *** Iteration 8 *** 
 mu = 4.26886 relative residual norm = 1.22835e-13
 *** sigma = 0.505767

Duality Gap: 74.7201
 Number of Corrections = 0 alpha = 1
 *** Iteration 9 *** 
 mu = 14.944 relative residual norm = 7.10543e-16
 *** sigma = 0.223693

Duality Gap: 35.3068
 Number of Corrections = 0 alpha = 1
 *** Iteration 10 *** 
 mu = 7.06137 relative residual norm = 5.32907e-16
 *** sigma = 0.00165875

Duality Gap: 1.91847
 Number of Corrections = 3 alpha = 0.978992
 *** Iteration 11 *** 
 mu = 0.383694 relative residual norm = 1.02696e-16
 *** sigma = 0.00411975

Duality Gap: 0.0711423
 Number of Corrections = 1 alpha = 0.999296
 *** Iteration 12 *** 
 mu = 0.0142285 relative residual norm = 8.73173e-15
 *** sigma = 3.7001e-05

Duality Gap: 9.98993e-05
 Number of Corrections = 0 alpha = 1
 *** Iteration 13 *** 
 mu = 1.99799e-05 relative residual norm = 7.00043e-16
 *** sigma = 1.73374e-13

Duality Gap: 1.72513e-12
 Number of Corrections = 1 alpha = 1
 *** Iteration 14 *** 
 mu = 2.73377e-13 relative residual norm = 1.79335e-14

 *** SUCCESSFUL TERMINATION ***
Solution: 
x[0] = 0.7625
x[1] = 0.475

你可能感兴趣的:(自动驾驶,自动驾驶,c++)