From 544de7dfa242933e615a72db2aadd696350e9734 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Fri, 25 Oct 2024 11:23:42 +0800 Subject: [PATCH] tmp update --- CMakeLists.txt | 5 +- tool/CMakeLists.txt | 2 + tool/levy_planner/CMakeLists.txt | 16 ++++++ tool/levy_planner/levy_planner.cpp | 84 ++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 tool/CMakeLists.txt create mode 100644 tool/levy_planner/CMakeLists.txt create mode 100644 tool/levy_planner/levy_planner.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b529f84..e713116 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,5 @@ configure_file( # 添加库源文件地址 add_subdirectory(lib) - -# 去掉注释编译示例 -add_subdirectory(example) \ No newline at end of file +add_subdirectory(example) +add_subdirectory(tool) \ No newline at end of file diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt new file mode 100644 index 0000000..b450179 --- /dev/null +++ b/tool/CMakeLists.txt @@ -0,0 +1,2 @@ +# add directories to compile the tool +add_subdirectory(levy_planner) \ No newline at end of file diff --git a/tool/levy_planner/CMakeLists.txt b/tool/levy_planner/CMakeLists.txt new file mode 100644 index 0000000..5469d66 --- /dev/null +++ b/tool/levy_planner/CMakeLists.txt @@ -0,0 +1,16 @@ +set(TOOL_NAME levy_planner) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) + +aux_source_directory(. TOOL_SRC) +add_executable(${TOOL_NAME} ${TOOL_SRC}) + +set_target_properties(${TOOL_NAME} PROPERTIES INSTALL_RPATH /usr/local/lib) +set_target_properties(${TOOL_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) + +target_link_libraries(${TOOL_NAME} PRIVATE ${GCTL_LIB}) +target_link_libraries(${TOOL_NAME} PRIVATE gctl_optimization) + +install(TARGETS ${TOOL_NAME} RUNTIME DESTINATION sbin) diff --git a/tool/levy_planner/levy_planner.cpp b/tool/levy_planner/levy_planner.cpp new file mode 100644 index 0000000..61920ec --- /dev/null +++ b/tool/levy_planner/levy_planner.cpp @@ -0,0 +1,84 @@ +/******************************************************** + * ██████╗ ███████╗████████╗██╗ + * ██╔════╝ ██╔════╝╚══██╔══╝██║ + * ██║ ███╗███████╗ ██║ ██║ + * ██║ ██║╚════██║ ██║ ██║ + * ╚██████╔╝███████║ ██║ ███████╗ + * ╚═════╝ ╚══════╝ ╚═╝ ╚══════╝ + * Generic Scientific Template Library + * + * Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn) + * + * The GSTL is distributed under a dual licensing scheme. 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 + * of the License, or (at your option) any later version. You should have + * received a copy of the GNU Lesser General Public License (LGPL) along with + * this program. If not, see . + * + * If the terms and conditions of the LGPL v.2. would prevent you from using + * the GSTL, please consider the option to obtain a commercial license for a + * fee. These licenses are offered by the GSTL's original author. As a rule, + * licenses are provided "as-is", unlimited in time for a one time fee. Please + * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget + * to include some description of your company and the realm of its activities. + * Also add information on how to contact you by electronic and paper mail. + ******************************************************/ + +#include "../../lib/optimization.h" + +class levy_planner : public gctl::lgd_solver +{ +public: + levy_planner(){} + virtual ~levy_planner(){} + virtual double LGD_Evaluate(const gctl::array &x, gctl::array &g){return 0;} +}; + +int main(int argc, char *argv[]) try +{ + gctl::display_logo(); + + levy_planner p; + gctl::lgd_para my_para = p.default_lgd_para(); + + double alpha, beta; + std::cout << "Input alpha (> 0) and beta (1.0 ~ 2.0): "; + std::cin >> alpha >> beta; + + if (alpha <= 0 || beta <= 1.0 || beta >= 2.0) + { + std::cout << "Invalid inputs\n"; + return 0; + } + + my_para.flight_times = 100000; + my_para.beta = beta; + p.set_lgd_para(my_para); + + gctl::array dist; + p.get_levy_distribution(dist); + + for (size_t i = 0; i < dist.size(); i++) + { + dist[i] *= alpha; + } + + double mean = dist.mean(); + double std = dist.std(); + double cnt = 0.0; + + for (size_t i = 0; i < dist.size(); i++) + { + if (fabs(dist[i] - mean) > 3.0*std) cnt += 1.0; + } + + std::cout << "Step Avg. = " << mean << "\n"; + std::cout << "Step STD = " << std << "\n"; + std::cout << "Large Ones = " << cnt/1000.0 << "%\n"; + return 0; +} +catch (std::exception &e) +{ + GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0); +} \ No newline at end of file