Giter Site home page Giter Site logo

az13js / cpp-genetic-algorithm Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 45 KB

C++ 遗传算法 ( C++ Genetic Algorithm ):使用遗传算法求解 De jong 函数 f2,源码方法和属性有中文注释,命名和文件组织方式统一,使用面向对象实现,封装和调用上基本遵循遗传算法的逻辑

License: MIT License

CMake 3.46% C++ 96.54%

cpp-genetic-algorithm's People

Contributors

az13js avatar mengshaoying avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

cpp-genetic-algorithm's Issues

win10 mingw run this exe

I successfully compiled and ran the genetic algorithm program on Windows. Here's what I did:

Create an "include" folder inside the "main.cpp" folder.
Move the "GeneticAlgorithm" file into the "include" folder.
Modify the "CMakeLists.txt" file with the necessary changes (details omitted).
Add a "run_exe.bat" file that can be double-clicked to run the program.
Please note that I've omitted the specific details of the changes you made to the "CMakeLists.txt" file as you mentioned "xxx" in your message.

cmakelist.txt

替换此文件中的 main.out 可以改变生成的可执行文件名

cmake_minimum_required(VERSION 3.10)

设置项目名称和项目版本

project(main VERSION 0.1)

开启静态编译,静态编译会把程序运行时的链接库也一起编译到可执行文件里面

set(CMAKE_EXE_LINKER_FLAGS "-static")

设置编译器支持的C++语言版本的检查

set(CMAKE_CXX_STANDARD_REQUIRED True)

设置编译器C++语言版本

set(CMAKE_CXX_STANDARD 14)

添加编译选项

SET(CMAKE_CXX_FLAGS "-std=c++17 -O2")

生成记录项目版本的头文件

configure_file(main.h.in main.h)

设置为扫描当前目录及子目录下所有.cpp结尾的文件并添加到CPP_FILES

file(GLOB_RECURSE CPP_FILES ./*.cpp)

get_filename_component(main_path "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)

include 目录

include_directories(SYSTEM ${main_path}/include)

file(GLOB_RECURSE CPP_FILES ${main_path}/include/*.cpp)

获取当前的CMake搜索路径

get_property(current_search_paths DIRECTORY PROPERTY INCLUDE_DIRECTORIES)

message("进入搜索")

遍历搜索路径列表并逐个打印

foreach(search_path IN LISTS current_search_paths)
message("Include directory: ${search_path}")
endforeach()

设置为所有CPP_FILES中的文件都编译到可执行文件main.out

add_executable(main main.cpp ${CPP_FILES})


run_exe.bat

@echo off
REM 开始计时
set start_time=%time%

chcp 65001
rem 删除build文件夹
rmdir /s /q build

rem 创建build文件夹
mkdir build
cd ./build
cmake .. -G "MinGW Makefiles"
mingw32-make -j20

REM 结束计时
set end_time=%time%

REM 计算耗费的时间
set /a hours=%end_time:~0,2%-%start_time:~0,2%
set /a minutes=%end_time:~3,2%-%start_time:~3,2%
set /a seconds=%end_time:~6,2%-%start_time:~6,2%

REM 处理借位
if %seconds% LSS 0 (
set /a seconds=60+%seconds%
set /a minutes-=1
)
if %minutes% LSS 0 (
set /a minutes=60+%minutes%
set /a hours-=1
)

REM 输出结果
echo 脚本执行耗时:%hours%小时%minutes%分钟%seconds%秒

copy main.cpp ..
main

echo "编译完毕"

pause

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.