Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10957


Ignore:
Timestamp:
06/05/14 16:51:39 (10 years ago)
Author:
bburlacu
Message:

#1763: Added a special arity check for multiplication and addition symbols that invalidates the tree when the node has less than 2 subtrees. Disabled right-hand side details box when the tree is invalid.

Location:
branches/HeuristicLab.InteractiveTreeSimplifier/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.InteractiveTreeSimplifier/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj

    r10545 r10957  
    4141    <DebugType>full</DebugType>
    4242    <Optimize>false</Optimize>
    43     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     43    <OutputPath>..\..\..\trunk\sources\bin\</OutputPath>
    4444    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4545    <ErrorReport>prompt</ErrorReport>
     
    100100      <SpecificVersion>False</SpecificVersion>
    101101      <HintPath>..\..\bin\EPPlus-3.1.3.dll</HintPath>
     102      <Private>False</Private>
     103    </Reference>
     104    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     105      <SpecificVersion>False</SpecificVersion>
     106      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     107      <Private>False</Private>
     108    </Reference>
     109    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     110      <SpecificVersion>False</SpecificVersion>
     111      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
     112      <Private>False</Private>
     113    </Reference>
     114    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     115      <SpecificVersion>False</SpecificVersion>
     116      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
     117      <Private>False</Private>
     118    </Reference>
     119    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     120      <SpecificVersion>False</SpecificVersion>
     121      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
     122      <Private>False</Private>
     123    </Reference>
     124    <Reference Include="HeuristicLab.Core.Views-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     125      <SpecificVersion>False</SpecificVersion>
     126      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Core.Views-3.3.dll</HintPath>
     127      <Private>False</Private>
     128    </Reference>
     129    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     130      <SpecificVersion>False</SpecificVersion>
     131      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
     132      <Private>False</Private>
     133    </Reference>
     134    <Reference Include="HeuristicLab.Data.Views-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     135      <SpecificVersion>False</SpecificVersion>
     136      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Data.Views-3.3.dll</HintPath>
     137      <Private>False</Private>
     138    </Reference>
     139    <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     140      <SpecificVersion>False</SpecificVersion>
     141      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
     142      <Private>False</Private>
     143    </Reference>
     144    <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     145      <SpecificVersion>False</SpecificVersion>
     146      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.dll</HintPath>
     147      <Private>False</Private>
     148    </Reference>
     149    <Reference Include="HeuristicLab.MainForm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     150      <SpecificVersion>False</SpecificVersion>
     151      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.MainForm-3.3.dll</HintPath>
     152      <Private>False</Private>
     153    </Reference>
     154    <Reference Include="HeuristicLab.MainForm.WindowsForms-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     155      <SpecificVersion>False</SpecificVersion>
     156      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath>
     157      <Private>False</Private>
     158    </Reference>
     159    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     160      <SpecificVersion>False</SpecificVersion>
     161      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
     162      <Private>False</Private>
     163    </Reference>
     164    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     165      <SpecificVersion>False</SpecificVersion>
     166      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     167      <Private>False</Private>
     168    </Reference>
     169    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     170      <SpecificVersion>False</SpecificVersion>
     171      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
     172      <Private>False</Private>
     173    </Reference>
     174    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     175      <SpecificVersion>False</SpecificVersion>
     176      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll</HintPath>
    102177      <Private>False</Private>
    103178    </Reference>
     
    200275    </Compile>
    201276    <Compile Include="Properties\AssemblyInfo.cs" />
    202   </ItemGroup>
    203   <ItemGroup>
    204     <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
    205       <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
    206       <Name>HeuristicLab.Collections-3.3</Name>
    207       <Private>False</Private>
    208     </ProjectReference>
    209     <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj">
    210       <Project>{0e27a536-1c4a-4624-a65e-dc4f4f23e3e1}</Project>
    211       <Name>HeuristicLab.Common.Resources-3.3</Name>
    212       <Private>False</Private>
    213     </ProjectReference>
    214     <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
    215       <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
    216       <Name>HeuristicLab.Common-3.3</Name>
    217       <Private>False</Private>
    218     </ProjectReference>
    219     <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">
    220       <Project>{E226881D-315F-423D-B419-A766FE0D8685}</Project>
    221       <Name>HeuristicLab.Core.Views-3.3</Name>
    222       <Private>False</Private>
    223     </ProjectReference>
    224     <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
    225       <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
    226       <Name>HeuristicLab.Core-3.3</Name>
    227       <Private>False</Private>
    228     </ProjectReference>
    229     <ProjectReference Include="..\..\HeuristicLab.Data.Views\3.3\HeuristicLab.Data.Views-3.3.csproj">
    230       <Project>{72104A0B-90E7-42F3-9ABE-9BBBADD4B943}</Project>
    231       <Name>HeuristicLab.Data.Views-3.3</Name>
    232       <Private>False</Private>
    233     </ProjectReference>
    234     <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
    235       <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
    236       <Name>HeuristicLab.Data-3.3</Name>
    237       <Private>False</Private>
    238     </ProjectReference>
    239     <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj">
    240       <Project>{423BD94F-963A-438E-BA45-3BB3D61CD03B}</Project>
    241       <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4</Name>
    242       <Private>False</Private>
    243     </ProjectReference>
    244     <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">
    245       <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project>
    246       <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name>
    247       <Private>False</Private>
    248     </ProjectReference>
    249     <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.3\HeuristicLab.MainForm.WindowsForms-3.3.csproj">
    250       <Project>{AB687BBE-1BFE-476B-906D-44237135431D}</Project>
    251       <Name>HeuristicLab.MainForm.WindowsForms-3.3</Name>
    252       <Private>False</Private>
    253     </ProjectReference>
    254     <ProjectReference Include="..\..\HeuristicLab.MainForm\3.3\HeuristicLab.MainForm-3.3.csproj">
    255       <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project>
    256       <Name>HeuristicLab.MainForm-3.3</Name>
    257       <Private>False</Private>
    258     </ProjectReference>
    259     <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    260       <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
    261       <Name>HeuristicLab.Optimization-3.3</Name>
    262       <Private>False</Private>
    263     </ProjectReference>
    264     <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    265       <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    266       <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    267       <Private>False</Private>
    268     </ProjectReference>
    269     <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
    270       <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
    271       <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
    272       <Private>False</Private>
    273     </ProjectReference>
    274     <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
    275       <Project>{DF87C13E-A889-46FF-8153-66DCAA8C5674}</Project>
    276       <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name>
    277       <Private>False</Private>
    278     </ProjectReference>
    279277  </ItemGroup>
    280278  <ItemGroup>
  • branches/HeuristicLab.InteractiveTreeSimplifier/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r10798 r10957  
    3535    private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes;
    3636    private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts;
     37
    3738    private enum TreeState { Valid, Invalid }
    3839    private TreeState treeState;
    3940
    40     public InteractiveSymbolicDataAnalysisSolutionSimplifierView() {
     41    protected InteractiveSymbolicDataAnalysisSolutionSimplifierView() {
    4142      InitializeComponent();
    4243      foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     
    5758    /// <param name="newChild">The replacement subtree</param>
    5859    /// <param name="removeSubtree">Flag used to indicate if whole subtrees should be removed (default behavior), or just the subtree root</param>
    59     private void Modify(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode oldChild, ISymbolicExpressionTreeNode newChild, bool removeSubtree = true) {
    60       if (oldChild == null && newChild == null) throw new ArgumentNullException("Cannot deduce operation type from the arguments. Please provide non null operands.");
    61       if (oldChild == null) { // insertion operation
     60    private void Modify(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode parent,
     61      ISymbolicExpressionTreeNode oldChild, ISymbolicExpressionTreeNode newChild, bool removeSubtree = true) {
     62      if (oldChild == null && newChild == null)
     63        throw new ArgumentNullException("Cannot deduce operation type from the arguments. Please provide non null operands.");
     64      if (oldChild == null) {
     65        // insertion operation
    6266        parent.AddSubtree(newChild);
    6367        newChild.Parent = parent;
    64       } else if (newChild == null) { // removal operation
     68      } else if (newChild == null) {
     69        // removal operation
    6570        parent.RemoveSubtree(parent.IndexOfSubtree(oldChild));
    66         changedNodes.Remove(oldChild);
    67         foldedNodes.Remove(oldChild);
    68         if (removeSubtree) {
    69           foreach (var subtree in oldChild.IterateNodesPrefix()) {
    70             changedNodes.Remove(subtree);
    71             foldedNodes.Remove(subtree);
    72           }
    73         } else {
     71        if (!removeSubtree) {
    7472          for (int i = oldChild.SubtreeCount - 1; i >= 0; --i) {
    7573            var subtree = oldChild.GetSubtree(i);
     
    7876          }
    7977        }
    80       } else { // replacement operation
     78      } else {
     79        // replacement operation
    8180        var replacementIndex = parent.IndexOfSubtree(oldChild);
    8281        parent.RemoveSubtree(replacementIndex);
     
    9190      }
    9291      treeState = IsValid(tree) ? TreeState.Valid : TreeState.Invalid;
    93       if (treeState == TreeState.Valid) UpdateModel(Content.Model.SymbolicExpressionTree);
    94     }
    95 
     92      switch (treeState) {
     93        case TreeState.Valid:
     94          this.grpViewHost.Enabled = true;
     95          UpdateModel(Content.Model.SymbolicExpressionTree);
     96          break;
     97        case TreeState.Invalid:
     98          this.grpViewHost.Enabled = false;
     99          break;
     100      }
     101    }
     102
     103    // the optimizer always assumes 2 children for multiplication and addition nodes
     104    // thus, we enforce that the tree stays valid so that the constant optimization won't throw an exception
     105    // by returning 2 as the minimum allowed arity for addition and multiplication symbols
     106    private readonly Func<ISymbol, int> GetMinArity = symbol => {
     107      var min = symbol.MinimumArity;
     108      if (symbol is Multiplication || symbol is Addition) return Math.Max(2, min);
     109      return min;
     110    };
    96111    private bool IsValid(ISymbolicExpressionTree tree) {
    97112      treeChart.Tree = tree;
    98113      treeChart.Repaint();
    99       bool valid = !tree.IterateNodesPostfix().Any(node => node.SubtreeCount < node.Symbol.MinimumArity || node.SubtreeCount > node.Symbol.MaximumArity);
     114      bool valid = !tree.IterateNodesPostfix().Any(node => node.SubtreeCount < GetMinArity(node.Symbol) || node.SubtreeCount > node.Symbol.MaximumArity);
    100115      if (valid) {
    101116        btnOptimizeConstants.Enabled = true;
Note: See TracChangeset for help on using the changeset viewer.