#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; using System.Collections.Generic; using System.Drawing; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.PluginInfrastructure; namespace HeuristicLab.Problems.VehicleRouting { [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")] [Creatable("Problems")] [StorableClass] public sealed class VehicleRoutingProblem : ParameterizedNamedItem, ISingleObjectiveProblem { public override Image ItemImage { get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; } } #region ISingleObjectiveProblem Members public IParameter BestKnownQualityParameter { get { throw new NotImplementedException(); } } public ISingleObjectiveEvaluator Evaluator { get { throw new NotImplementedException(); } } #endregion #region IProblem Members public IParameter SolutionCreatorParameter { get { throw new NotImplementedException(); } } public ISolutionCreator SolutionCreator { get { throw new NotImplementedException(); } } public IParameter EvaluatorParameter { get { throw new NotImplementedException(); } } IEvaluator IProblem.Evaluator { get { throw new NotImplementedException(); } } public IEnumerable Operators { get { throw new NotImplementedException(); } } #endregion #region Parameter Properties public ValueParameter MaximizationParameter { get { return (ValueParameter)Parameters["Maximization"]; } } IParameter ISingleObjectiveProblem.MaximizationParameter { get { return MaximizationParameter; } } #endregion #region Properties #endregion [Storable] private List operators; [StorableConstructor] private VehicleRoutingProblem(bool deserializing) : base(deserializing) { } public VehicleRoutingProblem() : base() { Parameters.Add(new ValueParameter("Maximization", "Set to false as the Vehicle Routing Problem is a minimization problem.", new BoolValue(false))); InitializeRandomVRPInstance(); ParameterizeSolutionCreator(); ParameterizeEvaluator(); InitializeOperators(); AttachEventHandlers(); } public override IDeepCloneable Clone(Cloner cloner) { VehicleRoutingProblem clone = (VehicleRoutingProblem)base.Clone(cloner); clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList(); clone.AttachEventHandlers(); return clone; } #region Events public event EventHandler SolutionCreatorChanged; private void OnSolutionCreatorChanged() { EventHandler handler = SolutionCreatorChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler EvaluatorChanged; private void OnEvaluatorChanged() { EventHandler handler = EvaluatorChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler OperatorsChanged; private void OnOperatorsChanged() { EventHandler handler = OperatorsChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler Reset; private void OnReset() { EventHandler handler = Reset; if (handler != null) handler(this, EventArgs.Empty); } #endregion #region Helpers [StorableHook(HookType.AfterDeserialization)] private void AfterDeserializationHook() { AttachEventHandlers(); } private void AttachEventHandlers() { } private void InitializeOperators() { operators = new List(); ParameterizeAnalyzer(); //operators.AddRange(ApplicationManager.Manager.GetInstances().Cast().OrderBy(op => op.Name)); ParameterizeOperators(); UpdateMoveEvaluators(); InitializeMoveGenerators(); } private void InitializeMoveGenerators() { } private void UpdateMoveEvaluators() { ParameterizeOperators(); OnOperatorsChanged(); } private void ParameterizeSolutionCreator() { } private void ParameterizeEvaluator() { } private void ParameterizeAnalyzer() { } private void ParameterizeOperators() { } private void ClearDistanceMatrix() { } #endregion public void ImportFromSolomon(string solomonFileName) { SolomonParser parser = new SolomonParser(solomonFileName); parser.Parse(); this.Name = parser.ProblemName; OnReset(); } public void ImportFromTSPLib(string tspFileName) { TSPLIBParser parser = new TSPLIBParser(tspFileName); parser.Parse(); this.Name = parser.Name; int problemSize = parser.Demands.Length; if (parser.Depot != 1) throw new Exception("Invalid depot specification"); if (parser.WeightType != TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D) throw new Exception("Invalid weight type"); OnReset(); } public void ImportFromORLib(string orFileName) { ORLIBParser parser = new ORLIBParser(orFileName); parser.Parse(); this.Name = parser.Name; int problemSize = parser.Demands.Length; OnReset(); } private void InitializeRandomVRPInstance() { System.Random rand = new System.Random(); int cities = 100; } } }