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)};
|
std::vector<vcg::Point2i> singleBarReducedModelEdges{vcg::Point2i(0, 3)};
|
||||||
FlatPattern singleBarReducedModel(numberOfNodesPerSlot,
|
FlatPattern singleBarReducedModel(numberOfNodesPerSlot,
|
||||||
singleBarReducedModelEdges);
|
singleBarReducedModelEdges);
|
||||||
singleBarReducedModel.setLabel("Single bar reduced model");
|
singleBarReducedModel.setLabel("SingleBar_reduced");
|
||||||
singleBarReducedModel.scale(0.03);
|
singleBarReducedModel.scale(0.03);
|
||||||
singleBarReducedModel.savePly(singleBarReducedModel.getLabel() + ".ply");
|
|
||||||
|
|
||||||
std::vector<vcg::Point2i> CWreducedModelEdges{vcg::Point2i(1, 5),
|
std::vector<vcg::Point2i> CWreducedModelEdges{vcg::Point2i(1, 5),
|
||||||
vcg::Point2i(3, 1)};
|
vcg::Point2i(3, 1)};
|
||||||
FlatPattern CWReducedModel(numberOfNodesPerSlot, CWreducedModelEdges);
|
FlatPattern CWReducedModel(numberOfNodesPerSlot, CWreducedModelEdges);
|
||||||
CWReducedModel.setLabel("CW reduced model");
|
CWReducedModel.setLabel("CW_reduced");
|
||||||
CWReducedModel.scale(0.03);
|
CWReducedModel.scale(0.03);
|
||||||
|
|
||||||
std::vector<vcg::Point2i> CCWreducedModelEdges{vcg::Point2i(1, 5),
|
std::vector<vcg::Point2i> CCWreducedModelEdges{vcg::Point2i(1, 5),
|
||||||
vcg::Point2i(3, 5)};
|
vcg::Point2i(3, 5)};
|
||||||
FlatPattern CCWReducedModel(numberOfNodesPerSlot, CCWreducedModelEdges);
|
FlatPattern CCWReducedModel(numberOfNodesPerSlot, CCWreducedModelEdges);
|
||||||
CCWReducedModel.setLabel("CCW reduced model");
|
CCWReducedModel.setLabel("CCW_reduced");
|
||||||
CCWReducedModel.scale(0.03);
|
CCWReducedModel.scale(0.03);
|
||||||
|
|
||||||
std::vector<FlatPattern *> reducedModels{&singleBarReducedModel,
|
std::vector<FlatPattern *> reducedModels{&singleBarReducedModel,
|
||||||
&CWReducedModel, &CCWReducedModel};
|
&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
|
// Test set of full patterns
|
||||||
std::string fullPatternsTestSetDirectory = "../TestSet";
|
std::string fullPatternsTestSetDirectory = "../TestSet";
|
||||||
// "/home/iason/Documents/PhD/Research/Approximating shapes with flat "
|
// "/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)
|
// for (double rangeOffset = 0.15; rangeOffset <= 0.95; rangeOffset += 0.05)
|
||||||
// {
|
// {
|
||||||
ReducedModelOptimizer::Settings settings;
|
ReducedModelOptimizer::Settings settings;
|
||||||
for (settings.maxSimulations = 2600; settings.maxSimulations < 5000;
|
for (settings.maxSimulations = 100; settings.maxSimulations < 3500;
|
||||||
settings.maxSimulations += 200) {
|
settings.maxSimulations += 100) {
|
||||||
ReducedModelOptimizer::xRange beamWidth{"B", 0.5, 1.5};
|
|
||||||
ReducedModelOptimizer::xRange beamDimensionsRatio{"bOverh", 0.7, 1.3};
|
|
||||||
ReducedModelOptimizer::xRange beamE{"E", 0.1, 1.9};
|
|
||||||
std::string xRangesString = beamWidth.toString() + " " +
|
std::string xRangesString = beamWidth.toString() + " " +
|
||||||
beamDimensionsRatio.toString() + " " +
|
beamDimensionsRatio.toString() + " " +
|
||||||
beamE.toString();
|
beamE.toString();
|
||||||
std::cout << xRangesString << std::endl;
|
std::cout << xRangesString << std::endl;
|
||||||
settings.xRanges = {beamWidth, beamDimensionsRatio, beamE};
|
settings.xRanges = {beamWidth, beamDimensionsRatio, beamE};
|
||||||
std::filesystem::path thisOptimizationDirectory(
|
// std::filesystem::path thisOptimizationDirectory(
|
||||||
std::filesystem::path("../OptimizationResults").append(xRangesString));
|
// std::filesystem::path("../OptimizationResults").append(xRangesString));
|
||||||
std::filesystem::create_directories(thisOptimizationDirectory);
|
// std::filesystem::create_directories(thisOptimizationDirectory);
|
||||||
// csvfile thisOptimizationStatistics(
|
// csvfile thisOptimizationStatistics(
|
||||||
// std::filesystem::path(thisOptimizationDirectory)
|
// std::filesystem::path(thisOptimizationDirectory)
|
||||||
// .append("statistics.csv")
|
// .append("statistics.csv")
|
||||||
|
|
@ -96,10 +96,9 @@ int main(int argc, char *argv[]) {
|
||||||
resultsPerPattern(patternPairs.size());
|
resultsPerPattern(patternPairs.size());
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
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();
|
for (int patternPairIndex = 0; patternPairIndex < patternPairs.size();
|
||||||
patternPairIndex++) {
|
patternPairIndex++) {
|
||||||
FlatPattern *pPattern = patternPairs[patternPairIndex].first;
|
|
||||||
// const auto filepathString = filepath.string();
|
// const auto filepathString = filepath.string();
|
||||||
// Use only the base triangle version
|
// Use only the base triangle version
|
||||||
// std::cout << "Full pattern:" << filepathString << std::endl;
|
// std::cout << "Full pattern:" << filepathString << std::endl;
|
||||||
|
|
@ -120,27 +119,13 @@ int main(int argc, char *argv[]) {
|
||||||
// cp.copy(*reducedModels[0]);
|
// cp.copy(*reducedModels[0]);
|
||||||
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
||||||
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
||||||
optimizer.initializePatterns(*pPattern,
|
optimizer.initializePatterns(*patternPairs[patternPairIndex].first,
|
||||||
*patternPairs[patternPairIndex].second,
|
*patternPairs[patternPairIndex].second,
|
||||||
|
optimizationSpaceSamplingDisplacements,
|
||||||
optimizationExcludedEi);
|
optimizationExcludedEi);
|
||||||
// optimizer.optimize({ReducedModelOptimizer::Axial});
|
// optimizer.optimize({ReducedModelOptimizer::Axial});
|
||||||
ReducedModelOptimizer::Results optimizationResults =
|
ReducedModelOptimizer::Results optimizationResults =
|
||||||
optimizer.optimize(settings);
|
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;
|
totalError += optimizationResults.objectiveValue;
|
||||||
resultsPerPattern[patternPairIndex] =
|
resultsPerPattern[patternPairIndex] =
|
||||||
|
|
@ -159,6 +144,16 @@ int main(int argc, char *argv[]) {
|
||||||
auto runtime_ms =
|
auto runtime_ms =
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
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")
|
csvfile statistics(std::filesystem::path("../OptimizationResults")
|
||||||
.append("statistics.csv")
|
.append("statistics.csv")
|
||||||
.string(),
|
.string(),
|
||||||
|
|
@ -176,19 +171,18 @@ int main(int argc, char *argv[]) {
|
||||||
statistics << totalError;
|
statistics << totalError;
|
||||||
for (const auto &patternObjectiveValue : resultsPerPattern) {
|
for (const auto &patternObjectiveValue : resultsPerPattern) {
|
||||||
statistics << patternObjectiveValue.second.objectiveValue;
|
statistics << patternObjectiveValue.second.objectiveValue;
|
||||||
}
|
|
||||||
statistics << runtime_ms.count() / 1000.0;
|
|
||||||
for (const auto &patternObjectiveValue : resultsPerPattern) {
|
|
||||||
for (const double &optimalX : patternObjectiveValue.second.x) {
|
for (const double &optimalX : patternObjectiveValue.second.x) {
|
||||||
statistics << optimalX;
|
statistics << optimalX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
statistics << runtime_ms.count() / 1000.0;
|
||||||
|
|
||||||
statistics << endrow;
|
statistics << endrow;
|
||||||
}
|
}
|
||||||
for(auto patternPair:patternPairs){
|
|
||||||
delete patternPair.first;
|
for (auto patternPair : patternPairs) {
|
||||||
delete patternPair.second;
|
delete patternPair.first;
|
||||||
}
|
delete patternPair.second;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue