Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
19 
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 
47 
48 public:
59  typedef boost::unordered_map< EntityElements , EntityOP, Vec1Hash, EntityElementsEqual > TraitEntityHashMap;
60 
61 public:
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();
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();
80 
81  virtual void set_func( FitnessFunctionOP f );
82  virtual void set_rand( EntityRandomizerOP r );
84  virtual core::Size max_generations() const { return max_generations_; }
85  virtual void set_max_generations( core::Size s );
89  virtual void set_checkpoint_prefix( std::string const & p ) { checkpoint_prefix_ = p; }
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;
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:
138 
139 };
140 
141 
142 } // namespace genetic_algorithm
143 } // namespace protocols
144 
145 #endif