Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/09 19:41:58 (15 years ago)
Author:
gkronber
Message:

GP Refactoring #713

  • cleaned code
  • reintegrated GP.Boolean and GP.SantaFe
  • worked on serialization of function trees
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs

    r2212 r2216  
    2222using System.Text;
    2323using HeuristicLab.GP.Interfaces;
     24using System;
     25using System.Collections.Generic;
    2426
    2527namespace HeuristicLab.GP.StructureIdentification {
    26   public class SymbolicExpressionExporter : IFunctionTreeExporter, IFunctionTreeNameGenerator {
     28  public class SymbolicExpressionExporter : IFunctionTreeSerializer, IFunctionTreeNameGenerator {
    2729    private StringBuilder builder;
    2830    private string currentIndent;
     
    4850      } catch(UnknownFunctionException) {
    4951        exported = "";
     52        return false;
     53      }
     54    }
     55
     56    public IFunctionTree Import(string tree) {
     57      Queue<string> tokens = new Queue<string>(tree.Split(' ', '\n', '\t'));
     58      return ParseTree(tokens);
     59    }
     60
     61    private IFunctionTree ParseTree(Queue<string> tokens) {
     62      Expect("(", tokens);
     63      string funSymb = tokens.Peek();
     64      double constValue;
     65      if (double.TryParse(funSymb, out constValue)) {
     66        throw new UnknownFunctionException(funSymb);
     67      }
     68      switch (funSymb) {
     69        case "variable": return ParseVariable(tokens);
     70        case "differential": return ParseDifferential(tokens);
     71        default:
     72          IFunctionTree fNode = ParseFunction(tokens);
     73          Expect(")", tokens);
     74          return fNode;
     75      }
     76
     77    }
     78
     79    private IFunctionTree ParseFunction(Queue<string> tokens) {
     80      throw new UnknownFunctionException(tokens.Dequeue());
     81    }
     82
     83    private IFunctionTree ParseDifferential(Queue<string> tokens) {
     84      throw new UnknownFunctionException(tokens.Dequeue());
     85    }
     86
     87    private IFunctionTree ParseVariable(Queue<string> tokens) {
     88      throw new UnknownFunctionException(tokens.Dequeue());
     89    }
     90
     91    private void Expect(string p, Queue<string> tokens) {
     92      throw new NotImplementedException();
     93    }
     94
     95    public bool TryImport(string tree, out IFunctionTree importedTree) {
     96      try {
     97        importedTree = Import(tree);
     98        return true;
     99      }
     100      catch (UnknownFunctionException) {
     101        importedTree = null;
    50102        return false;
    51103      }
Note: See TracChangeset for help on using the changeset viewer.