-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_snakeA.cpp
59 lines (42 loc) · 1.27 KB
/
test_snakeA.cpp
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
#include <fstream>
#include <iostream>
#include <iomanip>
#include "snakeA.h"
#include "tr_optim.h"
using namespace std;
int points = 11;
int dims = 2;
void my_target_snakeA_hess(double *x_val, double *y_val, double *gradient, double *hessian) {
return target_snakeA_hess(points, x_val, y_val, gradient, hessian);
}
int main(int argc, const char *argv[]) {
int n_vars = points * dims;
double xx[n_vars];
double seglen = 0.2;
int i, j;
for (i = 0; i < points; i++) {
int pt = 2 * i;
xx[pt] = (0.1+seglen) * (i - points / 2);
xx[pt + 1] = 0.5;
}
for (i = 0; i < points; i++) {
int pt = 2 * i;
cout << "x:" << xx[pt + 0] << "\t" << xx[pt + 1] << endl;
}
double yy[1];
double gg[dims * points];
double hh[dims * points * dims * points];
my_target_snakeA_hess(xx, yy, gg, hh);
double *res = trust_region_optimization(my_target_snakeA_hess, n_vars, xx, 0.05, 1e-4, 10000);
for (i = 0; i < points; i++) {
int pt = 2 * i;
cout << res[pt + 0] << "\t" << res[pt + 1] << endl;
}
fstream fs;
fs.open(argv[1], std::fstream::out);
for (i = 0; i < points; i++) {
int pt = 2 * i;
fs << res[pt + 0] << "\t" << res[pt + 1] << endl;
}
return 0;
}