본문 바로가기
기타/프로그램 세팅

Google Ceres Solver installation(구글 Ceres-solver 설치)

by 루티즈 2018. 6. 20.
반응형

Google Ceres Solver installation

( http://ceres-solver.org )

Google에서 제공해주는 optimization(최적화) tool이다. ( Optimization-최적화: 특정한 함수의 최적의 값을 도출화 내는 과정). 기존 최적화 툴들에 비해 사용하기 편하고 깔끔한 편이다. 리눅스에 설치하는 것을 권고하나 필요에 의해 windows에 설치하는 방법을 정리한다. 위 링크 installation 참고했다.

 

설치 순서

 

1.  특정한 위치에 ceres 폴더 생성한다.

 

2.  Eigen 다운로드한다.

ceres 폴더 내 eigen 폴더를 생성하고 eigen 파일들을 다운로드 받은 후 폴더 내에 복사한다.

( http://eigen.tuxfamily.org/index.php )

-    eigen은 설치가 필요하지 않은 라이브러리다. 버전은 최소 eigen 3.1 이여야 한다.

 

3.  google-glog 설치한다.

( https://github.com/google/glog )

A.   Git에서 Code download

B.   Cmake 로 빌드 ( glog gflags를 포함시키지 않는다. WITH_GFLAGS 체크 해제)

C.   Visual studio glog 솔루션 빌드

 

4.  Gflags 설치한다.

( https://github.com/gflags/gflags )

A.   Git에서 Code download

B.   Cmake 로 빌드

C.   Visual studiogflags 솔루션 빌드

 

5.  필요에 따라서 SuiteSparse, 혹은 CXSparse 등을 설치한다.

 

6.  Ceres-Solver code를 다운로드

(git clone https://ceres-solver.googlesource.com/ceres-solver)

A.   Git에서 Code download

B.   Cmake 로 빌드

             i.      다운로드 받은 라이브러리의 참조 경로를 넣고 빌드한다.

            ii.      필요한 라이브러리를 추가 혹은 제외시켜서 빌드한다.(gpu,mp등등)

C.   Visual studioCeres-solver 솔루션 빌드

 

7.  만들어진 Ceres-solver라이브러리(lib, dll)를 이용해서 Test한다.


 

TEST(hello_world_ceres.cpp)


F(x) = 10 - x

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "ceres/ceres.h"
#include "glog/logging.h"
 
using ceres::AutoDiffCostFunction;
using ceres::CostFunction;
using ceres::Problem;
using ceres::Solver;
using ceres::Solve;
 
struct CostFunctor {
    template <typename T> bool operator()(const T* const x, T* residual) const {
        residual[0= T(10.0- x[0];
        return true;
    }
};
 
int main(int argc, char** argv) {
    google::InitGoogleLogging(argv[0]);
 
    double x = 0.5;
    const double initial_x = x;
 
    // Build the problem.
    Problem problem;
 
    CostFunction* cost_function =
        new AutoDiffCostFunction<CostFunctor, 11>(new CostFunctor);
    problem.AddResidualBlock(cost_function, NULL&x);
 
    // Run the solver!
    Solver::Options options;
    options.linear_solver_type = ceres::DENSE_QR;
    options.minimizer_progress_to_stdout = true;
    Solver::Summary summary;
    Solve(options, &problem, &summary);
 
    std::cout << summary.BriefReport() << "\n";
    std::cout << "x : " << initial_x
        << " -> " << x << "\n";
    return 0;
}
 
cs




초기값 x = 0.5

라이브러리 로 계산한

함수의 최적값은 x = 10이다.





반응형