Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2235


Ignore:
Timestamp:
08/05/09 11:17:08 (15 years ago)
Author:
gkronber
Message:

Fixed #323 (The default representation of FunctionTreeView should show coefficients and time-offsets of variables and values of constants).

Location:
trunk/sources
Files:
2 added
2 deleted
32 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.Interfaces/3.3/HeuristicLab.GP.Interfaces-3.3.csproj

    r2222 r2235  
    8080  </ItemGroup>
    8181  <ItemGroup>
    82     <Compile Include="IFunctionTreeNameGenerator.cs">
    83       <SubType>Code</SubType>
    84     </Compile>
    8582    <Compile Include="IFunctionTreeSerializer.cs">
    8683      <SubType>Code</SubType>
  • trunk/sources/HeuristicLab.GP.Interfaces/3.3/IFunctionTree.cs

    r2222 r2235  
    3737    void InsertSubTree(int index, IFunctionTree tree);
    3838    void RemoveSubTree(int index);
     39    string ToString();
    3940  }
    4041}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj

    r2222 r2235  
    8383  <ItemGroup>
    8484    <Compile Include="AlgorithmBase.cs" />
     85    <Compile Include="BaseClasses\FunctionTreeBase.cs" />
    8586    <Compile Include="Evaluators\SimpleGPEvaluatorBase.cs" />
    8687    <Compile Include="HL3TreeEvaluator.cs" />
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ModelAnalyzerExporter.cs

    r2222 r2235  
    2424
    2525namespace HeuristicLab.GP.StructureIdentification {
    26   public class ModelAnalyzerExporter : IFunctionTreeSerializer, IFunctionTreeNameGenerator {
     26  public class ModelAnalyzerExporter : IFunctionTreeSerializer {
    2727    #region IFunctionTreeExporter Members
    2828
     
    7373    #endregion
    7474
    75     private string ExportFunction(IFunction function, IFunctionTree tree) {
     75    private static string ExportFunction(IFunction function, IFunctionTree tree) {
    7676      // this is smelly, if there is a cleaner way to have a 'dynamic' visitor
    7777      // please let me know! (gkronber 14.10.2008)
     
    103103    }
    104104
    105     #region IFunctionTreeNameGenerator Members
    106 
    107     string IFunctionTreeNameGenerator.Name {
    108       get { return "HL2 Representation"; }
    109     }
    110 
    111     public string GetName(IFunctionTree tree) {
     105    public static string GetName(IFunctionTree tree) {
    112106      string name = "";
    113107      try {
     
    118112      return name;
    119113    }
    120 
    121     #endregion
    122 
    123 
    124114  }
    125115
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs

    r2222 r2235  
    2626
    2727namespace HeuristicLab.GP.StructureIdentification {
    28   public class SymbolicExpressionExporter : IFunctionTreeSerializer, IFunctionTreeNameGenerator {
     28  public class SymbolicExpressionExporter : IFunctionTreeSerializer {
    2929    private StringBuilder builder;
    3030    private string currentIndent;
     
    6666    }
    6767
    68     private string ExportFunction(IFunction function, IFunctionTree tree) {
     68    private static string ExportFunction(IFunction function, IFunctionTree tree) {
    6969      // this is smelly, if there is a cleaner way to have a 'dynamic' visitor
    7070      // please let me know! (gkronber 14.10.2008)
     
    9999    #endregion
    100100
    101     #region IFunctionTreeNameGenerator Members
    102 
    103     string IFunctionTreeNameGenerator.Name {
    104       get { return "Symbolic Expression"; }
    105     }
    106 
    107     public string GetName(IFunctionTree tree) {
     101    public static string GetName(IFunctionTree tree) {
    108102      string name = "";
    109103      try {
    110104        name = ExportFunction(tree.Function, tree);
    111       } catch(UnknownFunctionException) {
     105      }
     106      catch (UnknownFunctionException) {
    112107        name = "N/A";
    113108      }
     
    115110    }
    116111
    117     #endregion
     112    //public string GetName(IFunctionTree tree) {
     113    //  return SymbolicExpressionExporter.GetName(tree);
     114    //}
    118115  }
    119116
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Addition.cs

    r2222 r2235  
    3838      MaxSubTrees = 3;
    3939    }
     40
     41    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     42      return new FunctionTreeBase(this);
     43    }
    4044  }
    4145}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/And.cs

    r2222 r2235  
    3535      MinSubTrees = 2; MaxSubTrees = 3;
    3636    }
     37
     38    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     39      return new FunctionTreeBase(this);
     40    }
    3741  }
    3842}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Average.cs

    r2222 r2235  
    3333      MinSubTrees = 2; MaxSubTrees = 3;
    3434    }
     35
     36    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     37      return new FunctionTreeBase(this);
     38    }
    3539  }
    3640}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/ConstantFunctionTree.cs

    r2222 r2235  
    3030    public double Value { get; set; }
    3131
    32     public ConstantFunctionTree(Constant constant) : base(constant){
     32    public ConstantFunctionTree(Constant constant)
     33      : base(constant) {
    3334    }
    3435
    35     protected ConstantFunctionTree(ConstantFunctionTree original) : base(original){
     36    protected ConstantFunctionTree(ConstantFunctionTree original)
     37      : base(original) {
    3638      Value = original.Value;
    3739    }
     
    5759    }
    5860
     61    public override string ToString() {
     62      return SymbolicExpressionExporter.GetName(this);
     63    }
     64
     65    #region serialization
    5966    public override object Clone() {
    6067      return new ConstantFunctionTree(this);
     
    7380      Value = XmlConvert.ToDouble(node.Attributes["Value"].Value);
    7481    }
     82    #endregion
    7583
    7684    private IVariable CreateValueVariable() {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Cosinus.cs

    r2222 r2235  
    3030      : base() {
    3131    }
     32
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3236  }
    3337}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Division.cs

    r2222 r2235  
    3737
    3838    public Division() : base() { }
     39
     40    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     41      return new FunctionTreeBase(this);
     42    }
    3943  }
    4044}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Equal.cs

    r2222 r2235  
    3030
    3131    public Equal() : base() { }
     32
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3236  }
    3337}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Exponential.cs

    r2222 r2235  
    2828
    2929    public Exponential() : base() { }
     30
     31    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     32      return new FunctionTreeBase(this);
     33    }
    3034  }
    3135}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/GreaterThan.cs

    r2222 r2235  
    3131    public GreaterThan() : base() { }
    3232
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3336  }
    3437}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/IfThenElse.cs

    r2222 r2235  
    3434      MinSubTrees = 3; MaxSubTrees = 3;
    3535    }
     36   
     37    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     38      return new FunctionTreeBase(this);
     39    }
    3640  }
    3741}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/LessThan.cs

    r2222 r2235  
    3232      : base() {
    3333    }
     34
     35    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     36      return new FunctionTreeBase(this);
     37    }
    3438  }
    3539}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Logarithm.cs

    r2222 r2235  
    3030      : base() {
    3131    }
     32
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3236  }
    3337}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Multiplication.cs

    r2222 r2235  
    3737      MinSubTrees = 2; MaxSubTrees = 3;
    3838    }
     39
     40    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     41      return new FunctionTreeBase(this);
     42    }
    3943  }
    4044}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Not.cs

    r2222 r2235  
    3131      : base() {
    3232    }
     33
     34    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     35      return new FunctionTreeBase(this);
     36    }
    3337  }
    3438}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Or.cs

    r2222 r2235  
    3333      MinSubTrees = 2; MaxSubTrees = 3;
    3434    }
     35    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     36      return new FunctionTreeBase(this);
     37    }
    3538  }
    3639}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Power.cs

    r2222 r2235  
    3030      : base() {
    3131    }
     32
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3236  }
    3337}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Signum.cs

    r2222 r2235  
    3030      : base() {
    3131    }
     32
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3236  }
    3337}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Sinus.cs

    r2222 r2235  
    3030      : base() {
    3131    }
     32
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3236  }
    3337}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Sqrt.cs

    r2222 r2235  
    3030      : base() {
    3131    }
     32
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3236  }
    3337}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Subtraction.cs

    r2222 r2235  
    3535      : base() {
    3636    }
     37
     38    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     39      return new FunctionTreeBase(this);
     40    }
    3741  }
    3842}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Tangens.cs

    r2222 r2235  
    3030      : base() {
    3131    }
     32
     33    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     34      return new FunctionTreeBase(this);
     35    }
    3236  }
    3337}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/VariableFunctionTree.cs

    r2222 r2235  
    6767    }
    6868
     69    public override string ToString() {
     70      return SymbolicExpressionExporter.GetName(this);
     71    }
     72
     73    #region serialization
    6974    public override object Clone() {
    7075      return new VariableFunctionTree(this);
     
    9196      VariableName = node.Attributes["Variable"].Value;
    9297    }
     98    #endregion
    9399
    94100    private IVariable CreateSampleOffsetVariable() {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Xor.cs

    r2222 r2235  
    3232      : base() {
    3333    }
     34
     35    public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() {
     36      return new FunctionTreeBase(this);
     37    }
    3438  }
    3539}
  • trunk/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs

    r2222 r2235  
    9494    }
    9595
     96    public virtual string ToString() {
     97      return Function.Name;
     98    }
     99
    96100    #endregion
    97101
  • trunk/sources/HeuristicLab.GP/3.3/FunctionTreeView.cs

    r2222 r2235  
    3030    private IFunctionTree functionTree;
    3131    private IFunctionTree selectedBranch;
    32     private IFunctionTreeNameGenerator nameGenerator;
    33     private IFunctionTreeNameGenerator[] allNameGenerators;
    34     private MenuItem representationsMenu;
     32    //private IFunctionTreeNameGenerator nameGenerator;
     33    //private IFunctionTreeNameGenerator[] allNameGenerators;
     34    //private MenuItem representationsMenu;
    3535
    3636    public FunctionTreeView() {
    37       nameGenerator = new DefaultFunctionTreeNameGenerator();
     37      //nameGenerator = new DefaultFunctionTreeNameGenerator();
    3838      InitializeComponent();
    3939
    4040      DiscoveryService discoveryService = new DiscoveryService();
    41       allNameGenerators = discoveryService.GetInstances<IFunctionTreeNameGenerator>();
    42       representationsMenu = new MenuItem();
    43       representationsMenu.Text = "Tree representation";
    44       representationsMenu.Name = "Tree representation";
    45       foreach (IFunctionTreeNameGenerator generator in allNameGenerators) {
    46         MenuItem mi = new MenuItem(generator.Name, MakeNameGeneratorDelegate(generator), Shortcut.None);
    47         if (generator is DefaultFunctionTreeNameGenerator) mi.Checked = true;
    48         else mi.Checked = false;
    49         mi.Tag = generator;
    50         representationsMenu.MenuItems.Add(mi);
    51       }
     41      //allNameGenerators = discoveryService.GetInstances<IFunctionTreeNameGenerator>();
     42      //representationsMenu = new MenuItem();
     43      //representationsMenu.Text = "Tree representation";
     44      //representationsMenu.Name = "Tree representation";
     45      //foreach (IFunctionTreeNameGenerator generator in allNameGenerators) {
     46      //  MenuItem mi = new MenuItem(generator.Name, MakeNameGeneratorDelegate(generator), Shortcut.None);
     47      //  if (generator is DefaultFunctionTreeNameGenerator) mi.Checked = true;
     48      //  else mi.Checked = false;
     49      //  mi.Tag = generator;
     50      //  representationsMenu.MenuItems.Add(mi);
     51      //}
    5252    }
    5353
     
    6161      funTreeView.Nodes.Clear();
    6262      TreeNode rootNode = new TreeNode();
    63       rootNode.Name = functionTree.Function.Name;
    64       rootNode.Text = nameGenerator.GetName(functionTree);
     63      rootNode.Name = functionTree.ToString(); // functionTree.Function.Name;
     64      rootNode.Text = functionTree.ToString(); // nameGenerator.GetName(functionTree);
    6565      rootNode.Tag = functionTree;
    6666      treeNodeContextMenu.MenuItems.Clear();
    67       treeNodeContextMenu.MenuItems.Add(representationsMenu);
     67      //treeNodeContextMenu.MenuItems.Add(representationsMenu);
    6868      DiscoveryService discoveryService = new DiscoveryService();
    6969      IFunctionTreeSerializer[] exporters = discoveryService.GetInstances<IFunctionTreeSerializer>();
     
    9191    }
    9292
    93     private EventHandler MakeNameGeneratorDelegate(IFunctionTreeNameGenerator generator) {
    94       return delegate(object source, EventArgs args) {
    95         IFunctionTreeNameGenerator g = (IFunctionTreeNameGenerator)((MenuItem)source).Tag;
    96         this.nameGenerator = g;
    97         foreach (MenuItem otherMenuItem in representationsMenu.MenuItems) otherMenuItem.Checked = false;
    98         ((MenuItem)source).Checked = true;
    99         UpdateControls();
    100       };
    101     }
     93    //private EventHandler MakeNameGeneratorDelegate(IFunctionTreeNameGenerator generator) {
     94    //  return delegate(object source, EventArgs args) {
     95    //    IFunctionTreeNameGenerator g = (IFunctionTreeNameGenerator)((MenuItem)source).Tag;
     96    //    this.nameGenerator = g;
     97    //    foreach (MenuItem otherMenuItem in representationsMenu.MenuItems) otherMenuItem.Checked = false;
     98    //    ((MenuItem)source).Checked = true;
     99    //    UpdateControls();
     100    //  };
     101    //}
    102102
    103103    private EventHandler MakeExporterDelegate(IFunctionTreeSerializer exporter) {
     
    111111    private void CreateTree(TreeNode rootNode, IFunctionTree functionTree) {
    112112      TreeNode node = new TreeNode();
    113       node.Name = functionTree.Function.Name;
    114       node.Text = nameGenerator.GetName(functionTree);
     113      node.Name = functionTree.ToString();
     114      node.Text = functionTree.ToString();
    115115      node.Tag = functionTree;
    116116      node.ContextMenu = treeNodeContextMenu;
  • trunk/sources/HeuristicLab.GP/3.3/GeneticProgrammingModel.cs

    r2222 r2235  
    4747    }
    4848
    49     public GeneticProgrammingModel(IFunctionTree tree) : base() {
     49    public GeneticProgrammingModel(IFunctionTree tree)
     50      : base() {
    5051      FunctionTree = tree;
    5152    }
     
    8788      IFunction f = (IFunction)PersistenceManager.Restore(fNode, restoredObjects);
    8889      IFunctionTree tree = f.GetTreeNode();
    89       if(fNode.ChildNodes.Count>0) tree.Populate(fNode.ChildNodes[0], restoredObjects);
     90      if (fNode.ChildNodes.Count > 0) tree.Populate(fNode.ChildNodes[0], restoredObjects);
    9091      nodeIndex++;
    9192      for (int i = 0; i < subTrees; i++) {
  • trunk/sources/HeuristicLab.GP/3.3/HeuristicLab.GP-3.3.csproj

    r2222 r2235  
    103103    </Compile>
    104104    <Compile Include="GeneticProgrammingModel.cs" />
    105     <Compile Include="DefaultFunctionTreeNameGenerator.cs" />
    106105    <Compile Include="UnknownFunctionException.cs" />
    107106    <Compile Include="HeuristicLabGPPlugin.cs" />
Note: See TracChangeset for help on using the changeset viewer.