-
Notifications
You must be signed in to change notification settings - Fork 0
/
pla.h
65 lines (44 loc) · 1.21 KB
/
pla.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef pla_h
#define pla_h
#include <limits>
#include <vector>
#include <cmath>
#include <iostream>
#include <cassert>
#include "approx.h"
class PLA : public Approx {
public:
PLA();
~PLA() {}
struct segment{
unsigned long long start, end;
double slope;
double intercept;
};
void set_param(double);
void clear();
double estimate(ull);
void feed(point);
size_t memory_usage();
std::vector<segment> result;
private:
int tollerance;
double lower, upper;
//available slope range : [lower, upper]
point begin;
//current time segment start point : begin
point last;
//last point
bool initialized;
double buffer_lower, buffer_upper;
point buffer_begin, buffer_last;
bool buffer_initialized;
inline double valueAtTime(double slope, double intercept, unsigned long long time) {
return slope * time + intercept;
}
inline double pointSlope(point pt1, point pt2) {
assert(pt2.x > pt1.x);
return (pt2.y - pt1.y) / (pt2.x - pt1.x);
}
};
#endif