Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3413


Ignore:
Timestamp:
04/19/10 17:33:12 (15 years ago)
Author:
abeham
Message:

Updated Gender Specific Selection, Offspring Selector and other changes related to the OSGA #976
Removed old OS plugin, removed SelectedSubScopesLookupParameter

Location:
trunk/sources
Files:
1 added
3 deleted
7 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r3384 r3413  
    3030EndProject
    3131Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Operators.Programmable-3.3", "HeuristicLab.Operators.Programmable\3.3\HeuristicLab.Operators.Programmable-3.3.csproj", "{6A5F8C2D-B0C3-4B36-BC20-9B1A91EE6DB6}"
    32 EndProject
    33 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Selection.OffspringSelection-3.3", "HeuristicLab.Selection.OffspringSelection\3.3\HeuristicLab.Selection.OffspringSelection-3.3.csproj", "{81609E8A-9757-4865-8B89-0B6603F769E8}"
    3432EndProject
    3533Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.ThreadParallelEngine-3.3", "HeuristicLab.ThreadParallelEngine\3.3\HeuristicLab.ThreadParallelEngine-3.3.csproj", "{C2E99CCE-9FB0-456F-9BA0-57900E4AA799}"
     
    7775    {4ABA047D-46DD-4608-9E4A-41C5F92FDBB1} = {4ABA047D-46DD-4608-9E4A-41C5F92FDBB1}
    7876    {70DFD984-B1D9-46FE-8EB7-4DE92D71A9FC} = {70DFD984-B1D9-46FE-8EB7-4DE92D71A9FC}
    79     {81609E8A-9757-4865-8B89-0B6603F769E8} = {81609E8A-9757-4865-8B89-0B6603F769E8}
    8077    {8FA6898D-E4B0-4E08-A6D6-F9F520E7959F} = {8FA6898D-E4B0-4E08-A6D6-F9F520E7959F}
    8178    {D767C38D-8014-46B0-9A32-03A3AECCE34A} = {D767C38D-8014-46B0-9A32-03A3AECCE34A}
     
    415412    {6A5F8C2D-B0C3-4B36-BC20-9B1A91EE6DB6}.Services|x64.ActiveCfg = Release|x64
    416413    {6A5F8C2D-B0C3-4B36-BC20-9B1A91EE6DB6}.Services|x86.ActiveCfg = Release|x86
    417     {81609E8A-9757-4865-8B89-0B6603F769E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    418     {81609E8A-9757-4865-8B89-0B6603F769E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
    419     {81609E8A-9757-4865-8B89-0B6603F769E8}.Debug|x64.ActiveCfg = Debug|x64
    420     {81609E8A-9757-4865-8B89-0B6603F769E8}.Debug|x64.Build.0 = Debug|x64
    421     {81609E8A-9757-4865-8B89-0B6603F769E8}.Debug|x86.ActiveCfg = Debug|x86
    422     {81609E8A-9757-4865-8B89-0B6603F769E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
    423     {81609E8A-9757-4865-8B89-0B6603F769E8}.Release|Any CPU.Build.0 = Release|Any CPU
    424     {81609E8A-9757-4865-8B89-0B6603F769E8}.Release|x64.ActiveCfg = Release|x64
    425     {81609E8A-9757-4865-8B89-0B6603F769E8}.Release|x64.Build.0 = Release|x64
    426     {81609E8A-9757-4865-8B89-0B6603F769E8}.Release|x86.ActiveCfg = Release|x86
    427     {81609E8A-9757-4865-8B89-0B6603F769E8}.Release|x86.Build.0 = Release|x86
    428     {81609E8A-9757-4865-8B89-0B6603F769E8}.Services|Any CPU.ActiveCfg = Release|Any CPU
    429     {81609E8A-9757-4865-8B89-0B6603F769E8}.Services|Any CPU.Build.0 = Release|Any CPU
    430     {81609E8A-9757-4865-8B89-0B6603F769E8}.Services|x64.ActiveCfg = Release|x64
    431     {81609E8A-9757-4865-8B89-0B6603F769E8}.Services|x64.Build.0 = Release|x64
    432     {81609E8A-9757-4865-8B89-0B6603F769E8}.Services|x86.ActiveCfg = Release|x86
    433     {81609E8A-9757-4865-8B89-0B6603F769E8}.Services|x86.Build.0 = Release|x86
    434414    {C2E99CCE-9FB0-456F-9BA0-57900E4AA799}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    435415    {C2E99CCE-9FB0-456F-9BA0-57900E4AA799}.Debug|Any CPU.Build.0 = Debug|Any CPU
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs

    r3379 r3413  
    362362    private void ParameterizeComparisonFactorModifiers() {
    363363      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {
    364         modifier.IndexParameter.ActualName = "Generations"; // FIXME: hmmm, not so good, this variable is defined within the main loop
     364        modifier.IndexParameter.ActualName = "Generations";
    365365        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
    366366        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
    367367        modifier.StartIndexParameter.Value = new IntValue(0);
    368368        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
    369         modifier.ValueParameter.ActualName = "ComparisonFactor"; // FIXME: hmmm, not so good, this variable is defined within the main loop
     369        modifier.ValueParameter.ActualName = "ComparisonFactor";
    370370      }
    371371    }
     
    386386    private void UpdateComparisonFactorModifiers() {
    387387      IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;
     388      if (oldModifier == null) oldModifier = new LinearDiscreteDoubleValueModifier();
     389
    388390      ComparisonFactorModifierParameter.ValidValues.Clear();
    389391      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)
    390392        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
    391       if (oldModifier != null) {
    392         IDiscreteDoubleValueModifier modifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());
    393         if (modifier != null) ComparisonFactorModifierParameter.Value = modifier;
    394       } else if (ComparisonFactorModifierParameter.ValidValues.Count > 0) ComparisonFactorModifierParameter.Value = ComparisonFactorModifierParameter.ValidValues.First();
     393     
     394      IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());
     395      if (mod != null) ComparisonFactorModifierParameter.Value = mod;
    395396    }
    396397    private void UpdateCrossovers() {
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithmMainLoop.cs

    r3379 r3413  
    152152      ConditionalBranch osBeforeMutationBranch = new ConditionalBranch();
    153153      Placeholder evaluator1 = new Placeholder();
    154       ParentsQualityComparator qualityComparer1 = new ParentsQualityComparator();
     154      WeightedParentsQualityComparator qualityComparer1 = new WeightedParentsQualityComparator();
    155155      StochasticBranch mutationBranch1 = new StochasticBranch();
    156156      Placeholder mutator1 = new Placeholder();
     
    159159      Placeholder mutator2 = new Placeholder();
    160160      Placeholder evaluator3 = new Placeholder();
    161       ParentsQualityComparator qualityComparer2 = new ParentsQualityComparator();
     161      WeightedParentsQualityComparator qualityComparer2 = new WeightedParentsQualityComparator();
    162162      SubScopesRemover subScopesRemover = new SubScopesRemover();
     163      ConditionalSelector conditionalSelector = new ConditionalSelector();
    163164      OffspringSelector offspringSelector = new OffspringSelector();
    164165      SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
     
    281282      subScopesRemover.RemoveAllSubScopes = true;
    282283
     284      conditionalSelector.CopySelected = new BoolValue(false);
     285      conditionalSelector.ConditionParameter.ActualName = "SuccessfulOffspring";
     286
    283287      offspringSelector.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
    284288      offspringSelector.LuckyLosersParameter.ActualName = "OSLuckyLosers";
     
    286290      offspringSelector.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
    287291      offspringSelector.SelectionPressureParameter.ActualName = "SelectionPressure";
    288       offspringSelector.SuccessfulOffspringParameter.ActualName = "SuccessfulOffspring";
    289292      offspringSelector.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
    290293      offspringSelector.WinnersParameter.ActualName = "OSWinners";
     
    369372      childrenCreator.Successor = uniformSubScopesProcessor;
    370373      uniformSubScopesProcessor.Operator = crossover;
    371       uniformSubScopesProcessor.Successor = null;
     374      uniformSubScopesProcessor.Successor = conditionalSelector;
    372375      crossover.Successor = osBeforeMutationBranch;
    373376      osBeforeMutationBranch.TrueBranch = evaluator1;
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj

    r3384 r3413  
    8181  </ItemGroup>
    8282  <ItemGroup>
    83     <Compile Include="OffspringSelector.cs" />
    84     <Compile Include="ParentsQualityComparator.cs" />
    8583    <Compile Include="ProbabilisticQualityComparator.cs" />
    8684    <Compile Include="ResultsCollector.cs" />
     
    9694    <Compile Include="SolutionsCreator.cs" />
    9795    <Compile Include="UnidirectionalRingMigrator.cs" />
     96    <Compile Include="WeightedParentsQualityComparator.cs" />
    9897  </ItemGroup>
    9998  <ItemGroup>
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/WeightedParentsQualityComparator.cs

    r3407 r3413  
    3030
    3131namespace HeuristicLab.Optimization.Operators {
    32   [Item("ParentsQualityComparator", "Compares the quality against that of its parents (assumes the parents are subscopes to the child scope). This operator works with any number of subscopes > 0.")]
     32  [Item("WeightedParentsQualityComparator", "Compares the quality against that of its parents (assumes the parents are subscopes to the child scope). This operator works with any number of subscopes > 0.")]
    3333  [StorableClass]
    34   public class ParentsQualityComparator : SingleSuccessorOperator, ISubScopesQualityComparator {
     34  public class WeightedParentsQualityComparator : SingleSuccessorOperator, ISubScopesQualityComparator {
    3535    public IValueLookupParameter<BoolValue> MaximizationParameter {
    3636      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    4949    }
    5050
    51     public ParentsQualityComparator()
     51    public WeightedParentsQualityComparator()
    5252      : base() {
    5353      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, false otherwise"));
  • trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r3384 r3413  
    8686    <None Include="HeuristicLabParametersPlugin.cs.frame" />
    8787    <Compile Include="ConstrainedValueParameter.cs" />
    88     <Compile Include="SelectedSubScopesLookupParameter.cs" />
    8988    <Compile Include="OptionalConstrainedValueParameter.cs" />
    9089    <Compile Include="ValueParameter.cs" />
  • trunk/sources/HeuristicLab.Selection/3.3/ConditionalSelector.cs

    r3407 r3413  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Text;
    2524using HeuristicLab.Core;
    2625using HeuristicLab.Data;
    2726using HeuristicLab.Selection;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Parameters;
    2829
    29 namespace HeuristicLab.Scheduling.JSSP {
    30   public class ConditionalSelector : SelectorBase {
    31     public override string Description {
    32       get { return @"TODO\r\nOperator description still missing ..."; }
     30namespace HeuristicLab.Selection {
     31  [Item("ConditionalSelector", "Selects sub-scopes where a certain boolean variable is true.")]
     32  [StorableClass]
     33  public class ConditionalSelector : Selector {
     34    public SubScopesLookupParameter<BoolValue> ConditionParameter {
     35      get { return (SubScopesLookupParameter<BoolValue>)Parameters["Condition"]; }
     36    }
     37    public ValueParameter<BoolValue> CopySelectedParameter {
     38      get { return (ValueParameter<BoolValue>)Parameters["CopySelected"]; }
     39    }
     40
     41    public BoolValue CopySelected {
     42      get { return CopySelectedParameter.Value; }
     43      set { CopySelectedParameter.Value = value; }
    3344    }
    3445
    3546    public ConditionalSelector()
    3647      : base() {
    37       AddVariableInfo(new VariableInfo("Condition", "Input condition", typeof(BoolData), VariableKind.In));
     48      Parameters.Add(new SubScopesLookupParameter<BoolValue>("Condition", "The boolean variable based on which the scopes are selected into a true scope-branch and a false scope-branch."));
     49      Parameters.Add(new ValueParameter<BoolValue>("CopySelected", "The parameter that decides whether the selected scopes should be copied or moved.", new BoolValue(true)));
    3850    }
    3951
    40     private int GetFirstSelectedScopeIndex(IScope source) {
    41       for (int i = 0; i < source.SubScopes.Count; i++) {
    42         bool condition = GetVariableValue<BoolData>("Condition", source.SubScopes[i], true).Data;
    43         if (condition) {
    44           return i;
    45         }
    46       }
    47       return -1;
    48     }
    49 
    50     protected override void Select(IScope source, IScope target, bool copySelected) {
    51       if (copySelected) {
    52         for (int i = 0; i < source.SubScopes.Count; i++) {
    53           IScope selectedScope = source.SubScopes[i];
    54           bool condition = GetVariableValue<BoolData>("Condition", source.SubScopes[i], true).Data;
    55           if (condition) {
    56             target.AddSubScope((IScope)selectedScope.Clone());
     52    protected override IScope[] Select(List<IScope> scopes) {
     53      ItemArray<BoolValue> conditions = ConditionParameter.ActualValue;
     54      List<IScope> selected = new List<IScope>();
     55      if (CopySelected.Value) {
     56        for (int i = 0; i < scopes.Count; i++) {
     57          if (conditions[i].Value) {
     58            selected.Add((IScope)scopes[i].Clone());
    5759          }
    5860        }
    5961      } else {
    60         int removeAt = GetFirstSelectedScopeIndex(source);
    61         while (removeAt != -1) {
    62           IScope selectedScope = source.SubScopes[removeAt];
    63           target.AddSubScope(selectedScope);
    64           source.RemoveSubScope(selectedScope);
    65           removeAt = GetFirstSelectedScopeIndex(source);
     62        for (int i = 0; i < scopes.Count; i++) {
     63          if (conditions[i + selected.Count].Value) {
     64            selected.Add(scopes[i]);
     65            scopes.RemoveAt(i);
     66            i--;
     67          }
    6668        }
    6769      }
     70      return selected.ToArray();
    6871    }
    6972  }
  • trunk/sources/HeuristicLab.Selection/3.3/GenderSpecificSelector.cs

    r3404 r3413  
    3636  [StorableClass]
    3737  public class GenderSpecificSelector : AlgorithmOperator, ISingleObjectiveSelector, IStochasticOperator {
    38     private List<ISelector> femaleSelectors;
    39     private List<ISelector> maleSelectors;
    40 
    4138    #region Parameters
    4239    public IValueLookupParameter<BoolValue> MaximizationParameter {
     
    5552      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    5653    }
    57     public ConstrainedValueParameter<ISelector> FemaleSelectorParameter {
    58       get { return (ConstrainedValueParameter<ISelector>)Parameters["FemaleSelector"]; }
     54    public ValueParameter<ISelector> FemaleSelectorParameter {
     55      get { return (ValueParameter<ISelector>)Parameters["FemaleSelector"]; }
    5956    }
    60     public ConstrainedValueParameter<ISelector> MaleSelectorParameter {
    61       get { return (ConstrainedValueParameter<ISelector>)Parameters["MaleSelector"]; }
     57    public ValueParameter<ISelector> MaleSelectorParameter {
     58      get { return (ValueParameter<ISelector>)Parameters["MaleSelector"]; }
    6259    }
    6360    #endregion
     
    9693      Parameters.Add(new ValueLookupParameter<BoolValue>("CopySelected", "True if the scopes should be copied, false if they should be moved.", new BoolValue(true)));
    9794      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    98       Parameters.Add(new ConstrainedValueParameter<ISelector>("FemaleSelector", "The selection operator to select the first parent."));
    99       Parameters.Add(new ConstrainedValueParameter<ISelector>("MaleSelector", "The selection operator to select the second parent."));
     95      Parameters.Add(new ValueParameter<ISelector>("FemaleSelector", "The selection operator to select the first parent."));
     96      Parameters.Add(new ValueParameter<ISelector>("MaleSelector", "The selection operator to select the second parent."));
    10097      #endregion
    10198
     
    140137    }
    141138
     139    #region Events
     140    private void SelectorParameter_ValueChanged(object sender, EventArgs e) {
     141      IValueParameter<ISelector> selectorParam = (sender as IValueParameter<ISelector>);
     142      if (selectorParam != null)
     143        ParameterizeSelector(selectorParam.Value);
     144    }
     145    #endregion
     146
    142147    #region Helpers
    143148    [StorableHook(HookType.AfterDeserialization)]
    144149    private void Initialize() {
    145       InitializeSelectors();
    146       UpdateSelectors();
     150      FemaleSelectorParameter.ValueChanged += new EventHandler(SelectorParameter_ValueChanged);
     151      MaleSelectorParameter.ValueChanged += new EventHandler(SelectorParameter_ValueChanged);
     152      if (FemaleSelector == null) FemaleSelector = new ProportionalSelector();
     153      if (MaleSelector == null) MaleSelector = new RandomSelector();
    147154    }
    148 
    149     private void InitializeSelectors() {
    150       femaleSelectors = new List<ISelector>();
    151       maleSelectors = new List<ISelector>();
    152       IEnumerable<Type> types = ApplicationManager.Manager.GetTypes(typeof(ISelector)).OrderBy(x => x.FullName);
    153       foreach (Type type in types) {
    154         if (type != typeof(IMultiObjectiveSelector) && type != typeof(GenderSpecificSelector)) {
    155           femaleSelectors.Add((ISelector)Activator.CreateInstance(type));
    156           maleSelectors.Add((ISelector)Activator.CreateInstance(type));
    157         }
     155    private void ParameterizeSelector(ISelector selector) {
     156      selector.CopySelected = new BoolValue(true);
     157      IStochasticOperator stoOp = (selector as IStochasticOperator);
     158      if (stoOp != null) stoOp.RandomParameter.ActualName = RandomParameter.Name;
     159      ISingleObjectiveSelector soSelector = (selector as ISingleObjectiveSelector);
     160      if (soSelector != null) {
     161        soSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
     162        soSelector.QualityParameter.ActualName = QualityParameter.Name;
    158163      }
    159       ParameterizeSelectors(femaleSelectors);
    160       ParameterizeSelectors(maleSelectors);
    161     }
    162     private void ParameterizeSelectors(List<ISelector> selectors) {
    163       foreach (ISelector selector in selectors) {
    164         selector.CopySelected = new BoolValue(true);
    165       }
    166       foreach (IStochasticOperator op in selectors.OfType<IStochasticOperator>()) {
    167         op.RandomParameter.ActualName = RandomParameter.Name;
    168       }
    169       foreach (ISingleObjectiveSelector selector in selectors.OfType<ISingleObjectiveSelector>()) {
    170         selector.MaximizationParameter.ActualName = MaximizationParameter.Name;
    171         selector.QualityParameter.ActualName = QualityParameter.Name;
    172       }
    173     }
    174     private void UpdateSelectors() {
    175       ISelector oldFemaleSelector = FemaleSelector;
    176       FemaleSelectorParameter.ValidValues.Clear();
    177       foreach (ISelector selector in femaleSelectors)
    178         FemaleSelectorParameter.ValidValues.Add(selector);
    179       if (oldFemaleSelector == null) oldFemaleSelector = new ProportionalSelector();
    180       ISelector femaleSelector = FemaleSelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldFemaleSelector.GetType());
    181       if (femaleSelector != null) FemaleSelectorParameter.Value = femaleSelector;
    182 
    183       ISelector oldMaleSelector = MaleSelector;
    184       MaleSelectorParameter.ValidValues.Clear();
    185       foreach (ISelector selector in maleSelectors)
    186         MaleSelectorParameter.ValidValues.Add(selector);
    187       if (oldMaleSelector == null) oldMaleSelector = new RandomSelector();
    188       ISelector maleSelector = MaleSelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMaleSelector.GetType());
    189       if (maleSelector != null) MaleSelectorParameter.Value = maleSelector;
    190164    }
    191165    #endregion
  • trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.3.csproj

    r3404 r3413  
    8383    <None Include="HeuristicLabSelectionPlugin.cs.frame" />
    8484    <Compile Include="BestSelector.cs" />
     85    <Compile Include="ConditionalSelector.cs" />
    8586    <Compile Include="GenderSpecificSelector.cs" />
     87    <Compile Include="OffspringSelector.cs" />
    8688    <Compile Include="RightChildReducer.cs" />
    8789    <Compile Include="SingleObjectiveSelector.cs" />
Note: See TracChangeset for help on using the changeset viewer.