Interesting Problem

This is a discussion on Interesting Problem within the C++ Programming forums, part of the General Programming Boards category; Ok I am trying to figure out the likelihood of a 'gene' becoming the 'parent' of the 'next generation' in ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    208

    Interesting Problem

    Ok I am trying to figure out the likelihood of a 'gene' becoming the 'parent' of the 'next generation' in my genetic algorithm program and everything compiles fine and outputs fint up till figuring out the percent of the very last 'chromosome' for some reason it gives me a output that isn't even a decimal.I have tried making the for loop go once more through and that still gives me a wrong awsner on the last ones. I have no idea what I did wrong but I have narrowed it down to a problem within my chances() funtion. I'll comment rite beside where the error seems to be occuring


    Code:
    int chances()
    { float suminverse;
      suminverse=1/fitnesslvls[0]+1/fitnesslvls[1]+1/fitnesslvls[2]+1/fitnesslvls[3]+1/fitnesslvls[4];
      cout<<"\n\n The Sum Of Ths Multiplicative Inverses= "<<suminverse<<"\n";
        for (int t=0;t<=4;t++)//in this for loop but only on the las time.
         {liklihood[t]=1/fitnesslvls[t]/suminverse;
          cout<<"The Likelihood Of Chromosome "<<t<<" Being Picked= "<<liklihood[t]<<"\n";
         }
    }
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    208
    they are all declared globally

    the values for those really vary because to start out with the algorithm is entirly random
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    208
    oh sorry it is fitnesslvls[4]
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    208
    sorry to sound kinda stupid but what?
    I don't understand to access the 4th member of my array I need to declare a array of 5??
    I am working with ints?????
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  5. #5
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Think!

    fitnesslvls[0]
    fitnesslvls[1]
    fitnesslvls[2]
    fitnesslvls[3]
    fitnesslvls[4]

    How many variables in the array are you accessing?
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    208
    5 check out my code
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An interesting problem of qsort()
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 03-05-2008, 12:09 PM
  2. Interesting Problem with IOCP and AcceptEx() :: Winsock
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 10-07-2003, 10:16 PM
  3. Interesting number theory problem
    By Zach L. in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 09-20-2003, 08:45 AM
  4. Interesting virtual function problem.
    By Sebastiani in forum C++ Programming
    Replies: 12
    Last Post: 09-02-2003, 11:08 PM
  5. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 08:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21