#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 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.IO;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Optimization;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.RoutePlanning.Data.Osm;
using HeuristicLab.Problems.RoutePlanning.Interfaces;
namespace HeuristicLab.Problems.RoutePlanning {
[Item("Route Planning Problem", "Represents a Route Planning Problem.")]
[Creatable("Problems")]
[StorableClass]
public class RoutePlanningProblem : Problem {
private const string CoordinatesParameterName = "Coordinates";
private const string SourceParameterName = "Source";
private const string TargetParameterName = "Target";
public string Filename { get; set; }
IDataSource dataSource;
IGraph graph;
#region Parameter Properties
public OptionalValueParameter CoordinatesParameter {
get { return (OptionalValueParameter)Parameters[CoordinatesParameterName]; }
}
public ValueParameter SourceParameter {
get { return (ValueParameter)Parameters[SourceParameterName]; }
}
public ValueParameter TargetParameter {
get { return (ValueParameter)Parameters[TargetParameterName]; }
}
#endregion
#region Properties
public DoubleMatrix Coordinates {
get { return CoordinatesParameter.Value; }
set { CoordinatesParameter.Value = value; }
}
public IntValue Source {
get { return SourceParameter.Value; }
set { SourceParameter.Value = value; }
}
public IntValue Target {
get { return TargetParameter.Value; }
set { TargetParameter.Value = value; }
}
#endregion
#region Constructors
[StorableConstructor]
private RoutePlanningProblem(bool deserializing) : base(deserializing) { }
private RoutePlanningProblem(RoutePlanningProblem original, Cloner cloner)
: base(original, cloner) {
RegisterEventHandlers();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new RoutePlanningProblem(this, cloner);
}
public RoutePlanningProblem() {
Parameters.Add(new OptionalValueParameter(CoordinatesParameterName, "The x- and y-Coordinates of the cities."));
Parameters.Add(new ValueParameter(SourceParameterName, "Source Node."));
Parameters.Add(new ValueParameter(TargetParameterName, "Target Node."));
RegisterEventHandlers();
}
#endregion
private void RegisterEventHandlers() { }
public void LoadData(string file) {
FileInfo f = new FileInfo(file);
dataSource = new OsmDataSource(file);
graph = dataSource.GetRoutingGraph();
Name = f.Name;
OnReset();
}
}
}