-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
36 lines (24 loc) · 736 Bytes
/
Copy pathmain.cpp
File metadata and controls
36 lines (24 loc) · 736 Bytes
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
#include "Gradient.cpp"
#include <iostream>
#include <functional>
double ObjectFnc(std::vector<double> *funcLoc){
double x = funcLoc->at(0);
return (x*x);
}
int main(){
std::function<double(std::vector<double>*)> p_ObjectFcn{ObjectFnc};
// Test instance.
Gradient solver;
// Asign the object function.
solver.setObjectFn(p_ObjectFcn);
std::vector<double> startPoint = {-1.0};
solver.setStartPoint(startPoint);
solver.setMaxIterations(50);
solver.setStepSize(0.2);
std::vector<double> funcLoc;
double funcVal;
solver.Optimize(&funcLoc,&funcVal);
std::cout << "Function Location(x) : " << funcLoc[0] << std::endl;
std::cout << "Function value(y): " << funcVal << std::endl;
return 0;
}