protected override void PerformMutation(IGraphChromosome graph, float probability) { if (RandomizationProvider.Current.GetDouble() >= probability) { return; } // No edges to add if (graph.EdgeCount == graph.VertexCount * graph.VertexCount) { return; } // Shuffle var allIDs = graph.Vertices.Select(v => v.ID); uint[] fromVerts = MutationService.Shuffle(allIDs, RandomizationProvider.Current).ToArray(); uint[] toVerts = MutationService.Shuffle(allIDs, RandomizationProvider.Current).ToArray(); // Find the first that does not exist foreach (var v1 in fromVerts) { foreach (var v2 in toVerts) { if (!graph.ContainsEdge(v1, v2)) { graph.AddEdge(v1, v2, graph.CreateNewEdge()); return; } } } }
void SplitEdge(IGraphChromosome graph, Edge <IChromosome> edge) { uint newID = Factory.GetID(edge.IDFrom, edge.IDTo); graph.RemoveEdge(edge.IDFrom, edge.IDTo); graph.AddVertex(newID, graph.CreateNewVertex()); graph.AddEdge(edge.IDFrom, newID, edge.Value); graph.AddEdge(newID, edge.IDTo, graph.CreateNewEdge()); }