-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
66 lines (56 loc) · 2.16 KB
/
index.mjs
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
/*
Fitness Function Class Module
-----------------------------
Fitness functions are used to compare candidate solutions generated by the optimization algorithm.
The goal is to provide context for the optimization problem and decouple this context from the optimizer
in order to use multiple fitness models with the same optimization algorithm.
This class is intended to be extended adding the necessary methods. The ones provided here, are the
minimun required for the optimization library to work.
*/
import { generate_id } from '../tools/index.mjs';
export default class Fitness { // Fitness model class
constructor(params) {
this._id = generate_id(); // Fitness unique identifier
this._name = "Undefined name"; // Fitness model title (not defined yet)
for(let p in params)
this[p] = params[p];
}
get id() {
return this._id;
}
get name() {
return this._name;
}
get config() {
// Here you should return the parameters of the model to be
// able to duplicate the instance
return {};
}
objective_str(x) {
// This function shows the result of evaluating the objective function
// as a human-readable string.
return "No fitness model!";
}
eval(x) {
// This is the fitness function. This function should return a numeric scalar
// value that represents the solution's quality.
return 0;
}
//// GA INTERFACE ////
// In order to extend the optimization library to be used with other
// algorithms, then this part should be moved to a separated "Interface"
// class model.
get ga_config() {
// This function is part of the interface for the GA optimization
// model and is used to override the GA default configuration
// which may be necesary in some cases, specially when you dont
// expect the user to have deep knowledge on the problem and
// the working of the GA method
return {};
}
rand_encoded() {
// This function generates a random solution. Is necessary to
// inialize the population based methods as GA
return [];
}
}