Changeset 13385 for branches/ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAGroupingProblemSampleTest.cs
- Timestamp:
- 11/24/15 18:22:29 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAGroupingProblemSampleTest.cs
r12743 r13385 45 45 46 46 namespace HeuristicLab.Problems.Programmable { 47 public class CompiledSingleObjectiveProblemDefinition : Compiled ProblemDefinition, ISingleObjectiveProblemDefinition{47 public class CompiledSingleObjectiveProblemDefinition : CompiledSingleObjectiveProblemDefinition<LinearLinkageEncoding, LinearLinkage> { 48 48 private const int ProblemSize = 100; 49 public bool Maximization { get { return false; } }49 public override bool Maximization { get { return false; } } 50 50 51 51 private bool[,] allowedTogether; 52 52 53 53 public override void Initialize() { 54 var encoding = new LinearLinkageEncoding(""lle"", length: ProblemSize);55 allowedTogether = new bool[ encoding.Length, encoding.Length];54 Encoding.Length = ProblemSize; 55 allowedTogether = new bool[ProblemSize, ProblemSize]; 56 56 var random = new System.Random(13); 57 for (var i = 0; i < encoding.Length- 1; i++)58 for (var j = i + 1; j < encoding.Length; j++)57 for (var i = 0; i < ProblemSize - 1; i++) 58 for (var j = i + 1; j < ProblemSize; j++) 59 59 allowedTogether[i, j] = allowedTogether[j, i] = random.Next(2) == 0; 60 61 Encoding = encoding;62 60 } 63 61 64 public double Evaluate(Individual individual, IRandom random) {62 public override double Evaluate(LinearLinkage solution, IRandom random) { 65 63 var penalty = 0; 66 var groups = individual.LinearLinkage(""lle"").GetGroups().ToList();64 var groups = solution.GetGroups().ToList(); 67 65 for (var i = 0; i < groups.Count; i++) { 68 66 for (var j = 0; j < groups[i].Count; j++) … … 74 72 } 75 73 76 public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { }74 public override void Analyze(LinearLinkage[] solutions, double[] qualities, ResultCollection results, IRandom random) { } 77 75 78 public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) { 79 foreach (var move in ExhaustiveSwap2MoveGenerator.Generate(individual.LinearLinkage(""lle""))) { 80 var neighbor = individual.Copy(); 81 var lle = neighbor.LinearLinkage(""lle""); 82 Swap2MoveMaker.Apply(lle, move); 76 public override IEnumerable<LinearLinkage> GetNeighbors(LinearLinkage solution, IRandom random) { 77 foreach (var move in ExhaustiveSwap2MoveGenerator.Generate(solution)) { 78 var neighbor = (LinearLinkage)solution.Clone(); 79 Swap2MoveMaker.Apply(neighbor, move); 83 80 yield return neighbor; 84 81 } … … 115 112 116 113 #region Problem Configuration 117 var problem = new SingleObjective ProgrammableProblem() {114 var problem = new SingleObjectiveLinearLinkageProgrammableProblem() { 118 115 ProblemScript = { Code = ProblemCode } 119 116 };
Note: See TracChangeset
for help on using the changeset viewer.