You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Genetic Sharp to generate the Best team of Drones for a mission. Each gene in my chromossome stores the amount of a specific type of drone. The algorithm works perfectly fine except sometimes when performing a Uniform mutation it will try to change a gene outside of the chromossome. How could this happen? Am I doing something wrong?
Here is my code:
Chromossome
publicclassTeamChromosome:ChromosomeBase{privatereadonlyint[]_maxAmounts;publicTeamChromosome(int[]maxAmounts):base(maxAmounts.Length){_maxAmounts=maxAmounts;CreateGenes();}publicoverrideIChromosomeCreateNew(){returnnewTeamChromosome(_maxAmounts);}publicoverrideGeneGenerateGene(intgeneIndex){// Generate random gene value within the maximum amount for the typereturnnewGene(RandomizationProvider.Current.GetInt(0,_maxAmounts[geneIndex]+1));}}
And my fitness Function
publicclassDroneTeamFitness:IFitness{privateMissionPlannermissionPlanner;privateList<int>quantities;privateList<List<Drone>>capableDrones;privateboolbasedOnTime;publicDroneTeamFitness(MissionPlannermissionPlanner,List<int>quantities,List<List<Drone>>capableDrones,boolbasedOnTime){this.missionPlanner=missionPlanner;this.quantities=quantities;this.capableDrones=capableDrones;this.basedOnTime=basedOnTime;}publicdoubleEvaluate(IChromosomechromosome){vargenes=chromosome.GetGenes();List<Drone>team=newList<Drone>();intdroneIndex=0;for(inti=0;i<quantities.Count;i++){intcount=0;foreach(DronedroneincapableDrones[i]){count+=(int)genes[droneIndex].Value;for(intj=0;j<(int)genes[droneIndex].Value;j++){team.Add(drone);}droneIndex++;}if(count>quantities[i]){return0;}}// Check if the team is emptyif(team.Count==0){return0;}(List<Drone>teamOverWater,List<Drone>teamUnderWater)=missionPlanner.assignDroneToWorkingArea(team);// Check if the team can perform the missionMissionmission=missionPlanner.mission;if((mission.HeigthLimit.upperLimit>0&&teamOverWater.Count==0)||mission.HeigthLimit.lowerLimit<0&&teamUnderWater.Count==0)return0;List<List<DronePath>>missionPaths=missionPlanner.PlanMission(teamOverWater,teamUnderWater);doublemissionCost=PathEvaluation.calculateMissionCost(missionPaths);doublemissionTime=PathEvaluation.calculateMissionTime(missionPaths);// You can add more criteria to evaluate the fitnessif(basedOnTime){return1/missionTime;}return1/missionCost;}}
The text was updated successfully, but these errors were encountered:
Managed to fix it by changing the UniformMutation constructer from UniforMutation(true) to UniformMutation(mutableGenesIndexes) with the indexes of the chromossome.
I am using Genetic Sharp to generate the Best team of Drones for a mission. Each gene in my chromossome stores the amount of a specific type of drone. The algorithm works perfectly fine except sometimes when performing a Uniform mutation it will try to change a gene outside of the chromossome. How could this happen? Am I doing something wrong?
Here is my code:
And my fitness Function
The text was updated successfully, but these errors were encountered: