ReducedModelOptimization/src/main.cpp

109 lines
4.1 KiB
C++
Raw Normal View History

2020-11-23 10:06:45 +01:00
#include "beamformfinder.hpp"
2021-01-22 15:39:36 +01:00
#include "csvfile.hpp"
2020-11-23 10:06:45 +01:00
#include "edgemesh.hpp"
#include "reducedmodeloptimizer.hpp"
#include "simulationhistoryplotter.hpp"
2020-12-09 16:58:48 +01:00
#include "trianglepattterntopology.hpp"
2020-11-23 10:06:45 +01:00
#include <chrono>
#include <filesystem>
#include <iostream>
#include <iterator>
2020-11-23 10:06:45 +01:00
#include <stdexcept>
#include <string>
2020-12-09 16:58:48 +01:00
#include <vcg/complex/algorithms/update/position.h>
#ifdef POLYSCOPE_DEFINED
#include "polyscope/curve_network.h"
#include "polyscope/point_cloud.h"
#include "polyscope/polyscope.h"
#endif
2020-11-23 10:06:45 +01:00
int main(int argc, char *argv[]) {
if (argc < 3) {
std::cerr << "Specify at least the two pattern filepaths to be "
"optimized.Exiting.."
2021-02-19 16:32:15 +01:00
<< std::endl;
std::terminate();
}
2021-02-19 16:32:15 +01:00
// Populate the pattern pair to be optimized
////Full pattern
const std::string filepath_fullPattern = argv[1];
PatternGeometry fullPattern(filepath_fullPattern);
fullPattern.setLabel(
std::filesystem::path(filepath_fullPattern).stem().string());
fullPattern.scale(0.03);
////Reduced pattern
const std::string filepath_reducedPattern = argv[2];
PatternGeometry reducedPattern(filepath_reducedPattern);
reducedPattern.setLabel(
std::filesystem::path(filepath_reducedPattern).stem().string());
reducedPattern.scale(0.03);
// Set the optization settings
ReducedModelOptimizer::xRange beamWidth{"B", 0.5, 1.5};
ReducedModelOptimizer::xRange beamDimensionsRatio{"bOverh", 0.7, 1.3};
ReducedModelOptimizer::xRange beamE{"E", 0.1, 1.9};
ReducedModelOptimizer::xRange innerHexagonSize{"HexSize", 0.1, 0.8};
ReducedModelOptimizer::xRange innerHexagonAngle{"HexAngle", -29.5, 29.5};
2021-02-10 12:19:37 +01:00
ReducedModelOptimizer::Settings settings_optimization;
settings_optimization.xRanges = {beamWidth, beamDimensionsRatio, beamE,
innerHexagonSize, innerHexagonAngle};
2021-02-25 09:09:38 +01:00
const bool input_numberOfFunctionCallsDefined = argc >= 4;
settings_optimization.numberOfFunctionCalls =
2021-02-25 09:09:38 +01:00
input_numberOfFunctionCallsDefined ? std::atoi(argv[3]) : 100;
settings_optimization.normalizationStrategy =
ReducedModelOptimizer::Settings::NormalizationStrategy::Epsilon;
settings_optimization.normalizationParameter = 0.0003;
settings_optimization.solutionAccuracy = 0.01;
// Optimize pair
const std::string pairName =
fullPattern.getLabel() + "@" + reducedPattern.getLabel();
2021-02-19 16:32:15 +01:00
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
optimizer.initializePatterns(fullPattern, reducedPattern, {});
ReducedModelOptimizer::Results optimizationResults =
optimizer.optimize(settings_optimization);
// Export results
2021-02-25 09:09:38 +01:00
const bool input_resultDirectoryDefined = argc >= 5;
std::string optimizationResultsDirectory =
2021-02-25 09:09:38 +01:00
input_resultDirectoryDefined ? argv[4] : "OptimizationResults";
std::string resultsOutputDir;
if (optimizationResults.numberOfSimulationCrashes != 0) {
const auto crashedJobsDirPath =
std::filesystem::path(optimizationResultsDirectory)
.append("CrashedJobs")
.append(pairName);
std::filesystem::create_directories(crashedJobsDirPath);
resultsOutputDir = crashedJobsDirPath.string();
} else {
std::filesystem::path convergedJobsDirPath(
std::filesystem::path(optimizationResultsDirectory)
.append("ConvergedJobs")
.append(pairName));
std::filesystem::create_directories(convergedJobsDirPath);
resultsOutputDir = convergedJobsDirPath.string();
}
optimizationResults.save(resultsOutputDir);
// Write results in csv
2021-02-19 16:32:15 +01:00
csvFile csv_results({}, false);
// csvFile csv_results(std::filesystem::path(dirPath_thisOptimization)
// .append("results.csv")
// .string(),
// false);
csv_results << "Name";
optimizationResults.writeHeaderTo(settings_optimization, csv_results);
settings_optimization.writeHeaderTo(csv_results);
csv_results << endrow;
csv_results << pairName;
optimizationResults.writeResultsTo(settings_optimization, csv_results);
settings_optimization.writeSettingsTo(csv_results);
csv_results << endrow;
// optimizationResults.draw();
2021-02-10 12:19:37 +01:00
2020-11-23 10:06:45 +01:00
return 0;
}