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>
|
2021-02-01 15:10:24 +01:00
|
|
|
#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>
|
|
|
|
|
2021-02-24 18:41:12 +01:00
|
|
|
#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[]) {
|
2021-02-22 18:23:58 +01:00
|
|
|
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;
|
2021-02-18 14:33:31 +01:00
|
|
|
std::terminate();
|
|
|
|
}
|
2021-02-19 16:32:15 +01:00
|
|
|
|
2021-02-18 14:33:31 +01:00
|
|
|
// Populate the pattern pair to be optimized
|
|
|
|
////Full pattern
|
2021-02-22 18:23:58 +01:00
|
|
|
const std::string filepath_fullPattern = argv[1];
|
2021-03-15 18:56:14 +01:00
|
|
|
PatternGeometry fullPattern(filepath_fullPattern);
|
2021-02-18 14:33:31 +01:00
|
|
|
fullPattern.setLabel(
|
|
|
|
std::filesystem::path(filepath_fullPattern).stem().string());
|
|
|
|
fullPattern.scale(0.03);
|
|
|
|
////Reduced pattern
|
2021-02-22 18:23:58 +01:00
|
|
|
const std::string filepath_reducedPattern = argv[2];
|
2021-03-15 18:56:14 +01:00
|
|
|
PatternGeometry reducedPattern(filepath_reducedPattern);
|
2021-02-18 14:33:31 +01:00
|
|
|
reducedPattern.setLabel(
|
|
|
|
std::filesystem::path(filepath_reducedPattern).stem().string());
|
|
|
|
reducedPattern.scale(0.03);
|
|
|
|
|
|
|
|
// Set the optization settings
|
2021-02-04 15:05:48 +01:00
|
|
|
ReducedModelOptimizer::xRange beamWidth{"B", 0.5, 1.5};
|
|
|
|
ReducedModelOptimizer::xRange beamDimensionsRatio{"bOverh", 0.7, 1.3};
|
|
|
|
ReducedModelOptimizer::xRange beamE{"E", 0.1, 1.9};
|
2021-03-15 18:56:14 +01:00
|
|
|
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,
|
2021-03-15 18:56:14 +01:00
|
|
|
innerHexagonSize, innerHexagonAngle};
|
2021-02-25 09:09:38 +01:00
|
|
|
const bool input_numberOfFunctionCallsDefined = argc >= 4;
|
2021-02-18 14:33:31 +01:00
|
|
|
settings_optimization.numberOfFunctionCalls =
|
2021-02-25 09:09:38 +01:00
|
|
|
input_numberOfFunctionCallsDefined ? std::atoi(argv[3]) : 100;
|
2021-03-01 13:34:27 +01:00
|
|
|
settings_optimization.normalizationStrategy =
|
2021-03-15 18:56:14 +01:00
|
|
|
ReducedModelOptimizer::Settings::NormalizationStrategy::Epsilon;
|
2021-03-02 19:32:43 +01:00
|
|
|
settings_optimization.normalizationParameter = 0.0003;
|
2021-02-24 21:10:42 +01:00
|
|
|
settings_optimization.solutionAccuracy = 0.01;
|
2021-02-22 10:28:01 +01:00
|
|
|
|
2021-02-18 14:33:31 +01:00
|
|
|
// Optimize pair
|
|
|
|
const std::string pairName =
|
|
|
|
fullPattern.getLabel() + "@" + reducedPattern.getLabel();
|
2021-02-19 16:32:15 +01:00
|
|
|
|
2021-02-18 14:33:31 +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);
|
2021-02-22 10:28:01 +01:00
|
|
|
|
2021-02-18 14:33:31 +01:00
|
|
|
// Export results
|
2021-02-25 09:09:38 +01:00
|
|
|
const bool input_resultDirectoryDefined = argc >= 5;
|
2021-02-22 10:28:01 +01:00
|
|
|
std::string optimizationResultsDirectory =
|
2021-02-25 09:09:38 +01:00
|
|
|
input_resultDirectoryDefined ? argv[4] : "OptimizationResults";
|
2021-03-01 13:34:27 +01:00
|
|
|
std::string resultsOutputDir;
|
2021-02-22 10:28:01 +01:00
|
|
|
if (optimizationResults.numberOfSimulationCrashes != 0) {
|
|
|
|
const auto crashedJobsDirPath =
|
2021-02-22 18:43:10 +01:00
|
|
|
std::filesystem::path(optimizationResultsDirectory)
|
2021-02-22 10:28:01 +01:00
|
|
|
.append("CrashedJobs")
|
|
|
|
.append(pairName);
|
|
|
|
std::filesystem::create_directories(crashedJobsDirPath);
|
2021-03-01 13:34:27 +01:00
|
|
|
resultsOutputDir = crashedJobsDirPath.string();
|
2021-02-22 10:28:01 +01:00
|
|
|
} else {
|
2021-02-22 18:43:10 +01:00
|
|
|
std::filesystem::path convergedJobsDirPath(
|
|
|
|
std::filesystem::path(optimizationResultsDirectory)
|
2021-02-22 10:28:01 +01:00
|
|
|
.append("ConvergedJobs")
|
|
|
|
.append(pairName));
|
2021-02-22 18:43:10 +01:00
|
|
|
std::filesystem::create_directories(convergedJobsDirPath);
|
2021-03-01 13:34:27 +01:00
|
|
|
resultsOutputDir = convergedJobsDirPath.string();
|
2021-02-22 10:28:01 +01:00
|
|
|
}
|
2021-03-01 13:34:27 +01:00
|
|
|
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);
|
2021-02-22 10:28:01 +01:00
|
|
|
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;
|
2021-02-18 14:33:31 +01:00
|
|
|
|
|
|
|
// optimizationResults.draw();
|
2021-02-10 12:19:37 +01:00
|
|
|
|
2020-11-23 10:06:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|