Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help working with classes

    I am working on a genetic algorithm to minimize the spherical function. http://www.cs.cmu.edu/afs/cs/project...#tabla:DefFunc

    I have a class for each gene which is an array of size 30 with an associated fitness score.

    I am having trouble passing the class to my crossover function which selects the best fitness scores and mixes their genetics.

    Here is my code so far http://codepad.org/RWrPSXiE
    Last edited by FrogCity; 09-11-2011 at 10:43 PM. Reason: subscribe

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You can't call functions outside of any functions, move your call to srand into the main function before your for loop.

    Edit: You could also change your program so that the constructor on your Geotype randomizes the array.


    Edit: #2 This line: fitnessScore(Genotype individual); should be fitnessScore(individual); You don't need to specify the type again.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •