ElfPSP_AntColony
Protein Structure Prediction using Ant Colony Optimization
acopredictor.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include <vector>
6 #include <random>
7 
8 #include "hpchain.h"
9 #include "acosolution.h"
10 #include "config.h"
11 
14 class ACOPredictor {
18  int dCycles;
19  int dNAnts;
20  double dAlpha;
21  double dBeta;
22  double dEvap;
23  int dLSFreq;
25  int dRandSeed;
30  int dHCount;
31  double *dPheromone;
32  std::vector<std::mt19937> dRandGen;
33  std::uniform_real_distribution<> dRandDist;
38  double &pheromone(int i, int d) const;
39  double random(int tid = 0);
40  std::vector<double> get_heuristics(
41  const std::vector<vec3<int>> &possiblePos,
42  const std::vector<vec3<int>> &beadVector
43  );
44  std::vector<double> get_probabilities(int movIndex, std::vector<double> heuristics) const;
45  ACOSolution ant_develop_solution(int tid = 0);
46  void ant_deposit_pheromone(const std::vector<char> &directions, int nContacts);
47 
59  void perform_cycle(std::vector<ACOSolution> &antsSolutions, int *nContacts);
60 
61 public:
65  ACOPredictor(const Config &config);
66 
68  ~ACOPredictor();
69 
71  struct Results {
73  int contacts;
74  };
75 
78  struct Results predict();
79 };
80 
86 inline
87 void ACOPredictor::ant_deposit_pheromone(const std::vector<char> &directions, int nContacts){
88  for(unsigned i = 0; i < directions.size(); i++){
89  pheromone(i, directions[i]) += nContacts / dHCount;
90  }
91 }
92 
94 inline double &ACOPredictor::pheromone(int i, int d) const {
95  return dPheromone[i*5 + d];
96 }
97 
99 inline double ACOPredictor::random(int tid) {
100  double retval = dRandDist(dRandGen[tid]);
101  return retval;
102 }
Encapsulates a string representing an HP chain.
Definition: hpchain.h:8
ACOSolution dBestSol
Holds the best solution found by this colony.
Definition: acopredictor.h:35
Encapsulates the whole process of performing Ant Colony Optimization to find a protein conformation w...
Definition: acopredictor.h:14
double * dPheromone
Pheromone matrix.
Definition: acopredictor.h:31
Represents a triple (x, y, z) of any type.
Definition: vec3.h:12
int dNMovElems
Stores the number of moviments performed by an ant; its value is N-2 where N is the number of beads i...
Definition: acopredictor.h:29
int dHCount
Stores the number of hydrophobic (H) beads in the protein.
Definition: acopredictor.h:30
void ant_deposit_pheromone(const std::vector< char > &directions, int nContacts)
Deposits pheromones along the trail followed by the given ant.
Definition: acopredictor.h:87
ACOSolution solution
Best protein obtained by the ACO algorithm.
Definition: acopredictor.h:72
std::vector< double > get_heuristics(const std::vector< vec3< int >> &possiblePos, const std::vector< vec3< int >> &beadVector)
Returns a vector V with 5 heuristics.
Definition: acopredictor.cc:63
~ACOPredictor()
The destructor frees memory allocated for holding internal data structures.
Definition: acopredictor.cc:56
ACOSolution ant_develop_solution(int tid=0)
Makes an ant develop a solution, beginning from the start.
Definition: acopredictor_backtracking.cc:18
Reads the configuration file (eg configuration.yml) and stores the configuration parameters as intern...
Definition: config.h:11
HPChain dHPChain
See the user configuration file for documentation.
Definition: acopredictor.h:17
std::vector< std::mt19937 > dRandGen
Random number generators used throughout the ACO algorithm.
Definition: acopredictor.h:32
int dCycles
See the user configuration file for documentation.
Definition: acopredictor.h:18
int dBestContacts
Holds the num of contacts in the best solution.
Definition: acopredictor.h:36
int dLSFreq
See the user configuration file for documentation.
Definition: acopredictor.h:23
Structures used to return results to the callee.
Definition: acopredictor.h:71
int dNAnts
See the user configuration file for documentation.
Definition: acopredictor.h:19
int contacts
Number of H-H contacts within solution.
Definition: acopredictor.h:73
double dBeta
See the user configuration file for documentation.
Definition: acopredictor.h:21
void perform_cycle(std::vector< ACOSolution > &antsSolutions, int *nContacts)
Performs a cycle of the ant colony.
Definition: acopredictor_ant_cycle.cc:13
struct Results predict()
Runs the ACO optimization to predict the protein structure.
Definition: acopredictor_predict_mpi.cc:115
double dAlpha
See the user configuration file for documentation.
Definition: acopredictor.h:20
std::vector< double > get_probabilities(int movIndex, std::vector< double > heuristics) const
Return a vector V with 5 probabilities.
Definition: acopredictor.cc:110
double & pheromone(int i, int d) const
Returns the pheromone at step i and direction d.
Definition: acopredictor.h:94
int dRandSeed
See the user configuration file for documentation.
Definition: acopredictor.h:25
int dExchangedAnts
See the user configuration file for documentation.
Definition: acopredictor.h:24
ACOPredictor(const Config &config)
Constructor from configuration file.
Definition: acopredictor.cc:16
std::uniform_real_distribution dRandDist
Random distribution that uses dRandGen to generate random numbers.
Definition: acopredictor.h:33
double dEvap
See the user configuration file for documentation.
Definition: acopredictor.h:22
Encapsulates a solution that is built by an ant.
Definition: acosolution.h:12
double random(int tid=0)
Returns a random number in [0,1).
Definition: acopredictor.h:99