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"
|
2021-02-19 16:32:15 +01:00
|
|
|
#include "externvariables.hpp"
|
2020-11-23 10:06:45 +01:00
|
|
|
#include "flatpattern.hpp"
|
|
|
|
#include "polyscope/curve_network.h"
|
|
|
|
#include "polyscope/point_cloud.h"
|
|
|
|
#include "polyscope/polyscope.h"
|
|
|
|
#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-19 16:32:15 +01:00
|
|
|
bool printDebugInfo;
|
|
|
|
|
2020-11-23 10:06:45 +01:00
|
|
|
int main(int argc, char *argv[]) {
|
2021-02-19 16:32:15 +01:00
|
|
|
if (argc < 5) {
|
|
|
|
std::cerr << "Specify at least if D(ebug) or R(elease) and the pattern "
|
|
|
|
"pair to be optimized."
|
|
|
|
<< std::endl;
|
2021-02-18 14:33:31 +01:00
|
|
|
std::terminate();
|
|
|
|
}
|
2021-02-19 16:32:15 +01:00
|
|
|
|
|
|
|
if (argv[1] == "D") {
|
|
|
|
printDebugInfo = true;
|
|
|
|
} else {
|
|
|
|
printDebugInfo = false;
|
|
|
|
}
|
2021-02-18 14:33:31 +01:00
|
|
|
// Populate the pattern pair to be optimized
|
|
|
|
////Full pattern
|
2021-02-19 16:32:15 +01:00
|
|
|
const std::string filepath_fullPattern = argv[2];
|
2021-02-18 14:33:31 +01:00
|
|
|
FlatPattern fullPattern(filepath_fullPattern);
|
|
|
|
fullPattern.setLabel(
|
|
|
|
std::filesystem::path(filepath_fullPattern).stem().string());
|
|
|
|
fullPattern.scale(0.03);
|
|
|
|
////Reduced pattern
|
2021-02-19 16:32:15 +01:00
|
|
|
const std::string filepath_reducedPattern = argv[3];
|
2021-02-18 14:33:31 +01:00
|
|
|
FlatPattern reducedPattern(filepath_reducedPattern);
|
|
|
|
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-02-14 13:27:14 +01:00
|
|
|
ReducedModelOptimizer::xRange innerHexagonSize{"HS", 0.1, 0.9};
|
2021-02-10 12:19:37 +01:00
|
|
|
ReducedModelOptimizer::Settings settings_optimization;
|
|
|
|
settings_optimization.xRanges = {beamWidth, beamDimensionsRatio, beamE,
|
|
|
|
innerHexagonSize};
|
2021-02-19 16:32:15 +01:00
|
|
|
const bool input_numberOfFunctionCallsDefined = argc >= 5;
|
2021-02-18 14:33:31 +01:00
|
|
|
settings_optimization.numberOfFunctionCalls =
|
2021-02-19 16:32:15 +01:00
|
|
|
input_numberOfFunctionCallsDefined ? std::atoi(argv[4]) : 100;
|
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
|
|
|
if (printDebugInfo) {
|
|
|
|
std::cout << "Optimizing " << pairName << std::endl;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
// Export results
|
2021-02-19 16:32:15 +01:00
|
|
|
const bool input_resultDirectoryDefined = argc >= 6;
|
2021-02-18 14:33:31 +01:00
|
|
|
std::string optimiziationResultsDirectory =
|
2021-02-19 16:32:15 +01:00
|
|
|
input_resultDirectoryDefined ? argv[5] : "OptimizationResults";
|
2021-02-18 14:33:31 +01:00
|
|
|
std::filesystem::path dirPath_thisOptimization(
|
|
|
|
std::filesystem::path(optimiziationResultsDirectory).append(pairName));
|
|
|
|
std::filesystem::create_directories(dirPath_thisOptimization);
|
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-18 14:33:31 +01:00
|
|
|
settings_optimization.writeTo(csv_results);
|
|
|
|
optimizationResults.writeTo(settings_optimization, csv_results);
|
|
|
|
optimizationResults.save(dirPath_thisOptimization.string());
|
|
|
|
|
|
|
|
// optimizationResults.draw();
|
2021-02-10 12:19:37 +01:00
|
|
|
|
2020-11-23 10:06:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|