Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/15 18:22:29 (9 years ago)
Author:
abeham
Message:

#2521: fixed plugin dependencies and updated samples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAGroupingProblemSampleTest.cs

    r12743 r13385  
    4545
    4646namespace HeuristicLab.Problems.Programmable {
    47   public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
     47  public class CompiledSingleObjectiveProblemDefinition : CompiledSingleObjectiveProblemDefinition<LinearLinkageEncoding, LinearLinkage> {
    4848    private const int ProblemSize = 100;
    49     public bool Maximization { get { return false; } }
     49    public override bool Maximization { get { return false; } }
    5050
    5151    private bool[,] allowedTogether;
    52      
     52   
    5353    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];
    5656      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++)
    5959          allowedTogether[i, j] = allowedTogether[j, i] = random.Next(2) == 0;
    60      
    61       Encoding = encoding;
    6260    }
    6361
    64     public double Evaluate(Individual individual, IRandom random) {
     62    public override double Evaluate(LinearLinkage solution, IRandom random) {
    6563      var penalty = 0;
    66       var groups = individual.LinearLinkage(""lle"").GetGroups().ToList();
     64      var groups = solution.GetGroups().ToList();
    6765      for (var i = 0; i < groups.Count; i++) {
    6866        for (var j = 0; j < groups[i].Count; j++)
     
    7472    }
    7573
    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) { }
    7775
    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);
    8380        yield return neighbor;
    8481      }
     
    115112
    116113      #region Problem Configuration
    117       var problem = new SingleObjectiveProgrammableProblem() {
     114      var problem = new SingleObjectiveLinearLinkageProgrammableProblem() {
    118115        ProblemScript = { Code = ProblemCode }
    119116      };
Note: See TracChangeset for help on using the changeset viewer.