/// <summary> /// Létrehozza az egész gráfot rekurzívan. /// </summary> /// <param name="state"></param> private void GenerateDisplayGraph(StateType state) { string nodeText = state.TextRepresentation; if (this.IsHeuristicSearch) { nodeText += "\nHeurisztikus érték: " + this.problem.Heuristic.GetHeuristicValue(state); } DisplayGraphVertex vertex = new DisplayGraphVertex(nodeText); this.Graph.AddVertex(vertex); this.stateVertexDictionary.Add(state, vertex); foreach (var op in problem.Operators) { if (op.Usable(state)) { StateType newState = op.Apply(state); if (!this.stateVertexDictionary.ContainsKey(newState)) { this.GenerateDisplayGraph(newState); } DisplayGraphVertex childVertex = this.stateVertexDictionary[newState]; DisplayGraphEdge edge = new DisplayGraphEdge(vertex, childVertex); this.Graph.AddEdge(edge); } } }
/// <summary> /// Létrehozza az egész gráfot rekurzívan. /// </summary> /// <param name="state"></param> private void GenerateDisplayGraph(StateType state) { DisplayGraphVertex vertex = new DisplayGraphVertex(state.TextRepresentation); this.Graph.AddVertex(vertex); this.stateVertexDictionary.Add(state, vertex); foreach (var op in problem.Operators) { if (op.Usable(state)) { StateType newState = op.Apply(state); if (!this.stateVertexDictionary.ContainsKey(newState)) { this.GenerateDisplayGraph(newState); } DisplayGraphVertex childVertex = this.stateVertexDictionary[newState]; this.Graph.AddVertex(childVertex); DisplayGraphEdge edge = new DisplayGraphEdge(vertex, childVertex); this.Graph.AddEdge(edge); } } }
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); }