Refactoring
This commit is contained in:
parent
a61856211b
commit
e4c6bd040d
75
src/main.cpp
75
src/main.cpp
|
|
@ -25,6 +25,7 @@ int main(int argc, char *argv[]) {
|
|||
singleBarReducedModelEdges);
|
||||
singleBarReducedModel.setLabel("Single bar reduced model");
|
||||
singleBarReducedModel.scale(0.03);
|
||||
singleBarReducedModel.savePly(singleBarReducedModel.getLabel() + ".ply");
|
||||
|
||||
std::vector<vcg::Point2i> CWreducedModelEdges{vcg::Point2i(1, 5),
|
||||
vcg::Point2i(3, 1)};
|
||||
|
|
@ -42,26 +43,27 @@ int main(int argc, char *argv[]) {
|
|||
&CWReducedModel, &CCWReducedModel};
|
||||
|
||||
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
||||
for (double dimRationMax = 0.75; dimRationMax < 2; dimRationMax += 0.05) {
|
||||
// for (double rangeOffset = 0.15; rangeOffset <= 0.95; rangeOffset += 0.05)
|
||||
// {
|
||||
ReducedModelOptimizer::Settings settings;
|
||||
for (settings.maxSimulations = 600; settings.maxSimulations < 2000;
|
||||
settings.maxSimulations += 100) {
|
||||
ReducedModelOptimizer::xRange beamWidth{"B", 0.5, 1.5};
|
||||
ReducedModelOptimizer::xRange beamDimensionsRatio{"bOverh", 0.7,
|
||||
dimRationMax};
|
||||
ReducedModelOptimizer::xRange beamE{"E", 0.07, 1.5};
|
||||
ReducedModelOptimizer::xRange beamDimensionsRatio{"bOverh", 0.7, 1.3};
|
||||
ReducedModelOptimizer::xRange beamE{"E", 0.1, 1.9};
|
||||
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);
|
||||
// csvfile thisOptimizationStatistics(
|
||||
// std::filesystem::path(thisOptimizationDirectory)
|
||||
// .append("statistics.csv")
|
||||
// .string(),
|
||||
// true);
|
||||
|
||||
double totalError = 0;
|
||||
int totalNumberOfSimulationCrashes = 0;
|
||||
|
|
@ -69,6 +71,9 @@ int main(int argc, char *argv[]) {
|
|||
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";
|
||||
std::vector<std::pair<std::string, ReducedModelOptimizer::Results>>
|
||||
resultsPerPattern;
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
for (const auto &entry :
|
||||
filesystem::directory_iterator(fullPatternsTestSetDirectory)) {
|
||||
const auto filepath =
|
||||
|
|
@ -105,27 +110,32 @@ int main(int argc, char *argv[]) {
|
|||
// 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;
|
||||
// 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.push_back(
|
||||
std::make_pair(filepath.stem().string(), optimizationResults));
|
||||
totalNumberOfSimulationCrashes +=
|
||||
optimizationResults.numberOfSimulationCrashes;
|
||||
// }
|
||||
}
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto runtime_ms =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
|
||||
csvfile statistics(std::filesystem::path("../OptimizationResults")
|
||||
.append("statistics.csv")
|
||||
|
|
@ -141,7 +151,18 @@ int main(int argc, char *argv[]) {
|
|||
statistics << totalNumberOfSimulationCrashes;
|
||||
}
|
||||
|
||||
statistics << totalError << endrow;
|
||||
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 << endrow;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -655,7 +655,8 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::runOptimization(
|
|||
double (*objF)(double, double, double) = &objective;
|
||||
auto start = std::chrono::system_clock::now();
|
||||
dlib::function_evaluation result = dlib::find_min_global(
|
||||
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations));
|
||||
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
||||
std::chrono::hours(24 * 365 * 290), settings.solutionAccuracy);
|
||||
auto end = std::chrono::system_clock::now();
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(end - start);
|
||||
Results results{numOfSimulationCrashes, minX, minY};
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ public:
|
|||
|
||||
struct Settings {
|
||||
std::vector<xRange> xRanges;
|
||||
int maxSimulations{300};
|
||||
int maxSimulations{100};
|
||||
double solutionAccuracy{1e-5};
|
||||
};
|
||||
|
||||
inline static const std::string simulationScenarioStrings[] = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue