28#ifndef BERTINI_BASE_ENDGAME_HPP
29#define BERTINI_BASE_ENDGAME_HPP
60namespace bertini{
namespace endgame {
90template<
class FlavorT,
class PrecT>
92 public detail::Configured< typename AlgoTraits<FlavorT>::NeededConfigs >,
94 public virtual Observable
97 using TrackerType =
typename PrecT::TrackerType;
99 using BaseComplexType =
typename tracking::TrackerTraits<TrackerType>::BaseComplexType;
100 using BaseRealType =
typename tracking::TrackerTraits<TrackerType>::BaseRealType;
102 using EmitterType = FlavorT;
106 using BCT = BaseComplexType;
107 using BRT = BaseRealType;
110 using Configured = detail::Configured< typename AlgoTraits<FlavorT>::NeededConfigs >;
111 using Configs =
typename AlgoTraits<FlavorT>::NeededConfigs;
112 using ConfigsAsTuple =
typename Configs::ToTuple;
115 using NeededTypes = detail::TypeList<BCT>;
116 using TupOfVec =
typename NeededTypes::ToTupleOfVec;
117 using TupOfReal =
typename NeededTypes::ToTupleOfReal;
118 using TupleOfTimes =
typename NeededTypes::template ToTupleOfCont<TimeCont>;
119 using TupleOfSamps =
typename NeededTypes::template ToTupleOfCont<SampCont>;
124 mutable Vec<BCT> final_approximation_;
125 mutable Vec<BCT> previous_approximation_;
126 mutable unsigned int cycle_number_ = 0;
127 mutable NumErrorT approximate_error_;
138 const FlavorT& AsFlavor()
const
140 return dynamic_cast<const FlavorT&
>(*this);
148 return dynamic_cast<FlavorT&
>(*this);
156 SuccessCode Run(
const BCT & start_time,
const Vec<BCT> & start_point, BCT
const& target_time)
158 return this->AsFlavor().RunImpl(start_time, start_point, target_time);
166 SuccessCode Run(BCT
const& start_time, Vec<BCT>
const& start_point)
168 return Run(start_time, start_point,
static_cast<BCT
>(0));
172 template<
typename CT>
173 SuccessCode RefineAllSamples(SampCont<CT> & samples, TimeCont<CT> & times)
175 for (
size_t ii=0; ii<samples.size(); ++ii)
177 auto refine_success = this->RefineSample(samples[ii], samples[ii], times[ii],
178 this->FinalTolerance() * this->EndgameSettings().sample_point_refinement_factor,
179 this->EndgameSettings().max_num_newton_iterations);
180 if (refine_success != SuccessCode::Success)
183 return refine_success;
188 if (tracking::TrackerTraits<TrackerType>::IsAdaptivePrec)
190 auto max_precision = this->EnsureAtUniformPrecision(times, samples);
191 this->GetSystem().precision(max_precision);
194 return SuccessCode::Success;
201 SuccessCode RefineSample(Vec<BCT> & result, Vec<BCT>
const& current_sample, BCT
const& current_time, NumErrorT tol,
unsigned max_iterations)
const
203 return this->RefineSampleImpl(result, current_sample, current_time, tol, max_iterations);
206 void ChangePrecision(
unsigned p)
208 AsFlavor().ChangePrecision(p);
209 PrecT::ChangePrecision(p);
210 ChangePrecision(this->final_approximation_,p);
211 ChangePrecision(this->previous_approximation_,p);
219 const auto & EndgameSettings()
const
221 return Configured::template Get<EndgameConfig>();
225 const auto & SecuritySettings()
const
227 return this->
template Get<SecurityConfig>();
230 explicit EndgameBase(TrackerType
const& tr,
const ConfigsAsTuple& settings ) :
231 Configured( settings ), PrecT(tr), EndgamePrecPolicyBase<TrackerType>(tr)
235 template<
typename... Ts >
237 EndgameBase(TrackerType
const& tr,
const Ts&... ts ) : EndgameBase(tr, Configs::Unpermute( ts... ) )
241 inline unsigned CycleNumber()
const {
return cycle_number_;}
242 inline void CycleNumber(
unsigned c) { cycle_number_ = c;}
243 inline void IncrementCycleNumber(
unsigned inc) { cycle_number_ += inc;}
250 const auto& FinalTolerance()
const
252 return this->
template Get<EndgameConfig>().final_tolerance;
261 void SetFinalTolerance(BRT
const& ft){this->
template Get<EndgameConfig>().final_tolerance = ft;}
269 template<
typename CT>
271 const Vec<CT>& FinalApproximation()
const
273 return final_approximation_;
279 template<
typename CT>
281 const Vec<CT>& PreviousApproximation()
const
283 return previous_approximation_;
290 NumErrorT ApproximateError()
const
292 return approximate_error_;
300 const BCT& LatestTime()
const
302 return AsFlavor().LatestTimeImpl();
345 template<
typename CT>
346 SuccessCode ComputeInitialSamples(
const CT & start_time,
const CT & target_time,
const Vec<CT> & x_endgame_start, TimeCont<CT> & times, SampCont<CT> & samples)
348 using RT =
typename Eigen::NumTraits<CT>::Real;
349 assert(this->
template Get<EndgameConfig>().num_sample_points>0 &&
"number of sample points must be positive");
351 if (tracking::TrackerTraits<TrackerType>::IsAdaptivePrec)
353 assert(Precision(start_time)==Precision(x_endgame_start) &&
"Computing initial samples requires input time and space with uniform precision");
359 samples.push_back(x_endgame_start);
360 times.push_back(start_time);
362 auto num_vars = this->GetSystem().NumVariables();
364 for(
int ii=1; ii < this->
template Get<EndgameConfig>().num_sample_points; ++ii)
366 times.emplace_back((times[ii-1] + target_time) * RT(this->
template Get<EndgameConfig>().sample_factor));
367 samples.emplace_back(Vec<CT>(num_vars));
369 auto tracking_success = this->GetTracker().TrackPath(samples[ii],times[ii-1],times[ii],samples[ii-1]);
370 this->EnsureAtPrecision(times[ii],Precision(samples[ii]));
372 if (tracking_success!=SuccessCode::Success)
373 return tracking_success;
376 return SuccessCode::Success;
379 virtual ~EndgameBase() =
default;
void NotifyObservers(AnyEvent const &e) const
Sends an Event (more particularly, AnyEvent) to all watching observers of this object.
Definition observable.hpp:90
Configs and settings for endgames.
Contains the endgames/events base types.
Logging in Bertini using Boost.Log.
The main multiprecision complex number type. This is essentially boost::multiprecision' complex.
Provides the bertini::System class.
Configs and settings for tracking.