
Source-code of MBO algorithm in C++ 257
19.5 Source-code of MBO algorithm in C++
1 #i nclude <io st re am >
2 #i nclude <math . h>
3 #i nclude <time . h>
4 #i nclude <al go ri th m >
5 using namespace s td ;
6 //−−− fu n c t i on f o r swapping two v a l u e s i n t h e t a b l e
7 void swape ( f l o a t ∗xp , f l o a t ∗yp )
8 { f l o a t temp=∗xp ; ∗xp=∗yp ; ∗yp=temp ; }
9 //−−− fu n c t i on f o r r andom g e ne r at i o n o f number in exp d i s t r i b u t i o n
10 double ran_expo ( f l o a t lambda )
11 {double u ; u = rand ( ) /(RAND_MAX + 1 . 0 ) ;
12 return −l o g (1−u ) / lambda ; }
13 //−−− d e f i n i t i o n o f o b j e c t i v e fu n c t i