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 "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>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
2020-12-09 16:58:48 +01:00
|
|
|
#include <vcg/complex/algorithms/update/position.h>
|
|
|
|
|
2020-11-23 10:06:45 +01:00
|
|
|
int main(int argc, char *argv[]) {
|
2021-01-04 13:12:25 +01:00
|
|
|
|
2020-11-27 11:45:20 +01:00
|
|
|
// Create reduced models
|
2020-12-16 20:31:58 +01:00
|
|
|
// FormFinder::runUnitTests();
|
2020-11-27 11:45:20 +01:00
|
|
|
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
|
|
|
std::vector<vcg::Point2i> singleBarReducedModelEdges{vcg::Point2i(0, 3)};
|
|
|
|
FlatPattern singleBarReducedModel(numberOfNodesPerSlot,
|
|
|
|
singleBarReducedModelEdges);
|
|
|
|
singleBarReducedModel.setLabel("Single bar reduced model");
|
2020-12-22 17:47:29 +01:00
|
|
|
singleBarReducedModel.scale(0.03);
|
2020-11-27 11:45:20 +01:00
|
|
|
|
2020-12-14 10:07:43 +01:00
|
|
|
std::vector<vcg::Point2i> CWreducedModelEdges{vcg::Point2i(1, 5),
|
|
|
|
vcg::Point2i(3, 1)};
|
2020-12-22 17:47:29 +01:00
|
|
|
FlatPattern CWReducedModel(numberOfNodesPerSlot, CWreducedModelEdges);
|
|
|
|
CWReducedModel.setLabel("CW reduced model");
|
|
|
|
CWReducedModel.scale(0.03);
|
|
|
|
|
|
|
|
std::vector<vcg::Point2i> CCWreducedModelEdges{vcg::Point2i(1, 5),
|
|
|
|
vcg::Point2i(3, 5)};
|
|
|
|
FlatPattern CCWReducedModel(numberOfNodesPerSlot, CCWreducedModelEdges);
|
2020-12-14 10:07:43 +01:00
|
|
|
CCWReducedModel.setLabel("CCW reduced model");
|
2020-12-22 17:47:29 +01:00
|
|
|
CCWReducedModel.scale(0.03);
|
2020-11-27 11:45:20 +01:00
|
|
|
|
2020-12-14 10:07:43 +01:00
|
|
|
std::vector<FlatPattern *> reducedModels{&singleBarReducedModel,
|
|
|
|
&CWReducedModel, &CCWReducedModel};
|
2020-11-27 11:45:20 +01:00
|
|
|
|
2020-12-14 10:07:43 +01:00
|
|
|
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
2021-01-22 15:39:36 +01:00
|
|
|
for (double dimRationMax = 0.75; dimRationMax < 2; dimRationMax += 0.05) {
|
|
|
|
ReducedModelOptimizer::xRange beamWidth{"B", 0.5, 1.5};
|
|
|
|
ReducedModelOptimizer::xRange beamDimensionsRatio{"bOverh", 0.7,
|
|
|
|
dimRationMax};
|
|
|
|
ReducedModelOptimizer::xRange beamE{"E", 0.07, 1.5};
|
|
|
|
std::string xRangesString = beamWidth.toString() + " " +
|
|
|
|
beamDimensionsRatio.toString() + " " +
|
|
|
|
beamE.toString();
|
|
|
|
std::cout << xRangesString << std::endl;
|
|
|
|
ReducedModelOptimizer::Settings settings;
|
|
|
|
settings.xRanges = {beamWidth, beamDimensionsRatio, beamE};
|
|
|
|
|
|
|
|
std::filesystem::path thisOptimizationDirectory(
|
|
|
|
std::filesystem::path("../OptimizationResults").append(xRangesString));
|
|
|
|
std::filesystem::create_directory(thisOptimizationDirectory);
|
|
|
|
csvfile thisOptimizationStatistics(
|
|
|
|
std::filesystem::path(thisOptimizationDirectory)
|
|
|
|
.append("statistics.csv")
|
|
|
|
.string(),
|
|
|
|
true);
|
|
|
|
|
|
|
|
double totalError = 0;
|
|
|
|
int totalNumberOfSimulationCrashes = 0;
|
|
|
|
std::vector<double> errors;
|
|
|
|
std::string fullPatternsTestSetDirectory = "../TestSet";
|
|
|
|
// "/home/iason/Documents/PhD/Research/Approximating shapes with flat "
|
|
|
|
// "patterns/Pattern_enumerator/Results/1v_0v_2e_1e_1c_6fan/3/Valid";
|
|
|
|
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();
|
|
|
|
// Use only the base triangle version
|
|
|
|
const std::string tiledSuffix = "_tiled.ply";
|
|
|
|
if (filepathString.compare(filepathString.size() - tiledSuffix.size(),
|
|
|
|
tiledSuffix.size(), tiledSuffix) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// std::cout << "Full pattern:" << filepathString << std::endl;
|
|
|
|
FlatPattern pattern(filepathString);
|
|
|
|
pattern.setLabel(filepath.stem().string());
|
|
|
|
pattern.scale(0.03);
|
|
|
|
// for (int reducedPatternIndex = 0;
|
|
|
|
// reducedPatternIndex < reducedModels.size();
|
|
|
|
// reducedPatternIndex++) {
|
|
|
|
// FlatPattern *pReducedModel =
|
|
|
|
// reducedModels[reducedPatternIndex];
|
|
|
|
std::unordered_set<size_t> optimizationExcludedEi;
|
|
|
|
// if (pReducedModel !=
|
|
|
|
// reducedModels[0]) { // assumes that the singleBar reduced model
|
|
|
|
// // is
|
|
|
|
// // the
|
|
|
|
// // first in the reducedModels vector
|
|
|
|
// optimizationExcludedEi.insert(0);
|
|
|
|
// }
|
|
|
|
// FlatPattern cp;
|
|
|
|
// cp.copy(*reducedModels[0]);
|
|
|
|
optimizer.initializePatterns(pattern, *reducedModels[0],
|
|
|
|
optimizationExcludedEi);
|
|
|
|
// optimizer.optimize({ReducedModelOptimizer::Axial});
|
|
|
|
ReducedModelOptimizer::Results optimizationResults =
|
|
|
|
optimizer.optimize(settings);
|
|
|
|
errors.push_back(optimizationResults.objectiveValue);
|
|
|
|
SimulationResultsReporter::createPlot(
|
|
|
|
"", "Objective value", errors,
|
|
|
|
std::filesystem::path(thisOptimizationDirectory)
|
|
|
|
.append("ObjectiveValues.png")
|
|
|
|
.string());
|
|
|
|
thisOptimizationStatistics << filepath.stem().string()
|
|
|
|
<< optimizationResults.objectiveValue;
|
|
|
|
if (optimizationResults.numberOfSimulationCrashes == 0) {
|
|
|
|
thisOptimizationStatistics << "No crashes";
|
|
|
|
} else {
|
|
|
|
thisOptimizationStatistics
|
|
|
|
<< optimizationResults.numberOfSimulationCrashes;
|
|
|
|
}
|
|
|
|
thisOptimizationStatistics << endrow;
|
|
|
|
|
|
|
|
totalError += optimizationResults.objectiveValue;
|
|
|
|
totalNumberOfSimulationCrashes +=
|
|
|
|
optimizationResults.numberOfSimulationCrashes;
|
|
|
|
// }
|
2020-12-14 10:07:43 +01:00
|
|
|
}
|
2020-11-23 10:06:45 +01:00
|
|
|
|
2021-01-22 15:39:36 +01:00
|
|
|
csvfile statistics(std::filesystem::path("../OptimizationResults")
|
|
|
|
.append("statistics.csv")
|
|
|
|
.string(),
|
|
|
|
false);
|
|
|
|
for (const auto &range : settings.xRanges) {
|
|
|
|
statistics << range.min << range.max;
|
|
|
|
}
|
|
|
|
statistics << settings.maxSimulations;
|
|
|
|
if (totalNumberOfSimulationCrashes == 0) {
|
|
|
|
statistics << "No crashes";
|
|
|
|
} else {
|
|
|
|
statistics << totalNumberOfSimulationCrashes;
|
|
|
|
}
|
2020-12-09 16:58:48 +01:00
|
|
|
|
2021-01-22 15:39:36 +01:00
|
|
|
statistics << totalError << endrow;
|
|
|
|
}
|
2020-11-23 10:06:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|