Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/GQAPPathRelinking.cs @ 7423

Last change on this file since 7423 was 7423, checked in by abeham, 12 years ago

#1614

  • worked on path relinking operator
File size: 8.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.IntegerVectorEncoding;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Operators {
33  [Item("GQAPPathRelinking", "Operator that performs path relinking between two solutions. It is described in Mateus, G., Resende, M., and Silva, R. 2011. GRASP with path-relinking for the generalized quadratic assignment problem. Journal of Heuristics 17, Springer Netherlands, pp. 527-565.")]
34  [StorableClass]
35  public class GQAPPathRelinking : GQAPCrossover, IQualitiesAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator,
36  IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, ITransportationCostsAwareGQAPOperator,
37  IOverbookedCapacityPenaltyAwareGQAPOperator {
38
39    public ILookupParameter<BoolValue> MaximizationParameter {
40      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
41    }
42    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
43      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
44    }
45    public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter {
46      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
47    }
48    public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter {
49      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
50    }
51    public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter {
52      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
53    }
54    public ILookupParameter<DoubleArray> DemandsParameter {
55      get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
56    }
57    public ILookupParameter<DoubleArray> CapacitiesParameter {
58      get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
59    }
60    public ILookupParameter<DoubleMatrix> WeightsParameter {
61      get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
62    }
63    public ILookupParameter<DoubleMatrix> DistancesParameter {
64      get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
65    }
66    public ILookupParameter<DoubleMatrix> InstallationCostsParameter {
67      get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
68    }
69    public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
70      get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
71    }
72    public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {
73      get { return (IValueLookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; }
74    }
75
76    [StorableConstructor]
77    protected GQAPPathRelinking(bool deserializing) : base(deserializing) { }
78    protected GQAPPathRelinking(GQAPPathRelinking original, Cloner cloner) : base(original, cloner) { }
79    public GQAPPathRelinking()
80      : base() {
81      Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
82      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
83      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
84      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
85      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
86      Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
87      Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
88      Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
89      Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
90      Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
91      Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
92      Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));
93    }
94
95    public override IDeepCloneable Clone(Cloner cloner) {
96      return new GQAPPathRelinking(this, cloner);
97    }
98
99    public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents, ItemArray<DoubleValue> qualities, DoubleArray demands,
100      DoubleArray capacities, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, DoubleValue transportationCosts,
101      DoubleValue overbookedCapacityPenalty) {
102      if (random == null) throw new ArgumentNullException("random", "No IRandom provider is given.");
103      if (parents == null || !parents.Any()) throw new ArgumentException("No parents given for path relinking.", "parents");
104      if (parents.Length != 2) throw new ArgumentException(String.Format("Two parents were expected for path relinking, but {0} was/were given.", parents.Length.ToString()), "parents");
105      if (parents[0].Length != parents[1].Length) throw new ArgumentException("The length of the parents is not equal.", "parents");
106      if (qualities == null || qualities.Length == 0) throw new ArgumentException("The qualities are not given.", "qualities");
107      if (qualities.Length != parents.Length) throw new ArgumentException(String.Format("There are a different number of parents ({0}) than quality values ({1})", parents.Length.ToString(), qualities.Length.ToString()));
108
109      var source = parents[0];
110      var target = parents[1];
111
112      var pi_prime = (IntegerVector)source.Clone();
113      var fix = new HashSet<int>();
114      var nonFix = new HashSet<int>(Enumerable.Range(0, demands.Length));
115      var phi = GQAPIntegerVectorProximityCalculator.GetDifference(pi_prime, target);
116
117      while (phi.Any()) {
118        var B = new HashSet<IntegerVector>();
119        foreach (var v in phi) {
120          pi_prime[v] = target[v];
121          var pi2 = makeFeasible(pi_prime, v);
122
123          double flowDistanceQuality, installationQuality, overbookedCapacity;
124          GQAPEvaluator.Evaluate(pi2, weights, distances, installationCosts, demands, capacities,
125            out flowDistanceQuality, out installationQuality, out overbookedCapacity);
126        }
127      }
128
129      return pi_prime;
130    }
131
132    protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) {
133      return Apply(random, parents, QualityParameter.ActualValue, DemandsParameter.ActualValue,
134        CapacitiesParameter.ActualValue, WeightsParameter.ActualValue, DistancesParameter.ActualValue,
135        InstallationCostsParameter.ActualValue, TransportationCostsParameter.ActualValue,
136        OverbookedCapacityPenaltyParameter.ActualValue);
137    }
138
139    private static IntegerVector makeFeasible(IntegerVector assignment, int equipment) {
140      // TODO: implement
141      return assignment;
142    }
143  }
144}
Note: See TracBrowser for help on using the repository browser.