From de83cb3d672626f551459b50e610d7b9ff132316 Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Sun, 31 Jan 2021 23:36:46 +0200 Subject: [PATCH] Working on windows. Fixed memory leak. --- CMakeLists.txt | 45 ++++++++++++++++------------------- src/main.cpp | 31 +++++++++++++++++------- src/reducedmodeloptimizer.cpp | 6 ++++- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa0d48a..b30098a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,14 @@ download_project(PROJ MATPLOTPLUSPLUS ) add_subdirectory(${MATPLOTPLUSPLUS_SOURCE_DIR}) +##MySources +download_project(PROJ MYSOURCES + GIT_REPOSITORY https://gitea-s2i2s.isti.cnr.it/manolas/MySources.git + GIT_TAG master + PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/build/external/ + ${UPDATE_DISCONNECTED_IF_AVAILABLE} + ) + #Polyscope download_project(PROJ POLYSCOPE GIT_REPOSITORY https://github.com/nmwsharp/polyscope.git @@ -33,17 +41,6 @@ download_project(PROJ POLYSCOPE ) add_subdirectory(${POLYSCOPE_SOURCE_DIR}) -#bobyqa-cpp -download_project(PROJ BOBYQA - GIT_REPOSITORY https://github.com/elsid/bobyqa-cpp.git - GIT_TAG master - PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/build/external/ - ${UPDATE_DISCONNECTED_IF_AVAILABLE} -) -add_compile_definitions(BOBYQA_DEBUG) -add_subdirectory(${BOBYQA_SOURCE_DIR}) -message(STATUS "BOBYQA bin dir:${BOBYQA_BINARY_DIR}") - #dlib download_project(PROJ DLIB GIT_REPOSITORY https://github.com/davisking/dlib.git @@ -52,7 +49,6 @@ download_project(PROJ DLIB ${UPDATE_DISCONNECTED_IF_AVAILABLE} ) add_subdirectory(${DLIB_SOURCE_DIR}) -#message(STATUS "BOBYQA bin dir:${BOBYQA_BINARY_DIR}") ##vcglib devel branch @@ -68,25 +64,26 @@ file(GLOB EXT_SOURCES ${vcglib_devel_SOURCE_DIR}/wrap/ply/plylib.cpp) find_package(Eigen3 3.3 REQUIRED) #OpenMP -find_package(OpenMP REQUIRED) +find_package(OpenMP) -set(MYSOURCESDIR "/home/iason/Coding/Libraries/MySources") -file(GLOB MYSOURCES ${MYSOURCESDIR}/*.hpp ${MYSOURCESDIR}/*.cpp +#set(MYSOURCESDIR "/home/iason/Coding/Libraries/MySources") +file(GLOB MYSOURCES ${MYSOURCES_SOURCE_DIR}/*.hpp ${MYSOURCES_SOURCE_DIR}/*.cpp ) #Add the project sources file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) + +if(MSVC) + add_compile_definitions(_HAS_STD_BYTE=0) +endif(MSVC) + add_executable(${PROJECT_NAME} ${SOURCES} ${MYSOURCES} ${EXT_SOURCES} ) + target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) target_include_directories(${PROJECT_NAME} PRIVATE ${vcglib_devel_SOURCE_DIR} - PRIVATE ${MYSOURCESDIR} - PRIVATE ${BOBYQA_SOURCE_DIR}/include/ + PRIVATE ${MYSOURCES_SOURCE_DIR} + PRIVATE ${MYSOURCES_SOURCE_DIR}/boost_graph ) -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20") -else(MSVC) - target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) -endif(MSVC) - -target_link_libraries(${PROJECT_NAME} polyscope Eigen3::Eigen OpenMP::OpenMP_CXX matplot bobyqa_shared dlib::dlib) + link_directories(${MYSOURCES_SOURCE_DIR}/boost_graph/libs) +target_link_libraries(${PROJECT_NAME} polyscope Eigen3::Eigen OpenMP::OpenMP_CXX matplot dlib::dlib) diff --git a/src/main.cpp b/src/main.cpp index 553ffcd..b11ee25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include int main(int argc, char *argv[]) { @@ -46,8 +47,8 @@ int main(int argc, char *argv[]) { // for (double rangeOffset = 0.15; rangeOffset <= 0.95; rangeOffset += 0.05) // { ReducedModelOptimizer::Settings settings; - for (settings.maxSimulations = 600; settings.maxSimulations < 2000; - settings.maxSimulations += 100) { + for (settings.maxSimulations = 2200; settings.maxSimulations < 5000; + settings.maxSimulations += 200) { ReducedModelOptimizer::xRange beamWidth{"B", 0.5, 1.5}; ReducedModelOptimizer::xRange beamDimensionsRatio{"bOverh", 0.7, 1.3}; ReducedModelOptimizer::xRange beamE{"E", 0.1, 1.9}; @@ -58,7 +59,7 @@ int main(int argc, char *argv[]) { settings.xRanges = {beamWidth, beamDimensionsRatio, beamE}; std::filesystem::path thisOptimizationDirectory( std::filesystem::path("../OptimizationResults").append(xRangesString)); - std::filesystem::create_directory(thisOptimizationDirectory); + std::filesystem::create_directories(thisOptimizationDirectory); // csvfile thisOptimizationStatistics( // std::filesystem::path(thisOptimizationDirectory) // .append("statistics.csv") @@ -74,12 +75,23 @@ int main(int argc, char *argv[]) { std::vector> resultsPerPattern; auto start = std::chrono::high_resolution_clock::now(); - for (const auto &entry : - filesystem::directory_iterator(fullPatternsTestSetDirectory)) { - const auto filepath = - // std::filesystem::path(fullPatternsTestSetDirectory).append("305.ply"); - entry.path(); - const auto filepathString = filepath.string(); + int patternsOptimized = 0; + + //extract paths + std::vector fullPatternSetFilenames; + for (const auto& entry : + filesystem::directory_iterator(fullPatternsTestSetDirectory)) { + const auto filepath = + // std::filesystem::path(fullPatternsTestSetDirectory).append("305.ply"); + entry.path(); + fullPatternSetFilenames.push_back(filepath); + } + +//#pragma omp parallel for //schedule(static) num_threads(8) + for (int fullPatternIndex = 0; fullPatternIndex < fullPatternSetFilenames.size();fullPatternIndex++) { + const auto& filepath = fullPatternSetFilenames[fullPatternIndex]; + const std::string& filepathString = fullPatternSetFilenames[fullPatternIndex].string(); + //const auto filepathString = filepath.string(); // Use only the base triangle version const std::string tiledSuffix = "_tiled.ply"; if (filepathString.compare(filepathString.size() - tiledSuffix.size(), @@ -131,6 +143,7 @@ int main(int argc, char *argv[]) { std::make_pair(filepath.stem().string(), optimizationResults)); totalNumberOfSimulationCrashes += optimizationResults.numberOfSimulationCrashes; + std::cout << "Have optimized " <<++patternsOptimized<<"/"<< static_cast(std::distance(std::filesystem::directory_iterator(fullPatternsTestSetDirectory),std::filesystem::directory_iterator()))<<" patterns." << std::endl; // } } auto end = std::chrono::high_resolution_clock::now(); diff --git a/src/reducedmodeloptimizer.cpp b/src/reducedmodeloptimizer.cpp index 149b240..86346f8 100644 --- a/src/reducedmodeloptimizer.cpp +++ b/src/reducedmodeloptimizer.cpp @@ -1,5 +1,4 @@ #include "reducedmodeloptimizer.hpp" -#include "bobyqa.h" #include "flatpattern.hpp" #include "gradientDescent.h" #include "simulationhistoryplotter.hpp" @@ -35,6 +34,7 @@ double minY{std::numeric_limits::max()}; std::vector minX; std::vector> failedSimulationsXRatio; int numOfSimulationCrashes{false}; +int numberOfFunctionCalls{ 0 }; // struct OptimizationCallback { // double operator()(const size_t &iterations, const Eigen::VectorXd &x, @@ -300,6 +300,9 @@ double ReducedModelOptimizer::objective(long n, const double *x) { minY = error; minX.assign(x, x + n); } + if(++numberOfFunctionCalls%50==0){ + std::cout << "Number of function calls:"<