protected void RemoveNode(SearchTreeNode <StateType> node) { var vertex = this.stateVertexDictionary[node.State]; this.Graph.RemoveVertex(vertex); this.stateVertexDictionary.Remove(node.State); this.stateNodeDictionary.Remove(node.State); }
protected override void NodeFound(SearchTreeNode <StateType> node) { if (this.GetNodeForState(node.State) == null) // ha még nem létezett { this.elementToProcess.Push(node); this.AddNewNode(node); } }
public override bool Equals(object obj) { SearchTreeNode <StateType> otherNode = obj as SearchTreeNode <StateType>; if (otherNode == null) { return(false); } return(this.State.Equals(otherNode.State)); }
public SearchTreeSearch(Problem <StateType> problem) { this.Status = SearchStatus.InProgress; this.Problem = problem; this.Graph = new DisplayGraph(); this.stateVertexDictionary = new Dictionary <StateType, DisplayGraphVertex>(); this.stateNodeDictionary = new Dictionary <StateType, SearchTreeNode <StateType> >(); SearchTreeNode <StateType> startNode = new SearchTreeNode <StateType>(problem.StartState, null); this.NodeFound(startNode); }
public void NextStep() { if (this.selectedNodeToExpand == null) { this.selectedNodeToExpand = this.GetNextNodeToExpand(); this.stateVertexDictionary[this.selectedNodeToExpand.State].VertexStatus = VertexStatus.SelectedToExpand; return; } foreach (var op in Problem.Operators) { if (op.Usable(this.selectedNodeToExpand.State)) { StateType newState = op.Apply(this.selectedNodeToExpand.State); var newNode = new SearchTreeNode <StateType>(newState, this.selectedNodeToExpand); if (this.IsCostSearch) { newNode.Cost = this.selectedNodeToExpand.Cost + op.GetCost(this.selectedNodeToExpand.State); } if (this.IsHeuristicSearch) { newNode.HeuristicValue = this.Problem.Heuristic.GetHeuristicValue(newState); } this.NodeFound(newNode); } } if (this.Problem.GoalStateChecker.IsGoalState(this.selectedNodeToExpand.State)) { this.stateVertexDictionary[this.selectedNodeToExpand.State].VertexStatus = VertexStatus.GoalState; this.Status = SearchStatus.SolutionFound; } else { this.stateVertexDictionary[this.selectedNodeToExpand.State].VertexStatus = VertexStatus.Marked; } this.selectedNodeToExpand = null; if (!this.HasNextNodeToExpand()) { this.Status = SearchStatus.Finished; } }
protected override void NodeFound(SearchTreeNode <StateType> node) { var nodeInDataBase = this.GetNodeForState(node.State); if (nodeInDataBase != null && node.Cost < nodeInDataBase.Cost) { this.elementsToProcess.Remove(nodeInDataBase); this.RemoveNode(nodeInDataBase); } if (nodeInDataBase == null || nodeInDataBase.Cost > node.Cost) { this.elementsToProcess.Add(node); this.AddNewNode(node); } }
protected void AddNewNode(SearchTreeNode <StateType> node) { string nodeText = node.State.TextRepresentation; if (this.IsCostSearch) { nodeText += "\nKöltség: " + node.Cost; } if (this.IsHeuristicSearch) { nodeText += "\nHeurisztikus érték: " + node.HeuristicValue; } if (this.IsCostSearch && this.IsHeuristicSearch) { nodeText += "\nBecsült költség: " + node.EstimatedCost; } DisplayGraphVertex vertex = new DisplayGraphVertex(nodeText); this.Graph.AddVertex(vertex); if (node.Parent != null) { DisplayGraphEdge edge; if (this.IsCostSearch) { string edgeLabel = (node.Cost - node.Parent.Cost).ToString(); edge = new DisplayGraphEdge(this.stateVertexDictionary[node.Parent.State], vertex, edgeLabel); } else { edge = new DisplayGraphEdge(this.stateVertexDictionary[node.Parent.State], vertex); } this.Graph.AddEdge(edge); } this.stateVertexDictionary.Add(node.State, vertex); this.stateNodeDictionary.Add(node.State, node); }
public SearchTreeNode(StateType state, SearchTreeNode <StateType> parent) { this.State = state; this.Parent = parent; }
protected abstract void NodeFound(SearchTreeNode <StateType> node);