feat: add support for dynamically varying algorithm paramters

This commit is contained in:
2024-11-23 18:41:02 +01:00
parent 3d2b41d7df
commit f5197bfc85
2 changed files with 65 additions and 20 deletions

View File

@@ -8,8 +8,8 @@ static constexpr int kFPS = 60;
static constexpr float kDT = 1.0 / kFPS;
float f(vec<2> x) {
return 50 * (std::pow(std::sin((x.x - 10)/2),2) + std::pow(std::sin(x.y/2),2))
+ std::pow(std::abs(x.x - 10), 1.2) + std::pow(std::abs(x.y), 1.2);
return 50 * (std::pow(std::sin((x.x - 10)/2),2) + std::pow(std::sin(x.y/2),2)) +
std::pow(std::abs(x.x - 3.141592653589), 1.2) + std::pow(std::abs(x.y), 1.2);
}
int
@@ -18,7 +18,7 @@ main(int argc, char **argv) {
if(argc < 2) iter_count = 100;
else sscanf(argv[1], "%d", &iter_count);
Swarm<2> swarm(f);
Swarm<2> swarm(f, iter_count);
Screen scr(80, 24);
TanhColorizer tanh_col;
@@ -148,7 +148,7 @@ main(int argc, char **argv) {
case 'p':
auto [y, x] = swarm.best();
printf("Current best: f(%.3f, %.3f) = %.3f", x.x, x.y, y);
printf("Current best: f(%.10f, %.10f) = %.10f", x.x, x.y, y);
break;
}