primitives.cc

来自「标准的GP源代码,由Andy Singleton维护」· CC 代码 · 共 1,578 行 · 第 1/3 页

CC
1,578 行
字号
	BOOL a = sub_tree_contains(chrome,target);	chrome->ip = save_ip;	return a;}//end tree_contains//////////////////////////////////////////////////////////////////////void indexed_memory::clear( int& seed){	Aux1 = Aux2 = Aux3 = 0;	if (seed==0) {		memset(store,     0,sizeof(store));	}	else {		for ( int i = 1; i<store_limit; i++ ) {			store[i] = random_value(seed);		}        }}void clear( int& seed){#ifdef ADF	memset(calls,0,sizeof(calls));#endif	Primitive_error = 0;	Memory_errors = 0;#ifdef ORIGINAL_LOOP        inner_loop_value = 0;#else        clear_loop_value();#endif        iterate_count = 0;	Arg1 = Arg2 = 0;	ARG1 = ARG2 = 0;	Aux1 = Aux2 = Aux3 = 0;	if (seed==0) {		memset(store,     0,sizeof(store));	}	else {		for ( int i = 1; i<store_limit; i++ ) {			store[i] = random_value(seed);		}        }#ifdef STACK_PRIM	makenullEval();#endif}void indexed_memory::clear_stats(){	memset(store_used,0,sizeof(store_used));}void clear_stats(){	memset(store_used,0,sizeof(store_used));#ifdef TIMINGS	ThisTimmer->clear();#endif}void indexed_memory::save_active(){	Aux1 = ::Aux1;	Aux2 = ::Aux2;	Aux3 = ::Aux3;	memcpy(store,     ::store,sizeof(store));	memcpy(store_used,::store_used,sizeof(store_used));}void indexed_memory::load_active(){	::Aux1 = Aux1;	::Aux2 = Aux2;	::Aux3 = Aux3;	memcpy(::store,     ::store,sizeof(store));	memcpy(::store_used,::store_used,sizeof(store_used));}int indexed_memory::cells_used(){	int used = 0;	for ( int i = 1; i<store_limit; i++ ) {		if(store_used[i]!=0) used++;}	return used;}int cells_used(){	int used = 0;	for ( int i = 1; i<store_limit; i++ ) {		if(store_used[i]!=0) used++;}	return used;}int indexed_memory::cells_used_spanned(){	int lowest_used  = store_limit + 1;	int highest_used = -1;	for ( int i = 1; i<store_limit; i++ ) {		if(store_used[i]!=0) {			if(i>highest_used) highest_used = i;			if(i<lowest_used ) lowest_used  = i;		}	}		return (highest_used<0) ? 0 : highest_used + 1 - lowest_used;}int cells_used_spanned(){	int lowest_used  = store_limit + 1;	int highest_used = -1;	for ( int i = 1; i<store_limit; i++ ) {		if(store_used[i]!=0) {			if(i>highest_used) highest_used = i;			if(i<lowest_used ) lowest_used  = i;		}	}		return (highest_used<0) ? 0 : highest_used + 1 - lowest_used;}int indexed_memory::cells_written(){	int used = 0;	for ( int i = 1; i<store_limit; i++ ) {		if((store_used[i]&store_written)!=0) used++;}	return used;}int cells_written(){	int used = 0;	for ( int i = 1; i<store_limit; i++ ) {		if((store_used[i]&store_written)!=0) used++;}	return used;}int indexed_memory::cells_written_spanned(){	int lowest_used  = store_limit + 1;	int highest_used = -1;	for ( int i = 1; i<store_limit; i++ ) {		if((store_used[i]&store_written)!=0) {			if(i>highest_used) highest_used = i;			if(i<lowest_used ) lowest_used  = i;		}	}		return (highest_used<0) ? 0 : highest_used + 1 - lowest_used;}int cells_written_spanned(){	int lowest_used  = store_limit + 1;	int highest_used = -1;	for ( int i = 1; i<store_limit; i++ ) {		if((store_used[i]&store_written)!=0) {			if(i>highest_used) highest_used = i;			if(i<lowest_used ) lowest_used  = i;		}	}		return (highest_used<0) ? 0 : highest_used + 1 - lowest_used;}int indexed_memory::cells_read_before_write(){	int used = 0;	for ( int i = 1; i<store_limit; i++ ) {		if((store_used[i]&store_read_unassigned)!=0) used++;}		return used;}int cells_read_before_write(){	int used = 0;	for ( int i = 1; i<store_limit; i++ ) {		if((store_used[i]&store_read_unassigned)!=0) used++;}		return used;}void indexed_memory::write( ostream& fout ){	fout<<" Aux1 = " << Aux1;#ifdef AUX2	fout<<" Aux2 = " << Aux2;	fout<<" Aux3 = " << Aux3;#endif#ifdef BYREF	fout<<" lvusd  " <<last_var_used;#endif //BYREF	fout<<endl;	for ( int i = 1; i<store_limit; i++ ) {		if(store_used[i]!=0){			fout <<i + Array_bot - 1<<"\t";			if((store_used[i]&store_read_unassigned)!=0)				fout<<"u";			else				fout<<" ";			if((store_used[i]&store_written)!=0)				fout<<"w ";			else				fout<<"  ";				fout<<store[i]<<endl;		}	}}void write( ostream& fout ){	fout<<" Aux1 = " << Aux1;#ifdef AUX2	fout<<" Aux2 = " << Aux2;	fout<<" Aux3 = " << Aux3;#endif#ifdef BYREF	fout<<" lvusd  " <<last_var_used;#endif //BYREF	fout<<endl;	for ( int i = 1; i<store_limit; i++ ) {		if(store_used[i]!=0){			fout <<i + Array_bot - 1 <<"\t";			if((store_used[i]&store_read_unassigned)!=0)				fout<<"u";			else				fout<<" ";			if((store_used[i]&store_written)!=0)				fout<<"w ";			else				fout<<"  ";				fout<<store[i]<<endl;		}	}}//////////////////////////////////////////////////////////////////////static retval print_buffer[print_buffer_size];       int    print_buffer_position;OPDEF(printEval){#ifdef DEBUGcout<<"printEval start "<<IP<<flush;#endifretval value = EVAL;#ifdef DEBUGcout<<"printEval end "<<IP<<endl;#endifif(print_buffer_position<print_buffer_size) {	print_buffer[print_buffer_position++] = value;	return print_buffer_position;}else	Primitive_error |= print_overrun_error;	return 0;}//inlined WBL 21 Feb 95//void print_clear()//{//	print_buffer_position = 0;//   //	memset(print_buffer,0,sizeof(print_buffer));//}void print_write(ostream& fout){	fout<<"prtbuf=\t"<<print_buffer_position;	for(int i = 0; i<print_buffer_position; i++) {		fout<<" "<<print_buffer[i];	}}BOOL print_equals(int length, retval* buffer){	if (print_buffer_position != length)		return FALSE;	for(int i = 0; i<print_buffer_position; i++) {		if(print_buffer[i] != buffer[i])			return FALSE;	}	return TRUE;}float print_match(int length, retval* buffer, BOOL& exact){	float score = 0.0;	if (print_buffer_position == length) {		if(memcmp(print_buffer,buffer,length*sizeof(retval))==0) {			exact = TRUE;			return print_match_max_score(length);		}	}	score += print_match_length_score(length, print_buffer_position);	for(int i = 0; i<length; i++) {		for (int j = 0; j<print_buffer_position; j++) {			if(print_buffer[j] == buffer[i]) {				score += print_match_item_score(length);				break; //leave j loop			}		}	}	float max_order_score = 0.0;	for(int k = 0; k<length; k++) { 	int   last_match_j = -1;	float order_score  = 0.0;	BOOL match = FALSE;	for(int i = k; i<length; i++) {		for (int j = 1+last_match_j; j<print_buffer_position; j++) {			if(print_buffer[j] == buffer[i]) {				last_match_j = j;				order_score += print_match_order_score(length);				match = TRUE;				break; //leave loop j			}		}	}#ifdef DEBUG	cout<<"k="<<k<<" order_score "<<order_score<<flush;#endif	if(order_score > max_order_score) max_order_score = order_score;	if(max_order_score+0.00001 >= length*print_match_order_score(length)) {#ifdef DEBUG		cout<<"Reached print_match_order_score "<<max_order_score		    <<" "<<k<<endl;#endif		break;	}	if( (print_buffer_position-k-1) * print_match_order_score(length)	                                                   <= max_order_score){#ifdef DEBUG		cout<<"Cant exceed max_order_score "<<max_order_score		    <<" "<<k<<endl;#endif		break;        }	if(match==FALSE) {#ifdef DEBUG		cout<<"No matches "<<k<<endl;#endif		break;        }	}//end loop k	score += max_order_score;	return score;}int randEval_seed = 1;OPDEF(randEval) //assumes retval=float{	float range = EVAL;	intrnd (randEval_seed);	return range*(float(randEval_seed)/2147483647.0);}//LastEval//////////////////////////////////////////////////////////////////////void gp::AddF1 (int t, Function* f ){AddF(f);addtofuncbag(t, f);}void gp::AddFbar1 (int exclude_tree, Function* f ){AddF(f);for ( int i = 0; i < NUM_TREES; i++ )	{if ( i != exclude_tree) addtofuncbag(i, f);};}void gp::AddF2 (int t1, int t2, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);}void gp::AddF3 (int t1, int t2, int t3, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);}void gp::AddF4 (int t1, int t2, int t3, int t4, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);addtofuncbag(t4, f);}void gp::AddF5 (int t1, int t2, int t3, int t4, int t5, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);addtofuncbag(t4, f);addtofuncbag(t5, f);}void gp::AddF6 (int t1, int t2, int t3, int t4, int t5, int t6, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);addtofuncbag(t4, f);addtofuncbag(t5, f);addtofuncbag(t6, f);}void gp::AddF7 (int t1, int t2, int t3, 		int t4, int t5, int t6, int t7, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);addtofuncbag(t4, f);addtofuncbag(t5, f);addtofuncbag(t6, f);addtofuncbag(t7, f);}void gp::AddF8 (int t1, int t2, int t3, 		int t4, int t5, int t6, int t7, int t8, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);addtofuncbag(t4, f);addtofuncbag(t5, f);addtofuncbag(t6, f);addtofuncbag(t7, f);addtofuncbag(t8, f);}void gp::AddF9 (int t1, int t2, int t3, 		int t4, int t5, int t6, int t7, int t8, int t9, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);addtofuncbag(t4, f);addtofuncbag(t5, f);addtofuncbag(t6, f);addtofuncbag(t7, f);addtofuncbag(t8, f);addtofuncbag(t9, f);}void gp::AddF11 (int t1, int t2, int t3,  int t4, int t5, int t6, int t7,                  int t8, int t9, int t10, int t11, Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);addtofuncbag(t4, f);addtofuncbag(t5, f);addtofuncbag(t6, f);addtofuncbag(t7, f);addtofuncbag(t8, f);addtofuncbag(t9, f);addtofuncbag(t10, f);addtofuncbag(t11, f);}void gp::AddF13 (int t1, int t2, int t3,  int t4,  int t5,  int t6, int t7,                  int t8, int t9, int t10, int t11, int t12, int t13, 		 Function* f ){AddF(f);addtofuncbag(t1, f);addtofuncbag(t2, f);addtofuncbag(t3, f);addtofuncbag(t4, f);addtofuncbag(t5, f);addtofuncbag(t6, f);addtofuncbag(t7, f);addtofuncbag(t8, f);addtofuncbag(t9, f);addtofuncbag(t10, f);addtofuncbag(t11, f);addtofuncbag(t12, f);addtofuncbag(t13, f);}#ifdef ADFvoid gp::AddFmain (Function* f ){AddFbar1(adf1, f);}#endif //ADFvoid gp::AddFall (Function* f ){AddFbar1 (-1, f);}

⌨️ 快捷键说明

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