Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/13/18 13:01:08 (6 years ago)
Author:
lkammere
Message:

#2886: Add graphviz output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs

    r15746 r15765  
    1 using System.Collections.Generic;
     1using System;
     2using System.Collections.Generic;
    23using System.Linq;
     4using System.Text;
    35using System.Threading;
    46using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;
     
    3234    private readonly string MaxTreeSizeParameterName = "Max. Tree Nodes";
    3335    private readonly string GuiUpdateIntervalParameterName = "GUI Update Interval";
    34    
     36
    3537    public override bool SupportsPause { get { return false; } }
    3638
     
    7476    public Grammar Grammar;
    7577
     78    public StringBuilder dotFileBuilder;
     79
    7680    #region ctors
    7781    public override IDeepCloneable Clone(Cloner cloner) {
     
    99103      #region init
    100104      InitResults();
     105
     106      dotFileBuilder = new StringBuilder();
    101107
    102108      AllSentences = new Dictionary<int, List<SymbolString>>();
     
    120126        SymbolString currPhrase = fetchedPhrase.SymbolString;
    121127
     128        if (dotFileBuilder.Length == 0) {
     129          dotFileBuilder.AppendLine("digraph searchgraph {");
     130          dotFileBuilder.AppendLine(fetchedPhrase.Hash + " [label=\"" + Grammar.PostfixToInfixParser(fetchedPhrase.SymbolString) + "\", shape=doublecircle];");
     131        } else {
     132          dotFileBuilder.AppendLine(fetchedPhrase.Hash + " [label=\"" + Grammar.PostfixToInfixParser(fetchedPhrase.SymbolString) + "\"];");
     133        }
     134
    122135        ArchivedPhrases.Add(fetchedPhrase.Hash, currPhrase);
    123136
     
    135148            var phraseHash = Grammar.CalcHashCode(newPhrase);
    136149
     150            dotFileBuilder.AppendLine(fetchedPhrase.Hash + " -> " + phraseHash + " [label=\"" + expandedSymbol.StringRepresentation + "&rarr;" + productionAlternative + "\"];");
     151
    137152            if (newPhrase.IsSentence()) { // Sentence was generated.
    138153              SaveToAllSentences(phraseHash, newPhrase);
     
    143158                DistinctSentences[phraseHash] = newPhrase;
    144159                EvaluateSentence(newPhrase);
     160
     161                dotFileBuilder.AppendLine(phraseHash + " [label=\"" + Grammar.PostfixToInfixParser(newPhrase) + "\", style=\"filled\"];");
    145162              }
    146163              UpdateView(AllSentences, DistinctSentences, Expansions);
     
    152169        }
    153170      }
     171
     172      dotFileBuilder.AppendLine(Grammar.CalcHashCode(BestTrainingSentence) + " [label=\"" + Grammar.PostfixToInfixParser(BestTrainingSentence) + "\", shape=Mcircle, style=\"filled,bold\"];");
     173      dotFileBuilder.AppendLine("}");
     174
     175      System.IO.File.WriteAllText(Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory)+ @"\searchgraph.dot", dotFileBuilder.ToString());
    154176
    155177      UpdateView(AllSentences, DistinctSentences, Expansions, force: true);
     
    257279    }
    258280    #endregion
    259  
     281
    260282  }
    261283}
Note: See TracChangeset for help on using the changeset viewer.