simplest/
simplest.rs

1// Copyright 2019 Brendan Cox
2// 
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15extern crate aristeia;
16
17use aristeia::agent::Agent;
18use aristeia::manager::create_manager;
19use aristeia::fitness::ScoreError;
20
21fn main() {
22
23    let mut manager = create_manager(fitness_function, 0);
24    manager.set_number_of_genes(5, true);
25    manager.run(1250);
26    let agents = manager.get_population().get_agents();
27
28    println!("Population: {}", agents.len());
29
30    let mut viewing = 10;
31    for (score_index, agent) in agents.iter().rev() {
32        println!("Score: {}", score_index);
33        println!("{:?}", agent.get_genes());
34
35        viewing -= 1;
36        if viewing == 0 {
37            break;
38        }
39    }
40}
41
42fn fitness_function(agent: &Agent<u8>, _data: &u8) -> Result<u64, ScoreError> {
43    let mut score = 0;
44
45    for gene in agent.get_genes() {
46        score += *gene as u64;
47    }
48
49    Ok(score)
50}