From 99f6905e122ce63dade4bd286979df3a97ded0d7 Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Tue, 18 Jan 2022 18:04:04 +0200 Subject: [PATCH] Refactoring --- src/main.cpp | 12 +++--------- src/reducedmodeloptimizer.cpp | 30 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d0fd56e..e583d75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,15 +23,9 @@ int main(int argc, char *argv[]) { // ReducedModelOptimization::Results optResults; - // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" - // "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)"); - // optResults.load("/home/iason/Coding/Projects/Approximating shapes with flat " - // "patterns/ReducedModelOptimization/Results/OptimizationResults/" - // "objectiveFunction/ConvergedJobs/testSet/7#12"); - // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" - // "singlePattern_dlib_23_12/12@single_reduced(100000_1.20)"); - // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" - // "singlePattern_ensmallen_AllVars_optParameters/7#12"); + // optResults.load("/home/iason/Desktop/finding_submissionCode/" + // "build-ReducedModelOptimization-Clang-RelWithDebInfo/OptimizationResults/" + // "ConvergedJobs/12@single_reduced(100000_1.20)"); // ReducedModelEvaluator::evaluateReducedModel(optResults); if (argc <= 5) { std::cerr << "Wrong number of input parameters. Expects at least 4 input parameters." diff --git a/src/reducedmodeloptimizer.cpp b/src/reducedmodeloptimizer.cpp index 45fda4a..3b10f31 100644 --- a/src/reducedmodeloptimizer.cpp +++ b/src/reducedmodeloptimizer.cpp @@ -186,7 +186,8 @@ struct EnsmallenOptimizationObjective //#ifdef POLYSCOPE_DEFINED // std::cout << "Out of range" << std::endl; //#endif - // return std::numeric_limits::max(); + // return std::numeric_limits::max(); + // return 1e7; // return 1000; x[xi] = global.xMax[xi]; } else if (x[xi] < global.xMin[xi]) { @@ -194,6 +195,7 @@ struct EnsmallenOptimizationObjective // std::cout << "Out of range" << std::endl; //#endif // return std::numeric_limits::max(); + // return 1e7; // return 1000; x[xi] = global.xMin[xi]; } @@ -1093,10 +1095,10 @@ void ReducedModelOptimizer::runOptimization(const Settings &settings, // that is able to handle arbitrary functions. EnsmallenOptimizationObjective optimizationFunction; //Set min max values - // ens::SA optimizer; - // ens::CNE optimizer; - // ens::DE optimizer; - // ens::SPSA optimizer; + // ens::SA optimizer; + // ens::CNE optimizer; + // ens::DE optimizer; + // ens::SPSA optimizer; // arma::mat xMin_arma(global.xMin); // arma::mat xMax_arma(global.xMax); // ens::LBestPSO optimizer(64, xMin_arma, xMax_arma, 1000); @@ -1110,13 +1112,13 @@ void ReducedModelOptimizer::runOptimization(const Settings &settings, 2.35); // ens::LBestPSO optimizer; const double minima = optimizer.Optimize(optimizationFunction, x); - // for (int xIndex = 0; xIndex < parameterGroup.size(); xIndex++) { - // if (x[xIndex] > global.xMax[xIndex]) { - // x[xIndex] = global.xMax[xIndex]; - // } else if (x[xIndex] < global.xMin[xIndex]) { - // x[xIndex] = global.xMin[xIndex]; - // } - // } + for (int xIndex = 0; xIndex < parameterGroup.size(); xIndex++) { + if (x[xIndex] > global.xMax[xIndex]) { + x[xIndex] = global.xMax[xIndex]; + } else if (x[xIndex] < global.xMin[xIndex]) { + x[xIndex] = global.xMin[xIndex]; + } + } #ifdef POLYSCOPE_DEFINED std::cout << "optimal x:" @@ -1868,7 +1870,7 @@ void ReducedModelOptimizer::optimize( global.optimizationSettings = optimizationSettings; global.pFullPatternSimulationMesh = m_pFullPatternSimulationMesh; - constexpr bool recomputeForceMagnitudes = true; + constexpr bool recomputeForceMagnitudes = false; std::array fullPatternSimulationScenarioMaxMagnitudes = getFullPatternMaxSimulationForces(desiredBaseSimulationScenarioIndices, intermediateResultsDirectoryPath, @@ -1919,7 +1921,7 @@ void ReducedModelOptimizer::optimize( .append(m_pFullPatternSimulationMesh->getLabel()) .append(pFullPatternSimulationJob->getLabel())); // .append(pFullPatternSimulationJob->getLabel() + ".json") - constexpr bool recomputeFullPatternResults = true; + constexpr bool recomputeFullPatternResults = false; SimulationResults fullPatternResults; if (!recomputeFullPatternResults && std::filesystem::exists(jobResultsDirectoryPath)) { fullPatternResults.load(std::filesystem::path(jobResultsDirectoryPath).append("Results"),