Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
output.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/nag_algorithms/output.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/output.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/output.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) 2017 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
30
31#pragma once
32
35
36
37namespace bertini {
38namespace algorithm {
39namespace output {
40
44template <typename AlgoT>
46{ };
47
48
49template <typename ...T>
50struct Classic
51{};
52
53
54template <typename A, typename B, typename C, typename D, template<typename, typename> class E>
55struct Classic <ZeroDim<A,B,C,D,E>>
56{
57 using ZDT = ZeroDim<A,B,C,D,E>;
58
59 template <typename OutT>
60 static
61 void All(OutT & out, ZDT const& zd)
62 {
63 out << "\n\n\n MAINDATA \n\n\n";
64 MainData(out, zd);
65
66 out << "\n\n\n RAWDATA \n\n\n";
67 RawData(out, zd);
68 }
69
70
71 template <typename OutT>
72 static
73 void MainData(OutT & out, ZDT const& zd)
74 {
75 NumVariables(out, zd);
76 Variables(out, zd,"\n\n");
77
78 const auto& s = zd.FinalSolutions();
79 const auto& m = zd.FinalSolutionMetadata();
80 const auto n = s.size();
81 for (decltype(s.size()) ii{0}; ii<n; ++ii)
82 {
83 if (zd.FinalSolutionMetadata()[ii].endgame_success == SuccessCode::NeverStarted)
84 continue;
85
86 EndPointMDFull(ii, out, zd);
87 EndPoint(ii, out, zd,"\n\n");
88 }
89
90 out << "\n\n";
91 TargetSystem(out,zd,"\n\n");
92
93 StartSystem(out,zd,"\n\n");
94
95 Homotopy(out,zd,"\n\n");
96 }
97
98 template <typename OutT>
99 static
100 void RawData(OutT & out, ZDT const& zd)
101 {
102 const auto n = zd.FinalSolutions().size();
103 NumVariables(out, zd,"\n\n");
104 for (decltype(zd.FinalSolutions().size()) ii{0}; ii<n; ++ii)
105 {
106 if (zd.FinalSolutionMetadata()[ii].endgame_success == SuccessCode::NeverStarted)
107 continue;
108 EndPointMDRaw(ii,out,zd,"\n\n");
109 }
110
111 out << "\n\n";
112 TargetSystem(out,zd,"\n\n");
113 }
114
115
116 template <typename OutT>
117 static
118 void NumVariables(OutT & out, ZDT const& zd, std::string const& additional = "\n")
119 {
120 const auto& sys = zd.TargetSystem();
121 out << sys.NumVariables() << additional;
122 }
123
124
125 template <typename OutT>
126 static
127 void Variables(OutT & out, ZDT const& zd, std::string const& additional = "\n")
128 {
129 const auto& sys = zd.TargetSystem();
130 const auto& vars = sys.VariableOrdering();
131 for (const auto& x : vars)
132 out << *x << ' ';
133 out << additional;
134 }
135
136
137 template <typename OutT>
138 static
139 void TargetSystem(OutT & out, ZDT const& zd, std::string const& additional = "\n")
140 {
141 out << zd.TargetSystem() << additional;
142 }
143
144 template <typename OutT>
145 static
146 void StartSystem(OutT & out, ZDT const& zd, std::string const& additional = "\n")
147 {
148 out << zd.StartSystem() << additional;
149 }
150
151 template <typename OutT>
152 static
153 void Homotopy(OutT & out, ZDT const& zd, std::string const& additional = "\n")
154 {
155 out << zd.Homotopy() << additional;
156 }
157
158 template <typename IndexT, typename OutT>
159 static
160 void EndPoint(IndexT const& ind, OutT & out, ZDT const& zd, std::string const& additional = "")
161 {
162 generators::Classic::generate(boost::spirit::ostream_iterator(out), zd.FinalSolutions()[ind]);
163 out << additional;
164 }
165
166 template <typename IndexT, typename OutT>
167 static
168 void EndPointDehom(IndexT const& ind, OutT & out, ZDT const& zd, std::string const& additional = "")
169 {
170 DefaultPrecision(Precision(zd.FinalSolutions()[ind]));
171
172 generators::Classic::generate(boost::spirit::ostream_iterator(out), zd.TargetSystem().DehomogenizePoint(zd.FinalSolutions()[ind]));
173 out << additional;
174 }
175
176 template <typename IndexT, typename OutT>
177 static
178 void EndPointMDFull(IndexT const& ind, OutT & out, ZDT const& zd, std::string const& additional = "\n")
179 {
180 const auto& data = zd.FinalSolutionMetadata()[ind];
181 out << data.path_index << '\n'
182 << data.solution_index << '\n'
183 << data.condition_number << '\n'
184 << data.function_residual << '\n'
185 << data.newton_residual << '\n';
186 generators::Classic::generate(boost::spirit::ostream_iterator(out), data.final_time_used);
187 out << '\n' << data.max_precision_used << '\n';
188
189 generators::Classic::generate(boost::spirit::ostream_iterator(out), data.time_of_first_prec_increase);
190 out << '\n' << data.accuracy_estimate << '\n'
191 << data.accuracy_estimate_user_coords << '\n'
192 << data.cycle_num << '\n'
193 << data.multiplicity << '\n'
194 << data.pre_endgame_success << ' ' << data.endgame_success << '\n';
195 out << additional;
196 }
197
198
199
200 template <typename IndexT, typename OutT>
201 static
202 void EndPointMDRaw(IndexT const& ind, OutT & out, ZDT const& zd, std::string const& additional = "\n")
203 {
204 const auto& pt = zd.FinalSolutions()[ind];
205 const auto& data = zd.FinalSolutionMetadata()[ind];
206 out << data.path_index << '\n'
207 << Precision(pt) << '\n';
208 EndPoint(ind, out, zd);
209 out << data.function_residual << '\n'
210 << data.condition_number << '\n'
211 << data.newton_residual << '\n';
212 generators::Classic::generate(boost::spirit::ostream_iterator(out), data.final_time_used);
213 out << '\n' << data.accuracy_estimate << '\n';
214 generators::Classic::generate(boost::spirit::ostream_iterator(out), data.time_of_first_prec_increase);
215 out << '\n' << data.cycle_num << '\n'
216 << data.endgame_success << '\n'
217 << additional;
218 }
219
220
221};
222
223
224struct NonsingularSolutions
225{
226
227
228 template<typename AlgoT>
229 static
230 auto Extract(AlgoT const& alg)
231 {
232 using BCT = typename AlgoTraits<AlgoT>::BaseComplexType;
233
234 const auto& sys = alg.TargetSystem();
235
236 SampCont<BCT> solns;
237
238 const auto& s = alg.FinalSolutions();
239 const auto& m = alg.FinalSolutionMetadata();
240 const auto n = s.size();
241 for (decltype(s.size()) ii{0}; ii<n; ++ii)
242 {
243 const auto& d = m[ii];
244 if (d.endgame_success == SuccessCode::Success &&
245 d.multiplicity==1)
246 {
247 solns.push_back(sys.DehomogenizePoint(s[ii]));
248 }
249 }
250
251 return solns;
252 }
253};
254
255
256struct AllSolutions
257{
258
259
260 template<typename AlgoT>
261 static
262 auto Extract(AlgoT const& alg)
263 {
264 using BCT = typename AlgoTraits<AlgoT>::BaseComplexType;
265
266 const auto& sys = alg.TargetSystem();
267
268 SampCont<BCT> solns;
269
270 const auto& s = alg.FinalSolutions();
271 const auto& m = alg.FinalSolutionMetadata();
272 const auto n = s.size();
273 for (decltype(s.size()) ii{0}; ii<n; ++ii)
274 {
275 solns.push_back(sys.DehomogenizePoint(s[ii]));
276 }
277
278 return solns;
279 }
280};
281
282
283} // namespace output
284} // namespace algorithm
285} // namespace bertini
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object. If the object is empty, it's the precision of a default-constru...
Definition eigen_extensions.hpp:292
Provides the generators for bertini2.
std::shared_ptr< Node > E()
Definition special_number.cpp:37
the basic zero dim algorithm, which solves a system.
Definition zero_dim_solve.hpp:248
Prints data from algorithms.
Definition output.hpp:46
Provides the algorithm for computing all zero-dimensional solutions for an algberaic system.