Created
March 6, 2011 07:45
-
-
Save ytomino/857122 to your computer and use it in GitHub Desktop.
The crossover operator for Genetic Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Crossover (X, Y : Array_Type; Start_Index : Index_Type) return Array_Type is | |
Result : Array_Type := X; | |
Start_Item : constant Element_Type := X (Start_Index); | |
Index : Index_Type := Start_Index; | |
begin | |
while Y (Index) /= Start_Item loop | |
for I in X'Range loop | |
if X (I) = Y (Index) then | |
Result (Index) := Y (Index); | |
Index := I; | |
goto Found; | |
end if; | |
end loop; | |
raise Program_Error; | |
<<Found>> null; | |
end loop; | |
Result (Index) := Y (Index); | |
return Result; | |
end Crossover; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generic | |
type Index_Type is (<>); | |
type Element_Type is private; | |
type Array_Type is array (Index_Type) of Element_Type; | |
function Crossover (X, Y : Array_Type; Start_Index : Index_Type) return Array_Type; | |
pragma Pure (Crossover); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment