Line data Source code
1 : !!****m* ABINIT/m_ga
2 : !! NAME
3 : !! m_ga
4 : !!
5 : !! FUNCTION
6 : !! This module provides several routines and datatypes for the
7 : !! Genetic algorithm stochastic search implementation.
8 : !!
9 : !! COPYRIGHT
10 : !! Copyright (C) 2012-2026 ABINIT group (MT)
11 : !! This file is distributed under the terms of the
12 : !! GNU General Public License, see ~abinit/COPYING
13 : !! or http://www.gnu.org/copyleft/gpl.txt .
14 : !!
15 : !! SOURCE
16 :
17 : #if defined HAVE_CONFIG_H
18 : #include "config.h"
19 : #endif
20 :
21 : #include "abi_common.h"
22 :
23 : MODULE m_ga
24 :
25 : use defs_basis
26 : use m_errors
27 : use m_abicore
28 : use m_dtset
29 :
30 : implicit none
31 :
32 : private
33 :
34 : !public procedures
35 : public :: ga_init
36 : public :: ga_destroy
37 : public :: ga_nullify
38 : !!***
39 :
40 : !!****t* m_ga/ga_type
41 : !! NAME
42 : !! ga_type
43 : !!
44 : !! FUNCTION
45 : !! Datatype with the variables required to perform GA random search
46 : !!
47 : !! NOTES
48 : !!
49 : !! SOURCE
50 :
51 : type,public :: ga_type
52 : ! Scalars
53 : integer :: ga_start ! Starting iteration for the Genetic algorithm
54 : integer :: ga_n_rules ! Number of genetic rules chosen by the user
55 : integer :: ga_fitness ! Fitness function chosen by the user
56 : integer :: ga_algor ! Genetic algorithm
57 : real(dp) :: ga_opt_percent ! Percentage of the population that passes from one iteration to the next
58 : ! Arrays same dimension as defined for the whole data input data structure
59 : integer :: ga_rules(30) ! Genetic rules chosen by the user
60 : integer,allocatable :: ga_iatfix(:,:) ! defined fixed atoms and directions
61 : end type ga_type
62 : !!***
63 :
64 : CONTAINS !===========================================================
65 : !!***
66 :
67 : !!****f* m_ga/ga_init
68 : !! NAME
69 : !! ga_init
70 : !!
71 : !! FUNCTION
72 : !! Initialize a datastructure of type ga_type.
73 : !!
74 : !! INPUTS
75 : !! dtset <type(dataset_type)>=all input variables in current dataset
76 : !!
77 : !! OUTPUT
78 : !!
79 : !! SIDE EFFECTS
80 : !! ga_param=datastructure of type ga_type.
81 : !! several parameters for Genetic Algorithm random search.
82 : !!
83 : !! SOURCE
84 :
85 3975 : subroutine ga_init(dtset,ga_param)
86 :
87 : !Arguments ------------------------------------
88 : !scalars
89 : type(dataset_type),target,intent(in) :: dtset
90 : type(ga_type),intent(inout) :: ga_param
91 :
92 : !************************************************************************
93 :
94 3975 : if(dtset%imgmov==4)then
95 1 : ga_param%ga_n_rules = dtset%ga_n_rules
96 31 : ga_param%ga_rules(:) = dtset%ga_rules
97 1 : ga_param%ga_fitness = dtset%ga_fitness
98 1 : ga_param%ga_opt_percent = dtset%ga_opt_percent
99 1 : ga_param%ga_algor = dtset%ga_algor
100 3 : ABI_MALLOC(ga_param%ga_iatfix,(3,dtset%natom))
101 34 : ga_param%ga_iatfix = dtset%iatfix
102 : end if
103 :
104 3975 : end subroutine ga_init
105 : !!***
106 :
107 : !----------------------------------------------------------------------
108 :
109 : !!****f* m_ga/ga_destroy
110 : !! NAME
111 : !! ga_destroy
112 : !!
113 : !! FUNCTION
114 : !! Destroy the content of a datastructure of type ga_type.
115 : !!
116 : !! INPUTS
117 : !!
118 : !! OUTPUT
119 : !!
120 : !! SIDE EFFECTS
121 : !! ga_param=datastructure of type ga_type.
122 : !! parameters for Genetic algorithm search.
123 : !!
124 : !! SOURCE
125 :
126 3975 : subroutine ga_destroy(ga_param)
127 :
128 : !Arguments ------------------------------------
129 : !scalars
130 : type(ga_type),intent(inout) :: ga_param
131 :
132 : !************************************************************************
133 :
134 3975 : if(allocated(ga_param%ga_iatfix))then
135 1 : ABI_FREE(ga_param%ga_iatfix)
136 : endif
137 3975 : call ga_nullify(ga_param)
138 :
139 3975 : end subroutine ga_destroy
140 : !!***
141 :
142 : !----------------------------------------------------------------------
143 :
144 : !!****f* m_ga/ga_nullify
145 : !! NAME
146 : !! ga_nullify
147 : !!
148 : !! FUNCTION
149 : !! Nullify the content of a datastructure of type ga_type.
150 : !!
151 : !! INPUTS
152 : !!
153 : !! OUTPUT
154 : !!
155 : !! SIDE EFFECTS
156 : !! ga_param=datastructure of type ga_type.
157 : !! several parameters for Genetic algorithm search.
158 : !!
159 : !! SOURCE
160 :
161 3975 : subroutine ga_nullify(ga_param)
162 :
163 : !Arguments ------------------------------------
164 : !scalars
165 : type(ga_type),intent(inout) :: ga_param
166 :
167 : !************************************************************************
168 :
169 3975 : ga_param%ga_start = -1
170 3975 : ga_param%ga_n_rules = -1
171 : ! ga_param%ga_algor = -1
172 3975 : ga_param%ga_opt_percent = zero
173 123225 : ga_param%ga_rules(:) = -1
174 :
175 0 : end subroutine ga_nullify
176 : !!***
177 :
178 0 : END MODULE m_ga
179 : !!***
|