#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Encodings.VariableVector { [Item("UniformActionManipulator", "Description missing")] [StorableClass] public class UniformActionManipulator : VariableVectorManipulator { #region Parameter Properties public ILookupParameter> PossibleActionsParameter { get { return (ILookupParameter>)Parameters["PossibleActions"]; } } #endregion [StorableConstructor] protected UniformActionManipulator(bool deserializing) : base(deserializing) { } protected UniformActionManipulator(UniformActionManipulator original, Cloner cloner) : base(original, cloner) { } public UniformActionManipulator() : base() { Parameters.Add(new LookupParameter>("PossibleActions")); } public override IDeepCloneable Clone(Cloner cloner) { return new UniformActionManipulator(this, cloner); } protected override VariableVector Manipulate(IRandom random, VariableVectorInput input, VariableVector child, double spreadpercentage) { return Manipulate(random, child, PossibleActionsParameter.ActualValue); } public static VariableVector Manipulate(IRandom random, VariableVector child, IEnumerable possibleActions) { var otherActions = possibleActions.Except((child.Action).ToEnumerable()); int actionIndex = random.Next(otherActions.Count()); VariableVectorAction newAction = otherActions.ElementAt(actionIndex); return new VariableVector(child.Condition.VariableDictionary.Values.Select(x => x.GetSetCopy()), newAction.VariableDictionary.Values.Select(x => x.GetSetCopy())); } } }