From c97d398e0355a3f00a1d9a0e45e2742686b6d821 Mon Sep 17 00:00:00 2001 From: Achim Gsell <achim.gsell@psi.ch> Date: Fri, 3 May 2024 15:23:12 +0200 Subject: [PATCH] boost pointers replaced with std pointers --- optimizer/Expression/GlobalFunctions.h | 2 +- optimizer/Expression/MaxNormRadialPeak.h | 4 +- optimizer/Expression/NumberOfPeaks.h | 2 +- optimizer/Expression/Parser/requirements.hpp | 1 - optimizer/Expression/ProbeVariable.h | 2 +- optimizer/Expression/RadialPeak.h | 3 +- optimizer/Expression/SDDSVariable.h | 3 +- optimizer/Expression/SeptumExpr.h | 4 +- optimizer/Expression/SumErrSq.h | 2 +- optimizer/Expression/SumErrSqRadialPeak.h | 5 +-- optimizer/Optimizer/EA/BlendCrossover.h | 3 +- optimizer/Optimizer/EA/FixedPisaNsga2.h | 19 ++++---- optimizer/Optimizer/EA/FixedPisaNsga2.tcc | 12 ++--- .../Optimizer/EA/IndependentBitMutation.h | 3 +- optimizer/Optimizer/EA/Individual.h | 4 +- .../Optimizer/EA/NaiveOnePointCrossover.h | 3 +- .../Optimizer/EA/NaiveUniformCrossover.h | 3 +- optimizer/Optimizer/EA/OneBitMutation.h | 3 +- optimizer/Optimizer/EA/Population.h | 4 +- .../Optimizer/EA/SimulatedBinaryCrossover.h | 3 +- optimizer/Optimizer/EA/Variator.h | 30 ++++++------- optimizer/Pilot/Pilot.h | 22 ++++------ optimizer/Pilot/Worker.h | 4 +- optimizer/Tests/CmdArgumentsTest.cpp | 3 +- optimizer/Tests/ExpressionTest.cpp | 11 +++-- optimizer/Tests/FromFileExpressionTest.cpp | 5 +-- optimizer/Tests/IndividualTest.cpp | 14 +++--- optimizer/Tests/ManagedIDsTest.cpp | 3 +- optimizer/Tests/PopulationTest.cpp | 44 +++++++++---------- optimizer/Tests/PythonExprTest.cpp | 3 +- optimizer/Tests/SumErrSqExpressionTest.cpp | 3 +- optimizer/Util/AsyncSendBuffers.h | 5 +-- optimizer/Util/CmdArguments.h | 3 +- optimizer/Util/Trace/Trace.h | 8 ++-- src/Optimize/OpalSimulation.cpp | 6 +-- src/Optimize/OpalSimulation.h | 2 +- src/Optimize/OptimizeCmd.cpp | 18 ++++---- src/Sample/FromFile.h | 2 +- src/Sample/LatinHyperCube.h | 2 +- src/Sample/Normal.h | 2 +- src/Sample/SampleCmd.cpp | 4 +- src/Sample/SampleGaussianSequence.h | 2 +- src/Sample/SamplePilot.h | 6 +-- src/Sample/SampleRandomizedSequence.h | 2 +- src/Sample/SampleSequence.h | 2 +- src/Sample/Sampler.cpp | 12 ++--- src/Sample/Sampler.h | 6 +-- src/Sample/SamplingMethod.h | 2 +- src/Sample/Uniform.h | 2 +- 49 files changed, 138 insertions(+), 175 deletions(-) diff --git a/optimizer/Expression/GlobalFunctions.h b/optimizer/Expression/GlobalFunctions.h index ca3c2aa55..0d1048eb7 100644 --- a/optimizer/Expression/GlobalFunctions.h +++ b/optimizer/Expression/GlobalFunctions.h @@ -50,7 +50,7 @@ struct _stat_sum { double step = boost::get<double>(args[2]); std::string name = boost::get<std::string>(args[3]); - boost::scoped_ptr<SDDSReader> sim_stats(new SDDSReader(stat_filename_)); + const std::unique_ptr<SDDSReader> sim_stats(new SDDSReader(stat_filename_)); try { sim_stats->parseFile(); } catch (OptPilotException &ex) { diff --git a/optimizer/Expression/MaxNormRadialPeak.h b/optimizer/Expression/MaxNormRadialPeak.h index 207e97f3e..a8035defc 100644 --- a/optimizer/Expression/MaxNormRadialPeak.h +++ b/optimizer/Expression/MaxNormRadialPeak.h @@ -60,8 +60,8 @@ struct MaxNormRadialPeak { bool is_valid = true; - boost::scoped_ptr<PeakReader> meas_peaks(new PeakReader(meas_filename_)); - boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_)); + const std::unique_ptr<PeakReader> meas_peaks(new PeakReader(meas_filename_)); + const std::unique_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_)); try { sim_peaks->parseFile(); meas_peaks->parseFile(); diff --git a/optimizer/Expression/NumberOfPeaks.h b/optimizer/Expression/NumberOfPeaks.h index 958c1e371..1d797c53c 100644 --- a/optimizer/Expression/NumberOfPeaks.h +++ b/optimizer/Expression/NumberOfPeaks.h @@ -52,7 +52,7 @@ struct NumberOfPeaks { bool is_valid = true; - boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_)); + const std::unique_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_)); std::size_t nPeaks = 0; try { diff --git a/optimizer/Expression/Parser/requirements.hpp b/optimizer/Expression/Parser/requirements.hpp index ed2bc6115..b36667a38 100644 --- a/optimizer/Expression/Parser/requirements.hpp +++ b/optimizer/Expression/Parser/requirements.hpp @@ -11,7 +11,6 @@ #include "error_handler.hpp" #include <set> #include <boost/function.hpp> -#include <boost/shared_ptr.hpp> #include <boost/phoenix/core.hpp> #include <boost/phoenix/function.hpp> #include <boost/phoenix/operator.hpp> diff --git a/optimizer/Expression/ProbeVariable.h b/optimizer/Expression/ProbeVariable.h index 2aecfb9ff..3e97ac53c 100644 --- a/optimizer/Expression/ProbeVariable.h +++ b/optimizer/Expression/ProbeVariable.h @@ -47,7 +47,7 @@ struct ProbeVariable { bool is_valid = true; - boost::scoped_ptr<ProbeReader> sim_probe(new ProbeReader(probe_filename_)); + const std::unique_ptr<ProbeReader> sim_probe(new ProbeReader(probe_filename_)); try { sim_probe->parseFile(); diff --git a/optimizer/Expression/RadialPeak.h b/optimizer/Expression/RadialPeak.h index c8ccc7410..32ded3d9e 100644 --- a/optimizer/Expression/RadialPeak.h +++ b/optimizer/Expression/RadialPeak.h @@ -6,7 +6,6 @@ #include "boost/type_traits/remove_cv.hpp" #include "boost/variant/get.hpp" #include "boost/variant/variant.hpp" -#include "boost/smart_ptr.hpp" #include "Util/Types.h" #include "Util/PeakReader.h" @@ -31,7 +30,7 @@ struct RadialPeak { bool is_valid = true; - boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(peak_filename_)); + const std::unique_ptr<PeakReader> sim_peaks(new PeakReader(peak_filename_)); try { sim_peaks->parseFile(); } catch (OptPilotException &ex) { diff --git a/optimizer/Expression/SDDSVariable.h b/optimizer/Expression/SDDSVariable.h index 4d494d7bc..723344d05 100644 --- a/optimizer/Expression/SDDSVariable.h +++ b/optimizer/Expression/SDDSVariable.h @@ -31,7 +31,6 @@ #include "boost/variant/get.hpp" #include "boost/variant/variant.hpp" -#include "boost/smart_ptr.hpp" #include "Util/Types.h" #include "Util/SDDSReader.h" @@ -68,7 +67,7 @@ struct SDDSVariable { bool is_valid = true; - boost::scoped_ptr<SDDSReader> sim_stats(new SDDSReader(stat_filename_)); + const std::unique_ptr<SDDSReader> sim_stats(new SDDSReader(stat_filename_)); try { sim_stats->parseFile(); } catch (SDDSParserException &ex) { diff --git a/optimizer/Expression/SeptumExpr.h b/optimizer/Expression/SeptumExpr.h index 2db55b002..10f62ae2d 100644 --- a/optimizer/Expression/SeptumExpr.h +++ b/optimizer/Expression/SeptumExpr.h @@ -51,10 +51,10 @@ struct SeptumExpr { double result = 0.0; try { - boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(probe + std::string(".peaks"))); + const std::unique_ptr<PeakReader> sim_peaks(new PeakReader(probe + std::string(".peaks"))); sim_peaks->parseFile(); - boost::scoped_ptr<ProbeHistReader> sim_hist(new ProbeHistReader(probe + std::string(".hist"))); + const std::unique_ptr<ProbeHistReader> sim_hist(new ProbeHistReader(probe + std::string(".hist"))); sim_hist->parseFile(); double upperBound = 0.0; diff --git a/optimizer/Expression/SumErrSq.h b/optimizer/Expression/SumErrSq.h index e326d49ec..debea1d06 100644 --- a/optimizer/Expression/SumErrSq.h +++ b/optimizer/Expression/SumErrSq.h @@ -69,7 +69,7 @@ struct SumErrSq { parseMeasurements(measurement_filename); bool is_valid = true; - boost::scoped_ptr<SDDSReader> sim_stats(new SDDSReader(stat_filename_)); + const std::unique_ptr<SDDSReader> sim_stats(new SDDSReader(stat_filename_)); try { sim_stats->parseFile(); } catch (OptPilotException &ex) { diff --git a/optimizer/Expression/SumErrSqRadialPeak.h b/optimizer/Expression/SumErrSqRadialPeak.h index 3acf78c24..aea024720 100644 --- a/optimizer/Expression/SumErrSqRadialPeak.h +++ b/optimizer/Expression/SumErrSqRadialPeak.h @@ -35,7 +35,6 @@ #include "boost/type_traits/remove_cv.hpp" #include "boost/variant/get.hpp" #include "boost/variant/variant.hpp" -#include "boost/smart_ptr.hpp" #include "Util/Types.h" #include "Util/PeakReader.h" @@ -58,8 +57,8 @@ struct SumErrSqRadialPeak { bool is_valid = true; - boost::scoped_ptr<PeakReader> meas_peaks(new PeakReader(meas_filename_)); - boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_)); + const std::unique_ptr<PeakReader> meas_peaks(new PeakReader(meas_filename_)); + const std::unique_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_)); try { sim_peaks->parseFile(); meas_peaks->parseFile(); diff --git a/optimizer/Optimizer/EA/BlendCrossover.h b/optimizer/Optimizer/EA/BlendCrossover.h index c9c417b2e..0a6323ceb 100644 --- a/optimizer/Optimizer/EA/BlendCrossover.h +++ b/optimizer/Optimizer/EA/BlendCrossover.h @@ -26,14 +26,13 @@ // You should have received a copy of the GNU General Public License // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // -#include "boost/smart_ptr.hpp" #include "Util/CmdArguments.h" #include <cmath> template <class T> struct BlendCrossover { - void crossover(boost::shared_ptr<T> ind1, boost::shared_ptr<T> ind2, + void crossover(std::shared_ptr<T> ind1, std::shared_ptr<T> ind2, CmdArguments_t /*args*/) { // BLX-0.5 performs better than BLX operators with any other \alpha diff --git a/optimizer/Optimizer/EA/FixedPisaNsga2.h b/optimizer/Optimizer/EA/FixedPisaNsga2.h index 818f00564..84156e11d 100644 --- a/optimizer/Optimizer/EA/FixedPisaNsga2.h +++ b/optimizer/Optimizer/EA/FixedPisaNsga2.h @@ -55,7 +55,6 @@ #include "Optimizer/EA/Population.h" #include "Optimizer/EA/Variator.h" -#include <boost/smart_ptr.hpp> #include <boost/chrono.hpp> #include <boost/property_tree/ptree.hpp> @@ -103,7 +102,7 @@ public: Variator_t; typedef Population< Individual_t > Population_t; /// alias for usage in template - using individual = boost::shared_ptr<typename FixedPisaNsga2::Individual_t>; + using individual = std::shared_ptr<typename FixedPisaNsga2::Individual_t>; protected: @@ -155,9 +154,9 @@ private: PisaState_t curState_m; /// collect some statistics of rejected and accepted individuals - boost::scoped_ptr<Statistics<size_t> > statistics_; + const std::unique_ptr<Statistics<size_t> > statistics_; - boost::scoped_ptr<Variator_t> variator_m; + std::unique_ptr<Variator_t> variator_m; std::vector<unsigned int> pp_all; ///< IDs of population std::vector<unsigned int> parent_queue_; ///< IDs that will make new offspring @@ -180,7 +179,7 @@ private: std::map<size_t, individual > jobmapping_m; /// population of pareto-front (for final output) - boost::shared_ptr<Population_t> paretoFront_m; + std::shared_ptr<Population_t> paretoFront_m; /// indicating if initial population has been created bool initialized_m; @@ -247,8 +246,8 @@ private: boost::chrono::system_clock::time_point last_clock_; // DEBUG output helpers - boost::scoped_ptr<Trace> job_trace_; - boost::scoped_ptr<Trace> progress_; + std::unique_ptr<Trace> job_trace_; + std::unique_ptr<Trace> progress_; // entry point for starting the selector side of the PISA state machine @@ -279,9 +278,9 @@ private: bool checkParetoFront(unsigned int id); /// Dumps index, objective values and bit string of all individuals in /// global_population. - void dumpPopulation(boost::shared_ptr<Population_t>); - void dumpPopulationToFile(boost::shared_ptr<Population_t>, std::ostringstream& filename, bool dump_offspring); - void dumpPopulationToJSON(boost::shared_ptr<Population_t>, std::ostringstream& filename, bool dump_offspring); + void dumpPopulation(std::shared_ptr<Population_t>); + void dumpPopulationToFile(std::shared_ptr<Population_t>, std::ostringstream& filename, bool dump_offspring); + void dumpPopulationToJSON(std::shared_ptr<Population_t>, std::ostringstream& filename, bool dump_offspring); void dumpIndividualToFile(int id, individual& ind, std::ofstream& file, diff --git a/optimizer/Optimizer/EA/FixedPisaNsga2.tcc b/optimizer/Optimizer/EA/FixedPisaNsga2.tcc index 77c9a8cf9..13cd5ebe5 100644 --- a/optimizer/Optimizer/EA/FixedPisaNsga2.tcc +++ b/optimizer/Optimizer/EA/FixedPisaNsga2.tcc @@ -149,16 +149,16 @@ FixedPisaNsga2<CO, MO>::FixedPisaNsga2( trace_filename << "opt.trace." << comms_.island_id; job_trace_.reset(new Trace("Optimizer Job Trace")); job_trace_->registerComponent( "sink", - boost::shared_ptr<TraceComponent>( + std::shared_ptr<TraceComponent>( new FileSink(trace_filename.str()))); std::ostringstream prog_filename; prog_filename << "opt.progress." << comms_.island_id; progress_.reset(new Trace("Optimizer Progress")); progress_->registerComponent( "timestamp", - boost::shared_ptr<TraceComponent>(new Timestamp())); + std::shared_ptr<TraceComponent>(new Timestamp())); progress_->registerComponent( "sink", - boost::shared_ptr<TraceComponent>( + std::shared_ptr<TraceComponent>( new FileSink(prog_filename.str()))); statistics_->registerStatistic("accepted", 0); @@ -698,7 +698,7 @@ void FixedPisaNsga2<CO, MO>::runStateMachine() { } template< template <class> class CO, template <class> class MO > -void FixedPisaNsga2<CO, MO>::dumpPopulation(boost::shared_ptr<Population_t> population) { +void FixedPisaNsga2<CO, MO>::dumpPopulation(std::shared_ptr<Population_t> population) { std::ostringstream filename; int fileNumber = act_gen; if (dump_offspring_m == false) fileNumber--; // parents are from generation earlier (keeping filenumbers the same) @@ -713,7 +713,7 @@ void FixedPisaNsga2<CO, MO>::dumpPopulation(boost::shared_ptr<Population_t> popu } template< template <class> class CO, template <class> class MO > -void FixedPisaNsga2<CO, MO>::dumpPopulationToFile(boost::shared_ptr<Population_t> population, +void FixedPisaNsga2<CO, MO>::dumpPopulationToFile(std::shared_ptr<Population_t> population, std::ostringstream& filename, bool dump_offspring) { @@ -783,7 +783,7 @@ void FixedPisaNsga2<CO, MO>::dumpIndividualToFile(int idx, } template< template <class> class CO, template <class> class MO > -void FixedPisaNsga2<CO, MO>::dumpPopulationToJSON(boost::shared_ptr<Population_t> population, +void FixedPisaNsga2<CO, MO>::dumpPopulationToJSON(std::shared_ptr<Population_t> population, std::ostringstream& filename, bool dump_offspring) { diff --git a/optimizer/Optimizer/EA/IndependentBitMutation.h b/optimizer/Optimizer/EA/IndependentBitMutation.h index c9e285042..e3702ca12 100644 --- a/optimizer/Optimizer/EA/IndependentBitMutation.h +++ b/optimizer/Optimizer/EA/IndependentBitMutation.h @@ -19,12 +19,11 @@ // You should have received a copy of the GNU General Public License // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // -#include "boost/smart_ptr.hpp" #include "Util/CmdArguments.h" template <class T> struct IndependentBitMutation { - void mutate(boost::shared_ptr<T> ind, CmdArguments_t args) { + void mutate(std::shared_ptr<T> ind, CmdArguments_t args) { const double probability = args->getArg<double>("gene-mutation-probability", 0.5); diff --git a/optimizer/Optimizer/EA/Individual.h b/optimizer/Optimizer/EA/Individual.h index bc2cc9dc4..394982963 100644 --- a/optimizer/Optimizer/EA/Individual.h +++ b/optimizer/Optimizer/EA/Individual.h @@ -33,8 +33,6 @@ #include "Expression/Expression.h" -#include "boost/smart_ptr.hpp" - class Individual { public: @@ -83,7 +81,7 @@ public: } /// copy another individual - Individual(boost::shared_ptr<Individual> individual) { + Individual(std::shared_ptr<Individual> individual) { genes_m = genes_t(individual->genes_m); objectives_m = objectives_t(individual->objectives_m); bounds_m = bounds_t(individual->bounds_m); diff --git a/optimizer/Optimizer/EA/NaiveOnePointCrossover.h b/optimizer/Optimizer/EA/NaiveOnePointCrossover.h index a5a719bbd..60e350287 100644 --- a/optimizer/Optimizer/EA/NaiveOnePointCrossover.h +++ b/optimizer/Optimizer/EA/NaiveOnePointCrossover.h @@ -18,12 +18,11 @@ // You should have received a copy of the GNU General Public License // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // -#include "boost/smart_ptr.hpp" #include "Util/CmdArguments.h" template <class T> struct NaiveOnePointCrossover { - void crossover(boost::shared_ptr<T> ind1, boost::shared_ptr<T> ind2, + void crossover(std::shared_ptr<T> ind1, std::shared_ptr<T> ind2, CmdArguments_t /*args*/) { typedef typename T::genes_t genes_t; diff --git a/optimizer/Optimizer/EA/NaiveUniformCrossover.h b/optimizer/Optimizer/EA/NaiveUniformCrossover.h index ea00cbc1a..c33f2bf1d 100644 --- a/optimizer/Optimizer/EA/NaiveUniformCrossover.h +++ b/optimizer/Optimizer/EA/NaiveUniformCrossover.h @@ -19,12 +19,11 @@ // You should have received a copy of the GNU General Public License // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // -#include "boost/smart_ptr.hpp" #include "Util/CmdArguments.h" template <class T> struct NaiveUniformCrossover { - void crossover(boost::shared_ptr<T> ind1, boost::shared_ptr<T> ind2, + void crossover(std::shared_ptr<T> ind1, std::shared_ptr<T> ind2, CmdArguments_t /*args*/) { Individual::genes_t genes_ind2 = ind2->genes_m; diff --git a/optimizer/Optimizer/EA/OneBitMutation.h b/optimizer/Optimizer/EA/OneBitMutation.h index 3977060fc..25d4d4880 100644 --- a/optimizer/Optimizer/EA/OneBitMutation.h +++ b/optimizer/Optimizer/EA/OneBitMutation.h @@ -19,12 +19,11 @@ // You should have received a copy of the GNU General Public License // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // -#include "boost/smart_ptr.hpp" #include "Util/CmdArguments.h" template <class T> struct OneBitMutation { - void mutate(boost::shared_ptr<T> ind, CmdArguments_t /*args*/) { + void mutate(std::shared_ptr<T> ind, CmdArguments_t /*args*/) { int range = ind->genes_m.size(); int position = static_cast<int>((rand() / (RAND_MAX + 1.0)) * range); diff --git a/optimizer/Optimizer/EA/Population.h b/optimizer/Optimizer/EA/Population.h index 5ab2ca6c3..bd92c5409 100644 --- a/optimizer/Optimizer/EA/Population.h +++ b/optimizer/Optimizer/EA/Population.h @@ -36,8 +36,6 @@ #include <fstream> #include <sstream> -#include "boost/smart_ptr.hpp" - #include "extlib/wfgHypervolume/hypervolume.h" @@ -52,7 +50,7 @@ public: ~Population() {} typedef typename Individual_t::genes_t genes_t; - typedef boost::shared_ptr<Individual_t> individual; + typedef std::shared_ptr<Individual_t> individual; typedef std::pair< unsigned int, individual > ind_t; /// population iterator type diff --git a/optimizer/Optimizer/EA/SimulatedBinaryCrossover.h b/optimizer/Optimizer/EA/SimulatedBinaryCrossover.h index 2d3696adf..68f4eceea 100644 --- a/optimizer/Optimizer/EA/SimulatedBinaryCrossover.h +++ b/optimizer/Optimizer/EA/SimulatedBinaryCrossover.h @@ -23,13 +23,12 @@ // #include <cmath> -#include "boost/smart_ptr.hpp" #include "Util/CmdArguments.h" template <class T> struct SimulatedBinaryCrossover { - void crossover(boost::shared_ptr<T> ind1, boost::shared_ptr<T> ind2, + void crossover(std::shared_ptr<T> ind1, std::shared_ptr<T> ind2, CmdArguments_t args) { double nu_c = args->getArg<double>("simbin-crossover-nu", 2.0, false); diff --git a/optimizer/Optimizer/EA/Variator.h b/optimizer/Optimizer/EA/Variator.h index 2fa721a72..391fc4a02 100644 --- a/optimizer/Optimizer/EA/Variator.h +++ b/optimizer/Optimizer/EA/Variator.h @@ -26,8 +26,6 @@ #include <map> #include <utility> -#include "boost/smart_ptr.hpp" - #include "Util/Types.h" #include "Util/CmdArguments.h" #include "Optimizer/EA/Population.h" @@ -70,7 +68,7 @@ public: } //FIXME: pass population as arg to variator - //boost::shared_ptr< Population<ind_t> > + //std::shared_ptr< Population<ind_t> > population_m.reset(new Population<ind_t>()); mutationProbability_m = @@ -86,7 +84,7 @@ public: } //FIXME access population from outside - boost::shared_ptr< Population<ind_t> > population() { + std::shared_ptr< Population<ind_t> > population() { return population_m; } @@ -155,7 +153,7 @@ public: } /// set an individual as infeasible: replace with a new individual - void infeasible(boost::shared_ptr<ind_t> ind) { + void infeasible(std::shared_ptr<ind_t> ind) { population_m->remove_individual(ind); new_individual(); } @@ -166,7 +164,7 @@ public: } /// return next individual to evaluate - boost::shared_ptr<ind_t> popIndividualToEvaluate() { + std::shared_ptr<ind_t> popIndividualToEvaluate() { unsigned int ind = individualsToEvaluate_m.front(); individualsToEvaluate_m.pop(); return population_m->get_staging(ind); @@ -191,13 +189,13 @@ public: // pop first individual unsigned int idx = tmp.front(); tmp.pop(); - boost::shared_ptr<ind_t> a = population_m->get_staging(idx); + std::shared_ptr<ind_t> a = population_m->get_staging(idx); // handle special case where we have an odd number of offspring if(tmp.empty()) { if (drand(1) <= mutationProbability_m) { // temporary copy in case not successful - boost::shared_ptr<ind_t> copyA(new ind_t(a)); + std::shared_ptr<ind_t> copyA(new ind_t(a)); int iter = 0; while (true) { // assign with shared pointer constructor @@ -219,13 +217,13 @@ public: // and second if any idx = tmp.front(); tmp.pop(); - boost::shared_ptr<ind_t> b = population_m->get_staging(idx); + std::shared_ptr<ind_t> b = population_m->get_staging(idx); // create new individuals // temporary copy in case not successful - boost::shared_ptr<ind_t> copyA(new ind_t(a)); - boost::shared_ptr<ind_t> copyB(new ind_t(b)); + std::shared_ptr<ind_t> copyA(new ind_t(a)); + std::shared_ptr<ind_t> copyB(new ind_t(b)); int iter = 0; while (true) { @@ -271,20 +269,20 @@ protected: /// create a new individual void new_individual(Individual::genes_t& dvars) { - boost::shared_ptr<ind_t> ind(new ind_t(dVarBounds_m, dNames_m, constraints_m)); + std::shared_ptr<ind_t> ind(new ind_t(dVarBounds_m, dNames_m, constraints_m)); std::swap(ind->genes_m, dvars); individualsToEvaluate_m.push( population_m->add_individual(ind) ); } /// create a new individual void new_individual() { - boost::shared_ptr<ind_t> ind(new ind_t(dVarBounds_m, dNames_m, constraints_m)); + std::shared_ptr<ind_t> ind(new ind_t(dVarBounds_m, dNames_m, constraints_m)); individualsToEvaluate_m.push( population_m->add_individual(ind) ); } /// copy an individual - void new_individual(boost::shared_ptr<ind_t> ind) { - boost::shared_ptr<ind_t> return_ind(new ind_t(ind)); + void new_individual(std::shared_ptr<ind_t> ind) { + std::shared_ptr<ind_t> return_ind(new ind_t(ind)); individualsToEvaluate_m.push( population_m->add_individual(return_ind) ) ; } @@ -292,7 +290,7 @@ protected: private: /// population of individuals - boost::shared_ptr< Population<ind_t> > population_m; + std::shared_ptr< Population<ind_t> > population_m; /// user specified command line arguments CmdArguments_t args_; diff --git a/optimizer/Pilot/Pilot.h b/optimizer/Pilot/Pilot.h index 197c8c454..57eb763d4 100644 --- a/optimizer/Pilot/Pilot.h +++ b/optimizer/Pilot/Pilot.h @@ -44,9 +44,6 @@ #include <string> #include <unistd.h> -#include "boost/smart_ptr.hpp" -//#include "boost/dynamic_bitset.hpp" - #include "Comm/MasterNode.h" #include "Comm/CommSplitter.h" @@ -105,7 +102,7 @@ public: // constructor only for Pilot classes inherited from this class // they have their own setup function - Pilot(CmdArguments_t args, boost::shared_ptr<Comm_t> comm, + Pilot(CmdArguments_t args, std::shared_ptr<Comm_t> comm, const DVarContainer_t &dvar) : Poller(comm->mpiComm()) , comm_(comm) @@ -115,7 +112,7 @@ public: // do nothing } - Pilot(CmdArguments_t args, boost::shared_ptr<Comm_t> comm, + Pilot(CmdArguments_t args, std::shared_ptr<Comm_t> comm, functionDictionary_t known_expr_funcs) : Poller(comm->mpiComm()) , comm_(comm) @@ -124,7 +121,7 @@ public: setup(known_expr_funcs); } - Pilot(CmdArguments_t args, boost::shared_ptr<Comm_t> comm, + Pilot(CmdArguments_t args, std::shared_ptr<Comm_t> comm, functionDictionary_t known_expr_funcs, const DVarContainer_t &dvar, const Expressions::Named_t &obj, @@ -163,7 +160,7 @@ protected: /// MPI communicator used for messages between all pilots MPI_Comm coworker_comm_; - boost::shared_ptr<Comm_t> comm_; + std::shared_ptr<Comm_t> comm_; CmdArguments_t cmd_args_; int global_rank_; @@ -174,7 +171,7 @@ protected: typedef MasterNode< typename Opt_t::SolutionState_t, SolPropagationGraph_t > MasterNode_t; - boost::scoped_ptr< MasterNode_t > master_node_; + std::unique_ptr< MasterNode_t > master_node_; /// input file for simulation with embedded optimization problem std::string input_file_; @@ -191,7 +188,6 @@ protected: // keep track of state of all workers std::vector<bool> is_worker_idle_; - //boost::dynamic_bitset<> is_worker_idle_; /// keep track of requests and running jobs typedef std::map<size_t, std::pair<Param_t, reqVarContainer_t> > Jobs_t; @@ -200,7 +196,7 @@ protected: Jobs_t request_queue_; //DEBUG - boost::scoped_ptr<Trace> job_trace_; + std::unique_ptr<Trace> job_trace_; private: void setup(functionDictionary_t known_expr_funcs, @@ -277,7 +273,7 @@ protected: << "\e[0m" << std::endl; std::cout << os.str() << std::flush; - boost::scoped_ptr<Opt_t> opt( + const std::unique_ptr<Opt_t> opt( new Opt_t(objectives_, constraints_, dvars_, objectives_.size(), comm_->getBundle(), cmd_args_, hypervolRef_, comm_->getNrWorkerGroups())); opt->initialize(); @@ -300,7 +296,7 @@ protected: pos = tmplfile.find("."); std::string simName = tmplfile.substr(0,pos); - boost::scoped_ptr< Worker<Sim_t> > w( + const std::unique_ptr< Worker<Sim_t> > w( new Worker<Sim_t>(objectives_, constraints_, simName, comm_->getBundle(), cmd_args_, userVariables)); @@ -320,7 +316,7 @@ protected: trace_filename << "pilot.trace." << comm_->getBundle().island_id; job_trace_.reset(new Trace("Optimizer Job Trace")); job_trace_->registerComponent( "sink", - boost::shared_ptr<TraceComponent>(new FileSink(trace_filename.str()))); + std::shared_ptr<TraceComponent>(new FileSink(trace_filename.str()))); worker_comm_ = comm_->getBundle().worker; opt_comm_ = comm_->getBundle().opt; diff --git a/optimizer/Pilot/Worker.h b/optimizer/Pilot/Worker.h index fd9876e0e..9476836f2 100644 --- a/optimizer/Pilot/Worker.h +++ b/optimizer/Pilot/Worker.h @@ -32,8 +32,6 @@ #include <iostream> -#include "boost/smart_ptr.hpp" - #include "Pilot/Poller.h" #include "Comm/types.h" @@ -100,7 +98,7 @@ public: protected: - typedef boost::scoped_ptr<Sim_t> SimPtr_t; + typedef const std::unique_ptr<Sim_t> SimPtr_t; bool is_idle_; MPI_Comm coworker_comm_; diff --git a/optimizer/Tests/CmdArgumentsTest.cpp b/optimizer/Tests/CmdArgumentsTest.cpp index 04f2183e1..8f4d27be4 100644 --- a/optimizer/Tests/CmdArgumentsTest.cpp +++ b/optimizer/Tests/CmdArgumentsTest.cpp @@ -20,7 +20,6 @@ // #include "Util/CmdArguments.h" #include "gtest/gtest.h" -#include "boost/smart_ptr.hpp" namespace { @@ -57,7 +56,7 @@ namespace { } // Objects declared here can be used by all tests in the test case - boost::scoped_ptr<CmdArguments> args_; + std::unique_ptr<CmdArguments> args_; }; TEST_F(CmdArgumentsTest, RetrieveCorrectFatal) { diff --git a/optimizer/Tests/ExpressionTest.cpp b/optimizer/Tests/ExpressionTest.cpp index 3e98942cf..654d220fa 100644 --- a/optimizer/Tests/ExpressionTest.cpp +++ b/optimizer/Tests/ExpressionTest.cpp @@ -28,7 +28,6 @@ #include "gtest/gtest.h" -#include "boost/smart_ptr.hpp" #include "boost/tuple/tuple.hpp" #include "boost/variant/get.hpp" #include "boost/variant/variant.hpp" @@ -94,7 +93,7 @@ struct my_pow { TEST_F(ExpressionTest, RequestedVars) { std::string testexpr = "abs(A * A * 2.0 * b + 2.0)"; - boost::scoped_ptr<Expression> e(new Expression(testexpr)); + const std::unique_ptr<Expression> e(new Expression(testexpr)); std::set<std::string> reqVars = e->getReqVars(); @@ -111,7 +110,7 @@ struct my_pow { ("abs", abs_func)); std::string testexpr = "abs(1.0 + A * A * 2.0 * B + 2.0)"; - boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs)); + const std::unique_ptr<Expression> e(new Expression(testexpr, funcs)); double a = 5.2; double b = -10.2; @@ -140,7 +139,7 @@ struct my_pow { ("abs", abs_func)); std::string testexpr = "abs(1.0 + A * 2.0) + abs(B + 2.0)"; - boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs)); + const std::unique_ptr<Expression> e(new Expression(testexpr, funcs)); double a = 5.2; double b = -10.2; @@ -173,7 +172,7 @@ struct my_pow { ("pow", pow_func)); std::string testexpr = "abs(1.0 + pow(A, 3) * 2.0) + abs(B + 2.0)"; - boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs)); + const std::unique_ptr<Expression> e(new Expression(testexpr, funcs)); double a = 5.2; double b = -10.2; @@ -196,7 +195,7 @@ struct my_pow { TEST_F(ExpressionTest, EvaluateBooleanExpression) { std::string testexpr = "a > 5.2 - 1e-6"; - boost::scoped_ptr<Expression> e(new Expression(testexpr)); + const std::unique_ptr<Expression> e(new Expression(testexpr)); double a = 5.2; diff --git a/optimizer/Tests/FromFileExpressionTest.cpp b/optimizer/Tests/FromFileExpressionTest.cpp index 98bb59d14..184cde74a 100644 --- a/optimizer/Tests/FromFileExpressionTest.cpp +++ b/optimizer/Tests/FromFileExpressionTest.cpp @@ -28,7 +28,6 @@ #include "gtest/gtest.h" -#include "boost/smart_ptr.hpp" #include "boost/tuple/tuple.hpp" #include "boost/variant/get.hpp" #include "boost/variant/variant.hpp" @@ -95,7 +94,7 @@ struct my_pow { ("fromFile", ff)); std::string testexpr = "fromFile(\"resources/fromfile_test.dat\")"; - boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs)); + const std::unique_ptr<Expression> e(new Expression(testexpr, funcs)); Expressions::Result_t result; EXPECT_NO_THROW({ result = e->evaluate(vars); @@ -126,7 +125,7 @@ struct my_pow { std::string testexpr = "sqrt(pow(fromFile(\"resources/fromfile_test.dat\"), 2) + " "pow(fromFile(\"resources/fromfile_test2.dat\"), 2))"; - boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs)); + const std::unique_ptr<Expression> e(new Expression(testexpr, funcs)); Expressions::Result_t result; EXPECT_NO_THROW({ result = e->evaluate(vars); diff --git a/optimizer/Tests/IndividualTest.cpp b/optimizer/Tests/IndividualTest.cpp index be7a39dba..d6fd74bc1 100644 --- a/optimizer/Tests/IndividualTest.cpp +++ b/optimizer/Tests/IndividualTest.cpp @@ -22,8 +22,6 @@ #include "Optimizer/EA/Individual.h" #include "gtest/gtest.h" -#include "boost/smart_ptr.hpp" - #include <string> namespace { @@ -55,7 +53,7 @@ namespace { // before the destructor). } - boost::shared_ptr<Individual> createIndividual(size_t num_genes, std::string constraint="") { + std::shared_ptr<Individual> createIndividual(size_t num_genes, std::string constraint="") { Individual::bounds_t bounds; Individual::names_t names; @@ -69,7 +67,7 @@ namespace { constraints.insert(std::pair<std::string,Expressions::Expr_t*> ("constraint0",new Expressions::Expr_t(constraint))); - boost::shared_ptr<Individual> ind(new Individual(bounds,names,constraints)); + std::shared_ptr<Individual> ind(new Individual(bounds,names,constraints)); return ind; } @@ -80,7 +78,7 @@ namespace { TEST_F(IndividualTest, IndividualRespectsBounds) { size_t num_genes = 1; - boost::shared_ptr<Individual> ind = createIndividual(num_genes); + std::shared_ptr<Individual> ind = createIndividual(num_genes); double gene = ind->genes_m[0]; EXPECT_LE(lower_bound_, gene) << "gene should respect lower bound"; @@ -95,7 +93,7 @@ namespace { TEST_F(IndividualTest, IndividualHasCorrectNumberOfGenes) { size_t num_genes = 12; - boost::shared_ptr<Individual> ind = createIndividual(num_genes); + std::shared_ptr<Individual> ind = createIndividual(num_genes); size_t my_size = ind->genes_m.size(); EXPECT_EQ(static_cast<size_t>(num_genes), my_size) @@ -106,7 +104,7 @@ namespace { TEST_F(IndividualTest, IndividualRandomGene) { size_t num_genes = 1; - boost::shared_ptr<Individual> ind = createIndividual(num_genes); + std::shared_ptr<Individual> ind = createIndividual(num_genes); double gene = ind->genes_m[0]; double new_gene = ind->new_gene(0); @@ -121,7 +119,7 @@ namespace { // create several individuals to test for (int i=0; i<10; i++) { - boost::shared_ptr<Individual> ind = createIndividual(num_genes,constraint); + std::shared_ptr<Individual> ind = createIndividual(num_genes,constraint); double gene0 = ind->genes_m[0]; double gene1 = ind->genes_m[1]; EXPECT_LE((gene0+gene1)/2, half) << "constraint should be respected"; diff --git a/optimizer/Tests/ManagedIDsTest.cpp b/optimizer/Tests/ManagedIDsTest.cpp index 00d9fdbde..f9d088c20 100644 --- a/optimizer/Tests/ManagedIDsTest.cpp +++ b/optimizer/Tests/ManagedIDsTest.cpp @@ -20,7 +20,6 @@ // #include "Util/ManagedIDs.h" #include "gtest/gtest.h" -#include "boost/smart_ptr.hpp" namespace { @@ -51,7 +50,7 @@ namespace { } // Objects declared here can be used by all tests in the test case - boost::scoped_ptr<ManagedIDs> ids_; + std::unique_ptr<ManagedIDs> ids_; }; TEST_F(ManagedIDsTest, OneID) { diff --git a/optimizer/Tests/PopulationTest.cpp b/optimizer/Tests/PopulationTest.cpp index f5e1ccfe5..3553b709c 100644 --- a/optimizer/Tests/PopulationTest.cpp +++ b/optimizer/Tests/PopulationTest.cpp @@ -22,8 +22,6 @@ #include "Optimizer/EA/Individual.h" #include "gtest/gtest.h" -#include "boost/smart_ptr.hpp" - namespace { // The fixture for testing class Foo. @@ -53,7 +51,7 @@ namespace { // population_->clean_population(); } - boost::shared_ptr<Individual> createIndividual(size_t num_genes) { + std::shared_ptr<Individual> createIndividual(size_t num_genes) { Individual::bounds_t bounds; Individual::names_t names; @@ -63,24 +61,24 @@ namespace { names.push_back("dvar"+std::to_string(i)); } - boost::shared_ptr<Individual> ind(new Individual(bounds,names,constraints)); + std::shared_ptr<Individual> ind(new Individual(bounds,names,constraints)); return ind; } // Objects declared here can be used by all tests in the test case - boost::scoped_ptr< Population<Individual> > population_; + std::unique_ptr< Population<Individual> > population_; }; TEST_F(PopulationTest, AddOneIndividual) { - boost::shared_ptr<Individual> ind = createIndividual(1); + std::shared_ptr<Individual> ind = createIndividual(1); unsigned int id = population_->add_individual(ind); double gene = ind->genes_m[0]; double obj = ind->objectives_m[0]; EXPECT_EQ(static_cast<size_t>(0), id) << "first individuals id should be 0"; - boost::shared_ptr<Individual> tmp = population_->get_individual(id); + std::shared_ptr<Individual> tmp = population_->get_individual(id); EXPECT_EQ(0, tmp.get()) << "no committed individuals after insert"; tmp = population_->get_staging(id); @@ -95,7 +93,7 @@ namespace { TEST_F(PopulationTest, CommitOneIndividual) { - boost::shared_ptr<Individual> ind = createIndividual(1); + std::shared_ptr<Individual> ind = createIndividual(1); unsigned int id = population_->add_individual(ind); double gene = ind->genes_m[0]; double obj = ind->objectives_m[0]; @@ -104,7 +102,7 @@ namespace { population_->commit_individuals(); - boost::shared_ptr<Individual> tmp = population_->get_staging(id); + std::shared_ptr<Individual> tmp = population_->get_staging(id); EXPECT_EQ(0, tmp.get()) << "no staging individuals after commit"; tmp = population_->get_individual(id); @@ -118,10 +116,10 @@ namespace { TEST_F(PopulationTest, KeepIndividuals) { - boost::shared_ptr<Individual> ind1 = createIndividual(1); - boost::shared_ptr<Individual> ind2 = createIndividual(1); - boost::shared_ptr<Individual> ind3 = createIndividual(1); - boost::shared_ptr<Individual> ind4 = createIndividual(1); + std::shared_ptr<Individual> ind1 = createIndividual(1); + std::shared_ptr<Individual> ind2 = createIndividual(1); + std::shared_ptr<Individual> ind3 = createIndividual(1); + std::shared_ptr<Individual> ind4 = createIndividual(1); size_t id0 = population_->add_individual(ind1); EXPECT_EQ(static_cast<size_t>(0), id0); @@ -143,17 +141,17 @@ namespace { size_t size = population_->size(); EXPECT_EQ(survivors.size(), size); - boost::shared_ptr<Individual> tmp = population_->get_individual(id1); + std::shared_ptr<Individual> tmp = population_->get_individual(id1); EXPECT_EQ(ind2->genes_m[0], tmp->genes_m[0]); EXPECT_EQ(ind2->objectives_m[0], tmp->objectives_m[0]); } TEST_F(PopulationTest, IDsContinuous) { - boost::shared_ptr<Individual> ind0 = createIndividual(1); - boost::shared_ptr<Individual> ind1 = createIndividual(1); - boost::shared_ptr<Individual> ind2 = createIndividual(1); - boost::shared_ptr<Individual> ind3 = createIndividual(1); + std::shared_ptr<Individual> ind0 = createIndividual(1); + std::shared_ptr<Individual> ind1 = createIndividual(1); + std::shared_ptr<Individual> ind2 = createIndividual(1); + std::shared_ptr<Individual> ind3 = createIndividual(1); size_t id0 = population_->add_individual(ind0); EXPECT_EQ(static_cast<size_t>(0), id0); @@ -167,30 +165,30 @@ namespace { unsigned int individual_to_be_removed_id = 1; population_->remove_individual(ind1); - boost::shared_ptr<Individual> newind = createIndividual(1); + std::shared_ptr<Individual> newind = createIndividual(1); unsigned int id_new = population_->add_individual(newind); EXPECT_EQ(individual_to_be_removed_id, id_new); - boost::shared_ptr<Individual> tmp = population_->get_staging(id_new); + std::shared_ptr<Individual> tmp = population_->get_staging(id_new); EXPECT_EQ(newind->genes_m[0], tmp->genes_m[0]); EXPECT_EQ(newind->objectives_m[0], tmp->objectives_m[0]); } TEST_F(PopulationTest, FindNonExistingStaging) { - boost::shared_ptr<Individual> tmp = population_->get_staging(124); + std::shared_ptr<Individual> tmp = population_->get_staging(124); EXPECT_EQ(0, tmp.get()); } TEST_F(PopulationTest, FindNonExistingIndividual) { - boost::shared_ptr<Individual> tmp = population_->get_individual(124); + std::shared_ptr<Individual> tmp = population_->get_individual(124); EXPECT_EQ(0, tmp.get()); } TEST_F(PopulationTest, RepresentedCheck) { - boost::shared_ptr<Individual> ind = createIndividual(1); + std::shared_ptr<Individual> ind = createIndividual(1); population_->add_individual(ind); population_->add_individual(ind); diff --git a/optimizer/Tests/PythonExprTest.cpp b/optimizer/Tests/PythonExprTest.cpp index 10d6cdfa2..6e6829324 100644 --- a/optimizer/Tests/PythonExprTest.cpp +++ b/optimizer/Tests/PythonExprTest.cpp @@ -29,7 +29,6 @@ #include "gtest/gtest.h" -#include "boost/smart_ptr.hpp" #include "boost/tuple/tuple.hpp" #include "boost/variant/get.hpp" #include "boost/variant/variant.hpp" @@ -77,7 +76,7 @@ namespace { ("python", python)); std::string testexpr = "python(\"resources/test.py\", 1.0)"; - boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs)); + const std::unique_ptr<Expression> e(new Expression(testexpr, funcs)); Expressions::Result_t result; EXPECT_NO_THROW({ result = e->evaluate(vars); diff --git a/optimizer/Tests/SumErrSqExpressionTest.cpp b/optimizer/Tests/SumErrSqExpressionTest.cpp index 382fe4d94..aa46f1478 100644 --- a/optimizer/Tests/SumErrSqExpressionTest.cpp +++ b/optimizer/Tests/SumErrSqExpressionTest.cpp @@ -29,7 +29,6 @@ #include "gtest/gtest.h" -#include "boost/smart_ptr.hpp" #include "boost/tuple/tuple.hpp" #include "boost/type_traits/remove_cv.hpp" #include "boost/variant/get.hpp" @@ -80,7 +79,7 @@ namespace { ("sumErrSq", errsumsq)); std::string testexpr = "sumErrSq(\"resources/measurement_test.dat\", \"rms_x\", \"resources/test.stat\")"; - boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs)); + const std::unique_ptr<Expression> e(new Expression(testexpr, funcs)); Expressions::Result_t result; EXPECT_NO_THROW({ result = e->evaluate(vars); diff --git a/optimizer/Util/AsyncSendBuffers.h b/optimizer/Util/AsyncSendBuffers.h index 68e001de3..b19fed347 100644 --- a/optimizer/Util/AsyncSendBuffers.h +++ b/optimizer/Util/AsyncSendBuffers.h @@ -22,7 +22,6 @@ #include <algorithm> #include <string.h> #include "mpi.h" -#include "boost/smart_ptr.hpp" #include "boost/bind.hpp" class AsyncSendBuffer { @@ -80,7 +79,7 @@ class AsyncSendBuffers { public: AsyncSendBuffers() {} - void insert(boost::shared_ptr<AsyncSendBuffer> buf) { + void insert(std::shared_ptr<AsyncSendBuffer> buf) { collection_.push_back(buf); } @@ -95,6 +94,6 @@ public: } private: - std::vector< boost::shared_ptr<AsyncSendBuffer> > collection_; + std::vector< std::shared_ptr<AsyncSendBuffer> > collection_; }; diff --git a/optimizer/Util/CmdArguments.h b/optimizer/Util/CmdArguments.h index 2f079944e..cb2d61dc9 100644 --- a/optimizer/Util/CmdArguments.h +++ b/optimizer/Util/CmdArguments.h @@ -34,7 +34,6 @@ #include <sstream> #include <set> -#include "boost/smart_ptr.hpp" #include "boost/utility/value_init.hpp" #include "Util/OptPilotException.h" @@ -173,7 +172,7 @@ private: }; -typedef boost::shared_ptr<CmdArguments> CmdArguments_t; +typedef std::shared_ptr<CmdArguments> CmdArguments_t; template<class T> inline T CmdArguments::arg(const std::string name) { diff --git a/optimizer/Util/Trace/Trace.h b/optimizer/Util/Trace/Trace.h index 3f3e24c74..086a66f2f 100644 --- a/optimizer/Util/Trace/Trace.h +++ b/optimizer/Util/Trace/Trace.h @@ -26,8 +26,6 @@ #include <vector> #include <map> -#include "boost/smart_ptr.hpp" - #include "Util/Trace/TraceComponent.h" class Trace { @@ -42,7 +40,7 @@ public: {} void registerComponent(std::string name, - boost::shared_ptr<TraceComponent> component) { + std::shared_ptr<TraceComponent> component) { nameToIdx_.insert( std::pair<std::string, size_t>(name, pipeline_.size())); pipeline_.push_back(component); @@ -53,7 +51,7 @@ public: } void log(std::ostringstream &dump) { - for(boost::shared_ptr<TraceComponent> component : pipeline_) { + for(std::shared_ptr<TraceComponent> component : pipeline_) { component->execute(dump); } } @@ -62,7 +60,7 @@ private: std::string name_; - std::vector< boost::shared_ptr<TraceComponent> > pipeline_; + std::vector< std::shared_ptr<TraceComponent> > pipeline_; std::map< std::string, size_t > nameToIdx_; }; diff --git a/src/Optimize/OpalSimulation.cpp b/src/Optimize/OpalSimulation.cpp index 3c195d3ed..fd4c0f313 100644 --- a/src/Optimize/OpalSimulation.cpp +++ b/src/Optimize/OpalSimulation.cpp @@ -539,9 +539,9 @@ void OpalSimulation::collectResults() { boost::trim_left_if(rhs_constr_str, boost::is_any_of("=")); functionDictionary_t funcs = constraint->getRegFuncs(); - boost::scoped_ptr<Expressions::Expr_t> lhs( + const std::unique_ptr<Expressions::Expr_t> lhs( new Expressions::Expr_t(lhs_constr_str, funcs)); - boost::scoped_ptr<Expressions::Expr_t> rhs( + const std::unique_ptr<Expressions::Expr_t> rhs( new Expressions::Expr_t(rhs_constr_str, funcs)); Expressions::Result_t lhs_res = lhs->evaluate(variable_dictionary); @@ -599,7 +599,7 @@ void OpalSimulation::getVariableDictionary(variableDictionary_t& dictionary, if(req_vars.empty()) return; // get remaining required variable values from the stat file - boost::scoped_ptr<SDDSReader> sddsr(new SDDSReader(filename)); + const std::unique_ptr<SDDSReader> sddsr(new SDDSReader(filename)); sddsr->parseFile(); for(std::string req_var : req_vars) { diff --git a/src/Optimize/OpalSimulation.h b/src/Optimize/OpalSimulation.h index 9bdf80435..28053e271 100644 --- a/src/Optimize/OpalSimulation.h +++ b/src/Optimize/OpalSimulation.h @@ -102,7 +102,7 @@ private: MPI_Comm comm_; /// object to generate simulation input files - boost::scoped_ptr<GenerateOpalSimulation> gs_; + std::unique_ptr<GenerateOpalSimulation> gs_; /// job id (SAMPLE command) int id_m; diff --git a/src/Optimize/OptimizeCmd.cpp b/src/Optimize/OptimizeCmd.cpp index aacb44756..7dc555dc1 100644 --- a/src/Optimize/OptimizeCmd.cpp +++ b/src/Optimize/OptimizeCmd.cpp @@ -588,7 +588,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef CommSplitter< ManyMasterSplit< NoCommTopology > > Comm_t; typedef SocialNetworkGraph< NoCommTopology > SolPropagationGraph_t; - boost::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD)); + std::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD)); if (comm->isWorker()) stashEnvironment(); @@ -604,7 +604,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef FixedPisaNsga2< BlendCrossover, IndependentBitMutation > Opt_t; typedef Pilot<Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t; - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, constraints, Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]), @@ -616,7 +616,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef FixedPisaNsga2< BlendCrossover, OneBitMutation > Opt_t; typedef Pilot<Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t; - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, constraints, Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]), @@ -628,7 +628,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef FixedPisaNsga2< NaiveOnePointCrossover, IndependentBitMutation > Opt_t; typedef Pilot<Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t; - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, constraints, Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]), @@ -640,7 +640,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef FixedPisaNsga2< NaiveOnePointCrossover, OneBitMutation > Opt_t; typedef Pilot<Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t; - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, constraints, Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]), @@ -652,7 +652,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef FixedPisaNsga2< NaiveUniformCrossover, IndependentBitMutation > Opt_t; typedef Pilot<Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t; - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, constraints, Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]), @@ -664,7 +664,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef FixedPisaNsga2< NaiveUniformCrossover, OneBitMutation > Opt_t; typedef Pilot<Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t; - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, constraints, Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]), @@ -676,7 +676,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef FixedPisaNsga2< SimulatedBinaryCrossover, IndependentBitMutation > Opt_t; typedef Pilot<Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t; - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, constraints, Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]), @@ -688,7 +688,7 @@ void OptimizeCmd::run(const CmdArguments_t& args, typedef FixedPisaNsga2< SimulatedBinaryCrossover, OneBitMutation > Opt_t; typedef Pilot<Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t; - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, constraints, Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]), diff --git a/src/Sample/FromFile.h b/src/Sample/FromFile.h index 294a87341..ccb76421a 100644 --- a/src/Sample/FromFile.h +++ b/src/Sample/FromFile.h @@ -78,7 +78,7 @@ public: in.close(); } - void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) { + void create(std::shared_ptr<SampleIndividual>& ind, size_t i) { ind->genes[i] = getNext(ind->id); } diff --git a/src/Sample/LatinHyperCube.h b/src/Sample/LatinHyperCube.h index 1de85281a..77ed60fc9 100644 --- a/src/Sample/LatinHyperCube.h +++ b/src/Sample/LatinHyperCube.h @@ -56,7 +56,7 @@ public: RNGStream::deleteInstance(RNGInstance_m); } - void create(boost::shared_ptr<SampleIndividual>& ind, std::size_t i) { + void create(std::shared_ptr<SampleIndividual>& ind, std::size_t i) { /* values are created within [0, 1], thus, they need to be mapped * the domain [lower, upper] */ diff --git a/src/Sample/Normal.h b/src/Sample/Normal.h index c12e98090..936d666c0 100644 --- a/src/Sample/Normal.h +++ b/src/Sample/Normal.h @@ -47,7 +47,7 @@ public: RNGStream::deleteInstance(RNGInstance_m); } - void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) { + void create(std::shared_ptr<SampleIndividual>& ind, size_t i) { ind->genes[i] = RNGInstance_m->getNext(dist_m); } diff --git a/src/Sample/SampleCmd.cpp b/src/Sample/SampleCmd.cpp index c22a36391..b9dcbbc75 100644 --- a/src/Sample/SampleCmd.cpp +++ b/src/Sample/SampleCmd.cpp @@ -468,7 +468,7 @@ void SampleCmd::execute() { try { CmdArguments_t args(new CmdArguments(argv.size(), &argv[0])); - boost::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD)); + std::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD)); if (comm->isWorker()) stashEnvironment(); @@ -480,7 +480,7 @@ void SampleCmd::execute() { } } - boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, + const std::unique_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, sampleMethods, storeobjstr, filesToKeep, userVariables)); if (comm->isWorker()) diff --git a/src/Sample/SampleGaussianSequence.h b/src/Sample/SampleGaussianSequence.h index 9d47fd324..d9b4c259b 100644 --- a/src/Sample/SampleGaussianSequence.h +++ b/src/Sample/SampleGaussianSequence.h @@ -52,7 +52,7 @@ public: } } - void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) { + void create(std::shared_ptr<SampleIndividual>& ind, size_t i) { ind->genes[i] = getNext(ind->id); } diff --git a/src/Sample/SamplePilot.h b/src/Sample/SamplePilot.h index 0e05cc436..827e4c12c 100644 --- a/src/Sample/SamplePilot.h +++ b/src/Sample/SamplePilot.h @@ -51,7 +51,7 @@ class SamplePilot : protected Pilot<Opt_t, public: - SamplePilot(CmdArguments_t args, boost::shared_ptr<Comm_t> comm, + SamplePilot(CmdArguments_t args, std::shared_ptr<Comm_t> comm, functionDictionary_t known_expr_funcs, const DVarContainer_t &dvar, const Expressions::Named_t &obj, @@ -124,7 +124,7 @@ protected: << "\e[0m" << std::endl; std::cout << os.str() << std::flush; - boost::scoped_ptr<Opt_t> opt( + const std::unique_ptr<Opt_t> opt( new Opt_t(sampleMethods_m, this->objectives_, this->dvars_, this->comm_->getBundle(), this->cmd_args_)); opt->initialize(); @@ -149,7 +149,7 @@ protected: pos = tmplfile.find("."); std::string simName = tmplfile.substr(0,pos); - boost::scoped_ptr< SampleWorker<Sim_t> > w( + const std::unique_ptr< SampleWorker<Sim_t> > w( new SampleWorker<Sim_t>(this->objectives_, this->constraints_, simName, this->comm_->getBundle(), this->cmd_args_, storeobjstr, filesToKeep, userVariables)); diff --git a/src/Sample/SampleRandomizedSequence.h b/src/Sample/SampleRandomizedSequence.h index b105b9296..d285a9113 100644 --- a/src/Sample/SampleRandomizedSequence.h +++ b/src/Sample/SampleRandomizedSequence.h @@ -42,7 +42,7 @@ public: , step_m(step) { } - void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) { + void create(std::shared_ptr<SampleIndividual>& ind, size_t i) { size_t idx = unif_m.getNext(); ind->genes[i] = static_cast<T>(lower_m + idx * step_m); } diff --git a/src/Sample/SampleSequence.h b/src/Sample/SampleSequence.h index caeeefec6..d40bbd1d8 100644 --- a/src/Sample/SampleSequence.h +++ b/src/Sample/SampleSequence.h @@ -37,7 +37,7 @@ public: , volumeLowerDimensions_m(modulo) { } - void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) { + void create(std::shared_ptr<SampleIndividual>& ind, size_t i) { unsigned int id = ind->id; diff --git a/src/Sample/Sampler.cpp b/src/Sample/Sampler.cpp index ebfd81850..ba55f778d 100644 --- a/src/Sample/Sampler.cpp +++ b/src/Sample/Sampler.cpp @@ -134,7 +134,7 @@ bool Sampler::onMessage(MPI_Status status, size_t length) { switch(tag) { case REQUEST_FINISHED: { unsigned int jid = static_cast<unsigned int>(length); - typename std::map<size_t, boost::shared_ptr<Individual_t> >::iterator it; + typename std::map<size_t, std::shared_ptr<Individual_t> >::iterator it; it = jobmapping_m.find(jid); if(it == jobmapping_m.end()) { @@ -144,7 +144,7 @@ bool Sampler::onMessage(MPI_Status status, size_t length) { } - boost::shared_ptr<Individual_t> ind = it->second; + std::shared_ptr<Individual_t> ind = it->second; reqVarContainer_t res; MPI_Recv_reqvars(res, status.MPI_SOURCE, comms_.opt); @@ -200,7 +200,7 @@ void Sampler::createNewIndividual() { dNames.push_back(dName); } - boost::shared_ptr<Individual_t> ind = boost::shared_ptr<Individual_t>( new Individual_t(dNames)); + std::shared_ptr<Individual_t> ind = std::shared_ptr<Individual_t>( new Individual_t(dNames)); ind->id = gid++; @@ -292,7 +292,7 @@ void Sampler::dumpIndividualsToJSON() { } -void Sampler::addIndividualToJSON(const boost::shared_ptr<Individual_t>& ind) { +void Sampler::addIndividualToJSON(const std::shared_ptr<Individual_t>& ind) { individualsToDump_m.push_back(*ind); if (jsonDumpFreq_m <= individualsToDump_m.size()) { @@ -340,7 +340,7 @@ void Sampler::runStateMachine() { void Sampler::dispatch_forward_solves() { while ( !individuals_m.empty() ) { - boost::shared_ptr<Individual_t> ind = individuals_m.front(); + std::shared_ptr<Individual_t> ind = individuals_m.front(); individuals_m.pop(); @@ -367,6 +367,6 @@ void Sampler::dispatch_forward_solves() { MPI_Send_params(params, pilot_rank, comms_.opt); jobmapping_m.insert( - std::pair<size_t, boost::shared_ptr<Individual_t> >(jid, ind)); + std::pair<size_t, std::shared_ptr<Individual_t> >(jid, ind)); } } \ No newline at end of file diff --git a/src/Sample/Sampler.h b/src/Sample/Sampler.h index 2f77350f9..f5fb14f61 100644 --- a/src/Sample/Sampler.h +++ b/src/Sample/Sampler.h @@ -119,9 +119,9 @@ private: Comm::Bundle_t comms_; /// mapping from unique job ID to individual - std::map<size_t, boost::shared_ptr<Individual_t> > jobmapping_m; + std::map<size_t, std::shared_ptr<Individual_t> > jobmapping_m; - std::queue<boost::shared_ptr<Individual_t> > individuals_m; + std::queue<std::shared_ptr<Individual_t> > individuals_m; /// bounds on each specified gene bounds_t dVarBounds_m; @@ -158,7 +158,7 @@ private: std::list<Individual_t> individualsToDump_m; void dumpIndividualsToJSON(); - void addIndividualToJSON(const boost::shared_ptr<Individual_t>& ind); + void addIndividualToJSON(const std::shared_ptr<Individual_t>& ind); void runStateMachine(); diff --git a/src/Sample/SamplingMethod.h b/src/Sample/SamplingMethod.h index 01bd8f72c..59146e4ac 100644 --- a/src/Sample/SamplingMethod.h +++ b/src/Sample/SamplingMethod.h @@ -34,7 +34,7 @@ class SamplingMethod public: virtual ~SamplingMethod() {}; - virtual void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) = 0; + virtual void create(std::shared_ptr<SampleIndividual>& ind, size_t i) = 0; /*! * Allocate memory for sampling. Not every sampling method diff --git a/src/Sample/Uniform.h b/src/Sample/Uniform.h index a727b4460..9a1e08b5f 100644 --- a/src/Sample/Uniform.h +++ b/src/Sample/Uniform.h @@ -54,7 +54,7 @@ public: RNGStream::deleteInstance(RNGInstance_m); } - void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) { + void create(std::shared_ptr<SampleIndividual>& ind, size_t i) { ind->genes[i] = RNGInstance_m->getNext(dist_m); } -- GitLab