Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2635


Ignore:
Timestamp:
01/18/10 10:56:50 (14 years ago)
Author:
gkronber
Message:

Fixed a bug in the network transformation operator and changed test-cases to detect the problem. #833

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/NetworkToFunctionTransformer.cs

    r2633 r2635  
    5151
    5252      var targetVariableEnumerator = targetVariables.Select(x => x.Data).GetEnumerator();
     53      List<IFunctionTree> transformedTrees = new List<IFunctionTree>(Transform(model.FunctionTree, targetVariables.Select(x => x.Data)));
    5354      // create a new sub-scope for each target variable with the transformed expression
    54       foreach (IFunctionTree transformedTree in Transform(model.FunctionTree, targetVariables.Select(x => x.Data))) {
     55      foreach (IFunctionTree transformedTree in transformedTrees) {
    5556        targetVariableEnumerator.MoveNext();
    5657        Scope exprScope = new Scope();
     
    7273      // create a new sub-scope for each target variable with the transformed expression
    7374      foreach (var targetVariable in targetVariables) {
    74         yield return TransformExpression(boundExpression, targetVariable, targetVariables.Except(new string[] { targetVariable }));
     75        yield return TransformExpression((IFunctionTree)boundExpression.Clone(), targetVariable, targetVariables.Except(new string[] { targetVariable }));
    7576      }
    7677    }
  • trunk/sources/HeuristicLab.GP.Tests/NetworkToFunctionTransformerTest.cs

    r2633 r2635  
    113113        IFunctionTree t2 = importer.Import("(- (variable 1.0 a 0) (variable 1.0 b 0))");
    114114
    115         CompareTrees(actualTrees, new List<IFunctionTree>() {
     115        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    116116        t0, t1, t2
    117117      });
     
    127127        IFunctionTree t2 = importer.Import("(/ (+ (variable 1.0 a 0) (+ (variable 1.0 b 0) 1.0)) 1.0 )");
    128128
    129         CompareTrees(actualTrees, new List<IFunctionTree>() {
     129        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    130130        t0, t1, t2
    131131      });
     
    142142
    143143
    144         CompareTrees(actualTrees, new List<IFunctionTree>() {
     144        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    145145        t0, t1, t2
    146146      });
     
    160160                                                (exp (variable 1.0 b 0)))");
    161161
    162         CompareTrees(actualTrees, new List<IFunctionTree>() {
     162        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    163163        t0, t1, t2
    164164      });
     
    176176                                                   (exp (exp (variable 1.0 b 0)))) 2.0)");
    177177
    178         CompareTrees(actualTrees, new List<IFunctionTree>() {
     178        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    179179        t0, t1, t2
    180180      });
     
    194194                                                   (/ (variable 1.0 b 0) 2.0)) 2.0)");
    195195
    196         CompareTrees(actualTrees, new List<IFunctionTree>() {
     196        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    197197        t0, t1, t2
    198198      });
     
    214214
    215215
    216         CompareTrees(actualTrees, new List<IFunctionTree>() {
     216        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    217217        t0, t1, t2
    218218      });
     
    229229
    230230
    231         CompareTrees(actualTrees, new List<IFunctionTree>() {
     231        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    232232        t0, t1, t2
    233233        });
     
    244244
    245245
    246         CompareTrees(actualTrees, new List<IFunctionTree>() {
     246        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    247247        t0, t1, t2
    248248        });
     
    259259
    260260
    261         CompareTrees(actualTrees, new List<IFunctionTree>() {
     261        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    262262        t0, t1, t2
    263263        });
     
    274274
    275275
    276         CompareTrees(actualTrees, new List<IFunctionTree>() {
     276        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
    277277        t0, t1, t2
    278278        });
     
    290290
    291291
    292         CompareTrees(actualTrees, new List<IFunctionTree>() {
    293         t0, t1, t2
    294         });
    295       }
    296     }
    297 
    298     private void CompareTrees(IEnumerable<IFunctionTree> actual, IEnumerable<IFunctionTree> expected) {
    299       var expectedEnumerator = expected.GetEnumerator();
     292        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
     293        t0, t1, t2
     294        });
     295      }
     296    }
     297
     298    private void CompareTrees(List<IFunctionTree> actual, List<IFunctionTree> expected) {
     299      var expectedEnumerator = expected.GetEnumerator();     
    300300      foreach (var actualTree in actual) {
    301301        if (!expectedEnumerator.MoveNext()) Assert.Fail();
Note: See TracChangeset for help on using the changeset viewer.