/// <summary> /// Evaluates the Genome according to mü-sigma and the Preference-Functional /// </summary> /// <param name="genome">Genome to evaluate</param> /// <returns> /// Double.NegativeInfinity in case of (1) there was no genome, (2) it was not an BPMN-Genome, (3) the genome has /// not root-element, (4) the object-dependencies are not correct or (5) the probability for every activity was not /// correct /// </returns> public Solution Evaluate(IGenome genome) { // Check if genome is null, not an BpmGenome or invalide if (genome == null || genome.GetType() != typeof(BpmGenome) || ((BpmGenome)genome).RootGene == null) { throw new Exception("no valid Genome received"); } return(Evaluate(genome as BpmGenome)); }
public override double GetCompatibilityScore(IGenome genome1, IGenome genome2) { if (genome1 is DoubleArrayGenome) { return ScoreDouble(genome1, genome2); } if (genome1 is IntegerArrayGenome) { return ScoreInt(genome1, genome2); } throw new AIFHError("This speciation does not support: " + genome1.GetType().Name); }
/// <summary> /// Mutates a handovered genome, by: /// 1. finding a random mutation point in the tree /// 2. removing the subtree beneath the mutation point (inclusive the mutationpoint node.) /// 3. adding a randomly generated subtree beneath the parent of the chosen mutationpoint. /// </summary> /// <param name="genome">Genome to mutate.</param> /// <param name="mutationProbability">Probability if handovered genome is mutated or not.</param> public IGenome Mutate(IGenome genome, double mutationProbability) { var mutate = genome as BpmGenome; if (mutate != null) { var genomeToMutate = (BpmGenome)mutate.Clone(); // Find gene at random mutation point in tree var mutationPointIndex = TreeHelper.RandomGenerator.Next(genomeToMutate.NumberOfGenes); genomeToMutate.RootGene.RenumberIndicesOfBpmTree(n => n.Children); var mutationPointGene = genomeToMutate.RootGene.DepthFirstSearch(n => n.Children, element => element.Index == mutationPointIndex); var mutationPointGeneDepth = mutationPointGene.CalculateNodeDepth(); mutationPointGeneDepth = Math.Max(0, ModelHelper.GetBpmModel().GetMaxDepthRandomGenome() - mutationPointGeneDepth); ProcessHelper.ProcessGenerator.GenerateRandomValidBpmGenome(mutationPointGeneDepth, mutationPointGene.Parent, genomeToMutate, mutationProbability); ProcessHelper.Validator.CheckForBpmnXorFailture(genomeToMutate.RootGene); return(genomeToMutate); } throw new InvalidDataException($"{genome} should be of type BpmGenome, but is {genome.GetType()}"); }