Line data Source code
1 : #include "FBCache.h"
2 : #include "FBSplittingFast.h"
3 : #include "FBStopping.h"
4 :
5 : #include <iostream>
6 :
7 0 : FBSplittingFast::FBSplittingFast(FBProblem & prob, Matrix & x0, double gamma) :
8 0 : FBSplitting(prob, x0, gamma) {
9 0 : m_previous = NULL;
10 0 : }
11 :
12 0 : FBSplittingFast::FBSplittingFast(FBProblem & prob, Matrix & x0, double gamma, FBStopping & sc) :
13 0 : FBSplitting(prob, x0, gamma, sc) {
14 0 : m_previous = NULL;
15 0 : }
16 :
17 0 : FBSplittingFast::FBSplittingFast(FBProblem & prob, Matrix & x0, double gamma, int maxit) :
18 0 : FBSplitting(prob, x0, gamma, maxit) {
19 0 : m_previous = NULL;
20 0 : }
21 :
22 500 : FBSplittingFast::FBSplittingFast(FBProblem & prob, Matrix & x0, double gamma, FBStopping & sc, int maxit) :
23 500 : FBSplitting(prob, x0, gamma, sc, maxit) {
24 500 : m_previous = NULL;
25 500 : }
26 :
27 27400 : int FBSplittingFast::iterate() {
28 : // store current point temporarily
29 27400 : Matrix * temp = new Matrix(*m_cache.get_point());
30 : // extrapolate if not first iterate
31 27400 : if (m_previous != NULL) {
32 : // y = x + k/(k+2) (x - x')
33 : // = (2k+2)/(k+2) x - k/(k+2) x'
34 26900 : Matrix::add(*m_cache.get_point(), -(1.0 * m_it) / (m_it + 2), *m_previous, (2.0 * m_it + 2.0) / (m_it + 2));
35 : // tell FBCache that the point has changed
36 26900 : m_cache.reset();
37 : // delete previously allocated 'm_previous'
38 26900 : delete m_previous;
39 : }
40 : // store m_previous point
41 27400 : m_previous = temp;
42 : // execute FBS iteration
43 27400 : return FBSplitting::iterate();
44 : }
45 :
46 27900 : int FBSplittingFast::stop() {
47 27900 : return FBSplitting::stop();
48 : }
49 :
50 :
51 1500 : FBSplittingFast::~FBSplittingFast() {
52 500 : if (m_previous != NULL) {
53 500 : delete m_previous;
54 500 : m_previous = NULL;
55 : }
56 1003 : }
|