public override void Initialize() { base.Initialize(); OnFinalSearchSpaceCreated(); var totalCount = SearchSpace.Count + TargetNodes.Count; // Create edges var edges = new DirectedGraphEdge[totalCount, totalCount]; for (int i = 0; i < totalCount; i++) { for (int j = 0; j < totalCount; j++) { edges[i, j] = new DirectedGraphEdge(i, j, Distances[i, j]); } } _edges = new TwoDArray <DirectedGraphEdge>(edges); // Sort edges if PreFilledSpanThreshold is satisfied. if (TargetNodes.Count / (double)totalCount >= PreFilledSpanThreshold) { using (var prioQueue = new LinkedListPriorityQueue <DirectedGraphEdge>(100, totalCount * totalCount)) { // A PriorityQueue is used for sorting. Should be faster than sorting-methods that don't exploit // sorting ints. var enqueued = 0; for (var i = 0; i < totalCount; i++) { for (var j = i + 1; j < totalCount; j++) { prioQueue.Enqueue(_edges[i, j]); enqueued++; } } _orderedEdges = new List <DirectedGraphEdge>(enqueued); while (!prioQueue.IsEmpty) { _orderedEdges.Add(prioQueue.Dequeue()); } } } InitializeGa(); }
public void AddEdge(DirectedGraphNode <NodeData> from, DirectedGraphNode <NodeData> to, DirectedGraphEdge <EdgeData> data) { if (!nodes.Contains(from)) { throw new ArgumentException("Node \"from\" does not exist in the graph."); } if (!nodes.Contains(to)) { throw new ArgumentException("Node \"to\" does not exist in the graph."); } if (!edges.ContainsKey(from)) { edges.Add(from, new Dictionary <DirectedGraphNode <NodeData>, DirectedGraphEdge <EdgeData> >()); } if (!edges[from].ContainsKey(to)) { edges[from].Add(to, data); } }