Hello all!! First of all, excuse me about my english.
I'm working on a genetic algorithm to solve the TSP. I already have a program that does the work, but I want to improve it. Particulary the crossover function. This is what I have so far:
class Path implements Comparable {
Map myMap;
IntList item;
Path(Map _myMap){
myMap = _myMap;
// init a random path
item = new IntList();
for(int i=0; i < myMap.n_cities; i++){
item.append(i);
}
item.shuffle();
}
....
Path crossover(Path partner){
Path son = new Path(myMap);
int cut = int(random(this.item.size()));
son.clear();
for(int i=0; i < cut; i++)
son.item.append(this.item.get(i));
for(int i=0; i < partner.item.size(); i++){
if(!son.item.hasValue(partner.item.get(i)))
son.item.append(partner.item.get(i));
}
return son;
}
........
}
As you can see, the crossover method copies the first n elements of the parent A (I cut the chromosome in 1 point), and then complete the rest with the elements of the parent B wich havent been copied yet.
Now, I'd like to select a subset inbetween the parent A, copy it to the child, and then complete it with the elements of B. (same concept, but this time cutting the chromosome in 3 points).
Do you have any idea how can I do this??
I figured a way to do it, but I need to use some methods of the IntList class like .getSubset() or .insert(), but I dont know why I cant use them. Here is the reference.
Im working in a little project and I need to know the distance between some point (x,y) and the first black pixel of an image in a given direction.
Im trying to simulate a maze solving robot. The point represents the robot, and the image will be the maze (black walls). The robot needs to know how far are the walls in the front and the sides.
I attach an image to illustrate this:
So, what I need is to know the lenght of the red lines.
I read that there is a problem in linux with the key functions. When I hold a key, the keyPressed() and keyReleased() functions are triggered
continuously.
I want to send a character via serial port only ONCE, when a key is pressed, and send another when the key is released. i.e. send an 'A' when the key A is pressed, and send an 'a' when its released.