Lattices can be copied using ``='' operator. The following listing shows an example of
``damage spreading'' experiment. We generate two lattices which differ only in one site,
and apply rule 22 to both of them for 20 consecutive iterations. At each iteration,
Hamming distance is computed and printed on the screen.
001 #include <hcell/hcell.h>
002 #include <iostream>
003 using namespace std;
004
005 int main()
006 {
007 CArule1d rule(1,22); // define rule 22
008 Lattice lat1(50); // define first lattice
009 Lattice lat2(50); // define second lattice
010 r250init(1234); //initialize RNG
011 //seed lattice randomly to get exactly 50% sites occupied
012 lat1.PreciseSeed(0.5);
013 lat2=lat1; //set lattice 2 to be equal to lattice 1
014 lat2[25]=1-lat1[25]; //flip bit nr. 25 in the second lattice
015 for(int j=1; j<20 ; j++)
016 {
017 cout <<Hamming(lat1,lat2)<<endl; //print Hamming distance
018 Evolve(&lat1, rule);
019 Evolve(&lat2, rule);
020 }
021 return 0;
022 }
In addition to the Hamming distance, HCELL allows to compute lattice density,
number of ones (called ``population''), as well as two types of entropy.
These operations are demonstrated in the listing below.
001 #include <hcell/hcell.h>
002 #include <iostream>
003 using namespace std;
004
005 int main()
006 {
007 CArule1d rule1(1,22); // define rule 22
008 CArule1d rule2(1,184); // define rule 184
009 Lattice lat1(50); // define first lattice
010 Lattice lat2(10); // define second lattice
011 r250init(1234); //initialize RNG
012 //seed lattice randomly to get exactly 50% sites occupied
013 lat1.PreciseSeed(0.5);
014 lat2=lat1; //set lattice 2 to be equal to lattice 1
015 //note that this resizes lattice 2 automatically
016 //let's iterate both rules 100 times
017 Evolve(&lat1, rule1,100);
018 Evolve(&lat2, rule2,100);
019 //now we print density of lattice 1
020 cout <<"Density of lat1 = "<<lat1.Density()<<endl;
021 //print number of ones in lattice 2
022 cout <<"Population of lat2 = "<<lat1.Population()<<endl;
023 //print spatial set entropy with block size 4
024 cout <<"Spatial set entropy of lat1 = "<< SpatialSetEntropy(lat1, 4)<<endl;
025 //print spatial measure entropy with block size 5
026 cout <<"Spatial measure entropy of lat2 = "<< SpatialSetEntropy(lat2, 5)<<endl;
027
028 return 0;
029 }
H.F.