From 1f7c135934b6604c5409d4b6f34861105c0a64cb Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 9 Jul 2012 12:01:50 -0600 Subject: It works well enough to solve polynomial maxima. --- src/phenotypebinary.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/phenotypebinary.cpp') 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() return sRet; } +void Genetic::PhenotypeBinary::extractBits( uint32_t &rTarget, int iStart, + int iBits ) +{ + rTarget = 0; + if( iBits > sizeof(rTarget)*8 ) + iBits = sizeof(rTarget)*8; + + // This is pretty much the same problem as copyFrom, so I'm doing it the + // same way for now. + for( int j = 0; j < iBits; j++ ) + { + int ws = wordWithBit(j+iStart); + if( (aGenes[ws]&(1<<((j+iStart)%BPW))) != 0 ) + rTarget |= (1<<(j%BPW)); + } +} + +void Genetic::PhenotypeBinary::extractBits( uint64_t &rTarget, int iStart, + int iBits ) +{ + rTarget = 0; + if( iBits > sizeof(rTarget)*8 ) + iBits = sizeof(rTarget)*8; + + // This is pretty much the same problem as copyFrom, so I'm doing it the + // same way for now. + for( int j = 0; j < iBits; j++ ) + { + int ws = wordWithBit(j+iStart); + if( (aGenes[ws]&(1<<((j+iStart)%BPW))) != 0 ) + rTarget |= (1ll<<(j)); + } +} + -- cgit v1.2.3