Rosetta 3.5
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
protocols
genetic_algorithm
GeneticAlgorithm.hh
Go to the documentation of this file.
1
// -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2
// vi: set ts=2 noet:
3
//
4
// (c) Copyright Rosetta Commons Member Institutions.
5
// (c) This file is part of the Rosetta software suite and is made available under license.
6
// (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7
// (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8
// (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9
10
/// @file GeneticAlgorithm.hh
11
/// @brief template class for genetic algorithm protocols
12
/// @author ashworth, based on template "pseudo"code by Colin Smith
13
14
#ifndef INCLUDED_protocols_genetic_algorithm_GeneticAlgorithm_hh
15
#define INCLUDED_protocols_genetic_algorithm_GeneticAlgorithm_hh
16
17
// Unit headers
18
#include <
protocols/genetic_algorithm/GeneticAlgorithm.fwd.hh
>
19
20
#include <
protocols/genetic_algorithm/Entity.fwd.hh
>
21
#include <
protocols/genetic_algorithm/EntityRandomizer.hh
>
22
#include <
protocols/genetic_algorithm/FitnessFunction.hh
>
23
24
#include <utility/pointer/ReferenceCount.hh>
25
26
#include <
core/types.hh
>
27
// AUTO-REMOVED #include <basic/Tracer.hh>
28
29
// AUTO-REMOVED #include <utility/file/file_sys_util.hh> // file_exists
30
// AUTO-REMOVED #include <utility/io/izstream.hh>
31
// AUTO-REMOVED #include <utility/io/ozstream.hh>
32
#include <utility/pointer/owning_ptr.hh>
33
// AUTO-REMOVED #include <utility/pointer/access_ptr.hh>
34
#include <utility/vector1.hh>
35
36
// AUTO-REMOVED #include <numeric/random/random.fwd.hh>
37
38
#include <boost/unordered_map.hpp>
39
40
#include <algorithm>
// std::copy
41
42
//Auto Headers
43
namespace
protocols {
44
namespace
genetic_algorithm {
45
46
class
GeneticAlgorithm
:
public
utility::pointer::ReferenceCount
{
47
48
public
:
49
typedef
FitnessFunction::OP
FitnessFunctionOP
;
50
typedef
EntityRandomizer::OP
EntityRandomizerOP
;
51
typedef
Entity::OP
EntityOP
;
52
typedef
Entity::COP
EntityCOP
;
53
typedef
Entity::COPs
EntityCOPs
;
54
typedef
Entity::CAP
EntityCAP
;
55
typedef
Entity::CAPs
EntityCAPs
;
56
typedef
utility::vector1< EntityOP >::iterator
pop_iter
;
57
typedef
utility::vector1< EntityOP >::const_iterator
pop_const_iter
;
58
typedef
utility::vector1< EntityCOP >::const_iterator
pop_const_const_iter
;
59
typedef
boost::unordered_map< EntityElements , EntityOP, Vec1Hash, EntityElementsEqual >
TraitEntityHashMap
;
60
61
public
:
62
GeneticAlgorithm
();
63
virtual
~GeneticAlgorithm
();
64
65
virtual
EntityOP
add_entity
(
EntityElements
const
& traits );
66
virtual
EntityOP
add_entity
(
EntityOP
entity );
67
virtual
EntityOP
add_parent_entity
(
EntityElements
const
& traits );
68
virtual
EntityOP
add_parent_entity
(
EntityOP
entity );
69
virtual
void
clear_parents
();
70
virtual
void
add_parents_from_current_generation
();
71
virtual
void
propagate_best_from_previous_generation
(
core::Size
size
= 1,
bool
unique =
true
);
72
virtual
void
fill_with_random_entities
(
core::Size
size
= 0 );
73
virtual
void
fill_by_crossover
(
core::Size
size
= 0 );
74
virtual
void
fill_by_mutation
(
core::Size
size
= 0 );
75
virtual
void
evaluate_fitnesses
();
76
virtual
void
evolve_next_generation
();
77
virtual
bool
current_generation_complete
();
78
virtual
bool
complete
();
79
virtual
core::Real
best_fitness_from_current_generation
()
const
;
80
81
virtual
void
set_func
(
FitnessFunctionOP
f );
82
virtual
void
set_rand
(
EntityRandomizerOP
r );
83
virtual
core::Size
current_generation
()
const
{
return
current_generation_
; }
84
virtual
core::Size
max_generations
()
const
{
return
max_generations_
; }
85
virtual
void
set_max_generations
(
core::Size
s );
86
virtual
void
set_max_pop_size
(
core::Size
s ) {
max_population_size_
= s; }
87
virtual
void
set_num_to_propagate
(
core::Size
s ) {
number_to_propagate_
= s; }
88
virtual
void
set_frac_by_recomb
(
core::Real
f ) {
fraction_by_recombination_
= f; }
89
virtual
void
set_checkpoint_prefix
(
std::string
const
& p ) {
checkpoint_prefix_
= p; }
90
virtual
void
set_checkpoint_write_interval
(
core::Size
i ) {
checkpoint_write_interval_
= i; }
91
virtual
void
set_checkpoint_gzip
(
bool
b
) {
checkpoint_gzip_
=
b
; }
92
virtual
void
set_checkpoint_rename
(
bool
b
) {
checkpoint_rename_
=
b
; }
93
94
///@brief non-const to permit sort
95
virtual
EntityCAPs
best_entities
(
core::Size
num );
96
virtual
Entity
const
&
tournament_select
(
utility::vector1< EntityCOP >
const
& pvec )
const
;
97
virtual
TraitEntityHashMap
&
entity_cache
();
98
virtual
TraitEntityHashMap
const
&
entity_cache
()
const
;
99
virtual
utility::vector1<utility::vector1< EntityOP >
>
const
&
generations
()
const
;
100
///@brief true const (read-only) access to entity population: new vector of const pointers
101
virtual
EntityCOPs
population
(
core::Size
gen_num )
const
;
102
virtual
void
print_generation_statistics
( std::ostream & os,
core::Size
gen_num )
const
;
103
virtual
void
print_population
( std::ostream & )
const
;
104
virtual
void
print_cache
( std::ostream & )
const
;
105
virtual
std::string
entities_checkpoint_filename
(
std::string
suffix =
""
)
const
;
106
///@brief for checkpointing fitness cache
107
virtual
bool
read_entities_checkpoint
(
bool
overwrite =
false
);
108
///@brief for checkpointing fitness cache
109
virtual
bool
write_entities_checkpoint
()
const
;
110
virtual
std::string
generations_checkpoint_filename
(
std::string
suffix =
""
)
const
;
111
virtual
bool
write_generations_checkpoint
()
const
;
112
virtual
bool
read_generations_checkpoint
();
113
virtual
bool
read_checkpoint
();
114
///@brief allows the prevention of accidental reuse of checkpoint files
115
virtual
void
rename_checkpoint_files
()
const
;
116
virtual
EntityCOP
entity_template
()
const
;
117
virtual
void
set_entity_template
(
EntityCOP
entity);
118
virtual
EntityOP
new_entity
();
119
120
protected
:
121
122
private
:
123
utility::vector1< utility::vector1< EntityOP >
>
generations_
;
124
utility::vector1< EntityCOP >
parent_entities_
;
125
TraitEntityHashMap
entity_cache_
;
126
FitnessFunctionOP
fitness_function_
;
127
EntityRandomizerOP
entity_randomizer_
;
128
EntityCOP
entity_template_
;
129
core::Size
current_generation_
;
130
core::Size
max_generations_
;
131
core::Size
max_population_size_
;
132
core::Size
number_to_propagate_
;
133
core::Real
fraction_by_recombination_
;
134
std::string
checkpoint_prefix_
;
135
core::Size
checkpoint_write_interval_
;
136
bool
checkpoint_gzip_
;
137
bool
checkpoint_rename_
;
138
139
};
140
141
142
}
// namespace genetic_algorithm
143
}
// namespace protocols
144
145
#endif
Generated on Sat Jun 1 2013 11:53:13 for Rosetta 3.5 by
1.8.4