Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18199 for branches


Ignore:
Timestamp:
01/14/22 15:58:30 (3 years ago)
Author:
mkommend
Message:

#3136: Fixed parsing of variables in subfunctions.

Location:
branches/3136_Structural_GP
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs

    r18198 r18199  
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3131using HeuristicLab.Optimization;
    32 using HeuristicLab.Optimization.Operators;
    3332using HeuristicLab.Parameters;
    3433using HeuristicLab.Problems.Instances;
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs

    r18195 r18199  
    4141        if (value == template) return;
    4242
     43        var parsedTree = Parser.Parse(value);
     44        //assignment must be done after successfully parsing the tree
    4345        template = value;
    44         var parsedTree = Parser.Parse(template);
     46
    4547        if (applyLinearScaling)
    4648          parsedTree = LinearScaling.AddLinearScalingTerms(parsedTree);
     
    6264      private set {
    6365        containsNumericParameters = null;
    64         tree = value;
    6566
    66         var newFunctions = CreateSubFunctions(tree);
     67        var newFunctions = CreateSubFunctions(value);
    6768        var oldFunctions = subFunctions?.Intersect(newFunctions)
    6869                           ?? Enumerable.Empty<SubFunction>();
     
    7172        subFunctions = functionsToAdd.Concat(oldFunctions).ToList();
    7273        RegisterSubFunctionEventHandlers(functionsToAdd);
     74
     75        tree = value;
    7376      }
    7477    }
     
    104107
    105108    protected InfixExpressionParser Parser { get; set; } = new InfixExpressionParser();
    106 
    107109    #endregion
    108110
     
    150152      subFunctions = new List<SubFunction>();
    151153      tree = null;
     154      containsNumericParameters = null;
    152155      Template = "f(_)";
    153156    }
     
    183186        sf.Changed += (o, e) => OnChanged();
    184187      }
    185     }   
     188    }
    186189  }
    187190}
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs

    r18194 r18199  
    105105          varSym.VariableNames = allowedInputVariables;
    106106        } else {
    107           var vars = new List<string>();
    108           var exceptions = new List<Exception>();
    109           foreach (var arg in Arguments) {
    110             if (allowedInputVariables.Contains(arg))
    111               vars.Add(arg);
    112             else
    113               exceptions.Add(new ArgumentException($"The argument '{arg}' for sub-function '{Name}' is not a valid variable."));
    114           }
    115           if (exceptions.Any())
    116             throw new AggregateException(exceptions);
    117           varSym.VariableNames = vars;
     107          varSym.VariableNames = Arguments.ToList();
    118108        }
    119109
Note: See TracChangeset for help on using the changeset viewer.