-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (71 loc) · 1.99 KB
/
Copy pathmain.cpp
File metadata and controls
89 lines (71 loc) · 1.99 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <cstring>
#include <vector>
#include <fstream>
#include <cstdlib>
#include "fractal_laplacian.h"
using namespace std;
int main(int argc, char** argv)
{
if (argc < 4)
{
cout << "Usage: " << argv[0] << " P PATH OUTPUT_FILE" << endl;
return 1;
}
double p = atof(argv[1]);
const char* path_str = argv[2];
const char* output_filename = argv[3];
if (p <= 0.0 || p >= 1.0 || p == 0.5)
{
cout << "P must be in (0, 1), excluding 0.5" << endl;
return 1;
}
int level = strlen(path_str) - 1;
vector<int> path;
for (int i = 0; i <= level; ++i)
{
if (!(path_str[i] >= '0' && path_str[i] <= '2'))
{
cout << "PATH must be a string of digits 0, 1, 2" << endl;
return 1;
}
path.push_back(path_str[i] - '0');
}
if (path[0] == 2)
{
cout << "The first digit in PATH must be 0 or 1" << endl;
return 1;
}
for (int i = 1; i <= level; ++i)
if (path[i] != path[0])
{
if (path[i] == 2)
{
cout << "Invalid PATH: if it starts with 0, the first non-zero digit must be 1; "
"if it starts with 1, the first digit different from 1 must be 0." << endl;
return 1;
}
break;
}
ofstream out(output_filename);
if (!out)
{
cout << "Failed to open " << output_filename << " for writing" << endl;
return 1;
}
int len = 1;
for (int i = 0; i < level; ++i)
len *= 3;
len++;
vector<double> func(len);
double lambda = compute_eigenpair(p, level, &path[0], &func[0]);
cout << "Level " << level << "; eigenvalue is " << lambda << endl;
out << scientific;
for (int i = 0; i < len; ++i)
{
double x = double(i) / double(len - 1);
out << x << ' ' << func[i] << endl;
}
cout << "Output written to " << output_filename << endl;
return 0;
}