Makes multiple copies of the reduced model such that they can be used in the openmp paralllel loop.
This commit is contained in:
parent
858282c859
commit
265680ea05
68
src/main.cpp
68
src/main.cpp
|
|
@ -24,25 +24,28 @@ int main(int argc, char *argv[]) {
|
|||
std::vector<vcg::Point2i> singleBarReducedModelEdges{vcg::Point2i(0, 3)};
|
||||
FlatPattern singleBarReducedModel(numberOfNodesPerSlot,
|
||||
singleBarReducedModelEdges);
|
||||
singleBarReducedModel.setLabel("Single bar reduced model");
|
||||
singleBarReducedModel.setLabel("SingleBar_reduced");
|
||||
singleBarReducedModel.scale(0.03);
|
||||
singleBarReducedModel.savePly(singleBarReducedModel.getLabel() + ".ply");
|
||||
|
||||
std::vector<vcg::Point2i> CWreducedModelEdges{vcg::Point2i(1, 5),
|
||||
vcg::Point2i(3, 1)};
|
||||
FlatPattern CWReducedModel(numberOfNodesPerSlot, CWreducedModelEdges);
|
||||
CWReducedModel.setLabel("CW reduced model");
|
||||
CWReducedModel.setLabel("CW_reduced");
|
||||
CWReducedModel.scale(0.03);
|
||||
|
||||
std::vector<vcg::Point2i> CCWreducedModelEdges{vcg::Point2i(1, 5),
|
||||
vcg::Point2i(3, 5)};
|
||||
FlatPattern CCWReducedModel(numberOfNodesPerSlot, CCWreducedModelEdges);
|
||||
CCWReducedModel.setLabel("CCW reduced model");
|
||||
CCWReducedModel.setLabel("CCW_reduced");
|
||||
CCWReducedModel.scale(0.03);
|
||||
|
||||
std::vector<FlatPattern *> reducedModels{&singleBarReducedModel,
|
||||
&CWReducedModel, &CCWReducedModel};
|
||||
|
||||
// Define the ranges that the optimizer will use
|
||||
ReducedModelOptimizer::xRange beamWidth{"B", 0.5, 1.5};
|
||||
ReducedModelOptimizer::xRange beamDimensionsRatio{"bOverh", 0.7, 1.3};
|
||||
ReducedModelOptimizer::xRange beamE{"E", 0.1, 1.9};
|
||||
// Test set of full patterns
|
||||
std::string fullPatternsTestSetDirectory = "../TestSet";
|
||||
// "/home/iason/Documents/PhD/Research/Approximating shapes with flat "
|
||||
|
|
@ -71,19 +74,16 @@ int main(int argc, char *argv[]) {
|
|||
// for (double rangeOffset = 0.15; rangeOffset <= 0.95; rangeOffset += 0.05)
|
||||
// {
|
||||
ReducedModelOptimizer::Settings settings;
|
||||
for (settings.maxSimulations = 2600; 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};
|
||||
for (settings.maxSimulations = 100; settings.maxSimulations < 3500;
|
||||
settings.maxSimulations += 100) {
|
||||
std::string xRangesString = beamWidth.toString() + " " +
|
||||
beamDimensionsRatio.toString() + " " +
|
||||
beamE.toString();
|
||||
std::cout << xRangesString << std::endl;
|
||||
settings.xRanges = {beamWidth, beamDimensionsRatio, beamE};
|
||||
std::filesystem::path thisOptimizationDirectory(
|
||||
std::filesystem::path("../OptimizationResults").append(xRangesString));
|
||||
std::filesystem::create_directories(thisOptimizationDirectory);
|
||||
// std::filesystem::path thisOptimizationDirectory(
|
||||
// std::filesystem::path("../OptimizationResults").append(xRangesString));
|
||||
// std::filesystem::create_directories(thisOptimizationDirectory);
|
||||
// csvfile thisOptimizationStatistics(
|
||||
// std::filesystem::path(thisOptimizationDirectory)
|
||||
// .append("statistics.csv")
|
||||
|
|
@ -96,10 +96,9 @@ int main(int argc, char *argv[]) {
|
|||
resultsPerPattern(patternPairs.size());
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
#pragma omp parallel for // schedule(static) num_threads(8)
|
||||
//#pragma omp parallel for
|
||||
for (int patternPairIndex = 0; patternPairIndex < patternPairs.size();
|
||||
patternPairIndex++) {
|
||||
FlatPattern *pPattern = patternPairs[patternPairIndex].first;
|
||||
// const auto filepathString = filepath.string();
|
||||
// Use only the base triangle version
|
||||
// std::cout << "Full pattern:" << filepathString << std::endl;
|
||||
|
|
@ -120,27 +119,13 @@ int main(int argc, char *argv[]) {
|
|||
// cp.copy(*reducedModels[0]);
|
||||
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
||||
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
||||
optimizer.initializePatterns(*pPattern,
|
||||
optimizer.initializePatterns(*patternPairs[patternPairIndex].first,
|
||||
*patternPairs[patternPairIndex].second,
|
||||
optimizationSpaceSamplingDisplacements,
|
||||
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;
|
||||
resultsPerPattern[patternPairIndex] =
|
||||
|
|
@ -159,6 +144,16 @@ int main(int argc, char *argv[]) {
|
|||
auto runtime_ms =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
|
||||
// for (int patternPairIndex = 0; patternPairIndex < patternPairs.size();
|
||||
// patternPairIndex++) {
|
||||
// std::filesystem::path
|
||||
// saveToPath(std::filesystem::path("../OptimizationResults")
|
||||
// .append(resultsPerPattern[patternPairIndex].first));
|
||||
// std::filesystem::create_directory(std::filesystem::path(saveToPath));
|
||||
|
||||
// resultsPerPattern[patternPairIndex].second.save(saveToPath);
|
||||
// }
|
||||
|
||||
csvfile statistics(std::filesystem::path("../OptimizationResults")
|
||||
.append("statistics.csv")
|
||||
.string(),
|
||||
|
|
@ -176,19 +171,18 @@ int main(int argc, char *argv[]) {
|
|||
statistics << totalError;
|
||||
for (const auto &patternObjectiveValue : resultsPerPattern) {
|
||||
statistics << patternObjectiveValue.second.objectiveValue;
|
||||
}
|
||||
statistics << runtime_ms.count() / 1000.0;
|
||||
for (const auto &patternObjectiveValue : resultsPerPattern) {
|
||||
for (const double &optimalX : patternObjectiveValue.second.x) {
|
||||
statistics << optimalX;
|
||||
}
|
||||
}
|
||||
statistics << runtime_ms.count() / 1000.0;
|
||||
|
||||
statistics << endrow;
|
||||
}
|
||||
for(auto patternPair:patternPairs){
|
||||
delete patternPair.first;
|
||||
delete patternPair.second;
|
||||
}
|
||||
|
||||
for (auto patternPair : patternPairs) {
|
||||
delete patternPair.first;
|
||||
delete patternPair.second;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue