
102 Crow Search Algorithm
8.4 Source-code of CSA in C++
1 #i nclude <io st re am >
2 #i nclude <c s t d l i b >
3 #i nclude <ctime>
4
5 using namespace s td ;
6 f l o a t OF( f l o a t x [ ] , i n t s i z e _ a r r a y ) {
7 f l o a t t = 0 ;
8 fo r ( in t i = 0 ; i < s i z e_ a r r a y ; i ++) t = t + x [ i ] ∗ x [ i ] ;
9 return t ;
10 }
11 f l o a t r ( ) { return ( f l o a t ) ( rand ( ) %1000) / 1 0 0 0 ;}
12
13 i n t main ( )
14 {
15 sran d ( time (NULL) ) ;
16 in t N=10; i n t d=5; i nt IterMax =30; i nt I t e r =0;
17 f l o a t Crowmax = 5. 1 2 ; f l o a t Crowmin= −5.12;
18 f l o a t f l =0 .9 ; f l o a t AP=0 . 5 ;
19 f l o a t Crows [N ] [ d ] ; f