#region License Information /* HeuristicLab * Copyright (C) 2002-2017 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.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.BinaryVectorEncoding; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.Optimization; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.Binary; using HeuristicLab.Problems.TravelingSalesman; namespace HeuristicLab.Networks.IntegratedOptimization.TravelingThief { [Item("Loot Profit Problem", "Represents a problem whose objective is to optimize a TTP loot for fixed TTP tour.")] [Creatable(CreatableAttribute.Categories.Problems, Priority = 999)] [StorableClass] public class LootProfitProblem : BinaryProblem { public override bool Maximization { get { return true; } } [Storable] public TravelingSalesmanProblem Tsp { get; set; } [Storable] public BinaryKnapsackProblem Ksp { get; set; } [Storable] public Permutation FixedTspSolution { get; set; } [Storable] public int[] Availability { get; set; } [Storable] public double RentingRatio { get; set; } [Storable] public double MinSpeed { get; set; } [Storable] public double MaxSpeed { get; set; } [Storable] public TtpUtils.DistanceType DistanceType { get; set; } [StorableConstructor] protected LootProfitProblem(bool deserializing) : base(deserializing) { } protected LootProfitProblem(LootProfitProblem original, Cloner cloner) : base(original, cloner) { Tsp = cloner.Clone(original.Tsp); Ksp = cloner.Clone(original.Ksp); FixedTspSolution = cloner.Clone(original.FixedTspSolution); Availability = original.Availability != null ? (int[])original.Availability.Clone() : null; RentingRatio = original.RentingRatio; MinSpeed = original.MinSpeed; MaxSpeed = original.MaxSpeed; DistanceType = original.DistanceType; } public LootProfitProblem() : base() { Encoding.Length = 5; } public override IDeepCloneable Clone(Cloner cloner) { return new LootProfitProblem(this, cloner); } public override double Evaluate(BinaryVector vector, IRandom random) { return TtpUtils.Evaluate(Tsp, FixedTspSolution.ToArray(), Ksp, vector.ToArray(), Availability, RentingRatio, MinSpeed, MaxSpeed, DistanceType); } public override IEnumerable GetNeighbors(Individual individual, IRandom random) { while (true) { var neighbor = individual.Copy(); SinglePositionBitflipManipulator.Apply(random, neighbor.BinaryVector()); yield return neighbor; } } } }