tmp update

This commit is contained in:
张壹 2024-10-25 11:23:42 +08:00
parent f30834f7e6
commit 544de7dfa2
4 changed files with 104 additions and 3 deletions

View File

@ -23,6 +23,5 @@ configure_file(
#
add_subdirectory(lib)
#
add_subdirectory(example)
add_subdirectory(example)
add_subdirectory(tool)

2
tool/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
# add directories to compile the tool
add_subdirectory(levy_planner)

View File

@ -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)

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* 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<double> &x, gctl::array<double> &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<double> 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);
}