Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4040588
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:46:18+00:00 2026-05-20T12:46:18+00:00

Am developing a genetic algorithm in Java, that like all of them, requires the

  • 0

Am developing a genetic algorithm in Java, that like all of them, requires the crossover of two parent chromosomes. These chromosomes can be quite long, anywhere from 30 to 500 (but whatever length they have, they will all be the same size, so if the length is 80, in that GA run all will be 80).

I thought of developing in different ways but they all just seem to me like very inefficient, so I thought I might ask for new, different points of view and suggestions.

For example, one of the ways I thought was of converting the string to an array of characters and iterating from the start point to the end of the crossover locus (ie from s1 & s2[25] to s1 & s2[40]) copying into temporal arrays each of the arrays characters between those points and then iterating again and swapping them with the characters from the temporal array of the “partner”. But like I said it seems like for a program that will have a population of about 1000 chromosomes and with around 1000 generations will be extremely slow.


Here is an illustration of what two-point crossover looks like:

enter image description here


There is also the easier one point crossover:

enter image description here


As am not very advanced at all in Java could you advice me on what approach to take, maybe a Java function am unaware of, or some algorithm that I could implement?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:46:18+00:00Added an answer on May 20, 2026 at 12:46 pm
    // chromosomes
    String s1;
    String s2;
    
    // crossovers
    String c1;
    String c2;
    
    Random r = new Random();
    
    // get 2 random indices
    int ind1 = r.nextInt(s1.length());
    int ind2 = r.nextInt(s1.length());
    // make sure ind2 > ind1... leaving this part out;
    
    // break both strings into parts like in your picture
    String s1part1 = s1.substring(0, ind1);
    String s1part2 = s1.substring(ind1, ind2);
    String s1part3 = s1.substring(ind2);
    
    String s2part1 = s2.substring(0, ind1);
    String s2part2 = s2.substring(ind1, ind2);
    String s2part3 = s2.substring(ind2);
    
    // combine the parts
    c1 = s1part1 + s2part2 + s1part3;
    c2 = s2part1 + s1part2 + s2part3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application in C# which deals with specific genetic algorithm problem.
I am currently developing a small AI framework ( genetic algorithms / neural networks)
I'm developing a web app that emulates a generic file browser for the desktop,
I was developing a generic linked list. Although the compiler doesn't give any error
The background I'm developing a REST API for a C#.NET web application using WCF.
I am developing a web application. I am using Eclipse as IDE. I was
We are developing an application in ASP.Net MVC 3 using jQuery UI Dialog. This
The app I'm developing needs to be able to pull from several different data
I am developing an ASP.NET MVC 3 application using EF 4 and POCOs. One
I have a following requirement for a very complex UI. (Complex here means there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.