LIBINT 2.7.2
tactic.h
1/*
2 * Copyright (C) 2004-2021 Edward F. Valeev
3 *
4 * This file is part of Libint.
5 *
6 * Libint is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include <cmath>
22#include <cstdlib>
23#include <ctime>
24#include <smart_ptr.h>
25
26#ifndef _libint2_src_bin_libint_tactic_h_
27#define _libint2_src_bin_libint_tactic_h_
28
29namespace libint2 {
30
31 class DirectedGraph;
32 class RecurrenceRelation;
33
34 class DummyRandomizePolicy;
35 class StdRandomizePolicy;
36
40 class Tactic {
41 public:
42 typedef SafePtr<RecurrenceRelation> RR;
43 typedef std::vector<RR> rr_stack;
44
45 Tactic() {}
46 virtual ~Tactic() {}
47
48 virtual RR optimal_rr(const rr_stack& stack) const =0;
49
50 // make return true if need to debug Tactic classes
51 static constexpr bool class_debug() {
52 return false;
53 }
54 };
55
58 template <class RandomizePolicy = DummyRandomizePolicy>
59 class FirstChoiceTactic : public Tactic {
60 public:
61 FirstChoiceTactic(const SafePtr<RandomizePolicy>& rpolicy = SafePtr<RandomizePolicy>(new RandomizePolicy)) : Tactic(), rpolicy_(rpolicy) {}
62 virtual ~FirstChoiceTactic() {}
63
64 RR optimal_rr(const rr_stack& stack) const {
65 if (!stack.empty())
66 return stack[0 + rpolicy_->noise(stack.size())];
67 else
68 return RR();
69 }
70
71 private:
72 SafePtr<RandomizePolicy> rpolicy_;
73 };
74
79 public:
80 FewestNewVerticesTactic(const SafePtr<DirectedGraph>& dg) : Tactic(), dg_(dg) {}
81 virtual ~FewestNewVerticesTactic() {}
82
83 RR optimal_rr(const rr_stack& stack) const;
84
85 private:
86 SafePtr<DirectedGraph> dg_;
87 };
88
93 public:
94 ZeroNewVerticesTactic(const SafePtr<DirectedGraph>& dg) : Tactic(), dg_(dg) {}
95 virtual ~ZeroNewVerticesTactic() {}
96
97 RR optimal_rr(const rr_stack& stack) const;
98
99 private:
100 SafePtr<DirectedGraph> dg_;
101 };
102
105 class RandomChoiceTactic : public Tactic {
106 public:
108 virtual ~RandomChoiceTactic() {}
109
110 RR optimal_rr(const rr_stack& stack) const;
111 };
112
115 class NullTactic : public Tactic {
116 public:
117 NullTactic() : Tactic() {}
118 virtual ~NullTactic() {}
119
120 RR optimal_rr(const rr_stack& stack) const;
121 };
122
128 public:
132 ParticleDirectionTactic(bool increase) : Tactic(), increase_(increase) {}
133 virtual ~ParticleDirectionTactic() {}
134
135 RR optimal_rr(const rr_stack& stack) const;
136 private:
137 bool increase_;
138 };
139
144 public:
149 TwoCenter_OS_Tactic(unsigned lbra0,
150 unsigned lket0) : Tactic(), lbra0_(lbra0), lket0_(lket0) {}
151 virtual ~TwoCenter_OS_Tactic() {}
152
153 RR optimal_rr(const rr_stack& stack) const;
154 private:
155 unsigned lbra0_;
156 unsigned lket0_;
157 };
158
163 public:
170 FourCenter_OS_Tactic(unsigned lbra0,
171 unsigned lket0,
172 unsigned lbra1,
173 unsigned lket1) : Tactic(), lbra0_(lbra0), lket0_(lket0),
174 lbra1_(lbra1), lket1_(lket1) {}
175 virtual ~FourCenter_OS_Tactic() {}
176
177 RR optimal_rr(const rr_stack& stack) const;
178 private:
179 unsigned lbra0_;
180 unsigned lket0_;
181 unsigned lbra1_;
182 unsigned lket1_;
183 };
184
186
188 unsigned int noise(unsigned int nrrs) const { return 0; }
189 };
190
197 public:
198 StdRandomizePolicy(double scale) : scale_(scale) {
199 // Initialize state randomly
200 time_t t;
201 srandom(time(&t));
202 }
203
204 unsigned int noise(unsigned int nrrs) const {
205 unsigned long rand = random();
206 const unsigned long range = RAND_MAX;
207 const unsigned int result = static_cast<unsigned int>(std::floor(nrrs*scale_*rand/range));
208 return result;
209 }
210
211 private:
212 double scale_;
213 };
214
215
216};
217
218#endif
219
FewestNewVerticesTactic chooses RR which adds fewest new vertices to DirectedGraph dg.
Definition: tactic.h:78
FirstChoiceTactic simply chooses the first RR.
Definition: tactic.h:59
FourCenter_OS_Tactic decides graph build for (bra0 ket0| bra1 ket1) = <bra0 bra1|ket0 ket1>
Definition: tactic.h:162
FourCenter_OS_Tactic(unsigned lbra0, unsigned lket0, unsigned lbra1, unsigned lket1)
Definition: tactic.h:170
NullTactic always returns null RecurrenceRelation.
Definition: tactic.h:115
ParticleDirectionTactic returns the first RR that transfers the quantum numbers between particles in ...
Definition: tactic.h:127
ParticleDirectionTactic(bool increase)
Definition: tactic.h:132
RandomChoiceTactic chooses randomly among the applicable RRs.
Definition: tactic.h:105
The shift parameter is computed as follows: delta = floor(nrrs*scale*random()/RAND_MAX) where nrrs is...
Definition: tactic.h:196
Tactic is used to choose the optimal (in some sense) recurrence relation to reduce a vertex.
Definition: tactic.h:40
TwoCenter_OS_Tactic decides graph build for <bra0|ket0>
Definition: tactic.h:143
TwoCenter_OS_Tactic(unsigned lbra0, unsigned lket0)
Definition: tactic.h:149
ZeroNewVerticesTactic chooses first RR which adds no new vertices on DirectedGraph dg.
Definition: tactic.h:92
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
Definition: tactic.h:187