Changeset 16532 for branches/2521_ProblemRefactoring
- Timestamp:
- 01/14/19 22:33:44 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 14 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab 3.3.sln
r14429 r16532 1 1 2 2 Microsoft Visual Studio Solution File, Format Version 12.00 3 # Visual Studio 144 VisualStudioVersion = 1 4.0.25420.13 # Visual Studio 2013 4 VisualStudioVersion = 12.0.31101.0 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) = preSolution454 HasPerformanceSessions = true455 EndGlobalSection456 453 GlobalSection(SolutionConfigurationPlatforms) = preSolution 457 454 Debug|Any CPU = Debug|Any CPU -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/HeuristicLab.Algorithms.GeneticAlgorithm-3.3.csproj
r14429 r16532 115 115 </ItemGroup> 116 116 <ItemGroup> 117 <Compile Include="BinaryCanonicalGeneticAlgorithm.cs" />118 <Compile Include="CanonicalGeneticAlgorithm.cs" />119 <Compile Include="EvolutionaryAlgorithmContext.cs" />120 117 <Compile Include="GeneticAlgorithm.cs" /> 121 118 <Compile Include="GeneticAlgorithmMainLoop.cs" /> … … 150 147 <Name>HeuristicLab.Data-3.3</Name> 151 148 <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>156 149 </ProjectReference> 157 150 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.LocalSearch/3.3/HeuristicLab.Algorithms.LocalSearch-3.3.csproj
r14429 r16532 114 114 </ItemGroup> 115 115 <ItemGroup> 116 <Compile Include="BinaryIteratedLocalSearch.cs" />117 <Compile Include="IteratedLocalSearch.cs" />118 <Compile Include="LocalSearchContext.cs" />119 116 <Compile Include="LocalSearchImprovementOperator.cs" /> 120 117 <Compile Include="LocalSearchMainLoop.cs" /> … … 153 150 <Name>HeuristicLab.Data-3.3</Name> 154 151 <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>159 152 </ProjectReference> 160 153 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> -
branches/2521_ProblemRefactoring/HeuristicLab.Core/3.3/Attributes/ItemAttribute.cs
r14429 r16532 39 39 set { description = value == null ? string.Empty : value; } 40 40 } 41 public bool ExcludeGenericTypeInfo { get; set; }42 41 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) { 42 public ItemAttribute() { 43 Name = string.Empty; 44 Description = string.Empty; 45 } 46 public ItemAttribute(string name, string description) { 46 47 Name = name; 47 48 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 var attribute = (ItemAttribute)attribs[0]; 55 string name = attribute.Name; 56 if (!attribute.ExcludeGenericTypeInfo && type.IsGenericType) { 54 string name = ((ItemAttribute)attribs[0]).Name; 55 if (type.IsGenericType) { 57 56 name += "<"; 58 57 Type[] typeParams = type.GetGenericArguments(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/NPointCrossover.cs
r14429 r16532 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Optimization;28 27 using HeuristicLab.Parameters; 29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 71 70 /// <param name="n">Number of crossover points.</param> 72 71 /// <returns>The newly created binary vector, resulting from the N point crossover.</returns> 73 public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, intn) {72 public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, IntValue n) { 74 73 if (parent1.Length != parent2.Length) 75 74 throw new ArgumentException("NPointCrossover: The parents are of different length."); 76 75 77 if (n > parent1.Length)76 if (n.Value > parent1.Length) 78 77 throw new ArgumentException("NPointCrossover: There cannot be more breakpoints than the size of the parents."); 79 78 80 if (n < 1)79 if (n.Value < 1) 81 80 throw new ArgumentException("NPointCrossover: N cannot be < 1."); 82 81 83 82 int length = parent1.Length; 84 83 bool[] result = new bool[length]; 85 int[] breakpoints = new int[n ];84 int[] breakpoints = new int[n.Value]; 86 85 87 86 //choose break points … … 91 90 breakpointPool.Add(i); 92 91 93 for (int i = 0; i < n ; i++) {92 for (int i = 0; i < n.Value; i++) { 94 93 int index = random.Next(breakpointPool.Count); 95 94 breakpoints[i] = breakpointPool[index]; … … 138 137 if (NParameter.ActualValue == null) throw new InvalidOperationException("NPointCrossover: Parameter " + NParameter.ActualName + " could not be found."); 139 138 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); 139 return Apply(random, parents[0], parents[1], NParameter.ActualValue); 176 140 } 177 141 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
r14429 r16532 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], 1);59 return NPointCrossover.Apply(random, parents[0], parents[1], new IntValue(1)); 60 60 } 61 61 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj
r14429 r16532 126 126 <Compile Include="Crossovers\NPointCrossover.cs" /> 127 127 <Compile Include="BinaryVector.cs" /> 128 <Compile Include="Interfaces\IBinaryLocalSearch.cs" />129 128 <Compile Include="Interfaces\IBinaryVectorMultiNeighborhoodShakingOperator.cs" /> 130 129 <Compile Include="Interfaces\IBinaryVectorSolutionsOperator.cs" /> … … 140 139 <Compile Include="BinaryVectorManipulator.cs" /> 141 140 <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" />146 141 <Compile Include="Manipulators\SomePositionsBitflipManipulator.cs" /> 147 142 <Compile Include="Manipulators\SinglePositionBitflipManipulator.cs" /> … … 210 205 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 211 206 <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>216 207 </ProjectReference> 217 208 </ItemGroup> -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCrossover.cs
r14429 r16532 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Optimization; 24 using HeuristicLab.Optimization.Crossover;25 24 26 25 namespace HeuristicLab.Encodings.BinaryVectorEncoding { … … 32 31 ILookupParameter<BinaryVector> ChildParameter { get; } 33 32 } 34 35 // TODO: probably unecessary36 public interface IBinaryCrossover<TContext> : ICrossover<TContext> { }37 33 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs
r14429 r16532 81 81 } 82 82 83 // TODO: There is no way to access the Operators collection other than through OperatorParameter.Value 83 84 84 protected override IEnumerable<IItem> GetOperators() { 85 85 if (Encoding == null) return base.GetOperators(); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r14429 r16532 120 120 </ItemGroup> 121 121 <ItemGroup> 122 <Compile Include="Algorithms\SingleObjective\HeuristicAlgorithmContext.cs" />123 122 <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" />127 123 <Compile Include="BasicProblems\CombinedSolution.cs" /> 128 124 <Compile Include="BasicProblems\Interfaces\IMultiEncodingOperator.cs" /> … … 174 170 <Compile Include="MetaOptimizers\Experiment.cs" /> 175 171 <Compile Include="MetaOptimizers\TimeLimitRun.cs" /> 176 <Compile Include="NewInfrastructure\Interfaces.cs" />177 172 <Compile Include="RunCollectionModification\RunCollectionRunRemover.cs" /> 178 173 <Compile Include="Plugin.cs" /> … … 317 312 <Private>False</Private> 318 313 </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>323 314 </ItemGroup> 324 315 <ItemGroup> -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
r14429 r16532 60 60 } 61 61 public ILookupParameter<KnapsackSolution> BestSolutionParameter { 62 get { return (ILookupParameter<KnapsackSolution>)Parameters["Best KnapsackSolution"]; }62 get { return (ILookupParameter<KnapsackSolution>)Parameters["BestSolution"]; } 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 KnapsackSolution", "The best Knapsack solution."));86 Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "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/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r14429 r16532 91 91 92 92 InitializeRandomKnapsackInstance(); 93 Encoding.Length = Weights.Length;94 93 95 94 InitializeOperators(); … … 98 97 99 98 public override double Evaluate(BinaryVector solution, IRandom random) { 100 var weights = Weights;101 var values = Values;102 99 var totalWeight = 0.0; 103 100 var totalValue = 0.0; 104 101 for (var i = 0; i < solution.Length; i++) { 105 102 if (!solution[i]) continue; 106 totalWeight += weights[i];107 totalValue += values[i];103 totalWeight += Weights[i]; 104 totalValue += Values[i]; 108 105 } 109 106 return totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue; … … 256 253 var sysrand = new System.Random(); 257 254 258 var power = sysrand.Next(5, 11); 259 var itemCount = (int)Math.Pow(2, power); 255 var itemCount = sysrand.Next(10, 100); 260 256 Weights = new IntArray(itemCount); 261 257 Values = new IntArray(itemCount); … … 264 260 265 261 for (int i = 0; i < itemCount; i++) { 266 var value = sysrand.Next(1, 30);267 var weight = sysrand.Next(1, 30);262 var value = sysrand.Next(1, 10); 263 var weight = sysrand.Next(1, 10); 268 264 269 265 Values[i] = value; … … 272 268 } 273 269 274 KnapsackCapacity = (int)Math.Round(0. 5* totalWeight);270 KnapsackCapacity = (int)Math.Round(0.7 * totalWeight); 275 271 } 276 272 } -
branches/2521_ProblemRefactoring/HeuristicLab.Selection/3.3/TournamentSelector.cs
r14429 r16532 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Optimization; 29 using HeuristicLab.Optimization.Selection;30 29 using HeuristicLab.Parameters; 31 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 91 90 } 92 91 } 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 }152 92 }
Note: See TracChangeset
for help on using the changeset viewer.