⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_binary_genotype.cpp

📁 free library of genetic algorithms
💻 CPP
字号:
#include <iostream>#include <stdlib.h>#include <cpplibga/genotype/Binary.h>int main(void){    {	typedef cpplibga::genotype::Binary<1> GT;        GT b,c;		if(GT::size()!=1){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}		b.setGene(0,true);	if(b.getGene(0)!=true){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}	b.setGene(0,false);	if(b.getGene(0)!=false){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}		b.invertGene(0);	if(b.getGene(0)!=true){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}		c=b;	if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}    }    {	typedef cpplibga::genotype::Binary<13> GT;        GT b,c;		if(GT::size()!=13){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}		for(unsigned long t=0;t<1000;t++)	{	    unsigned long i=t%13;	    bool v=rand()<RAND_MAX/2;		    b.setGene(i,v);    	    if(b.getGene(i)!=v){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}		    b.invertGene(i);	    if(b.getGene(i)==v){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}	}	c=b;	if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}		for(unsigned long t=0;t<1000;t++)	{	    unsigned long i=t%13;	    bool v=b.getGene(i);	    	    b.setGene(i,!v);	    if(c==b){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}	    	    b.invertGene(i);	    if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}	    	    b.invertGene(i);	    b.setGene(i,v);	    if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}	}    }    {	typedef cpplibga::genotype::Binary<128> GT;        GT b,c;		if(GT::size()!=128){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}		for(unsigned long t=0;t<1000;t++)	{	    unsigned long i=t%128;	    bool v=rand()<RAND_MAX/2;		    b.setGene(i,v);    	    if(b.getGene(i)!=v){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}		    b.invertGene(i);	    if(b.getGene(i)==v){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}	}	c=b;	if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;}    }    std::cout<<"Ok"<<std::endl;    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -