Question

Write a computer program to implement a generational GA for the One-Max problem: Use the following...

Write a computer program to implement a generational GA for the One-Max problem:

Use the following parameters:
• Representation: binary strings of length L=25;
• Initialization: random

• Parent selection: fitness proportionate, implemented using roulette wheel;
• Recombination: one-point crossover with probability pc= 0.7;
• Mutation: bit-flip with probability pm= 1/L;
• Population size = 100;
• Termination condition: 100 generation or optimum found.
After every generation find the best, worst, and mean fitness in the population and (possibly) plot then on a graph with time (generation) on the x axis.
Do 10 run and find the mean and standard deviation of the time (generations) taken to find the optimum.
Solution
Given the specification of the problem, it is rather simple to write a Java program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod (ll)(1e9 + 7)

// Iterative Function to calculate (x^y)%p in O(log y)
ll power(ll x, ll y, ll p)
{
   ll res = 1; // Initialize result

   x = x % p; // Update x if it is more than or
   // equal to p

   while (y > 0) {

       // If y is odd, multiply x with result
       if (y & 1)
           res = (res * x) % p;

       // y must be even now
       y = y >> 1; // y = y/2
       x = (x * x) % p;
   }
   return res;
}

// Function to count the number of binary
// strings of length N having only 0's and 1's
ll findCount(ll N)
{
   int count = power(2, N, mod);
   return count;
}

// Driver code
int main()
{
   ll N = 25;

   cout << findCount(N);

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a computer program to implement a generational GA for the One-Max problem: Use the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT