[11186] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[11187] | 25 | using HeuristicLab.Data;
|
---|
[11186] | 26 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
[11187] | 28 | using HeuristicLab.Parameters;
|
---|
[11186] | 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.Orienteering {
|
---|
| 32 |
|
---|
| 33 | [Item("Orienteering Problem", "Represents a single objective Orienteering Problem.")]
|
---|
| 34 | [Creatable("Problems")]
|
---|
| 35 | [StorableClass]
|
---|
| 36 | public class OrienteeringProblem
|
---|
| 37 | : SingleObjectiveHeuristicOptimizationProblem<IOrienteeringEvaluator, IIntegerVectorCreator>,
|
---|
| 38 | IStorableContent {
|
---|
| 39 |
|
---|
| 40 | public string Filename { get; set; }
|
---|
| 41 |
|
---|
[11187] | 42 | #region Parameter Properties
|
---|
| 43 | public OptionalValueParameter<DoubleMatrix> CoordinatesParameter {
|
---|
| 44 | get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
|
---|
| 45 | }
|
---|
| 46 | public OptionalValueParameter<DistanceMatrix> DistanceMatrixParameter {
|
---|
| 47 | get { return (OptionalValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
|
---|
| 48 | }
|
---|
| 49 | public ValueParameter<BoolValue> UseDistanceMatrixParameter {
|
---|
| 50 | get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public ValueParameter<IntValue> StartingPointParameter {
|
---|
| 54 | get { return (ValueParameter<IntValue>)Parameters["StartingPoint"]; }
|
---|
| 55 | }
|
---|
| 56 | public ValueParameter<IntValue> TerminusPointParameter {
|
---|
| 57 | get { return (ValueParameter<IntValue>)Parameters["TerminusPoint"]; }
|
---|
| 58 | }
|
---|
| 59 | public ValueParameter<DoubleValue> MaximumDistanceParameter {
|
---|
| 60 | get { return (ValueParameter<DoubleValue>)Parameters["MaximumDistance"]; }
|
---|
| 61 | }
|
---|
| 62 | public ValueParameter<DoubleArray> ScoresParameter {
|
---|
| 63 | get { return (ValueParameter<DoubleArray>)Parameters["Scores"]; }
|
---|
| 64 | }
|
---|
| 65 | public ValueParameter<DoubleValue> FixedPenaltyParameter {
|
---|
| 66 | get { return (ValueParameter<DoubleValue>)Parameters["FixedPenalty"]; }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public OptionalValueParameter<IntegerVector> BestKnownSolutionParameter {
|
---|
| 70 | get { return (OptionalValueParameter<IntegerVector>)Parameters["BestKnownSolution"]; }
|
---|
| 71 | }
|
---|
| 72 | #endregion
|
---|
| 73 |
|
---|
| 74 | #region Properties
|
---|
| 75 | public DoubleMatrix Coordinates {
|
---|
| 76 | get { return CoordinatesParameter.Value; }
|
---|
| 77 | set { CoordinatesParameter.Value = value; }
|
---|
| 78 | }
|
---|
| 79 | public DistanceMatrix DistanceMatrix {
|
---|
| 80 | get { return DistanceMatrixParameter.Value; }
|
---|
| 81 | set { DistanceMatrixParameter.Value = value; }
|
---|
| 82 | }
|
---|
| 83 | public BoolValue UseDistanceMatrix {
|
---|
| 84 | get { return UseDistanceMatrixParameter.Value; }
|
---|
| 85 | set { UseDistanceMatrixParameter.Value = value; }
|
---|
| 86 | }
|
---|
| 87 | public DoubleValue MaximumDistance {
|
---|
| 88 | get { return MaximumDistanceParameter.Value; }
|
---|
| 89 | set { MaximumDistanceParameter.Value = value; }
|
---|
| 90 | }
|
---|
| 91 | public DoubleArray Scores {
|
---|
| 92 | get { return ScoresParameter.Value; }
|
---|
| 93 | set { ScoresParameter.Value = value; }
|
---|
| 94 | }
|
---|
| 95 | public IntegerVector BestKnownSolution {
|
---|
| 96 | get { return BestKnownSolutionParameter.Value; }
|
---|
| 97 | set { BestKnownSolutionParameter.Value = value; }
|
---|
| 98 | }
|
---|
| 99 | #endregion
|
---|
| 100 |
|
---|
[11186] | 101 | [StorableConstructor]
|
---|
| 102 | private OrienteeringProblem(bool deserializing)
|
---|
| 103 | : base(deserializing) {
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | private OrienteeringProblem(OrienteeringProblem original, Cloner cloner)
|
---|
| 107 | : base(original, cloner) {
|
---|
| 108 | RegisterEventHandlers();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 112 | return new OrienteeringProblem(this, cloner);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | public OrienteeringProblem()
|
---|
| 117 | : base(new OrienteeringEvaluator(), new UniformRandomIntegerVectorCreator()) {
|
---|
[11187] | 118 | Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the points."));
|
---|
| 119 | Parameters.Add(new OptionalValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points."));
|
---|
| 120 | Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if the coordinates based evaluators should calculate the distance matrix from the coordinates and use it for evaluation similar to the distance matrix evaluator, otherwise false.", new BoolValue(true)));
|
---|
| 121 | Parameters.Add(new ValueParameter<IntValue>("StartingPoint", "Index of the starting point.", new IntValue(0)));
|
---|
| 122 | Parameters.Add(new ValueParameter<IntValue>("TerminusPoint", "Index of the ending point.", new IntValue(0)));
|
---|
| 123 | Parameters.Add(new ValueParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution."));
|
---|
| 124 | Parameters.Add(new ValueParameter<DoubleArray>("Scores", "The scores of the points.", new DoubleArray()));
|
---|
| 125 | Parameters.Add(new ValueParameter<DoubleValue>("FixedPenalty", "The penalty for each visited vertex."));
|
---|
| 126 | Parameters.Add(new OptionalValueParameter<IntegerVector>("BestKnownSolution", "The best known solution of this Orienteering instance."));
|
---|
[11186] | 127 |
|
---|
| 128 | Maximization.Value = true;
|
---|
| 129 | MaximizationParameter.Hidden = true;
|
---|
| 130 |
|
---|
| 131 | SolutionCreator.IntegerVectorParameter.ActualName = "OrienteeringSolution";
|
---|
| 132 |
|
---|
| 133 | InitializeRandomOrienteeringInstance();
|
---|
| 134 |
|
---|
| 135 | ParameterizeSolutionCreator();
|
---|
| 136 | ParameterizeEvaluator();
|
---|
| 137 |
|
---|
| 138 | InitializeOperators();
|
---|
| 139 | RegisterEventHandlers();
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[11187] | 142 | #region Events
|
---|
[11186] | 143 | protected override void OnSolutionCreatorChanged() {
|
---|
| 144 | base.OnSolutionCreatorChanged();
|
---|
| 145 | SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
|
---|
| 146 | ParameterizeSolutionCreator();
|
---|
| 147 | ParameterizeEvaluator();
|
---|
| 148 | ParameterizeAnalyzer();
|
---|
| 149 | ParameterizeOperators();
|
---|
| 150 | }
|
---|
| 151 | protected override void OnEvaluatorChanged() {
|
---|
| 152 | base.OnEvaluatorChanged();
|
---|
| 153 | ParameterizeEvaluator();
|
---|
| 154 | ParameterizeAnalyzer();
|
---|
| 155 | }
|
---|
| 156 | private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 157 | ParameterizeEvaluator();
|
---|
| 158 | ParameterizeAnalyzer();
|
---|
| 159 | ParameterizeOperators();
|
---|
| 160 | }
|
---|
| 161 | #endregion
|
---|
| 162 |
|
---|
| 163 | #region Helpers
|
---|
| 164 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 165 | private void AfterDeserialization() {
|
---|
| 166 | RegisterEventHandlers();
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | private void RegisterEventHandlers() {
|
---|
| 170 | SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
|
---|
[11187] | 171 | // TODO
|
---|
[11186] | 172 | }
|
---|
| 173 | private void ParameterizeSolutionCreator() {
|
---|
[11187] | 174 | if (SolutionCreator.LengthParameter.Value == null
|
---|
| 175 | || SolutionCreator.LengthParameter.Value.Value != Scores.Length) {
|
---|
| 176 | SolutionCreator.LengthParameter.Value = new IntValue(Scores.Length);
|
---|
| 177 | }
|
---|
[11186] | 178 | }
|
---|
| 179 | private void ParameterizeEvaluator() {
|
---|
| 180 | if (Evaluator is OrienteeringEvaluator) {
|
---|
| 181 | var orienteeringEvaluator = (OrienteeringEvaluator)Evaluator;
|
---|
| 182 | // TODO
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 | private void ParameterizeAnalyzer() {
|
---|
[11187] | 186 | // TODO
|
---|
[11186] | 187 | }
|
---|
| 188 | private void InitializeOperators() {
|
---|
| 189 | // TODO
|
---|
| 190 | }
|
---|
| 191 | private void ParameterizeOperators() {
|
---|
| 192 | // TODO
|
---|
| 193 | }
|
---|
| 194 | #endregion
|
---|
| 195 |
|
---|
| 196 | private void InitializeRandomOrienteeringInstance() {
|
---|
| 197 | // TODO
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 | } |
---|