<div>Hello,</div>
<div> </div>
<div> I am trying to use a GA1DArrayGenome with the elements of the array being instances of user defined class "Point". </div>
<div> </div>
<div>The error appears on the line when I try to isntantiate a genome of type GA1DArrayGenome<Point> :</div>
<div> </div>
<div>GA1DArrayGenome<Point> genome1(5,objective);</div>
<div>(I need to create an array of 5 points).</div>
<div> </div>
<div>Here is my code, and following that are the errors that I keep on getting. If anyone has any suggestions, I would greatly appreciate it.</div>
<div> </div>
<div>Regards,</div>
<div> </div>
<div>Faisal Goussous</div>
<div>Research Assistant</div>
<div>The University of Iowa</div>
<div>IA, USA</div>
<div> </div>
<div> </div>
<div>
<p>#include <iostream><br>#include <fstream><br>#include <stdio.h><br>#include <ga/ga.h><br>#include <ga/std_stream.h><br>#include <ga/GA1DArrayGenome.h><br>#include <ga/GA1DArrayGenome.c>
</p>
<p><br>#define INSTANTIATE_REAL_GENOME<br>#define ostream STD_OSTREAM</p>
<p>using std::ifstream;<br>using std::ofstream;<br>using std::ios;<br>using std::cout;<br>using std::cin;<br>using std::endl;</p>
<p>// function prototypes<br>float objective(GAGenome &);</p>
<p>/*************************************************************************************************/<br>class Point {<br>public:<br> Point(float x, float y, float z) { _x = x; _y = y; _z = z; }<br> Point(const Point & p) { _x = p._x; _y = p._y; _z = p._z; }
<br> Point(){} // default constructor</p>
<p> int operator ==(const Point & p) const<br> {<br> if((p.x()==_x)&&(p.y()==_y)&&(p.z()==_z))<br> return 1;<br> else return 0;<br> }</p>
<p> int operator !=(const Point & p) const<br> {<br> if((p.x()==_x)&&(p.y()==_y)&&(p.z()==_z))<br> return 0;<br> else return 1;<br> }</p>
<p> Point & operator=(const Point & p) { _x=p._x;_y=p._y;_z=p._z; return *this; }<br> ~Point() {}</p>
<p> float x() const { return _x; }<br> float y() const { return _y; }<br> float z() const { return _z; }<br> float x(float val) { return _x=val; }<br> float y(float val) { return _y=val; }<br> float z(float val) { return _z=val; }
</p>
<p> friend ostream & operator<<(ostream & os, const Point & p){<br> os << "(" << p._x << ", " << p._y << ", " << p._z << ")";
<br> return os;<br> }</p>
<p>protected:<br> float _x, _y, _z;<br>};</p>
<p>/***************************************************************************************************/<br>int main(int argc, char** argv)<br>{</p>
<p>// See if we've been given a seed to use (for testing purposes). When you<br>// specify a random seed, the evolution will be exactly the same each time<br>// you use that seed number.<br> unsigned int seed = 0;<br> for(int ii=1; ii<argc; ii++)
<br> {<br> if(strcmp(argv[ii++],"seed") == 0)<br> {<br> seed = atoi(argv[ii]);<br> }<br> }</p>
<p>// create the genome (design representation)<br>GA1DArrayGenome<Point> genome1(5,objective);</p>
<p>// Create a GA class and set its parameters and options<br>GASteadyStateGA ga1(genome1);</p>
<p>// no scaling of fitness function values<br>GANoScaling scale;<br>ga1.scaling(scale);</p>
<p>GAParameterList params;<br>GASteadyStateGA::registerDefaultParameters(params);<br>params.set(gaNnGenerations, 100); // number of generations<br>params.set(gaNpopulationSize, 110); // population size<br>params.set(gaNscoreFrequency, 10); // Specify how often the generational scores should be recorded
<br>params.set(gaNflushFrequency, 50); //specify how often the scores should be flushed to disk (every 50 generations)<br>params.set(gaNpCrossover, 0.6); // probability of crossover<br>params.set(gaNpMutation, 0.10); // probability of mutation (higher than normal, but suitable for the problem)
<br>params.set(gaNselectScores, (int)GAStatistics::AllScores);<br>params.parse(argc, argv, gaFalse);</p>
<p>ga1.parameters(params);<br>ga1.set(gaNscoreFilename, "faisal's output.dat");<br>ga1.initialize();</p>
<p>// start the evolution<br>ga1.evolve();</p>
<p>cout<< ga1.population().best();</p>
<p>return 0 ;</p>
<p>}</p>
<p>// The Fitness Function to be MAXIMIZED<br>float objective(GAGenome& g)<br>{<br> GA1DArrayGenome<Point>& genome = (GA1DArrayGenome<Point>&)g;</p>
<p> Point p1 = genome.gene(0);<br> Point p2 = genome.gene(1);<br> Point p3 = genome.gene(2);<br> Point p4 = genome.gene(3);<br> Point p5 = genome.gene(4);</p>
<p> float objective = p1.z()+p2.z()+p3.z()+ p4.z()+ p5.z(); // objective function<br> return objective;<br>}<br></p>
<p>Errors ( actually only 1 eerror):</p><font size="1">
<p><strong>Compiling...</strong></p>
<p><strong>main.cpp</strong></p>
<p><strong>D:\Profile\fgoussou\Desktop\GAs\GAlib\ga\GAArray.h(34) : error C2440: 'type cast' : cannot convert from 'int' to 'Point'</strong></p>
<p><strong>No constructor could take the source type, or constructor overload resolution was ambiguous</strong></p>
<p><strong>D:\Profile\fgoussou\Desktop\GAs\GAlib\ga\GAArray.h(33) : while compiling class-template member function 'GAArray<T>::GAArray(unsigned int)'</strong></p>
<p><strong>with</strong></p>
<p><strong>[</strong></p>
<p><strong>T=Point</strong></p>
<p><strong>]</strong></p>
<p><strong>D:\Profile\fgoussou\Desktop\GAs\GAlib\ga\GA1DArrayGenome.h(37) : see reference to class template instantiation 'GAArray<T>' being compiled</strong></p>
<p><strong>with</strong></p>
<p><strong>[</strong></p>
<p><strong>T=Point</strong></p>
<p><strong>]</strong></p>
<p><strong>main.cpp(80) : see reference to class template instantiation 'GA1DArrayGenome<T>' being compiled</strong></p>
<p><strong>with</strong></p>
<p><strong>[</strong></p>
<p><strong>T=Point</strong></p>
<p><strong>]</strong></p></font></div>