
algoritmo genético
#1
Escrito 11 agosto 2010 - 02:06
#2
Escrito 11 agosto 2010 - 06:58
http://www.mygnet.ne...ciones.1563.zip
No se que clase de código necesitás pero buscando en google: algoritmo + genetico + c++
Saludos
#3
Escrito 12 agosto 2010 - 05:00
Te muestro un printScreen de cuando intento acceder a la pagina que me recomiendas.
Muchas gracias de todos modos...Solo postee por si alguien del foro tenia algunos ejemplos propios o había incursionado en el tema.
Saludos
#5
Escrito 12 agosto 2010 - 03:45

#6
Escrito 07 septiembre 2010 - 04:49
#7
Escrito 07 septiembre 2010 - 08:40
Saludos.
#8
Escrito 15 septiembre 2010 - 02:10
GA2DBinaryStringGenome genome(width, height, Objective);
el error:
[C++ Error] Unit1.cpp(37): E2285 Could not find a match for 'GA2DBinaryStringGenome::GA2DBinaryStringGenome(int,int,void)'
#9
Escrito 15 septiembre 2010 - 03:35
[C++ Error] Unit1.cpp(37): E2285 Could not find a match for 'GA2DBinaryStringGenome::GA2DBinaryStringGenome(int,int,void)'
?? Seguro?, No será:
[C++ Error] Unit1.cpp(37): E2285 Could not find a match for 'GA2DBinaryStringGenome::GA2DBinaryStringGenome(int,int,void*)'
El problema es un error de tipos. Prueba así:
GA2DBinaryStringGenome genome(width, height, (void*)Objective);
Si Objective es un puntero y si no lo es, entonces:
GA2DBinaryStringGenome genome(width, height, (void*)&Objective);
Saludos.
#10
Escrito 16 septiembre 2010 - 05:41
Te diré que el error es tal y cual te dije sin cambios.
Probando el primer ejemplo que me mandas me da el siguiente error:
[C++ Error] Unit1.cpp(37): E2235 Member function must be called or its address taken
Probando el segundo me da el siguiente error:
[C++ Error] Unit1.cpp(37): E2031 Cannot cast from 'float (* (_closure )(GAGenome &))(GAGenome &)' to 'void *'
Aquí te mando el .cpp para que puedas ver que Objetive es una función y ver si me puedes ayudar
#11
Escrito 16 septiembre 2010 - 06:47
GA2DBinaryStringGenome::GA2DBinaryStringGenome
y
Objective
Saludos.
#12
Escrito 16 septiembre 2010 - 07:23
GA2DBinaryStringGenome::GA2DBinaryStringGenome
y
Objective
por favor chequea el adjunto.
#13
Escrito 16 septiembre 2010 - 07:27
Para compilar tuve que utilizar el make.exe que esta en el directorio:
C:\...carpeta donde esta instalado c++builder...\Bin\make.exe
la linea que le pase fue:
make -f makefile.bcc
La explicación mas detallada esta en el README de la propia librería. y el ejemplo que intento compilar es el 1.
Sin mas la librería adjunta.
Archivos adjuntos
#14
Escrito 16 septiembre 2010 - 10:44
GA2DBinaryStringGenome genome(width, height, (GAGenome::Evaluator)Objective);
Saludos.
#15
Escrito 16 septiembre 2010 - 11:17
lo que aun me salen errores aquí te lo expongo:
[C++ Error] Unit1.cpp(37): E2235 Member function must be called or its address taken
Saludos y gracias
#16
Escrito 16 septiembre 2010 - 11:35
[C++ Error] Unit1.cpp(37): E2235 Member function must be called or its address taken
¿Ese error te lo da en la línea?
GA2DBinaryStringGenome genome(width, height, (GAGenome::Evaluator)Objective);
¿O lo da en otro lado?
¿Objetive es la función que he visto en tu código?
Saludos.
#17
Escrito 16 septiembre 2010 - 12:11
aqui te adjunto una imagen del erro y la linea que me señala el builder
#18
Escrito 16 septiembre 2010 - 12:59
efectivamente el error me lo da en esa misma linea. y si Objetive es la función que esta declarada en el .cpp
aqui te adjunto una imagen del erro y la linea que me señala el builder
Bien. ¿Objetive está declarada antes de ser utilizada en la línea del error?.
Saludos.
#19
Escrito 16 septiembre 2010 - 01:08
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include <ga/GASimpleGA.h> // we're going to use the simple GA #include <ga/GA2DBinStrGenome.h> // and the 2D binary string genome #include <ga/std_stream.h> #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { int width = 10; int height = 5; int popsize = 30; int ngen = 400; float pmut = 0.001; float pcross = 0.9; GA2DBinaryStringGenome genome(width, height, (GAGenome::Evaluator)Objective); GASimpleGA ga(genome); ga.populationSize(popsize); ga.nGenerations(ngen); ga.pMutation(pmut); ga.pCrossover(pcross); ga.evolve(); cout << "The GA found:\n" << ga.statistics().bestIndividual() << "\n"; } //--------------------------------------------------------------------------- float Objective(GAGenome& g) { GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)g; float score=0.0; int count=0; for(int i=0; i<genome.width(); i++){ for(int j=0; j<genome.height(); j++){ if(genome.gene(i,j) == 0 && count%2 == 0) score += 1.0; if(genome.gene(i,j) == 1 && count%2 != 0) score += 1.0; count++; } } return score; }
y el .h
//--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; void __fastcall Button1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); float Objective(GAGenome& g); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif
#20
Escrito 16 septiembre 2010 - 01:14
Por un lado declaras Objetive como miembro de la clase TForm1, sin embargo, por otro lado la implamantas fuera de la clase:
//--------------------------------------------------------------------------- float Objective(GAGenome& g) { GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)g; float score=0.0; int count=0; for(int i=0; i<genome.width(); i++){ for(int j=0; j<genome.height(); j++){ if(genome.gene(i,j) == 0 && count%2 == 0) score += 1.0; if(genome.gene(i,j) == 1 && count%2 != 0) score += 1.0; count++; } } return score; }
Esto hace que esta función y la de la clase sean distintas. Es posible que no la tengas declarada al llamarla.
si quieres que objetive sea miembor de TForm1 debes hacerlo así:
//--------------------------------------------------------------------------- float TForm1::Objective(GAGenome& g) { GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)g; float score=0.0; int count=0; for(int i=0; i<genome.width(); i++){ for(int j=0; j<genome.height(); j++){ if(genome.gene(i,j) == 0 && count%2 == 0) score += 1.0; if(genome.gene(i,j) == 1 && count%2 != 0) score += 1.0; count++; } } return score; }
Saludos.