Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_Minimizer.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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file core/optimization/GA_Minimizer.hh
12 /// @brief Minimizer based on Genetic Algorithm
13 /// @author Sergey Lyskov
14 
15 #ifndef INCLUDED_core_optimization_GA_Minimizer_hh
16 #define INCLUDED_core_optimization_GA_Minimizer_hh
17 
18 // Package headers
21 // AUTO-REMOVED #include <core/optimization/Multifunc.hh>
22 
23 // AUTO-REMOVED #include <vector>
24 
26 #include <utility/vector1.hh>
27 
28 
29 namespace core {
30 namespace optimization {
31 
32 
33 /// Inner class for Genetic Algorithm, hold one population with some additional info
34 class EItem
35 {
36 public:
37  EItem() {};
38  EItem(const Multivec &vn) { v=vn; };
39 
40  Multivec v; ///< item value
41  char tag; ///< tag for debug. (m-mutation, c-crossover, ...etc)
42  double r; ///< result of FF evaluation.
43 
44  // for sorting: compare function
45  static inline bool sort_R_function(const EItem &e1, const EItem &e2) {return e1.r < e2.r;}
46 };
47 
48 
50 {
51 public:
52  GA_Minimizer(Multifunc & func_in, MinimizerOptions const & options):
53  func_( func_in ),
54  add_original_(true),
55  mutation_probability_( options.ga_mutation_probability() ),
56  minimize_tolerance_( options.minimize_tolerance() )
57  {}
58 
59  Real run( Multivec & phipsi_inout, int max_time); // starting position, and solution is returned here
60 
61 private:
62  EItem randomize(const EItem& sit, int &time);
63  EItem loop(std::vector<EItem> & pop, int &time);
64  void step(std::vector<EItem> &pop, int &c_time, int &mres, EItem &shift);
65 
66 
67  /// genetic operators
68  void mutate(EItem &); // mutate given vector using normal random.
69  void cross_over(EItem &V, EItem &A, EItem &B);
70 
72 
75  bool add_original_; // add original best if shifting?
76 
80 };
81 
82 
83 } // namespace optimization
84 } // namespace core
85 
86 
87 #endif // INCLUDED_core_optimization_GA_Minimizer_hh