Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VNS/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/VariableNeighborhoodSearch.cs @ 5622

Last change on this file since 5622 was 5622, checked in by svonolfe, 12 years ago

Worked on VNS (#1425)

File size: 5.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using HeuristicLab.Common;
8using HeuristicLab.Optimization;
9using HeuristicLab.Parameters;
10using HeuristicLab.Data;
11using HeuristicLab.Analysis;
12using HeuristicLab.Random;
13using HeuristicLab.Optimization.Operators;
14using HeuristicLab.Operators;
15using HeuristicLab.Algorithms.LocalSearch;
16
17namespace HeuristicLab.Algorithms.VariableNeighborhoodSearch {
18  [Item("Variable Neighborhood Search", "A variable neighborhood search algorithm.")]
19  [Creatable("Algorithms")]
20  [StorableClass]
21  public sealed class VariableNeighborhoodSearch : EngineAlgorithm, IStorableContent {
22    public string Filename { get; set; }
23
24    #region Problem Properties
25    public override Type ProblemType {
26      get { return typeof(ISingleObjectiveProblem); }
27    }
28    public new ISingleObjectiveProblem Problem {
29      get { return (ISingleObjectiveProblem)base.Problem; }
30      set { base.Problem = value; }
31    }
32    #endregion
33
34    #region Parameter Properties
35    private ValueParameter<IntValue> SeedParameter {
36      get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
37    }
38    private ValueParameter<BoolValue> SetSeedRandomlyParameter {
39      get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
40    }
41    public /*Constrained*/ValueParameter<ISingleObjectiveEvaluator> EvaluatorParameter {
42      get { return (/*Constrained*/ValueParameter<ISingleObjectiveEvaluator>)Parameters["Evaluator"]; }
43    }
44    private ValueParameter<ILocalImprovement> LocalImprovementParameter {
45      get { return (ValueParameter<ILocalImprovement>)Parameters["LocalImprovement"]; }
46    }
47    private ValueParameter<ShakingOperator> ShakingParameter {
48      get { return (ValueParameter<ShakingOperator>)Parameters["Shaking"]; }
49    }
50    private ValueParameter<IntValue> MaximumIterationsParameter {
51      get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
52    }
53    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
54      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
55    }
56    #endregion
57
58    #region Properties
59    private RandomCreator RandomCreator {
60      get { return (RandomCreator)OperatorGraph.InitialOperator; }
61    }
62    #endregion
63
64    [StorableConstructor]
65    private VariableNeighborhoodSearch(bool deserializing) : base(deserializing) { }
66    [StorableHook(HookType.AfterDeserialization)]
67    private void AfterDeserialization() {
68
69    }
70    private VariableNeighborhoodSearch(VariableNeighborhoodSearch original, Cloner cloner)
71      : base(original, cloner) {
72
73    }
74    public override IDeepCloneable Clone(Cloner cloner) {
75      return new VariableNeighborhoodSearch(this, cloner);
76    }
77    public VariableNeighborhoodSearch()
78      : base() {
79      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
80      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
81      Parameters.Add(new /*Constrained*/ValueParameter<ISingleObjectiveEvaluator>("Evaluator", "The operator used to evaluate the solutions."));
82      Parameters.Add(new ValueParameter<ILocalImprovement>("LocalImprovement", "The local improvement operation", new LocalSearchImprovement()));
83      Parameters.Add(new ValueParameter<ShakingOperator>("Shaking", "The shaking operation", new ShakingOperator()));
84      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
85      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves.", new MultiAnalyzer()));
86
87      RandomCreator randomCreator = new RandomCreator();
88      SolutionsCreator solutionsCreator = new SolutionsCreator();
89      VariableCreator variableCreator = new VariableCreator();
90      ResultsCollector resultsCollector = new ResultsCollector();
91      VariableNeighborhoodSearchMainLoop mainLoop = new VariableNeighborhoodSearchMainLoop();
92      OperatorGraph.InitialOperator = randomCreator;
93
94      randomCreator.RandomParameter.ActualName = "Random";
95      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
96      randomCreator.SeedParameter.Value = null;
97      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
98      randomCreator.SetSeedRandomlyParameter.Value = null;
99      randomCreator.Successor = solutionsCreator;
100
101      solutionsCreator.NumberOfSolutions = new IntValue(1);
102      solutionsCreator.Successor = variableCreator;
103
104      variableCreator.Name = "Initialize Evaluated Solutions";
105      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue()));
106      variableCreator.Successor = resultsCollector;
107
108      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
109      resultsCollector.ResultsParameter.ActualName = "Results";
110      resultsCollector.Successor = mainLoop;
111
112      mainLoop.LocalImprovementParameter.ActualName = LocalImprovementParameter.Name;
113      mainLoop.ShakingParameter.ActualName = ShakingParameter.Name;
114      mainLoop.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
115      mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
116      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
117      mainLoop.ResultsParameter.ActualName = "Results";
118      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
119      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
120
121      /*Initialize();*/
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.