Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
nag_algorithms/common/policies.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/nag_algorithms/common/policies.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/nag_algorithms/common/policies.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/nag_algorithms/common/policies.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) 2015 - 2021 by Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22// individual authors of this file include:
23// silviana amethyst, university of wisconsin-eau claire
24
32
33#pragma once
34
35
36namespace bertini {
37
38 namespace policy{
39
40
41
45 template< typename D,
46 typename SystemType, typename StartSystemType
47 ,typename StoredSystemType, typename StoredStartSystemType>
49 {
50
51 using SystemT = SystemType;
52 using StartSystemT = StartSystemType;
53
54 using StoredSystemT = StoredSystemType;
55 using StoredStartSystemT = StoredStartSystemType;
56
57private:
58 // convert the base endgame into the derived type.
59 const D& AsDerived() const
60 {
61 return static_cast<const D&>(*this);
62 }
63
64 // convert the base endgame into the derived type.
65 D& AsDerived()
66 {
67 return static_cast<D&>(*this);
68 }
69
70public:
74 const SystemT& TargetSystem() const
75 {
76 return AsDerived().target_system_;
77 }
78
82 const SystemT& Homotopy() const
83 {
84 return AsDerived().homotopy_;
85 }
86
90 const StartSystemT & StartSystem() const
91 {
92 return AsDerived().start_system_;
93 }
94
95
96
100 void TargetSystem(StoredSystemT const& sys)
101 {
102 AsDerived().target_system_ = sys;
103 }
104
108 void Homotopy(StoredSystemT const& sys)
109 {
110 AsDerived().homotopy_ = sys;
111 }
112
116 void StartSystem(StoredStartSystemT const& sys)
117 {
118 AsDerived().start_system_ = sys;
119 }
120 };
121
122
123
124
132 template<typename SystemType, typename StartSystemType>
133 struct CloneGiven : public SysMgmtPolicy<CloneGiven<SystemType, StartSystemType>, SystemType, StartSystemType, SystemType, StartSystemType>
134 {
135
136 using SMP = SysMgmtPolicy<CloneGiven<SystemType, StartSystemType>, SystemType, StartSystemType, SystemType, StartSystemType>;
137 friend SMP;
138
139 using StoredSystemT = typename SMP::StoredSystemT;
140 using StoredStartSystemT = typename SMP::StoredStartSystemT;
141
142 using SMP::TargetSystem;
143 using SMP::StartSystem;
144 using SMP::Homotopy;
145
146 using SystemT = SystemType;
147 using StartSystemT = StartSystemType;
148
149private:
150 StoredSystemT target_system_;
151 StoredStartSystemT start_system_;
152 StoredSystemT homotopy_;
153
154
155public:
159 CloneGiven(SystemType const& target) : target_system_(AtConstruct(target))
160 {}
161
162
163 static
164 StoredSystemT AtConstruct(SystemType const& sys)
165 {
166 return Clone(sys);
167 }
168
169
173 template<typename T>
174 static
175 T AtSet(T const& sys)
176 {
177 return sys;
178 }
179
180
184 static
185 void PrepareTarget(SystemType & target)
186 {
187 // target system came from the constructor
188 target.Homogenize(); // work over projective coordinates
189 target.AutoPatch(); // then patch if needed
190 }
191
192 static void FormStart(StartSystemType & start, SystemType const& target)
193 {
194 start = StartSystemType(target);
195 }
196
197 static
198 void FormHomotopy(SystemType & homotopy, SystemType const& target, StartSystemType const& start, std::string const& path_variable_name)
199 {
200 auto t = node::Variable::Make(path_variable_name);
201
202 homotopy = (1-t)*target + node::Rational::Make(node::Rational::Rand())*t*start;
203 homotopy.AddPathVariable(t);
204 }
205
218 void SystemSetup(std::string const& path_variable_name)
219 {
221
222 // now we populate the start system
223 FormStart(StartSystem(), TargetSystem());
224
225 FormHomotopy(Homotopy(), TargetSystem(), StartSystem(), path_variable_name);
226 }
227
228
232 SystemT& TargetSystem()
233 {
234 return target_system_;
235 }
236
240 SystemT& Homotopy()
241 {
242 return homotopy_;
243 }
244
248 StartSystemT & StartSystem()
249 {
250 return start_system_;
251 }
252 };
253
254
262 template<typename SystemType, typename StartSystemType>
263 struct RefToGiven : public SysMgmtPolicy<RefToGiven<SystemType, StartSystemType>, SystemType, StartSystemType,
264 std::reference_wrapper< const SystemType>, std::reference_wrapper< const StartSystemType>>
265 {
266 using SMP = SysMgmtPolicy<RefToGiven<SystemType, StartSystemType>, SystemType, StartSystemType,
267 std::reference_wrapper< const SystemType>, std::reference_wrapper< const StartSystemType>>;
268 friend SMP;
269
270 using StoredSystemT = typename SMP::StoredSystemT;
271 using StoredStartSystemT = typename SMP::StoredStartSystemT;
272
273 using SMP::TargetSystem;
274 using SMP::StartSystem;
275 using SMP::Homotopy;
276
277
278private:
279 StoredSystemT target_system_;
280 StoredStartSystemT start_system_;
281 StoredSystemT homotopy_;
282
283
284public:
288 RefToGiven(SystemType const& target, StartSystemType const& start, SystemType const& hom)
289 :
290 target_system_(std::ref(target)),
291 start_system_(std::ref(start)),
292 homotopy_(std::ref(hom))
293 {}
294
295
299 static
300 StoredSystemT AtConstruct(SystemType const& sys)
301 {
302 return std::ref(sys);
303 }
304
308 template<typename T>
309 static
310 T AtSet(T const& sys)
311 {
312 return std::ref(sys);
313 }
314
315 void SystemSetup(std::string const& path_variable_name) const
316 { }
317
318 };
319 } // ns policy
320} // ns bertini
double D(double const &norm_J, double const &norm_J_inverse, AdaptiveMultiplePrecisionConfig const &AMP_config)
Compute the expression from the AMP papers amp1, amp2.
Definition amp_criteria.hpp:88
static Rational Rand()
Get a random complex rational node. Numerator and denominator will have about 50 digits.
Definition number.hpp:343
static T AtSet(T const &sys)
Definition nag_algorithms/common/policies.hpp:175
void SystemSetup(std::string const &path_variable_name)
Sets up the homotopy for the system to be solved.
Definition nag_algorithms/common/policies.hpp:218
SystemT & TargetSystem()
Definition nag_algorithms/common/policies.hpp:232
StartSystemT & StartSystem()
Definition nag_algorithms/common/policies.hpp:248
static void PrepareTarget(SystemType &target)
Definition nag_algorithms/common/policies.hpp:185
SystemT & Homotopy()
Definition nag_algorithms/common/policies.hpp:240
CloneGiven(SystemType const &target)
Definition nag_algorithms/common/policies.hpp:159
RefToGiven(SystemType const &target, StartSystemType const &start, SystemType const &hom)
Definition nag_algorithms/common/policies.hpp:288
static T AtSet(T const &sys)
Store a reference to the argument system.
Definition nag_algorithms/common/policies.hpp:310
static StoredSystemT AtConstruct(SystemType const &sys)
Store a reference to the argument system.
Definition nag_algorithms/common/policies.hpp:300
A base class for system management for the zero-dim algorithm.
Definition nag_algorithms/common/policies.hpp:49
void StartSystem(StoredStartSystemT const &sys)
Definition nag_algorithms/common/policies.hpp:116
const StartSystemT & StartSystem() const
Definition nag_algorithms/common/policies.hpp:90
const SystemT & TargetSystem() const
Definition nag_algorithms/common/policies.hpp:74
void TargetSystem(StoredSystemT const &sys)
Definition nag_algorithms/common/policies.hpp:100
const SystemT & Homotopy() const
Definition nag_algorithms/common/policies.hpp:82
void Homotopy(StoredSystemT const &sys)
Definition nag_algorithms/common/policies.hpp:108
System Clone(System const &sys)
Do a deep clone of the system. This includes the entire structure, variables, etc....