Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/07/19 13:32:09 (5 years ago)
Author:
mkommend
Message:

#2974: Merged trunk changes into branch.

Location:
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3838      double @const = 0) {
    3939
    40       if (factorCoefficients.Length == 0 && coefficients.Length == 0) throw new ArgumentException();
     40      if (factorCoefficients.Length == 0 && coefficients.Length == 0 && @const==0) throw new ArgumentException();
     41
     42      // Combine both trees
     43      ISymbolicExpressionTreeNode add = (new Addition()).CreateTreeNode();
    4144
    4245      // Create tree for double variables
    43       ISymbolicExpressionTree tree = null;     
    4446      if (coefficients.Length > 0) {
    45         tree = CreateTree(variableNames, new int[variableNames.Length], coefficients, @const);
    46         if (factorCoefficients.Length == 0) return tree;
     47        var varTree = CreateTree(variableNames, new int[variableNames.Length], coefficients);
     48        foreach (var varNode in varTree.IterateNodesPrefix().OfType<VariableTreeNode>())
     49          add.AddSubtree(varNode);
    4750      }
    4851
    4952      // Create tree for string variables
    50       ISymbolicExpressionTree factorTree = null;     
    5153      if (factorCoefficients.Length > 0) {
    52         factorTree = CreateTree(factors, factorCoefficients, @const);
    53         if (tree == null) return factorTree; 
     54        var factorTree = CreateTree(factors, factorCoefficients);
     55        foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>())
     56          add.AddSubtree(binFactorNode);
    5457      }
    5558
    56       // Combine both trees
    57       ISymbolicExpressionTreeNode add = tree.Root.GetSubtree(0).GetSubtree(0);
    58       foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>())
    59         add.InsertSubtree(add.SubtreeCount - 1, binFactorNode);
     59      if (@const!=0.0) {
     60        ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     61        cNode.Value = @const;
     62        add.AddSubtree(cNode);
     63      }
     64
     65      ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
     66      ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
     67      tree.Root.AddSubtree(startNode);
     68      startNode.AddSubtree(add);
    6069      return tree;
    61 
    62       throw new ArgumentException();
    6370    }
    6471
Note: See TracChangeset for help on using the changeset viewer.