summaryrefslogtreecommitdiff
path: root/src/phenotypebinary.cpp
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2012-07-09 12:01:50 -0600
committerMike Buland <mike@xagasoft.com>2012-07-09 12:01:50 -0600
commit1f7c135934b6604c5409d4b6f34861105c0a64cb (patch)
treecc421e2e8620b72e202f0eddf2cd5f1478d3bc06 /src/phenotypebinary.cpp
parent40ee7ad5aeadeb9823e1cd6e1218a1999c608a65 (diff)
downloadlibgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.gz
libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.bz2
libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.xz
libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.zip
It works well enough to solve polynomial maxima.
Diffstat (limited to 'src/phenotypebinary.cpp')
-rw-r--r--src/phenotypebinary.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/phenotypebinary.cpp b/src/phenotypebinary.cpp
index d16588b..68f9ebf 100644
--- a/src/phenotypebinary.cpp
+++ b/src/phenotypebinary.cpp
@@ -99,3 +99,37 @@ Bu::String Genetic::PhenotypeBinary::toString()
99 return sRet; 99 return sRet;
100} 100}
101 101
102void Genetic::PhenotypeBinary::extractBits( uint32_t &rTarget, int iStart,
103 int iBits )
104{
105 rTarget = 0;
106 if( iBits > sizeof(rTarget)*8 )
107 iBits = sizeof(rTarget)*8;
108
109 // This is pretty much the same problem as copyFrom, so I'm doing it the
110 // same way for now.
111 for( int j = 0; j < iBits; j++ )
112 {
113 int ws = wordWithBit(j+iStart);
114 if( (aGenes[ws]&(1<<((j+iStart)%BPW))) != 0 )
115 rTarget |= (1<<(j%BPW));
116 }
117}
118
119void Genetic::PhenotypeBinary::extractBits( uint64_t &rTarget, int iStart,
120 int iBits )
121{
122 rTarget = 0;
123 if( iBits > sizeof(rTarget)*8 )
124 iBits = sizeof(rTarget)*8;
125
126 // This is pretty much the same problem as copyFrom, so I'm doing it the
127 // same way for now.
128 for( int j = 0; j < iBits; j++ )
129 {
130 int ws = wordWithBit(j+iStart);
131 if( (aGenes[ws]&(1<<((j+iStart)%BPW))) != 0 )
132 rTarget |= (1ll<<(j));
133 }
134}
135