Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17700 for branches


Ignore:
Timestamp:
07/27/20 14:38:37 (4 years ago)
Author:
dleko
Message:

#2825 Copy a reference point using a cloner instead of a copy constructor.

Location:
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/NSGA3.cs

    r17693 r17700  
    210210        public NSGA3(NSGA3 original, Cloner cloner) : base(original, cloner)
    211211        {
    212             // todo: don't forget to clone storable fields
    213212            random = cloner.Clone(original.random);
    214213            solutions = original.solutions?.Select(cloner.Clone).ToList();
    215             referencePoints = original.referencePoints?.Select(r =>
    216             {
    217                 var refPoint = new ReferencePoint(random, r.NumberOfDimensions);
    218                 r.Values.CopyTo(refPoint.Values, 0);
    219                 return refPoint;
    220             }).ToList();
     214            referencePoints = original.referencePoints?.Select(cloner.Clone).ToList();
    221215        }
    222216
     
    344338            if (referencePoints == null) return null;
    345339
    346             List<ReferencePoint> referencePointsCopy = new List<ReferencePoint>();
    347             foreach (var referencePoint in referencePoints)
    348                 referencePointsCopy.Add(new ReferencePoint(referencePoint));
    349 
    350             return referencePointsCopy;
     340            return referencePoints.Select(rp => (ReferencePoint)rp.Clone()).ToList();
    351341        }
    352342
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/ReferencePoint.cs

    r17693 r17700  
    2828            this.random = random;
    2929            Values = new double[numberOfDimensions];
    30         }
    31 
    32         public ReferencePoint(ReferencePoint other)
    33         {
    34             random = other.random;
    35             Values = new double[other.NumberOfDimensions];
    36             other.Values.CopyTo(Values, 0);
    3730        }
    3831
     
    216209            {
    217210                refPoint.Values[element] = ((double)left) / total;
    218                 var newRefPoint = new ReferencePoint(refPoint);
     211                var newRefPoint = (ReferencePoint)refPoint.Clone();
    219212                referencePoints.Add(newRefPoint);
    220213            }
Note: See TracChangeset for help on using the changeset viewer.