-
Notifications
You must be signed in to change notification settings - Fork 1
/
test1.d
66 lines (49 loc) · 1.55 KB
/
test1.d
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
import ES;
import std.stdio, std.conv;
import core.stdc.math;
import std.file : readText;
import std.range : appender;
import std.string : splitLines, stripLeft, stripRight;
import std.format : formattedWrite;
import JCutils;
import std.csv;
alias Solution!Func_params Func;
void main(string[] args) {
writeln();
auto problem = new Func_toSolve(args[2],to!int(args[3]),to!double(args[4]));
Init_params!Func_params init_params;
pragma(msg, typeof((Init_params!Func_params).tupleof[0]));
read_cfg!(double, double[2])(init_params, args[1]);
auto population = new Population!Func(problem,init_params,args[5]);
population.run();
auto best = population.best();
writeln(best[0]);
problem.print_fit(best[0].params,"fit.txt");
writeln();
}
//The types used for parameter values and mutabilities should implement
//their own initialisation.
//obviously no need to init explicitly for fixed arrays
alias Parameter!(double, double) d_param;
struct Func_params {
d_param x;
d_param y;
static auto blank() {
Func_params tmp;
foreach(ref param; tmp.tupleof) {
param.value = 0;
param.mutability = 0;
}
return tmp;
}
}
class Func_toSolve : Problem!Func_params {
this (string filename, int length=1000, double noise_ampl=0) {
}
override double fitness_calc(Func_params fit) {
return 0.05*(fit.x*fit.x + fit.y*fit.y) + sin(fit.x)*sin(fit.y);
}
void print_fit(Func_params fit, string filename) {
//do nothing??
}
}