Changeset 14429 for branches/ScopedAlgorithms
- Timestamp:
- 11/29/16 15:46:48 (8 years ago)
- Location:
- branches/ScopedAlgorithms
- Files:
-
- 19 added
- 13 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ScopedAlgorithms/HeuristicLab 3.3.sln
r13231 r14429 1 1 2 2 Microsoft Visual Studio Solution File, Format Version 12.00 3 # Visual Studio 20134 VisualStudioVersion = 1 2.0.31101.03 # Visual Studio 14 4 VisualStudioVersion = 14.0.25420.1 5 5 MinimumVisualStudioVersion = 10.0.40219.1 6 6 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{96396439-A764-4022-A8D2-BE021449B8D1}" … … 451 451 EndProject 452 452 Global 453 GlobalSection(Performance) = preSolution 454 HasPerformanceSessions = true 455 EndGlobalSection 453 456 GlobalSection(SolutionConfigurationPlatforms) = preSolution 454 457 Debug|Any CPU = Debug|Any CPU -
branches/ScopedAlgorithms/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/HeuristicLab.Algorithms.GeneticAlgorithm-3.3.csproj
r11623 r14429 115 115 </ItemGroup> 116 116 <ItemGroup> 117 <Compile Include="BinaryCanonicalGeneticAlgorithm.cs" /> 118 <Compile Include="CanonicalGeneticAlgorithm.cs" /> 119 <Compile Include="EvolutionaryAlgorithmContext.cs" /> 117 120 <Compile Include="GeneticAlgorithm.cs" /> 118 121 <Compile Include="GeneticAlgorithmMainLoop.cs" /> … … 147 150 <Name>HeuristicLab.Data-3.3</Name> 148 151 <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> 149 156 </ProjectReference> 150 157 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> -
branches/ScopedAlgorithms/HeuristicLab.Algorithms.LocalSearch/3.3/HeuristicLab.Algorithms.LocalSearch-3.3.csproj
r11623 r14429 114 114 </ItemGroup> 115 115 <ItemGroup> 116 <Compile Include="BinaryIteratedLocalSearch.cs" /> 117 <Compile Include="IteratedLocalSearch.cs" /> 118 <Compile Include="LocalSearchContext.cs" /> 116 119 <Compile Include="LocalSearchImprovementOperator.cs" /> 117 120 <Compile Include="LocalSearchMainLoop.cs" /> … … 150 153 <Name>HeuristicLab.Data-3.3</Name> 151 154 <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> 152 159 </ProjectReference> 153 160 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> -
branches/ScopedAlgorithms/HeuristicLab.Core/3.3/Attributes/ItemAttribute.cs
r12012 r14429 39 39 set { description = value == null ? string.Empty : value; } 40 40 } 41 public bool ExcludeGenericTypeInfo { get; set; } 41 42 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) { 47 46 Name = name; 48 47 Description = description; 48 ExcludeGenericTypeInfo = excludeGenericTypeInfo; 49 49 } 50 50 … … 52 52 object[] attribs = type.GetCustomAttributes(typeof(ItemAttribute), false); 53 53 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) { 56 57 name += "<"; 57 58 Type[] typeParams = type.GetGenericArguments(); -
branches/ScopedAlgorithms/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/NPointCrossover.cs
r12012 r14429 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 70 71 /// <param name="n">Number of crossover points.</param> 71 72 /// <returns>The newly created binary vector, resulting from the N point crossover.</returns> 72 public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, IntValuen) {73 public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, int n) { 73 74 if (parent1.Length != parent2.Length) 74 75 throw new ArgumentException("NPointCrossover: The parents are of different length."); 75 76 76 if (n .Value> parent1.Length)77 if (n > parent1.Length) 77 78 throw new ArgumentException("NPointCrossover: There cannot be more breakpoints than the size of the parents."); 78 79 79 if (n .Value< 1)80 if (n < 1) 80 81 throw new ArgumentException("NPointCrossover: N cannot be < 1."); 81 82 82 83 int length = parent1.Length; 83 84 bool[] result = new bool[length]; 84 int[] breakpoints = new int[n .Value];85 int[] breakpoints = new int[n]; 85 86 86 87 //choose break points … … 90 91 breakpointPool.Add(i); 91 92 92 for (int i = 0; i < n .Value; i++) {93 for (int i = 0; i < n; i++) { 93 94 int index = random.Next(breakpointPool.Count); 94 95 breakpoints[i] = breakpointPool[index]; … … 137 138 if (NParameter.ActualValue == null) throw new InvalidOperationException("NPointCrossover: Parameter " + NParameter.ActualName + " could not be found."); 138 139 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); 140 176 } 141 177 } -
branches/ScopedAlgorithms/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
r12012 r14429 57 57 if (parents.Length != 2) throw new ArgumentException("ERROR in SinglePointCrossover: The number of parents is not equal to 2"); 58 58 59 return NPointCrossover.Apply(random, parents[0], parents[1], new IntValue(1));59 return NPointCrossover.Apply(random, parents[0], parents[1], 1); 60 60 } 61 61 } -
branches/ScopedAlgorithms/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj
r13404 r14429 126 126 <Compile Include="Crossovers\NPointCrossover.cs" /> 127 127 <Compile Include="BinaryVector.cs" /> 128 <Compile Include="Interfaces\IBinaryLocalSearch.cs" /> 128 129 <Compile Include="Interfaces\IBinaryVectorMultiNeighborhoodShakingOperator.cs" /> 129 130 <Compile Include="Interfaces\IBinaryVectorSolutionsOperator.cs" /> … … 139 140 <Compile Include="BinaryVectorManipulator.cs" /> 140 141 <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" /> 141 146 <Compile Include="Manipulators\SomePositionsBitflipManipulator.cs" /> 142 147 <Compile Include="Manipulators\SinglePositionBitflipManipulator.cs" /> … … 205 210 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 206 211 <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> 207 216 </ProjectReference> 208 217 </ItemGroup> -
branches/ScopedAlgorithms/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCrossover.cs
r12012 r14429 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Optimization; 24 using HeuristicLab.Optimization.Crossover; 24 25 25 26 namespace HeuristicLab.Encodings.BinaryVectorEncoding { … … 31 32 ILookupParameter<BinaryVector> ChildParameter { get; } 32 33 } 34 35 // TODO: probably unecessary 36 public interface IBinaryCrossover<TContext> : ICrossover<TContext> { } 33 37 } -
branches/ScopedAlgorithms/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs
r13469 r14429 81 81 } 82 82 83 83 // TODO: There is no way to access the Operators collection other than through OperatorParameter.Value 84 84 protected override IEnumerable<IItem> GetOperators() { 85 85 if (Encoding == null) return base.GetOperators(); -
branches/ScopedAlgorithms/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r13376 r14429 120 120 </ItemGroup> 121 121 <ItemGroup> 122 <Compile Include="Algorithms\SingleObjective\HeuristicAlgorithmContext.cs" /> 122 123 <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" /> 123 127 <Compile Include="BasicProblems\CombinedSolution.cs" /> 124 128 <Compile Include="BasicProblems\Interfaces\IMultiEncodingOperator.cs" /> … … 170 174 <Compile Include="MetaOptimizers\Experiment.cs" /> 171 175 <Compile Include="MetaOptimizers\TimeLimitRun.cs" /> 176 <Compile Include="NewInfrastructure\Interfaces.cs" /> 172 177 <Compile Include="RunCollectionModification\RunCollectionRunRemover.cs" /> 173 178 <Compile Include="Plugin.cs" /> … … 312 317 <Private>False</Private> 313 318 </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> 314 323 </ItemGroup> 315 324 <ItemGroup> -
branches/ScopedAlgorithms/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
r13404 r14429 60 60 } 61 61 public ILookupParameter<KnapsackSolution> BestSolutionParameter { 62 get { return (ILookupParameter<KnapsackSolution>)Parameters["Best Solution"]; }62 get { return (ILookupParameter<KnapsackSolution>)Parameters["BestKnapsackSolution"]; } 63 63 } 64 64 public IValueLookupParameter<ResultCollection> ResultsParameter { … … 84 84 85 85 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the Knapsack solutions which should be visualized.")); 86 Parameters.Add(new LookupParameter<KnapsackSolution>("Best Solution", "The best Knapsack solution."));86 Parameters.Add(new LookupParameter<KnapsackSolution>("BestKnapsackSolution", "The best Knapsack solution.")); 87 87 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored.")); 88 88 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution.")); -
branches/ScopedAlgorithms/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r13469 r14429 91 91 92 92 InitializeRandomKnapsackInstance(); 93 Encoding.Length = Weights.Length; 93 94 94 95 InitializeOperators(); … … 97 98 98 99 public override double Evaluate(BinaryVector solution, IRandom random) { 100 var weights = Weights; 101 var values = Values; 99 102 var totalWeight = 0.0; 100 103 var totalValue = 0.0; 101 104 for (var i = 0; i < solution.Length; i++) { 102 105 if (!solution[i]) continue; 103 totalWeight += Weights[i];104 totalValue += Values[i];106 totalWeight += weights[i]; 107 totalValue += values[i]; 105 108 } 106 109 return totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue; … … 253 256 var sysrand = new System.Random(); 254 257 255 var itemCount = sysrand.Next(10, 100); 258 var power = sysrand.Next(5, 11); 259 var itemCount = (int)Math.Pow(2, power); 256 260 Weights = new IntArray(itemCount); 257 261 Values = new IntArray(itemCount); … … 260 264 261 265 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); 264 268 265 269 Values[i] = value; … … 268 272 } 269 273 270 KnapsackCapacity = (int)Math.Round(0. 7* totalWeight);274 KnapsackCapacity = (int)Math.Round(0.5 * totalWeight); 271 275 } 272 276 } -
branches/ScopedAlgorithms/HeuristicLab.Selection/3.3/TournamentSelector.cs
r12012 r14429 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Optimization; 29 using HeuristicLab.Optimization.Selection; 29 30 using HeuristicLab.Parameters; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 90 91 } 91 92 } 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 } 92 152 }
Note: See TracChangeset
for help on using the changeset viewer.