Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/29/16 15:46:48 (8 years ago)
Author:
abeham
Message:

#2701, #2708: Made a new branch from ProblemRefactoring and removed ScopedBasicAlgorithm branch (which becomes MemPR branch)

Location:
branches/ProblemRefactoring
Files:
19 added
13 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab 3.3.sln

    r13231 r14429  
    11
    22Microsoft Visual Studio Solution File, Format Version 12.00
    3 # Visual Studio 2013
    4 VisualStudioVersion = 12.0.31101.0
     3# Visual Studio 14
     4VisualStudioVersion = 14.0.25420.1
    55MinimumVisualStudioVersion = 10.0.40219.1
    66Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{96396439-A764-4022-A8D2-BE021449B8D1}"
     
    451451EndProject
    452452Global
     453  GlobalSection(Performance) = preSolution
     454    HasPerformanceSessions = true
     455  EndGlobalSection
    453456  GlobalSection(SolutionConfigurationPlatforms) = preSolution
    454457    Debug|Any CPU = Debug|Any CPU
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/HeuristicLab.Algorithms.GeneticAlgorithm-3.3.csproj

    r11623 r14429  
    115115  </ItemGroup>
    116116  <ItemGroup>
     117    <Compile Include="BinaryCanonicalGeneticAlgorithm.cs" />
     118    <Compile Include="CanonicalGeneticAlgorithm.cs" />
     119    <Compile Include="EvolutionaryAlgorithmContext.cs" />
    117120    <Compile Include="GeneticAlgorithm.cs" />
    118121    <Compile Include="GeneticAlgorithmMainLoop.cs" />
     
    147150      <Name>HeuristicLab.Data-3.3</Name>
    148151      <Private>False</Private>
     152    </ProjectReference>
     153    <ProjectReference Include="..\..\HeuristicLab.Encodings.BinaryVectorEncoding\3.3\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj">
     154      <Project>{66D249C3-A01D-42A8-82A2-919BC8EC3D83}</Project>
     155      <Name>HeuristicLab.Encodings.BinaryVectorEncoding-3.3</Name>
    149156    </ProjectReference>
    150157    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.LocalSearch/3.3/HeuristicLab.Algorithms.LocalSearch-3.3.csproj

    r11623 r14429  
    114114  </ItemGroup>
    115115  <ItemGroup>
     116    <Compile Include="BinaryIteratedLocalSearch.cs" />
     117    <Compile Include="IteratedLocalSearch.cs" />
     118    <Compile Include="LocalSearchContext.cs" />
    116119    <Compile Include="LocalSearchImprovementOperator.cs" />
    117120    <Compile Include="LocalSearchMainLoop.cs" />
     
    150153      <Name>HeuristicLab.Data-3.3</Name>
    151154      <Private>False</Private>
     155    </ProjectReference>
     156    <ProjectReference Include="..\..\HeuristicLab.Encodings.BinaryVectorEncoding\3.3\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj">
     157      <Project>{66D249C3-A01D-42A8-82A2-919BC8EC3D83}</Project>
     158      <Name>HeuristicLab.Encodings.BinaryVectorEncoding-3.3</Name>
    152159    </ProjectReference>
    153160    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
  • branches/ProblemRefactoring/HeuristicLab.Core/3.3/Attributes/ItemAttribute.cs

    r12012 r14429  
    3939      set { description = value == null ? string.Empty : value; }
    4040    }
     41    public bool ExcludeGenericTypeInfo { get; set; }
    4142
    42     public ItemAttribute() {
    43       Name = string.Empty;
    44       Description = string.Empty;
    45     }
    46     public ItemAttribute(string name, string description) {
     43    public ItemAttribute() : this(string.Empty, string.Empty, false) { }
     44    public ItemAttribute(string name, string description) : this(name, description, false) { }
     45    public ItemAttribute(string name, string description, bool excludeGenericTypeInfo) {
    4746      Name = name;
    4847      Description = description;
     48      ExcludeGenericTypeInfo = excludeGenericTypeInfo;
    4949    }
    5050
     
    5252      object[] attribs = type.GetCustomAttributes(typeof(ItemAttribute), false);
    5353      if (attribs.Length > 0) {
    54         string name = ((ItemAttribute)attribs[0]).Name;
    55         if (type.IsGenericType) {
     54        var attribute = (ItemAttribute)attribs[0];
     55        string name = attribute.Name;
     56        if (!attribute.ExcludeGenericTypeInfo && type.IsGenericType) {
    5657          name += "<";
    5758          Type[] typeParams = type.GetGenericArguments();
  • branches/ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/NPointCrossover.cs

    r12012 r14429  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Optimization;
    2728using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    7071    /// <param name="n">Number of crossover points.</param>
    7172    /// <returns>The newly created binary vector, resulting from the N point crossover.</returns>
    72     public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, IntValue n) {
     73    public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, int n) {
    7374      if (parent1.Length != parent2.Length)
    7475        throw new ArgumentException("NPointCrossover: The parents are of different length.");
    7576
    76       if (n.Value > parent1.Length)
     77      if (n > parent1.Length)
    7778        throw new ArgumentException("NPointCrossover: There cannot be more breakpoints than the size of the parents.");
    7879
    79       if (n.Value < 1)
     80      if (n < 1)
    8081        throw new ArgumentException("NPointCrossover: N cannot be < 1.");
    8182
    8283      int length = parent1.Length;
    8384      bool[] result = new bool[length];
    84       int[] breakpoints = new int[n.Value];
     85      int[] breakpoints = new int[n];
    8586
    8687      //choose break points
     
    9091        breakpointPool.Add(i);
    9192
    92       for (int i = 0; i < n.Value; i++) {
     93      for (int i = 0; i < n; i++) {
    9394        int index = random.Next(breakpointPool.Count);
    9495        breakpoints[i] = breakpointPool[index];
     
    137138      if (NParameter.ActualValue == null) throw new InvalidOperationException("NPointCrossover: Parameter " + NParameter.ActualName + " could not be found.");
    138139
    139       return Apply(random, parents[0], parents[1], NParameter.ActualValue);
     140      return Apply(random, parents[0], parents[1], NParameter.ActualValue.Value);
     141    }
     142  }
     143
     144  [Item("N-point Crossover", "", ExcludeGenericTypeInfo = true)]
     145  [StorableClass]
     146  public sealed class NPointCrossover<TContext> : ParameterizedNamedItem, IBinaryCrossover<TContext>
     147    where TContext : IMatingContext<BinaryVector>, IStochasticContext {
     148
     149    [Storable]
     150    private IValueParameter<IntValue> nparameter;
     151    public int N {
     152      get { return nparameter.Value.Value; }
     153      set {
     154        if (value < 1) throw new ArgumentException("Cannot set N to less than 1.");
     155        nparameter.Value.Value = value;
     156      }
     157    }
     158
     159    [StorableConstructor]
     160    private NPointCrossover(bool deserializing) : base(deserializing) { }
     161    private NPointCrossover(NPointCrossover<TContext> original, Cloner cloner)
     162      : base(original, cloner) {
     163      nparameter = cloner.Clone(original.nparameter);
     164    }
     165    public NPointCrossover() {
     166      Parameters.Add(nparameter = new ValueParameter<IntValue>("N", "The number of crossover points.", new IntValue(1)));
     167    }
     168
     169
     170    public override IDeepCloneable Clone(Cloner cloner) {
     171      return new NPointCrossover<TContext>(this, cloner);
     172    }
     173
     174    public void Cross(TContext context) {
     175      context.Child.Solution = NPointCrossover.Apply(context.Random, context.Parents.Item1.Solution, context.Parents.Item2.Solution, N);
    140176    }
    141177  }
  • branches/ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs

    r12012 r14429  
    5757      if (parents.Length != 2) throw new ArgumentException("ERROR in SinglePointCrossover: The number of parents is not equal to 2");
    5858
    59       return NPointCrossover.Apply(random, parents[0], parents[1], new IntValue(1));
     59      return NPointCrossover.Apply(random, parents[0], parents[1], 1);
    6060    }
    6161  }
  • branches/ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj

    r13404 r14429  
    126126    <Compile Include="Crossovers\NPointCrossover.cs" />
    127127    <Compile Include="BinaryVector.cs" />
     128    <Compile Include="Interfaces\IBinaryLocalSearch.cs" />
    128129    <Compile Include="Interfaces\IBinaryVectorMultiNeighborhoodShakingOperator.cs" />
    129130    <Compile Include="Interfaces\IBinaryVectorSolutionsOperator.cs" />
     
    139140    <Compile Include="BinaryVectorManipulator.cs" />
    140141    <Compile Include="Interfaces\IBinaryVectorMoveOperator.cs" />
     142    <Compile Include="LocalSearch\ExhaustiveBitflip.cs" />
     143    <Compile Include="Manipulators\MultiBitflipManipulator.cs" />
     144    <Compile Include="Manipulators\SingleBitflipManipulator.cs" />
     145    <Compile Include="Manipulators\BitflipManipulator.cs" />
    141146    <Compile Include="Manipulators\SomePositionsBitflipManipulator.cs" />
    142147    <Compile Include="Manipulators\SinglePositionBitflipManipulator.cs" />
     
    205210      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    206211      <Private>False</Private>
     212    </ProjectReference>
     213    <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
     214      <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
     215      <Name>HeuristicLab.Random-3.3</Name>
    207216    </ProjectReference>
    208217  </ItemGroup>
  • branches/ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCrossover.cs

    r12012 r14429  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Optimization;
     24using HeuristicLab.Optimization.Crossover;
    2425
    2526namespace HeuristicLab.Encodings.BinaryVectorEncoding {
     
    3132    ILookupParameter<BinaryVector> ChildParameter { get; }
    3233  }
     34
     35  // TODO: probably unecessary
     36  public interface IBinaryCrossover<TContext> : ICrossover<TContext> { }
    3337}
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs

    r13469 r14429  
    8181    }
    8282
    83 
     83    // TODO: There is no way to access the Operators collection other than through OperatorParameter.Value
    8484    protected override IEnumerable<IItem> GetOperators() {
    8585      if (Encoding == null) return base.GetOperators();
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r13376 r14429  
    120120  </ItemGroup>
    121121  <ItemGroup>
     122    <Compile Include="Algorithms\SingleObjective\HeuristicAlgorithmContext.cs" />
    122123    <Compile Include="Algorithms\BasicAlgorithm.cs" />
     124    <Compile Include="Algorithms\SingleObjective\HeuristicAlgorithm.cs" />
     125    <Compile Include="Algorithms\AlgorithmContext.cs" />
     126    <Compile Include="Algorithms\SingleObjective\SingleObjectiveSolutionScope.cs" />
    123127    <Compile Include="BasicProblems\CombinedSolution.cs" />
    124128    <Compile Include="BasicProblems\Interfaces\IMultiEncodingOperator.cs" />
     
    170174    <Compile Include="MetaOptimizers\Experiment.cs" />
    171175    <Compile Include="MetaOptimizers\TimeLimitRun.cs" />
     176    <Compile Include="NewInfrastructure\Interfaces.cs" />
    172177    <Compile Include="RunCollectionModification\RunCollectionRunRemover.cs" />
    173178    <Compile Include="Plugin.cs" />
     
    312317      <Private>False</Private>
    313318    </ProjectReference>
     319    <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
     320      <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
     321      <Name>HeuristicLab.Random-3.3</Name>
     322    </ProjectReference>
    314323  </ItemGroup>
    315324  <ItemGroup>
  • branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs

    r13404 r14429  
    6060    }
    6161    public ILookupParameter<KnapsackSolution> BestSolutionParameter {
    62       get { return (ILookupParameter<KnapsackSolution>)Parameters["BestSolution"]; }
     62      get { return (ILookupParameter<KnapsackSolution>)Parameters["BestKnapsackSolution"]; }
    6363    }
    6464    public IValueLookupParameter<ResultCollection> ResultsParameter {
     
    8484
    8585      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the Knapsack solutions which should be visualized."));
    86       Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best Knapsack solution."));
     86      Parameters.Add(new LookupParameter<KnapsackSolution>("BestKnapsackSolution", "The best Knapsack solution."));
    8787      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored."));
    8888      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
  • branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r13469 r14429  
    9191
    9292      InitializeRandomKnapsackInstance();
     93      Encoding.Length = Weights.Length;
    9394
    9495      InitializeOperators();
     
    9798
    9899    public override double Evaluate(BinaryVector solution, IRandom random) {
     100      var weights = Weights;
     101      var values = Values;
    99102      var totalWeight = 0.0;
    100103      var totalValue = 0.0;
    101104      for (var i = 0; i < solution.Length; i++) {
    102105        if (!solution[i]) continue;
    103         totalWeight += Weights[i];
    104         totalValue += Values[i];
     106        totalWeight += weights[i];
     107        totalValue += values[i];
    105108      }
    106109      return totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue;
     
    253256      var sysrand = new System.Random();
    254257
    255       var itemCount = sysrand.Next(10, 100);
     258      var power = sysrand.Next(5, 11);
     259      var itemCount = (int)Math.Pow(2, power);
    256260      Weights = new IntArray(itemCount);
    257261      Values = new IntArray(itemCount);
     
    260264
    261265      for (int i = 0; i < itemCount; i++) {
    262         var value = sysrand.Next(1, 10);
    263         var weight = sysrand.Next(1, 10);
     266        var value = sysrand.Next(1, 30);
     267        var weight = sysrand.Next(1, 30);
    264268
    265269        Values[i] = value;
     
    268272      }
    269273
    270       KnapsackCapacity = (int)Math.Round(0.7 * totalWeight);
     274      KnapsackCapacity = (int)Math.Round(0.5 * totalWeight);
    271275    }
    272276  }
  • branches/ProblemRefactoring/HeuristicLab.Selection/3.3/TournamentSelector.cs

    r12012 r14429  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Optimization;
     29using HeuristicLab.Optimization.Selection;
    2930using HeuristicLab.Parameters;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    9091    }
    9192  }
     93
     94  [Item("Tournament Selector", "", ExcludeGenericTypeInfo = true)]
     95  [StorableClass]
     96  public sealed class TournamentSelector<TContext, TProblem, TEncoding, TSolution> : ParameterizedNamedItem, ISelector<TContext>
     97      where TContext : ISingleObjectivePopulationContext<TSolution>, IMatingpoolContext<TSolution>, IStochasticContext,
     98                       IProblemContext<TProblem, TEncoding, TSolution>
     99      where TProblem : class, ISingleObjectiveProblem<TEncoding, TSolution>, ISingleObjectiveProblemDefinition<TEncoding, TSolution>
     100      where TEncoding : class, IEncoding<TSolution>
     101      where TSolution : class, ISolution {
     102
     103    [Storable]
     104    private IValueParameter<IntValue> groupSizeParameter;
     105    public int GroupSize {
     106      get { return groupSizeParameter.Value.Value; }
     107      set {
     108        if (value < 1) throw new ArgumentException("Cannot use a group size less than 1 in tournament selection.");
     109        groupSizeParameter.Value.Value = value;
     110      }
     111    }
     112   
     113    [StorableConstructor]
     114    private TournamentSelector(bool deserializing) : base(deserializing) { }
     115    private TournamentSelector(TournamentSelector<TContext, TProblem, TEncoding, TSolution> original, Cloner cloner)
     116      : base(original, cloner) {
     117      groupSizeParameter = cloner.Clone(groupSizeParameter);
     118    }
     119    public TournamentSelector() {
     120      Parameters.Add(groupSizeParameter = new ValueParameter<IntValue>("GroupSize", "The group size that competes in the tournament.", new IntValue(2)));
     121    }
     122
     123    public override IDeepCloneable Clone(Cloner cloner) {
     124      return new TournamentSelector<TContext, TProblem, TEncoding, TSolution>(this, cloner);
     125    }
     126
     127    public void Select(TContext context, int n, bool withRepetition) {
     128      context.MatingPool = Select(context.Random, context.Problem.IsBetter, context.Population, GroupSize, n, withRepetition);
     129    }
     130
     131    public static IEnumerable<ISingleObjectiveSolutionScope<TSolution>> Select(IRandom random, Func<double, double, bool> isBetterFunc, IEnumerable<ISingleObjectiveSolutionScope<TSolution>> population, int groupSize, int n, bool withRepetition) {
     132      var pop = population.Where(x => !double.IsNaN(x.Fitness)).ToList();
     133
     134      var i = n;
     135      while (i > 0 && pop.Count > 0) {
     136        var best = random.Next(pop.Count);
     137        for (var j = 1; j < groupSize; j++) {
     138          var index = random.Next(pop.Count);
     139          if (isBetterFunc(pop[index].Fitness, pop[best].Fitness)) {
     140            best = index;
     141          }
     142        }
     143
     144        yield return pop[best];
     145        i--;
     146        if (!withRepetition) {
     147          pop.RemoveAt(i);
     148        }
     149      }
     150    }
     151  }
    92152}
Note: See TracChangeset for help on using the changeset viewer.