Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8346


Ignore:
Timestamp:
07/27/12 15:21:20 (12 years ago)
Author:
jkarder
Message:

#1331:

  • added operators for the VehicleRouting problem
  • minor code improvements
Location:
trunk/sources
Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r8332 r8346  
    316316    #region Helpers
    317317    private void Initialize() {
    318       if (Problem != null) {
     318      if (Problem != null)
    319319        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    320       }
    321       ParameterizeMainLoop();
    322320    }
    323321    private void UpdateAnalyzers() {
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinCrossover.cs

    r8053 r8346  
    6363    }
    6464
    65     protected Tour FindRoute(PotvinEncoding solution, int city) {
     65    protected static Tour FindRoute(PotvinEncoding solution, int city) {
    6666      Tour found = null;
    6767
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs

    r8053 r8346  
    2424using HeuristicLab.Encodings.PermutationEncoding;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2627
    2728namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    4344    }
    4445
    45     protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
    46       bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
    47 
     46    public static PotvinEncoding Apply(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2, IVRPProblemInstance problemInstance, bool allowInfeasible) {
    4847      PotvinEncoding child = parent2.Clone() as PotvinEncoding;
    4948
     
    7574            child.Unrouted.Add(city);
    7675
    77         if (Repair(random, child, replacing, ProblemInstance, allowInfeasible) || allowInfeasible)
     76        if (Repair(random, child, replacing, problemInstance, allowInfeasible) || allowInfeasible)
    7877          return child;
    7978        else {
     
    8786      }
    8887    }
     88
     89    protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
     90      return Apply(random, parent1, parent2, ProblemInstance, AllowInfeasibleSolutions.Value.Value);
     91    }
    8992  }
    9093}
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs

    r8053 r8346  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2526
    2627namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    4243    }
    4344
    44     protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
    45       bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
    46 
     45    public static PotvinEncoding Apply(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2, IVRPProblemInstance problemInstance, bool allowInfeasible) {
    4746      PotvinEncoding child = parent1.Clone() as PotvinEncoding;
    4847      Tour newTour = new Tour();
    4948
    50       int cities = ProblemInstance.Cities.Value;
     49      int cities = problemInstance.Cities.Value;
    5150
    5251      if (cities > 0) {
     
    7776            child.Unrouted.Add(city);
    7877
    79         if (Repair(random, child, newTour, ProblemInstance, allowInfeasible) || allowInfeasible) {
     78        if (Repair(random, child, newTour, problemInstance, allowInfeasible) || allowInfeasible) {
    8079          return child;
    8180        } else {
     
    8988      }
    9089    }
     90
     91    protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
     92      return Apply(random, parent1, parent2, ProblemInstance, AllowInfeasibleSolutions.Value.Value);
     93    }
    9194  }
    9295}
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj

    r7923 r8346  
    139139    <Compile Include="Encodings\Potvin\Moves\TwoOptStar\PotvinTwoOptStarMultiMoveGenerator.cs" />
    140140    <Compile Include="Encodings\Potvin\Moves\TwoOptStar\PotvinTwoOptStarSingleMoveGenerator.cs" />
     141    <Compile Include="Improver\VRPImprovementOperator.cs" />
    141142    <Compile Include="Interfaces\IVRPLocalSearchManipulator.cs" />
    142143    <Compile Include="Interpreters\MDCVRPTWInterpreter.cs" />
     
    145146    <Compile Include="Interpreters\CVRPInterpreter.cs" />
    146147    <Compile Include="Interpreters\IVRPDataInterpreter.cs" />
     148    <Compile Include="PathRelinkers\VRPPathRelinker.cs" />
    147149    <Compile Include="Properties\AssemblyInfo.cs" />
    148150    <Compile Include="Encodings\Alba\AlbaEncoding.cs" />
     
    336338    <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPPDTW\CVRPPDTWEvaluator.cs" />
    337339    <Compile Include="ProblemInstances\SingleDepotVRP\SingleDepotVRPEvaluator.cs" />
     340    <Compile Include="SimilarityCalculators\VRPSimilarityCalculator.cs" />
    338341    <Compile Include="SolutionParser.cs" />
    339342    <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedProblemInstance.cs" />
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r8121 r8346  
    178178
    179179    private void AttachProblemInstanceEventHandlers() {
    180       var solutionCreatorParameter = SolutionCreatorParameter as ConstrainedValueParameter<IVRPCreator>;
    181       solutionCreatorParameter.ValidValues.Clear();
    182 
    183180      if (ProblemInstance != null) {
    184181        EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator;
    185         IVRPCreator defaultCreator = null;
    186         foreach (IVRPCreator creator in Operators.Where(o => o is IVRPCreator)) {
    187           solutionCreatorParameter.ValidValues.Add(creator);
    188           if (creator is Encodings.Alba.RandomCreator)
    189             defaultCreator = creator;
    190         }
    191         if (defaultCreator != null)
    192           solutionCreatorParameter.Value = defaultCreator;
    193 
    194182        ProblemInstance.EvaluationChanged += new EventHandler(ProblemInstance_EvaluationChanged);
    195183      }
     
    246234
    247235    private void InitializeOperators() {
     236      var solutionCreatorParameter = SolutionCreatorParameter as ConstrainedValueParameter<IVRPCreator>;
     237      solutionCreatorParameter.ValidValues.Clear();
     238
    248239      Operators.Clear();
    249240
     
    252243        ProblemInstance.Operators.Concat(
    253244          ApplicationManager.Manager.GetInstances<IGeneralVRPOperator>().Cast<IOperator>()).OrderBy(op => op.Name));
     245        Operators.Add(new VRPSimilarityCalculator());
     246
     247        IVRPCreator defaultCreator = null;
     248        foreach (IVRPCreator creator in Operators.Where(o => o is IVRPCreator)) {
     249          solutionCreatorParameter.ValidValues.Add(creator);
     250          if (creator is Encodings.Alba.RandomCreator)
     251            defaultCreator = creator;
     252        }
     253        if (defaultCreator != null)
     254          solutionCreatorParameter.Value = defaultCreator;
    254255      }
    255256
     
    263264        }
    264265      }
    265     }
     266      if (ProblemInstance != null) {
     267        foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) {
     268          op.SolutionParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
     269          op.SolutionParameter.Hidden = true;
     270        }
     271        foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) {
     272          op.ParentsParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
     273          op.ParentsParameter.Hidden = true;
     274        }
     275        foreach (VRPSimilarityCalculator op in Operators.OfType<VRPSimilarityCalculator>()) {
     276          op.SolutionVariableName = SolutionCreator.VRPToursParameter.ActualName;
     277          op.QualityVariableName = ProblemInstance.SolutionEvaluator.QualityParameter.ActualName;
     278          op.ProblemInstance = ProblemInstance;
     279        }
     280      }
     281    }
     282
    266283    #endregion
    267284
Note: See TracChangeset for help on using the changeset viewer.