#region License Information /* HeuristicLab * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.IntegerVectorEncoding; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.Orienteering { [Item("Orienteering Problem", "Represents a single objective Orienteering Problem.")] [Creatable("Problems")] [StorableClass] public class OrienteeringProblem : SingleObjectiveHeuristicOptimizationProblem, IStorableContent { public string Filename { get; set; } #region Parameter Properties public OptionalValueParameter CoordinatesParameter { get { return (OptionalValueParameter)Parameters["Coordinates"]; } } public OptionalValueParameter DistanceMatrixParameter { get { return (OptionalValueParameter)Parameters["DistanceMatrix"]; } } public ValueParameter UseDistanceMatrixParameter { get { return (ValueParameter)Parameters["UseDistanceMatrix"]; } } public ValueParameter StartingPointParameter { get { return (ValueParameter)Parameters["StartingPoint"]; } } public ValueParameter TerminusPointParameter { get { return (ValueParameter)Parameters["TerminusPoint"]; } } public ValueParameter MaximumDistanceParameter { get { return (ValueParameter)Parameters["MaximumDistance"]; } } public ValueParameter ScoresParameter { get { return (ValueParameter)Parameters["Scores"]; } } public ValueParameter FixedPenaltyParameter { get { return (ValueParameter)Parameters["FixedPenalty"]; } } public OptionalValueParameter BestKnownSolutionParameter { get { return (OptionalValueParameter)Parameters["BestKnownSolution"]; } } #endregion #region Properties public DoubleMatrix Coordinates { get { return CoordinatesParameter.Value; } set { CoordinatesParameter.Value = value; } } public DistanceMatrix DistanceMatrix { get { return DistanceMatrixParameter.Value; } set { DistanceMatrixParameter.Value = value; } } public BoolValue UseDistanceMatrix { get { return UseDistanceMatrixParameter.Value; } set { UseDistanceMatrixParameter.Value = value; } } public DoubleValue MaximumDistance { get { return MaximumDistanceParameter.Value; } set { MaximumDistanceParameter.Value = value; } } public DoubleArray Scores { get { return ScoresParameter.Value; } set { ScoresParameter.Value = value; } } public IntegerVector BestKnownSolution { get { return BestKnownSolutionParameter.Value; } set { BestKnownSolutionParameter.Value = value; } } #endregion [StorableConstructor] private OrienteeringProblem(bool deserializing) : base(deserializing) { } private OrienteeringProblem(OrienteeringProblem original, Cloner cloner) : base(original, cloner) { RegisterEventHandlers(); } public override IDeepCloneable Clone(Cloner cloner) { return new OrienteeringProblem(this, cloner); } public OrienteeringProblem() : base(new OrienteeringEvaluator(), new UniformRandomIntegerVectorCreator()) { Parameters.Add(new OptionalValueParameter("Coordinates", "The x- and y-Coordinates of the points.")); Parameters.Add(new OptionalValueParameter("DistanceMatrix", "The matrix which contains the distances between the points.")); Parameters.Add(new ValueParameter("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))); Parameters.Add(new ValueParameter("StartingPoint", "Index of the starting point.", new IntValue(0))); Parameters.Add(new ValueParameter("TerminusPoint", "Index of the ending point.", new IntValue(0))); Parameters.Add(new ValueParameter("MaximumDistance", "The maximum distance constraint for a Orienteering solution.")); Parameters.Add(new ValueParameter("Scores", "The scores of the points.", new DoubleArray())); Parameters.Add(new ValueParameter("FixedPenalty", "The penalty for each visited vertex.")); Parameters.Add(new OptionalValueParameter("BestKnownSolution", "The best known solution of this Orienteering instance.")); Maximization.Value = true; MaximizationParameter.Hidden = true; SolutionCreator.IntegerVectorParameter.ActualName = "OrienteeringSolution"; InitializeRandomOrienteeringInstance(); ParameterizeSolutionCreator(); ParameterizeEvaluator(); InitializeOperators(); RegisterEventHandlers(); } #region Events protected override void OnSolutionCreatorChanged() { base.OnSolutionCreatorChanged(); SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged); ParameterizeSolutionCreator(); ParameterizeEvaluator(); ParameterizeAnalyzer(); ParameterizeOperators(); } protected override void OnEvaluatorChanged() { base.OnEvaluatorChanged(); ParameterizeEvaluator(); ParameterizeAnalyzer(); } private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) { ParameterizeEvaluator(); ParameterizeAnalyzer(); ParameterizeOperators(); } #endregion #region Helpers [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { RegisterEventHandlers(); } private void RegisterEventHandlers() { SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged); // TODO } private void ParameterizeSolutionCreator() { if (SolutionCreator.LengthParameter.Value == null || SolutionCreator.LengthParameter.Value.Value != Scores.Length) { SolutionCreator.LengthParameter.Value = new IntValue(Scores.Length); } } private void ParameterizeEvaluator() { if (Evaluator is OrienteeringEvaluator) { var orienteeringEvaluator = (OrienteeringEvaluator)Evaluator; // TODO } } private void ParameterizeAnalyzer() { // TODO } private void InitializeOperators() { // TODO } private void ParameterizeOperators() { // TODO } #endregion private void InitializeRandomOrienteeringInstance() { // TODO } } }