Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/ProblemInstanceIdentifier/InstanceExplorer.cs @ 14690

Last change on this file since 14690 was 14690, checked in by abeham, 7 years ago

#2457: working on identification of problem instances

File size: 2.7 KB
Line 
1using System.Linq;
2using System.Threading;
3using HeuristicLab.Analysis.FitnessLandscape;
4using HeuristicLab.Data;
5using HeuristicLab.Encodings.PermutationEncoding;
6using HeuristicLab.Problems.QuadraticAssignment;
7using HeuristicLab.SequentialEngine;
8
9namespace ProblemInstanceIdentifier {
10  public abstract class InstanceExplorer {
11
12    public abstract string Name { get; }
13    public abstract int Effort { get; }
14    protected InstanceExplorer() { }
15
16    public abstract InstanceDescriptor Explore(QuadraticAssignmentProblem problem, int? seed = null);
17  }
18
19  public class PathRelinkingExplorer : InstanceExplorer {
20    public int Paths { get; set; }
21    public bool LocalOptima { get; set; }
22
23    public override string Name { get { return "Path-Relinking Explorer"; } }
24    public override int Effort { get { return Paths; } }
25
26    public PathRelinkingExplorer() {
27     
28    }
29
30    public override InstanceDescriptor Explore(QuadraticAssignmentProblem problem, int? seed = null) {
31      var walk = new QAPDirectedWalk {
32        Problem = problem,
33        BestImprovement = true,
34        Paths = Paths,
35        Seed = seed,
36        LocalOptima = LocalOptima
37      };
38      var features = walk.Calculate().ToDictionary(x => x.Name, x => x.Value);
39
40      return new InstanceDescriptor(problem.Name, InstanceDescriptor.GetClass(problem.Name), problem.Weights.Rows,
41        features.Keys.ToArray(), features.Values.Select(x => ((DoubleValue)x).Value).ToArray());
42    }
43  }
44
45
46  public class RandomWalkExplorer : InstanceExplorer {
47    public int Iterations { get; set; }
48
49    public override string Name { get { return "Random-Walk Explorer"; } }
50    public override int Effort { get { return Iterations; } }
51
52    public RandomWalkExplorer() {
53
54    }
55
56    public override InstanceDescriptor Explore(QuadraticAssignmentProblem problem, int? seed = null) {
57      var walk = new RandomWalk() {
58        SeedParameter = { Value = { Value = seed ?? 0 } },
59        SetSeedRandomlyParameter = { Value = { Value = seed.HasValue } },
60        MaximumIterationsParameter = { Value = { Value = Iterations } },
61        RepetitionsParameter = { Value = { Value = 1 } }
62      };
63      walk.Problem = problem;
64      walk.Engine = new SequentialEngine();
65      walk.MutatorParameter.Value = walk.MutatorParameter.ValidValues.First(x => x is Swap2Manipulator);
66      var calculator = new RandomWalkCalculator(walk) { Problem = problem };
67      var features = calculator.Calculate().ToDictionary(x => x.Name, x => x.Value);
68     
69      return new InstanceDescriptor(problem.Name, InstanceDescriptor.GetClass(problem.Name), problem.Weights.Rows,
70        features.Keys.ToArray(), features.Values.Select(x => ((DoubleValue)x).Value).ToArray());
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.