using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Analysis.FitnessLandscape.MultiTrajectory { [StorableClass] public abstract class PreassignedSolutionCreator : SingleSuccessorOperator, ISolutionCreator { #region Parameters public ValueParameter SolutionCollectionParameter { get { return (ValueParameter)Parameters["SolutionCollection"]; } } public ValueParameter CurrentSolutionIndexParameter { get { return (ValueParameter)Parameters["CurrentSolutionIndex"]; } } public ValueParameter OriginalSolutionCreatorParameter { get { return (ValueParameter)Parameters["OriginalSolutionCreator"]; } } #endregion #region Parameter Values public IScope SolutionCollection { get { return SolutionCollectionParameter.Value; } set { SolutionCollectionParameter.Value = value; } } public int CurrentSolutionIndex { get { return CurrentSolutionIndexParameter.Value.Value; } set { CurrentSolutionIndexParameter.Value = new IntValue(value); } } public ISolutionCreator OriginalSolutionCreator { get { return OriginalSolutionCreatorParameter.Value; } set { OriginalSolutionCreatorParameter.Value = value; } } #endregion [StorableConstructor] protected PreassignedSolutionCreator(bool deserializing) : base(deserializing) { } protected PreassignedSolutionCreator(PreassignedSolutionCreator original, Cloner cloner) : base(original, cloner) { } public PreassignedSolutionCreator() { Parameters.Add(new ValueParameter("SolutionCollection", "Scope with subscopes that contains the list of solutions.")); Parameters.Add(new ValueParameter("CurrentSolutionIndex", "Index of currently created solution.")); Parameters.Add(new ValueParameter("OriginalSolutionCreator", "Original solution creator used for a certain problem.")); } public abstract void Create(IScope scope); public sealed override IOperation Apply() { if (CurrentSolutionIndex < 0 && OriginalSolutionCreator != null) { OperationCollection collection = new OperationCollection(); collection.Add(ExecutionContext.CreateOperation(OriginalSolutionCreator)); collection.Add(base.Apply()); return collection; } else { Create(SolutionCollection.SubScopes[CurrentSolutionIndex]); CurrentSolutionIndex = (CurrentSolutionIndex+1) % SolutionCollection.SubScopes.Count; return base.Apply(); } } } }