Working on windows. Fixed memory leak.

This commit is contained in:
iasonmanolas 2021-01-31 23:36:46 +02:00
parent be02ca99b7
commit de83cb3d67
3 changed files with 48 additions and 34 deletions

View File

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

View File

@ -14,6 +14,7 @@
#include <stdexcept>
#include <string>
#include <vcg/complex/algorithms/update/position.h>
#include <iterator>
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<std::pair<std::string, ReducedModelOptimizer::Results>>
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<std::filesystem::path> 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<int>(std::distance(std::filesystem::directory_iterator(fullPatternsTestSetDirectory),std::filesystem::directory_iterator()))<<" patterns." << std::endl;
// }
}
auto end = std::chrono::high_resolution_clock::now();

View File

@ -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<double>::max()};
std::vector<double> minX;
std::vector<std::vector<double>> 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:"<<numberOfFunctionCalls << std::endl;
}
// compute error and return it
gObjectiveValueHistory.push_back(error);
@ -652,6 +655,7 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::runOptimization(
xMax(i) = settings.xRanges[i].max;
}
numberOfFunctionCalls = 0;
double (*objF)(double, double, double) = &objective;
auto start = std::chrono::system_clock::now();
dlib::function_evaluation result = dlib::find_min_global(