Changeset 14364 for branches/Templates/EmptyAlgorithm
- Timestamp:
- 10/31/16 15:11:46 (8 years ago)
- Location:
- branches/Templates/EmptyAlgorithm/EmptyAlgorithm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Templates/EmptyAlgorithm/EmptyAlgorithm/EmptyAlgorithm.csproj
r14363 r14364 47 47 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath> 48 48 </Reference> 49 <Reference Include="HeuristicLab.Encodings. IntegerVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">49 <Reference Include="HeuristicLab.Encodings.BinaryVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 50 50 <SpecificVersion>False</SpecificVersion> 51 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Encodings. IntegerVectorEncoding-3.3.dll</HintPath>51 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.dll</HintPath> 52 52 </Reference> 53 53 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> … … 65 65 <Reference Include="HeuristicLab.PluginInfrastructure-3.3"> 66 66 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 67 </Reference> 68 <Reference Include="HeuristicLab.Problems.Binary-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 69 <SpecificVersion>False</SpecificVersion> 70 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Binary-3.3.dll</HintPath> 71 </Reference> 72 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 73 <SpecificVersion>False</SpecificVersion> 74 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath> 67 75 </Reference> 68 76 <Reference Include="System" /> -
branches/Templates/EmptyAlgorithm/EmptyAlgorithm/MyAlgorithm.cs
r14362 r14364 1 using System.Threading; 1 using System; 2 using System.Threading; 2 3 using HeuristicLab.Common; // required for parameters collection 3 4 using HeuristicLab.Core; // required for parameters collection 4 5 using HeuristicLab.Data; // IntValue, ... 6 using HeuristicLab.Encodings.BinaryVectorEncoding; 5 7 using HeuristicLab.Optimization; // BasicAlgorithm 6 8 using HeuristicLab.Parameters; 7 9 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 10 using HeuristicLab.Problems.Binary; 11 using HeuristicLab.Random; // MersenneTwister 8 12 9 13 namespace EmptyAlgorithm { … … 17 21 [StorableClass] // for persistence (storing your algorithm to a files or transfer to HeuristicLab.Hive 18 22 public class MyAlgorithm : BasicAlgorithm { 23 // This algorithm only works for BinaryProblems. 24 // Overriding the ProblemType property has the effect that only BinaryProblems can be set as problem 25 // for the algorithm in the GUI 26 public override Type ProblemType { get { return typeof(BinaryProblem); } } 27 public new BinaryProblem Problem { get { return (BinaryProblem)base.Problem; } } 28 19 29 #region parameters 20 30 // If an algorithm has parameters then we usually also add properties to access these parameters. … … 53 63 protected override void Run(CancellationToken cancellationToken) { 54 64 int maxIters = MaxIterations; 65 var problem = Problem; 66 var rand = new MersenneTwister(1234); 67 68 var bestQuality = problem.Maximization ? double.MinValue : double.MaxValue; 69 70 var curItersItem = new IntValue(); 71 var bestQualityItem = new DoubleValue(bestQuality); 72 var curItersResult = new Result("Iteration", curItersItem); 73 var bestQualityResult = new Result("Best quality", bestQualityItem); 74 Results.Add(curItersResult); 75 Results.Add(bestQualityResult); 76 77 for (int i = 0; i < maxIters; i++) { 78 curItersItem.Value = i; 79 80 // ----------------------------- 81 // IMPLEMENT YOUR ALGORITHM HERE 82 // ----------------------------- 55 83 56 84 57 var curIters = new IntValue(); 58 var curItersResult = new Result("Iteration", curIters); 59 Results.Add(curItersResult); 60 61 for (int i = 0; i < maxIters; i++) { 62 curIters.Value = i; 85 // this is an example for random search 86 // for a more elaborate algorithm check the source code of "HeuristicLab.Algorithms.ParameterlessPopulationPyramid" 87 var cand = new BinaryVector(problem.Length, rand); 88 var quality = problem.Evaluate(cand, rand); // calling Evaluate like this is not possible for all problems... 89 if (problem.Maximization) bestQuality = Math.Max(bestQuality, quality); 90 else bestQuality = Math.Min(quality, bestQuality); 91 bestQualityItem.Value = bestQuality; 63 92 64 93 // check the cancellation token to see if the used clicked "Stop" -
branches/Templates/EmptyAlgorithm/EmptyAlgorithm/Plugin.cs
r14362 r14364 11 11 // not correct then your plugin cannot be used on HeuristicLab.Hive 12 12 // 13 // [PluginDependency("HeuristicLab.Data", "3.3")] 14 // [PluginDependency("HeuristicLab.Core", "3.3")] 13 [PluginDependency("HeuristicLab.Collections", "3.3")] 14 [PluginDependency("HeuristicLab.Common", "3.3")] 15 [PluginDependency("HeuristicLab.Core", "3.3")] 16 [PluginDependency("HeuristicLab.Data", "3.3")] 17 [PluginDependency("HeuristicLab.Encodings.BinaryVectorEncoding", "3.3")] 18 [PluginDependency("HeuristicLab.Optimization", "3.3")] 19 [PluginDependency("HeuristicLab.Parameters", "3.3")] 20 [PluginDependency("HeuristicLab.Persistence", "3.3")] 21 [PluginDependency("HeuristicLab.Problems.Binary", "3.3")] 22 [PluginDependency("HeuristicLab.Random", "3.3")] 15 23 16 24 // HL plugin infrastructure discovers plugins on startup by trying to load all .dll and .exe files and looking for
Note: See TracChangeset
for help on using the changeset viewer.