Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15504


Ignore:
Timestamp:
12/10/17 22:11:10 (6 years ago)
Author:
abeham
Message:

#1614: refactored code

  • change problem to derive from basic problem
  • using a combined instance class instead of individual parameters
Location:
branches/GeneralizedQAP
Files:
4 added
17 deleted
44 edited
18 moved

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Algorithms.GRASP/3.3/Plugin.cs.frame

    r15490 r15504  
    3535  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3636  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    37   [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3")]
    3837  [PluginDependency("HeuristicLab.Random", "3.3")]
    3938  [PluginDependency("HeuristicLab.Selection", "3.3")]
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentArchiveView.Designer.cs

    r7438 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentArchiveView.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    8585          if (Content == null) return;
    8686          foreach (var solution in Content.Solutions) {
    87             if (solution.OverbookedCapacity.Value <= 0.0) {
    88               paretoFrontChart.Series[0].Points.AddXY(solution.FlowDistanceQuality.Value, solution.InstallationQuality.Value);
     87            if (solution.Evaluation.ExcessDemand <= 0.0) {
     88              paretoFrontChart.Series[0].Points.AddXY(solution.Evaluation.FlowCosts, solution.Evaluation.InstallationCosts);
    8989              paretoFrontChart.Series[0].Points.Last().Tag = solution;
    9090            }
     
    101101      if (h.ChartElementType == ChartElementType.DataPoint) {
    102102        var solution = (GQAPSolution)((DataPoint)h.Object).Tag;
    103         var assignment = new GQAPAssignment(solution.Assignment, solution.Quality, solution.FlowDistanceQuality, solution.InstallationQuality, solution.OverbookedCapacity, Content.EquipmentNames, Content.LocationNames, Content.Distances, Content.Weights, Content.InstallationCosts, Content.Demands, Content.Capacities, Content.TransportationCosts, Content.ExpectedRandomQuality, Content.Evaluator);
     103        var assignment = new GQAPAssignment(solution.Assignment, Content.ProblemInstance, solution.Evaluation);
    104104
    105105        var view = MainFormManager.MainForm.ShowContent(assignment);
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.Designer.cs

    r7471 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2828using HeuristicLab.Common.Resources;
    2929using HeuristicLab.Core.Views;
    30 using HeuristicLab.Data;
    3130using HeuristicLab.Encodings.IntegerVectorEncoding;
    3231using HeuristicLab.MainForm;
     
    131130          qualityLabel.Text = "-";
    132131        } else {
    133           qualityLabel.Text = Content.Quality.ToString();
     132          qualityLabel.Text = Content.ProblemInstance.ToSingleObjective(Content.Evaluation).ToString();
    134133        }
    135134      }
     
    139138      if (InvokeRequired) Invoke((Action)UpdateFlowDistanceQuality);
    140139      else {
    141         if (Content == null || Content.FlowDistanceQuality == null) {
     140        if (Content == null || Content.Evaluation == null) {
    142141          flowDistanceQualityLabel.Text = "-";
    143142        } else {
    144           flowDistanceQualityLabel.Text = Content.FlowDistanceQuality.ToString();
     143          flowDistanceQualityLabel.Text = Content.Evaluation.FlowCosts.ToString();
    145144        }
    146145      }
     
    150149      if (InvokeRequired) Invoke((Action)UpdateInstallationQuality);
    151150      else {
    152         if (Content == null || Content.InstallationQuality == null) {
     151        if (Content == null || Content.Evaluation == null) {
    153152          installationQualityLabel.Text = "-";
    154153        } else {
    155           installationQualityLabel.Text = Content.InstallationQuality.ToString();
     154          installationQualityLabel.Text = Content.Evaluation.InstallationCosts.ToString();
    156155        }
    157156      }
     
    161160      if (InvokeRequired) Invoke((Action)UpdateOverbookedCapacity);
    162161      else {
    163         if (Content == null || Content.OverbookedCapacity == null) {
     162        if (Content == null || Content.Evaluation == null) {
    164163          overbookedCapacityLabel.Text = "-";
    165164        } else {
    166           overbookedCapacityLabel.Text = Content.OverbookedCapacity.ToString();
     165          overbookedCapacityLabel.Text = Content.Evaluation.ExcessDemand.ToString();
    167166        }
    168167      }
     
    179178            if (!locationNodes.ContainsKey(assignment[i])) {
    180179              string locationName = assignment[i].ToString();
    181               if (Content.LocationNames != null && Content.LocationNames.Length > assignment[i])
    182                 locationName = Content.LocationNames[assignment[i]];
     180              if (Content.ProblemInstance.LocationNames != null && Content.ProblemInstance.LocationNames.Length > assignment[i])
     181                locationName = Content.ProblemInstance.LocationNames[assignment[i]];
    183182              locationNodes.Add(assignment[i], new LocationNode(assignment[i], locationName));
    184183            }
    185184            string equipmentName = i.ToString();
    186             if (Content.EquipmentNames != null && Content.EquipmentNames.Length > i)
    187               equipmentName = Content.EquipmentNames[i];
     185            if (Content.ProblemInstance.EquipmentNames != null && Content.ProblemInstance.EquipmentNames.Length > i)
     186              equipmentName = Content.ProblemInstance.EquipmentNames[i];
    188187            locationNodes[assignment[i]].Nodes.Add(new EquipmentNode(i, equipmentName));
    189188          }
     
    205204      foreach (var node in GetAllSubNodes(assignmentTreeView.Nodes).OfType<EquipmentNode>()) {
    206205        int location = Content.Assignment[node.Equipment];
    207         installationCosts[node] = Content.InstallationCosts[node.Equipment, location];
     206        installationCosts[node] = Content.ProblemInstance.InstallationCosts[node.Equipment, location];
    208207      }
    209208      double max = installationCosts.Values.Max();
     
    224223      int equipment = selectedNode.Equipment;
    225224      double rowSum = 0, colSum = 0;
    226       for (int i = 0; i < Content.Weights.Columns; i++)
    227         if (i != equipment) rowSum += Content.Weights[equipment, i];
    228       for (int i = 0; i < Content.Weights.Rows; i++)
    229         if (i != equipment) colSum += Content.Weights[i, equipment];
     225      for (int i = 0; i < Content.ProblemInstance.Weights.Columns; i++)
     226        if (i != equipment) rowSum += Content.ProblemInstance.Weights[equipment, i];
     227      for (int i = 0; i < Content.ProblemInstance.Weights.Rows; i++)
     228        if (i != equipment) colSum += Content.ProblemInstance.Weights[i, equipment];
    230229
    231230      var otherEquipments = GetAllSubNodes(assignmentTreeView.Nodes)
     
    240239          other.ForeColor = assignmentTreeView.ForeColor;
    241240        } else {
    242           double rowInvProportion = rowSum == 0 ? 1.0 : (rowSum - Content.Weights[equipment, other.Equipment]) / rowSum;
    243           double colInvProportion = colSum == 0 ? 1.0 : (colSum - Content.Weights[other.Equipment, equipment]) / colSum;
     241          double rowInvProportion = rowSum == 0 ? 1.0 : (rowSum - Content.ProblemInstance.Weights[equipment, other.Equipment]) / rowSum;
     242          double colInvProportion = colSum == 0 ? 1.0 : (colSum - Content.ProblemInstance.Weights[other.Equipment, equipment]) / colSum;
    244243          int colorComponent = (int)(255 * Math.Pow(Math.Min(rowInvProportion, colInvProportion), 2));
    245244          other.BackColor = Color.FromArgb(colorComponent, 255, colorComponent);
     
    258257        rowSums[e] = 0;
    259258        colSums[e] = 0;
    260         for (int i = 0; i < Content.Weights.Columns; i++) {
    261           if (!equipments.Contains(i)) rowSums[e] += Content.Weights[e, i];
    262           if (!equipments.Contains(i)) colSums[e] += Content.Weights[i, e];
     259        for (int i = 0; i < Content.ProblemInstance.Weights.Columns; i++) {
     260          if (!equipments.Contains(i)) rowSums[e] += Content.ProblemInstance.Weights[e, i];
     261          if (!equipments.Contains(i)) colSums[e] += Content.ProblemInstance.Weights[i, e];
    263262        }
    264263      }
     
    272271          other.ForeColor = assignmentTreeView.ForeColor;
    273272        } else {
    274           double rowInvProportion = relevantEquipments.Min(x => rowSums[x] == 0 ? 1.0 : (rowSums[x] - Content.Weights[x, other.Equipment]) / rowSums[x]);
    275           double colInvProportion = relevantEquipments.Min(x => colSums[x] == 0 ? 1.0 : (colSums[x] - Content.Weights[other.Equipment, x]) / colSums[x]);
     273          double rowInvProportion = relevantEquipments.Min(x => rowSums[x] == 0 ? 1.0 : (rowSums[x] - Content.ProblemInstance.Weights[x, other.Equipment]) / rowSums[x]);
     274          double colInvProportion = relevantEquipments.Min(x => colSums[x] == 0 ? 1.0 : (colSums[x] - Content.ProblemInstance.Weights[other.Equipment, x]) / colSums[x]);
    276275          int colorComponent = (int)(255 * Math.Pow(Math.Min(rowInvProportion, colInvProportion), 2));
    277276          other.BackColor = Color.FromArgb(colorComponent, 255, colorComponent);
     
    314313
    315314    private void recalculateButton_Click(object sender, EventArgs e) {
    316       double fdq, iq, oc;
    317       Content.Evaluator.Evaluate(Content.Assignment, Content.Weights,
    318         Content.Distances, Content.InstallationCosts, Content.Demands,
    319         Content.Capacities, out fdq, out iq, out oc);
    320       Content.FlowDistanceQuality = new DoubleValue(fdq);
    321       Content.InstallationQuality = new DoubleValue(iq);
    322       Content.OverbookedCapacity = new DoubleValue(oc);
    323       Content.Quality = new DoubleValue(
    324         Content.Evaluator.GetFitness(fdq, iq, oc,
    325         Content.TransportationCosts.Value, Content.ExpectedRandomQuality.Value));
     315      Content.Evaluation = Content.ProblemInstance.Evaluate(Content.Assignment);
    326316    }
    327317  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/Properties/AssemblyInfo.cs.frame

    r7345 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3131[assembly: AssemblyCompany("HEAL")]
    3232[assembly: AssemblyProduct("HeuristicLab")]
    33 [assembly: AssemblyCopyright("(c) 2002-2011 HEAL")]
     33[assembly: AssemblyCopyright("(c) 2002-2017 HEAL")]
    3434[assembly: AssemblyTrademark("")]
    3535[assembly: AssemblyCulture("")]
     
    5454// [assembly: AssemblyVersion("1.0.*")]
    5555[assembly: AssemblyVersion("3.3.0.0")]
    56 [assembly: AssemblyFileVersion("3.3.6.$WCREV$")]
     56[assembly: AssemblyFileVersion("3.3.14.$WCREV$")]
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluation/GQAPNMoveEvaluator.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using System;
     23using System.Linq;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
     
    2527using HeuristicLab.Encodings.IntegerVectorEncoding;
    2628using HeuristicLab.Operators;
    27 using HeuristicLab.Optimization;
    2829using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3233  [Item("N-Move Evaluator", "Evaluates an N-Move.")]
    3334  [StorableClass]
    34   public class GQAPNMoveEvaluator : SingleSuccessorOperator, IGQAPNMoveEvaluator, IAssignmentAwareGQAPOperator,
    35   IQualityAwareGQAPOperator, ITransportationCostsAwareGQAPOperator,
    36   IExpectedRandomQualityAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator,
    37   IInstallationCostsAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator,
    38   IEvaluatorAwareGQAPOperator {
     35  public class GQAPNMoveEvaluator : SingleSuccessorOperator, IGQAPNMoveEvaluator,
     36    IQualityAwareGQAPOperator, IProblemInstanceAwareGQAPOperator {
    3937
    4038    #region Parameter Descriptions
    4139    public static readonly string MoveQualityDescription = "The quality of the move if it would be applied.";
    42     public static readonly string MoveFlowDistanceQualityDescription = "The quality of the move regarding the flow-distance criteria.";
    43     public static readonly string MoveInstallationQualityDescription = "The quality of the move regarding the installation costs.";
    44     public static readonly string MoveOverbookedCapacityDescription = "The sum of the overbooked capacities of the move relative to the capacity of each location.";
     40    public static readonly string MoveEvaluationDescription = "The results of evaluating the move.";
    4541    #endregion
    4642
    4743    #region Parameter Properties
    48     ILookupParameter<BoolValue> IQualityAwareGQAPOperator.MaximizationParameter {
    49       get { return MaximizationParameter; }
    50     }
    51     ILookupParameter<BoolValue> IGQAPMoveEvaluator.MaximizationParameter {
    52       get { return MaximizationParameter; }
    53     }
    54     public ILookupParameter<BoolValue> MaximizationParameter {
    55       get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    56     }
    5744    public ILookupParameter<DoubleValue> MoveQualityParameter {
    5845      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    5946    }
    60     public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter {
    61       get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; }
    62     }
    63     public ILookupParameter<DoubleValue> MoveInstallationQualityParameter {
    64       get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; }
    65     }
    66     public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter {
    67       get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; }
     47    public ILookupParameter<Evaluation> MoveEvaluationParameter {
     48      get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; }
    6849    }
    6950    public ILookupParameter<NMove> MoveParameter {
     
    7354      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
    7455    }
    75     ILookupParameter<DoubleValue> ISingleObjectiveMoveEvaluator.QualityParameter {
    76       get { return QualityParameter; }
    77     }
    78     ILookupParameter<DoubleValue> IQualityAwareGQAPOperator.QualityParameter {
    79       get { return QualityParameter; }
    80     }
    8156    public ILookupParameter<DoubleValue> QualityParameter {
    8257      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    8358    }
    84     public ILookupParameter<DoubleValue> FlowDistanceQualityParameter {
    85       get { return (ILookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
     59    public ILookupParameter<Evaluation> EvaluationParameter {
     60      get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; }
    8661    }
    87     public ILookupParameter<DoubleValue> InstallationQualityParameter {
    88       get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
    89     }
    90     public ILookupParameter<DoubleValue> OverbookedCapacityParameter {
    91       get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
    92     }
    93     public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
    94       get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
    95     }
    96     public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter {
    97       get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }
    98     }
    99     public ILookupParameter<DoubleMatrix> WeightsParameter {
    100       get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
    101     }
    102     public ILookupParameter<DoubleMatrix> DistancesParameter {
    103       get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
    104     }
    105     public ILookupParameter<DoubleMatrix> InstallationCostsParameter {
    106       get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
    107     }
    108     public ILookupParameter<DoubleArray> DemandsParameter {
    109       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
    110     }
    111     public ILookupParameter<DoubleArray> CapacitiesParameter {
    112       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    113     }
    114     public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
    115       get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
     62    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     63      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
    11664    }
    11765    #endregion
     
    12472      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
    12573      Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
    126       Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
    127       Parameters.Add(new LookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
    128       Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
    129       Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
    130       Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
     74      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
     75      Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
    13176      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", MoveQualityDescription));
    132       Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", MoveFlowDistanceQualityDescription));
    133       Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", MoveInstallationQualityDescription));
    134       Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", MoveOverbookedCapacityDescription));
    135       Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription));
    136       Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
    137       Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
    138       Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
    139       Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
    140       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    141       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    142       Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));
     77      Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", MoveEvaluationDescription));
     78      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
    14379    }
    14480
     
    14783    }
    14884
    149     public static double Evaluate(NMove move, IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts,
    150       DoubleArray demands, DoubleArray capacities, double transportationCosts, double expectedRandomQuality, IGQAPEvaluator evaluator) {
    151       double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity;
    152       Evaluate(move, assignment, weights, distances, installationCosts, demands, capacities, evaluator,
    153         out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity);
    154       return evaluator.GetFitness(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity,
    155         transportationCosts, expectedRandomQuality);
    156     }
    157 
    158     public static void Evaluate(NMove move, IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts,
    159       DoubleArray demands, DoubleArray capacities, IGQAPEvaluator evaluator, out double moveFlowDistanceQuality, out double moveInstallationQuality, out double moveOverbookedCapacity) {
    160       moveFlowDistanceQuality = moveInstallationQuality = moveOverbookedCapacity = 0.0;
     85    public static Evaluation Evaluate(NMove move, IntegerVector assignment, Evaluation evaluation, GQAPInstance problemInstance) {
    16186      int moves = move.N;
    162       var slack = (DoubleArray)capacities.Clone();
    163       var oldSlack = (DoubleArray)slack.Clone();
    164       bool first = true;
     87      var newEvaluation = new Evaluation() {
     88        ExcessDemand = evaluation.ExcessDemand,
     89        FlowCosts = evaluation.FlowCosts,
     90        InstallationCosts = evaluation.InstallationCosts,
     91        Slack = evaluation.Slack.ToArray()
     92      };
    16593      foreach (var kvp in move.NewAssignments) {
    16694        int equip = kvp.Key;
    16795        int newLoc = kvp.Value;
    168         moveInstallationQuality -= installationCosts[equip, assignment[equip]];
    169         moveInstallationQuality += installationCosts[equip, newLoc];
     96        int oldLoc = assignment[equip];
     97        var equipDemand = problemInstance.Demands[equip];
     98        newEvaluation.InstallationCosts -= problemInstance.InstallationCosts[equip, oldLoc];
     99        newEvaluation.InstallationCosts += problemInstance.InstallationCosts[equip, newLoc];
    170100        for (int j = 0; j < assignment.Length; j++) {
    171101          if (!move.NewAssignments.ContainsKey(j)) {
    172             moveFlowDistanceQuality += weights[equip, j] * distances[newLoc, assignment[j]];
    173             moveFlowDistanceQuality -= weights[equip, j] * distances[assignment[equip], assignment[j]];
    174             moveFlowDistanceQuality += weights[j, equip] * distances[assignment[j], newLoc];
    175             moveFlowDistanceQuality -= weights[j, equip] * distances[assignment[j], assignment[equip]];
    176             if (first) { // only once for each untouched equipment deduct the demand from the capacity
    177               slack[assignment[j]] -= demands[j];
    178               oldSlack[assignment[j]] -= demands[j];
    179             }
     102            newEvaluation.FlowCosts += problemInstance.Weights[equip, j] * problemInstance.Distances[newLoc, assignment[j]];
     103            newEvaluation.FlowCosts -= problemInstance.Weights[equip, j] * problemInstance.Distances[oldLoc, assignment[j]];
     104            newEvaluation.FlowCosts += problemInstance.Weights[j, equip] * problemInstance.Distances[assignment[j], newLoc];
     105            newEvaluation.FlowCosts -= problemInstance.Weights[j, equip] * problemInstance.Distances[assignment[j], oldLoc];
    180106          } else {
    181             moveFlowDistanceQuality += weights[equip, j] * distances[newLoc, move.NewAssignments[j]];
    182             moveFlowDistanceQuality -= weights[equip, j] * distances[assignment[equip], assignment[j]];
     107            newEvaluation.FlowCosts += problemInstance.Weights[equip, j] * problemInstance.Distances[newLoc, move.NewAssignments[j]];
     108            newEvaluation.FlowCosts -= problemInstance.Weights[equip, j] * problemInstance.Distances[oldLoc, assignment[j]];
    183109          }
    184110        }
    185         first = false;
    186         slack[newLoc] -= demands[equip];
    187         oldSlack[assignment[equip]] -= demands[equip];
     111        newEvaluation.Slack[oldLoc] += equipDemand;
     112        if (newEvaluation.Slack[oldLoc] < equipDemand)
     113          newEvaluation.ExcessDemand -= Math.Min(equipDemand, equipDemand - newEvaluation.Slack[oldLoc]);
     114        newEvaluation.Slack[newLoc] -= equipDemand;
     115        if (newEvaluation.Slack[newLoc] < 0)
     116          newEvaluation.ExcessDemand += Math.Min(equipDemand, -newEvaluation.Slack[newLoc]);
    188117      }
    189118
    190       moveOverbookedCapacity = evaluator.EvaluateOverbooking(slack, capacities) - evaluator.EvaluateOverbooking(oldSlack, capacities);
     119      return newEvaluation;
    191120    }
    192121
    193122    public override IOperation Apply() {
    194       var evaluator = EvaluatorParameter.ActualValue;
    195       double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity;
    196       double quality = QualityParameter.ActualValue.Value;
    197       double transportationCosts = TransportationCostsParameter.ActualValue.Value;
    198       double expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue.Value;
     123      var problemInstance = ProblemInstanceParameter.ActualValue;
     124      var evaluation = EvaluationParameter.ActualValue;
    199125
    200       double flowDistanceQuality = FlowDistanceQualityParameter.ActualValue.Value;
    201       double installationQuality = InstallationQualityParameter.ActualValue.Value;
    202       double overbookedCapacity = OverbookedCapacityParameter.ActualValue.Value;
     126      var moveEvaluation = Evaluate(MoveParameter.ActualValue,
     127               AssignmentParameter.ActualValue,
     128               evaluation,
     129               problemInstance);
    203130
    204       Evaluate(MoveParameter.ActualValue,
    205                AssignmentParameter.ActualValue,
    206                WeightsParameter.ActualValue, DistancesParameter.ActualValue,
    207                InstallationCostsParameter.ActualValue,
    208                DemandsParameter.ActualValue, CapacitiesParameter.ActualValue,
    209                evaluator,
    210                out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity);
    211 
    212       MoveFlowDistanceQualityParameter.ActualValue = new DoubleValue(flowDistanceQuality + moveFlowDistanceQuality);
    213       MoveInstallationQualityParameter.ActualValue = new DoubleValue(installationQuality + moveInstallationQuality);
    214       MoveOverbookedCapacityParameter.ActualValue = new DoubleValue(overbookedCapacity + moveOverbookedCapacity);
    215 
    216       MoveQualityParameter.ActualValue = new DoubleValue(evaluator.GetFitness(
    217         flowDistanceQuality + moveFlowDistanceQuality,
    218         installationQuality + moveInstallationQuality,
    219         overbookedCapacity + moveOverbookedCapacity,
    220         transportationCosts, expectedRandomQuality));
     131      MoveEvaluationParameter.ActualValue = moveEvaluation;
    221132      return base.Apply();
    222133    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAP.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Drawing;
     23using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Analysis.QualityAnalysis;
     25using HeuristicLab.Analysis;
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
     
    2929using HeuristicLab.Encodings.IntegerVectorEncoding;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3839  [Creatable("Problems")]
    3940  [StorableClass]
    40   public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent,
     41  public sealed class GQAP : SingleObjectiveBasicProblem<IntegerVectorEncoding>,
    4142    IProblemInstanceConsumer<QAPData>,
    4243    IProblemInstanceConsumer<CTAPData>,
     
    4546    IProblemInstanceConsumer<GQAPData> {
    4647
    47     public override Image ItemImage {
    48       get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
    49     }
    50 
    51     public string Filename { get; set; }
     48    public override bool Maximization { get { return false; } }
    5249
    5350    #region Parameter Descriptions
    54     public static readonly string MaximizationDescription = "False if the fitness function should be minimized (default) or otherwise True if it should be maximized.";
    55     public static readonly string WeightsDescription = "The weights matrix describes the flows between the equipments.";
    56     public static readonly string DistancesDescription = "The distances matrix describes the distances between the locations at which the equipment can be installed.";
    57     public static readonly string InstallationCostsDescription = "The installation costs matrix describes the installation costs of installing equipment i at location j";
    58     public static readonly string DemandsDescription = "The demands vector describes the space requirements of the equipments.";
    59     public static readonly string CapacitiesDescription = "The capacities vector describes the available space at the locations.";
    60     public static readonly string TransportationCostsDescription = "The transportation cost represents the flow-unit per distance-unit cost factor. This value can also be set to 1 if these costs are factored into the weights matrix already.";
    6151    public static readonly string BestKnownQualityDescription = "The best known quality (if available).";
    6252    public static readonly string BestKnownSolutionDescription = "The best known solution (if available).";
    6353    public static readonly string BestKnownSolutionsDescription = "Contains an archive of best-known solutions regarding flow-distance quality and installation quality.";
    64     public static readonly string EquipmentNamesDescription = "Optional: A list of names that describes the equipments.";
    65     public static readonly string LocationNamesDescription = "Optional: A list of names that describes the locations.";
    66     public static readonly string ExpectedRandomQualityDescription = "The expected quality value of a random solution.";
     54    public static readonly string ProblemInstanceDescription = "The problem instance that is to be solved.";
     55    public static readonly string EvaluationDescription = "The evaluation result of a solution to the GQAP.";
    6756    #endregion
    6857
    6958    #region Parameter Properties
    70     public ValueParameter<DoubleMatrix> WeightsParameter {
    71       get { return (ValueParameter<DoubleMatrix>)Parameters["Weights"]; }
    72     }
    73     public ValueParameter<DoubleMatrix> DistancesParameter {
    74       get { return (ValueParameter<DoubleMatrix>)Parameters["Distances"]; }
    75     }
    76     public ValueParameter<DoubleMatrix> InstallationCostsParameter {
    77       get { return (ValueParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
    78     }
    79     public ValueParameter<DoubleArray> DemandsParameter {
    80       get { return (ValueParameter<DoubleArray>)Parameters["Demands"]; }
    81     }
    82     public ValueParameter<DoubleArray> CapacitiesParameter {
    83       get { return (ValueParameter<DoubleArray>)Parameters["Capacities"]; }
    84     }
    85     public FixedValueParameter<DoubleValue> TransportationCostsParameter {
    86       get { return (FixedValueParameter<DoubleValue>)Parameters["TransportationCosts"]; }
    87     }
    88     public FixedValueParameter<DoubleValue> ExpectedRandomQualityParameter {
    89       get { return (FixedValueParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }
    90     }
    9159    public OptionalValueParameter<GQAPAssignment> BestKnownSolutionParameter {
    9260      get { return (OptionalValueParameter<GQAPAssignment>)Parameters["BestKnownSolution"]; }
     
    9563      get { return (OptionalValueParameter<GQAPAssignmentArchive>)Parameters["BestKnownSolutions"]; }
    9664    }
    97     public OptionalValueParameter<StringArray> EquipmentNamesParameter {
    98       get { return (OptionalValueParameter<StringArray>)Parameters["EquipmentNames"]; }
    99     }
    100     public OptionalValueParameter<StringArray> LocationNamesParameter {
    101       get { return (OptionalValueParameter<StringArray>)Parameters["LocationNames"]; }
     65    public IValueParameter<GQAPInstance> ProblemInstanceParameter {
     66      get { return (IValueParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
    10267    }
    10368    #endregion
    10469
    10570    #region Properties
    106     public DoubleMatrix Weights {
    107       get { return WeightsParameter.Value; }
    108       set { WeightsParameter.Value = value; }
    109     }
    110     public DoubleMatrix Distances {
    111       get { return DistancesParameter.Value; }
    112       set { DistancesParameter.Value = value; }
    113     }
    114     public DoubleMatrix InstallationCosts {
    115       get { return InstallationCostsParameter.Value; }
    116       set { InstallationCostsParameter.Value = value; }
    117     }
    118     public DoubleArray Demands {
    119       get { return DemandsParameter.Value; }
    120       set { DemandsParameter.Value = value; }
    121     }
    122     public DoubleArray Capacities {
    123       get { return CapacitiesParameter.Value; }
    124       set { CapacitiesParameter.Value = value; }
    125     }
    126     public double TransportationCosts {
    127       get { return TransportationCostsParameter.Value.Value; }
    128       set { TransportationCostsParameter.Value.Value = value; }
    129     }
    130     public double ExpectedRandomQuality {
    131       get { return ExpectedRandomQualityParameter.Value.Value; }
    132       set { ExpectedRandomQualityParameter.Value.Value = value; }
    133     }
    134     public StringArray EquipmentNames {
    135       get { return EquipmentNamesParameter.Value; }
    136       set { EquipmentNamesParameter.Value = value; }
    137     }
    138     public StringArray LocationNames {
    139       get { return LocationNamesParameter.Value; }
    140       set { LocationNamesParameter.Value = value; }
    141     }
    14271    public GQAPAssignment BestKnownSolution {
    14372      get { return BestKnownSolutionParameter.Value; }
     
    14877      set { BestKnownSolutionsParameter.Value = value; }
    14978    }
    150     #endregion
    151 
    152     public BestGQAPSolutionAnalyzer BestSolutionAnalyzer {
    153       get { return Operators.OfType<BestGQAPSolutionAnalyzer>().FirstOrDefault(); }
    154     }
    155     public GQAPSolutionArchiveAnalyzer SolutionArchiveAnalyzer {
    156       get { return Operators.OfType<GQAPSolutionArchiveAnalyzer>().FirstOrDefault(); }
    157     }
     79    public GQAPInstance ProblemInstance {
     80      get { return ProblemInstanceParameter.Value; }
     81      set { ProblemInstanceParameter.Value = value; }
     82    }
     83    #endregion
    15884
    15985    [StorableConstructor]
    160     private GeneralizedQuadraticAssignmentProblem(bool deserializing) : base(deserializing) { }
    161     private GeneralizedQuadraticAssignmentProblem(GeneralizedQuadraticAssignmentProblem original, Cloner cloner)
     86    private GQAP(bool deserializing) : base(deserializing) { }
     87    private GQAP(GQAP original, Cloner cloner)
    16288      : base(original, cloner) {
    16389      RegisterEventHandlers();
    16490    }
    165     public GeneralizedQuadraticAssignmentProblem()
    166       : base(new GQAPAdditivePenaltyEvaluator(), new RandomSolutionCreator()) {
    167       Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", WeightsDescription, new DoubleMatrix(), false));
    168       Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", DistancesDescription, new DoubleMatrix(), false));
    169       Parameters.Add(new ValueParameter<DoubleMatrix>("InstallationCosts", InstallationCostsDescription, new DoubleMatrix(), false));
    170       Parameters.Add(new FixedValueParameter<DoubleValue>("TransportationCosts", TransportationCostsDescription, new DoubleValue(1)));
    171       Parameters.Add(new FixedValueParameter<DoubleValue>("ExpectedRandomQuality", ExpectedRandomQualityDescription, new DoubleValue(0), true));
    172       Parameters.Add(new ValueParameter<DoubleArray>("Demands", DemandsDescription, new DoubleArray(), false));
    173       Parameters.Add(new ValueParameter<DoubleArray>("Capacities", CapacitiesDescription, new DoubleArray(), false));
     91    public GQAP() : base() {
     92      Encoding = new IntegerVectorEncoding("Assignment");
    17493      Parameters.Add(new OptionalValueParameter<GQAPAssignment>("BestKnownSolution", BestKnownSolutionDescription, null, false));
    17594      Parameters.Add(new OptionalValueParameter<GQAPAssignmentArchive>("BestKnownSolutions", BestKnownSolutionsDescription, null, false));
    176       Parameters.Add(new OptionalValueParameter<StringArray>("EquipmentNames", EquipmentNamesDescription, null, false));
    177       Parameters.Add(new OptionalValueParameter<StringArray>("LocationNames", LocationNamesDescription, null, false));
    178 
    179       WeightsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
    180       DistancesParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
    181       InstallationCostsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
    182       DemandsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
    183       CapacitiesParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
    184 
    185       Weights = new DoubleMatrix(5, 5);
    186       Weights[0, 0] = Weights[1, 1] = Weights[2, 2] = Weights[3, 3] = Weights[4, 4] = 0;
    187       Weights[0, 1] = Weights[1, 0] = Weights[0, 2] = Weights[2, 0] = Weights[0, 3] = Weights[3, 0] = Weights[0, 4] = Weights[4, 0] = 10;
    188       Weights[1, 2] = Weights[2, 1] = Weights[1, 3] = Weights[3, 1] = Weights[1, 4] = Weights[4, 1] = 5;
    189       Weights[2, 3] = Weights[3, 2] = Weights[2, 4] = Weights[4, 2] = 7.5;
    190       Weights[3, 4] = Weights[4, 3] = 2.5;
    191 
    192       Distances = new DoubleMatrix(3, 3);
    193       Distances[0, 0] = Distances[1, 1] = Distances[2, 2] = 0;
    194       Distances[0, 1] = Distances[1, 0] = Distances[1, 2] = Distances[2, 1] = 1;
    195       Distances[0, 2] = Distances[2, 0] = 2;
    196 
    197       InstallationCosts = new DoubleMatrix(5, 3);
    198 
    199       Demands = new DoubleArray(5);
    200       Demands[0] = 2; Demands[1] = 1; Demands[2] = 3; Demands[3] = 1; Demands[4] = 1;
    201 
    202       Capacities = new DoubleArray(3);
    203       Capacities[0] = 4; Capacities[1] = 1; Capacities[2] = 4;
    204 
    205       SolutionCreator.AssignmentParameter.ActualName = "Assignment";
     95      Parameters.Add(new ValueParameter<GQAPInstance>("ProblemInstance", "The problem instance that is to be solved.", new GQAPInstance(), false));
    20696
    20797      InitializeOperators();
     
    210100
    211101    public override IDeepCloneable Clone(Cloner cloner) {
    212       return new GeneralizedQuadraticAssignmentProblem(this, cloner);
     102      return new GQAP(this, cloner);
     103    }
     104
     105    public override double Evaluate(Individual individual, IRandom random = null) {
     106      var assignment = individual.IntegerVector();
     107      var evaluation = ProblemInstance.Evaluate(assignment);
     108      individual["Evaluation"] = evaluation;
     109      return ProblemInstance.ToSingleObjective(evaluation);
     110    }
     111
     112    public double Evaluate(IntegerVector assignment) {
     113      var evaluation = ProblemInstance.Evaluate(assignment);
     114      return ProblemInstance.ToSingleObjective(evaluation);
     115    }
     116
     117    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     118      AnalyzeBestSolution(results, GetBestIndividual(individuals, qualities));
     119      AnalyzeParetoArchive(results,
     120        individuals.Select(i => Tuple.Create((IntegerVector)i.IntegerVector().Clone(),
     121        (Evaluation)i["Evaluation"])));
     122    }
     123
     124    private void AnalyzeBestSolution(ResultCollection results, Tuple<Individual, double> best) {
     125      var bestVector = best.Item1.IntegerVector();
     126      var bestEvaluation = (Evaluation)best.Item1["Evaluation"];
     127
     128      IResult bestResult;
     129      if (!results.TryGetValue("Best Solution", out bestResult)) {
     130        bestResult = new Result("Best Solution", typeof(GQAPAssignment));
     131        results.Add(bestResult);
     132      }
     133      var item = bestResult.Value as GQAPAssignment;
     134      if (item == null) bestResult.Value = new GQAPAssignment((IntegerVector)bestVector.Clone(), ProblemInstance, bestEvaluation);
     135      else if (ProblemInstance.ToSingleObjective(bestEvaluation)
     136        < ProblemInstance.ToSingleObjective(item.Evaluation)) {
     137        item.ProblemInstance = ProblemInstance;
     138        item.Assignment = (IntegerVector)bestVector.Clone();
     139        item.Evaluation = bestEvaluation;
     140      }
     141    }
     142
     143    private void AnalyzeParetoArchive(ResultCollection results, IEnumerable<Tuple<IntegerVector, Evaluation>> solutions) {
     144      IResult archiveResult;
     145      if (!results.TryGetValue("Solution Archive", out archiveResult)) {
     146        archiveResult = new Result("Solution Archive", typeof(GQAPAssignmentArchive));
     147        results.Add(archiveResult);
     148      }
     149      var archive = archiveResult.Value as GQAPAssignmentArchive;
     150      if (archive == null) archive = new GQAPAssignmentArchive(ProblemInstance);
     151      else archive.ProblemInstance = ProblemInstance;
     152     
     153      var combinedArchive = solutions
     154        .Select(x => new GQAPSolution(x.Item1, x.Item2))
     155        .Concat(archive.Solutions);
     156      archive.Solutions = GetFeasibleParetoFront(combinedArchive);
     157     
     158      if (BestKnownSolutions == null) {
     159        BestKnownSolutions = archive;
     160      } else {
     161        var combinedArchive2 = solutions
     162        .Select(x => new GQAPSolution(x.Item1, x.Item2))
     163        .Concat(BestKnownSolutions.Solutions);
     164        BestKnownSolutions.Solutions = GetFeasibleParetoFront(combinedArchive2);
     165      }
    213166    }
    214167
     
    304257
    305258      if (data.BestKnownAssignment == null && data.BestKnownQuality.HasValue) {
    306         BestKnownQuality = new DoubleValue(data.BestKnownQuality.Value);
     259        BestKnownQuality = data.BestKnownQuality.Value;
    307260      }
    308261    }
     
    318271@"The weights matrix of the given instance contains
    319272an unequal number of rows and columns.");
    320       Weights = weights;
    321 
    322273      if (distances == null || distances.Rows == 0)
    323274        throw new System.IO.InvalidDataException(
     
    327278@"The distances matrix of the given instance contains
    328279an unequal number of rows and columns.");
    329       Distances = distances;
    330 
    331280      if (installationCosts == null || installationCosts.Rows == 0)
    332281        throw new System.IO.InvalidDataException(
     
    339288weights matrix and a different number of columns than
    340289given in the distances matrix.");
    341       InstallationCosts = installationCosts;
    342 
    343290      if (capacities == null || capacities.Length == 0)
    344291        throw new System.IO.InvalidDataException(
     
    348295@"The given instance contains a different number of
    349296capacities than rows given in the distances matrix.");
    350       Capacities = capacities;
    351 
    352297      if (demands == null || demands.Length == 0)
    353298        throw new System.IO.InvalidDataException(
     
    357302@"The given instance contains a different number of
    358303demands than rows given in the weights matrix.");
    359       Demands = demands;
    360 
    361304      if (transportationCosts == null)
    362305        throw new System.IO.InvalidDataException(
    363306@"The given instance does not contain transportation costs.");
    364       TransportationCosts = transportationCosts.Value;
    365 
    366       BestKnownQuality = null;
     307
     308      ProblemInstance = new GQAPInstance() {
     309        Weights = weights,
     310        Distances = distances,
     311        InstallationCosts = installationCosts,
     312        Capacities = capacities,
     313        Demands = demands,
     314        TransportationCosts = transportationCosts.Value
     315      };
     316      BestKnownQualityParameter.Value = null;
    367317      BestKnownSolution = null;
    368318      BestKnownSolutions = null;
    369       CalculateExpectedRandomQuality();
    370     }
    371 
    372     private void CalculateExpectedRandomQuality() {
    373       if (IsConfigurationValid()) {
    374         double[] avgDistances = new double[Capacities.Length];
    375         for (int i = 0; i < Capacities.Length; i++) {
    376           for (int j = 0; j < Capacities.Length; j++)
    377             avgDistances[i] += Distances[i, j];
    378           avgDistances[i] /= Capacities.Length;
    379         }
    380         double[] avgWeight = new double[Demands.Length];
    381         for (int i = 0; i < Demands.Length; i++) {
    382           for (int j = 0; j < Demands.Length; j++)
    383             avgWeight[i] += Weights[i, j];
    384           avgWeight[i] /= Demands.Length;
    385         }
    386         double avgCosts = InstallationCosts.Average();
    387         double quality = 0;
    388         for (int i = 0; i < Demands.Length; i++) {
    389           double equipmentInfluence = 0;
    390           for (int j = 0; j < Capacities.Length; j++)
    391             equipmentInfluence += avgWeight[i] * avgDistances[j];
    392           quality += equipmentInfluence * Demands.Length / (double)Capacities.Length;
    393         }
    394         quality *= TransportationCosts;
    395         quality += avgCosts * Demands.Length;
    396 
    397         ExpectedRandomQuality = quality;
    398       }
     319      ProblemInstance.CalculatePenaltyLevel();
    399320    }
    400321    private void EvaluateAndLoadAssignment(int[] vector) {
     
    403324    }
    404325    public void EvaluateAndLoadAssignment(IntegerVector assignment) {
    405       if (!IsConfigurationValid()) {
    406         BestKnownQuality = null;
     326      if (!ProblemInstance.IsValid()) {
     327        BestKnownQualityParameter.Value = null;
    407328        BestKnownSolution = null;
    408329        BestKnownSolutions = null;
    409       }
    410       double flowDistanceQuality, installationQuality, overbookedCapacity;
    411       Evaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities,
    412         out flowDistanceQuality, out installationQuality, out overbookedCapacity);
    413       double quality = Evaluator.GetFitness(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts, ExpectedRandomQuality);
    414       BestKnownSolution = new GQAPAssignment((IntegerVector)assignment.Clone(), new DoubleValue(quality),
    415         new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality),
    416         new DoubleValue(overbookedCapacity), EquipmentNames, LocationNames, Distances, Weights, InstallationCosts,
    417         Demands, Capacities, new DoubleValue(TransportationCosts), new DoubleValue(ExpectedRandomQuality), Evaluator);
    418       BestKnownQuality = new DoubleValue(quality);
    419       BestKnownSolutions = new GQAPAssignmentArchive(EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, Demands, Capacities, new DoubleValue(TransportationCosts), new DoubleValue(ExpectedRandomQuality), Evaluator);
    420       BestKnownSolutions.Solutions.Add(new GQAPSolution((IntegerVector)assignment.Clone(), new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity)));
     330        return;
     331      }
     332      var evaluation = ProblemInstance.Evaluate(assignment);
     333      var quality = ProblemInstance.ToSingleObjective(evaluation);
     334     
     335      BestKnownSolution = new GQAPAssignment((IntegerVector)assignment.Clone(), ProblemInstance, evaluation);
     336      BestKnownQuality = quality;
     337      BestKnownSolutions = new GQAPAssignmentArchive(ProblemInstance);
     338      BestKnownSolutions.Solutions.Add(new GQAPSolution((IntegerVector)assignment.Clone(), evaluation));
    421339    }
    422340    #endregion
     
    427345      Parameterize();
    428346    }
    429     protected override void OnEvaluatorChanged() {
    430       base.OnEvaluatorChanged();
    431       Parameterize();
    432       if (BestKnownSolution != null) EvaluateAndLoadAssignment(BestKnownSolution.Assignment);
    433       Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    434     }
    435     protected override void OnSolutionCreatorChanged() {
    436       base.OnSolutionCreatorChanged();
    437       Parameterize();
    438       SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
    439     }
    440 
    441     private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    442       Parameterize();
    443     }
    444     private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) {
     347    protected override void OnEncodingChanged() {
     348      base.OnEncodingChanged();
    445349      Parameterize();
    446350    }
     
    454358
    455359    private void RegisterEventHandlers() {
    456       Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    457       SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
     360      ProblemInstanceParameter.ValueChanged += ProblemInstanceParameterOnValueChanged;
     361      ProblemInstance.CapacitiesParameter.ValueChanged += ProblemInstanceCapacitiesParameterOnValueChanged;
     362      ProblemInstance.DemandsParameter.ValueChanged += ProblemInstanceDemandsParameterOnValueChanged;
     363      ProblemInstance.Capacities.Reset += ProblemInstanceCapacitiesOnReset;
     364      ProblemInstance.Demands.Reset += ProblemInstanceDemandsOnReset;
     365    }
     366
     367    private void ProblemInstanceParameterOnValueChanged(object sender, EventArgs e) {
     368      ProblemInstance.CapacitiesParameter.ValueChanged += ProblemInstanceCapacitiesParameterOnValueChanged;
     369      ProblemInstance.Capacities.Reset += ProblemInstanceCapacitiesOnReset;
     370      ProblemInstance.DemandsParameter.ValueChanged += ProblemInstanceDemandsParameterOnValueChanged;
     371      ProblemInstance.Demands.Reset += ProblemInstanceDemandsOnReset;
     372      UpdateEncoding();
     373    }
     374    private void ProblemInstanceCapacitiesParameterOnValueChanged(object sender, EventArgs e) {
     375      ProblemInstance.Capacities.Reset += ProblemInstanceCapacitiesOnReset;
     376      UpdateEncoding();
     377    }
     378    private void ProblemInstanceDemandsParameterOnValueChanged(object sender, EventArgs e) {
     379      ProblemInstance.Demands.Reset += ProblemInstanceDemandsOnReset;
     380      UpdateEncoding();
     381    }
     382    private void ProblemInstanceDemandsOnReset(object sender, EventArgs e) {
     383      UpdateEncoding();
     384    }
     385    private void ProblemInstanceCapacitiesOnReset(object sender, EventArgs e) {
     386      UpdateEncoding();
     387    }
     388
     389    private void UpdateEncoding() {
     390      Encoding.Length = ProblemInstance.Demands.Length;
     391      Encoding.Bounds = new IntMatrix(new int[,] { { 0, ProblemInstance.Capacities.Length } });
    458392    }
    459393
     
    461395      Operators.Clear();
    462396      Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPOperator>());
    463       Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>());
    464397      Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
    465398      Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>());
    466       Operators.Add(new ScaledQualityDifferenceAnalyzer());
     399      Operators.Add(new HammingSimilarityCalculator());
     400      Operators.Add(new QualitySimilarityCalculator());
     401     
     402      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    467403      Parameterize();
    468404    }
    469405
    470406    private void Parameterize() {
    471 
    472407      var operators = Operators.Union(new IOperator[] { SolutionCreator, Evaluator }).ToArray();
    473 
    474       foreach (var op in operators.OfType<IAssignmentAwareGQAPOperator>()) {
    475         op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
    476         op.AssignmentParameter.Hidden = true;
    477       }
     408     
    478409      foreach (var op in operators.OfType<IBestKnownQualityAwareGQAPOperator>()) {
    479410        op.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
     
    488419        op.BestKnownSolutionsParameter.Hidden = true;
    489420      }
    490       foreach (var op in operators.OfType<ICapacitiesAwareGQAPOperator>()) {
    491         op.CapacitiesParameter.ActualName = CapacitiesParameter.Name;
    492         op.CapacitiesParameter.Hidden = true;
    493       }
    494       foreach (var op in operators.OfType<IDemandsAwareGQAPOperator>()) {
    495         op.DemandsParameter.ActualName = DemandsParameter.Name;
    496         op.DemandsParameter.Hidden = true;
    497       }
    498       foreach (var op in operators.OfType<IDistancesAwareGQAPOperator>()) {
    499         op.DistancesParameter.ActualName = DistancesParameter.Name;
    500         op.DistancesParameter.Hidden = true;
    501       }
    502       foreach (var op in operators.OfType<IEquipmentNamesAwareGQAPOperator>()) {
    503         op.EquipmentNamesParameter.ActualName = EquipmentNamesParameter.Name;
    504         op.EquipmentNamesParameter.Hidden = true;
    505       }
    506421      foreach (var op in operators.OfType<IGQAPCrossover>()) {
    507         op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
     422        op.ParentsParameter.ActualName = Encoding.Name;
    508423        op.ParentsParameter.Hidden = true;
    509         op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
     424        op.ChildParameter.ActualName = Encoding.Name;
    510425        op.ChildParameter.Hidden = true;
    511       }
    512       foreach (var op in operators.OfType<IInstallationCostsAwareGQAPOperator>()) {
    513         op.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name;
    514         op.InstallationCostsParameter.Hidden = true;
    515       }
    516       foreach (var op in operators.OfType<ILocationNamesAwareGQAPOperator>()) {
    517         op.LocationNamesParameter.ActualName = LocationNamesParameter.Name;
    518         op.LocationNamesParameter.Hidden = true;
    519426      }
    520427      var moveEvaluator = operators.OfType<IGQAPMoveEvaluator>().FirstOrDefault();
     
    523430          op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName;
    524431          op.MoveQualityParameter.Hidden = true;
    525           op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName;
    526           op.MoveFlowDistanceQualityParameter.Hidden = true;
    527           op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName;
    528           op.MoveInstallationQualityParameter.Hidden = true;
    529           op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName;
    530           op.MoveOverbookedCapacityParameter.Hidden = true;
     432          op.MoveEvaluationParameter.ActualName = "MoveEvaluation";
     433          op.MoveEvaluationParameter.Hidden = true;
    531434        }
    532435      }
     
    535438          op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName;
    536439          op.MoveQualityParameter.Hidden = true;
    537           op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName;
    538           op.MoveFlowDistanceQualityParameter.Hidden = true;
    539           op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName;
    540           op.MoveInstallationQualityParameter.Hidden = true;
    541           op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName;
    542           op.MoveOverbookedCapacityParameter.Hidden = true;
     440          op.MoveEvaluationParameter.ActualName = "MoveEvaluation";
     441          op.MoveEvaluationParameter.Hidden = true;
    543442        }
    544         op.MaximizationParameter.ActualName = MaximizationParameter.Name;
    545         op.MaximizationParameter.Hidden = true;
    546       }
    547       foreach (var op in operators.OfType<IExpectedRandomQualityAwareGQAPOperator>()) {
    548         op.ExpectedRandomQualityParameter.ActualName = ExpectedRandomQualityParameter.Name;
    549         op.ExpectedRandomQualityParameter.Hidden = true;
     443      }
     444      foreach (var op in operators.OfType<IProblemInstanceAwareGQAPOperator>()) {
     445        op.ProblemInstanceParameter.ActualName = ProblemInstanceParameter.Name;
     446        op.ProblemInstanceParameter.Hidden = true;
    550447      }
    551448      foreach (var op in operators.OfType<IQualitiesAwareGQAPOperator>()) {
    552449        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    553450        op.QualityParameter.Hidden = true;
    554         op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName;
    555         op.FlowDistanceQualityParameter.Hidden = true;
    556         op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName;
    557         op.InstallationQualityParameter.Hidden = true;
    558         op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName;
    559         op.OverbookedCapacityParameter.Hidden = true;
    560         op.MaximizationParameter.ActualName = MaximizationParameter.Name;
    561         op.MaximizationParameter.Hidden = true;
     451        op.EvaluationParameter.ActualName = "Evaluation";
     452        op.EvaluationParameter.Hidden = true;
    562453      }
    563454      foreach (var op in operators.OfType<IQualityAwareGQAPOperator>()) {
    564455        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    565456        op.QualityParameter.Hidden = true;
    566         op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName;
    567         op.FlowDistanceQualityParameter.Hidden = true;
    568         op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName;
    569         op.InstallationQualityParameter.Hidden = true;
    570         op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName;
    571         op.OverbookedCapacityParameter.Hidden = true;
    572         op.MaximizationParameter.ActualName = MaximizationParameter.Name;
    573         op.MaximizationParameter.Hidden = true;
    574       }
    575       foreach (var op in operators.OfType<ITransportationCostsAwareGQAPOperator>()) {
    576         op.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name;
    577         op.TransportationCostsParameter.Hidden = true;
    578       }
    579       foreach (var op in operators.OfType<IWeightsAwareGQAPOperator>()) {
    580         op.WeightsParameter.ActualName = WeightsParameter.Name;
    581         op.WeightsParameter.Hidden = true;
    582       }
    583       foreach (var op in operators.OfType<IEvaluatorAwareGQAPOperator>()) {
    584         op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
    585         op.EvaluatorParameter.Hidden = true;
    586       }
    587 
    588       foreach (var op in operators.OfType<IIntegerVectorCrossover>()) {
    589         op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
    590         op.ParentsParameter.Hidden = true;
    591         op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
    592         op.ChildParameter.Hidden = true;
    593       }
    594       foreach (var op in operators.OfType<IIntegerVectorManipulator>()) {
    595         op.IntegerVectorParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
    596         op.IntegerVectorParameter.Hidden = true;
    597       }
    598 
    599       foreach (var op in operators.OfType<ScaledQualityDifferenceAnalyzer>()) {
    600         op.MinimumQualityParameter.ActualName = BestKnownQualityParameter.Name;
    601         op.MinimumQualityParameter.Hidden = true;
    602         op.MaximumQualityParameter.ActualName = ExpectedRandomQualityParameter.Name;
    603         op.MaximumQualityParameter.Hidden = true;
    604         op.QualityParameter.ActualName = "BestQuality";
    605         op.QualityParameter.Hidden = true;
    606       }
    607     }
    608     #endregion
    609 
    610     public bool IsConfigurationValid() {
    611       return Weights != null && Distances != null && Demands != null && Capacities != null && InstallationCosts != null
    612         && Weights.Rows == Weights.Columns && Weights.Rows == InstallationCosts.Rows
    613         && Distances.Rows == Distances.Columns && Distances.Rows == InstallationCosts.Columns
    614         && Demands.Length == Weights.Rows && Capacities.Length == Distances.Rows;
     457        op.EvaluationParameter.ActualName = "Evaluation";
     458        op.EvaluationParameter.Hidden = true;
     459      }
     460    }
     461    #endregion
     462
     463    public static ItemList<GQAPSolution> GetFeasibleParetoFront(IEnumerable<GQAPSolution> solutions) {
     464      var front = new ItemList<GQAPSolution>(solutions.Where(x => x.Evaluation.IsFeasible));
     465
     466      for (int i = 0; i < front.Count - 1; i++) {
     467        for (int j = i + 1; j < front.Count; j++) {
     468          if (front[i].Evaluation.FlowCosts <= front[j].Evaluation.FlowCosts
     469            && front[i].Evaluation.InstallationCosts <= front[j].Evaluation.InstallationCosts) {
     470            front.RemoveAt(j);
     471            j--;
     472          } else if (front[i].Evaluation.FlowCosts >= front[j].Evaluation.FlowCosts
     473            && front[i].Evaluation.InstallationCosts >= front[j].Evaluation.InstallationCosts) {
     474            front.RemoveAt(i);
     475            j = i;
     476          }
     477        }
     478      }
     479      return front;
    615480    }
    616481  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPAssignment.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Data;
    2625using HeuristicLab.Encodings.IntegerVectorEncoding;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3736      get { return assignment; }
    3837      set {
    39         bool changed = (assignment != value);
     38        if (assignment == value) return;
    4039        assignment = value;
    41         if (changed) OnPropertyChanged("Assignment");
     40        OnPropertyChanged(nameof(Assignment));
    4241      }
    4342    }
    4443
    4544    [Storable]
    46     private DoubleValue quality;
    47     public DoubleValue Quality {
    48       get { return quality; }
     45    private Evaluation evaluation;
     46    public Evaluation Evaluation {
     47      get { return evaluation; }
    4948      set {
    50         bool changed = (quality != value);
    51         quality = value;
    52         if (changed) OnPropertyChanged("Quality");
     49        if (evaluation == value) return;
     50        evaluation = value;
     51        OnPropertyChanged(nameof(Evaluation));
    5352      }
    5453    }
    5554
    5655    [Storable]
    57     private DoubleValue flowDistanceQuality;
    58     public DoubleValue FlowDistanceQuality {
    59       get { return flowDistanceQuality; }
     56    private GQAPInstance problemInstance;
     57    public GQAPInstance ProblemInstance {
     58      get { return problemInstance; }
    6059      set {
    61         bool changed = (flowDistanceQuality != value);
    62         flowDistanceQuality = value;
    63         if (changed) OnPropertyChanged("FlowDistanceQuality");
    64       }
    65     }
    66 
    67     [Storable]
    68     private DoubleValue installationQuality;
    69     public DoubleValue InstallationQuality {
    70       get { return installationQuality; }
    71       set {
    72         bool changed = (installationQuality != value);
    73         installationQuality = value;
    74         if (changed) OnPropertyChanged("InstallationQuality");
    75       }
    76     }
    77 
    78     [Storable]
    79     private DoubleValue overbookedCapacity;
    80     public DoubleValue OverbookedCapacity {
    81       get { return overbookedCapacity; }
    82       set {
    83         bool changed = (overbookedCapacity != value);
    84         overbookedCapacity = value;
    85         if (changed) OnPropertyChanged("OverbookedCapacity");
    86       }
    87     }
    88 
    89     [Storable]
    90     private StringArray equipmentNames;
    91     public StringArray EquipmentNames {
    92       get { return equipmentNames; }
    93       set {
    94         bool changed = (equipmentNames != value);
    95         equipmentNames = value;
    96         if (changed) OnPropertyChanged("EquipmentNames");
    97       }
    98     }
    99 
    100     [Storable]
    101     private StringArray locationNames;
    102     public StringArray LocationNames {
    103       get { return locationNames; }
    104       set {
    105         bool changed = (locationNames != value);
    106         locationNames = value;
    107         if (changed) OnPropertyChanged("LocationNames");
    108       }
    109     }
    110 
    111     [Storable]
    112     private DoubleMatrix distances;
    113     public DoubleMatrix Distances {
    114       get { return distances; }
    115       set {
    116         bool changed = (distances != value);
    117         distances = value;
    118         if (changed) OnPropertyChanged("Distances");
    119       }
    120     }
    121 
    122     [Storable]
    123     private DoubleMatrix weights;
    124     public DoubleMatrix Weights {
    125       get { return weights; }
    126       set {
    127         bool changed = (weights != value);
    128         weights = value;
    129         if (changed) OnPropertyChanged("Weights");
    130       }
    131     }
    132 
    133     [Storable]
    134     private DoubleMatrix installationCosts;
    135     public DoubleMatrix InstallationCosts {
    136       get { return installationCosts; }
    137       set {
    138         bool changed = (installationCosts != value);
    139         installationCosts = value;
    140         if (changed) OnPropertyChanged("InstallationCosts");
    141       }
    142     }
    143 
    144     [Storable]
    145     private DoubleArray demands;
    146     public DoubleArray Demands {
    147       get { return demands; }
    148       set {
    149         bool changed = (demands != value);
    150         demands = value;
    151         if (changed) OnPropertyChanged("Demands");
    152       }
    153     }
    154 
    155     [Storable]
    156     private DoubleArray capacities;
    157     public DoubleArray Capacities {
    158       get { return capacities; }
    159       set {
    160         bool changed = (capacities != value);
    161         capacities = value;
    162         if (changed) OnPropertyChanged("Capacities");
    163       }
    164     }
    165 
    166     [Storable]
    167     private DoubleValue transportationCosts;
    168     public DoubleValue TransportationCosts {
    169       get { return transportationCosts; }
    170       set {
    171         bool changed = (transportationCosts != value);
    172         transportationCosts = value;
    173         if (changed) OnPropertyChanged("TransportationCosts");
    174       }
    175     }
    176 
    177     [Storable]
    178     private DoubleValue expectedRandomQuality;
    179     public DoubleValue ExpectedRandomQuality {
    180       get { return expectedRandomQuality; }
    181       set {
    182         bool changed = (expectedRandomQuality != value);
    183         expectedRandomQuality = value;
    184         if (changed) OnPropertyChanged("ExpectedRandomQuality");
    185       }
    186     }
    187 
    188     [Storable]
    189     private IGQAPEvaluator evaluator;
    190     public IGQAPEvaluator Evaluator {
    191       get { return evaluator; }
    192       set {
    193         bool changed = (evaluator != value);
    194         evaluator = value;
    195         if (changed) OnPropertyChanged("Evaluator");
     60        if (problemInstance == value) return;
     61        problemInstance = value;
     62        OnPropertyChanged(nameof(ProblemInstance));
    19663      }
    19764    }
     
    20269      : base(original, cloner) {
    20370      assignment = cloner.Clone(original.assignment);
    204       quality = cloner.Clone(original.quality);
    205       flowDistanceQuality = cloner.Clone(original.flowDistanceQuality);
    206       installationQuality = cloner.Clone(original.installationQuality);
    207       overbookedCapacity = cloner.Clone(original.overbookedCapacity);
    208       equipmentNames = cloner.Clone(original.equipmentNames);
    209       locationNames = cloner.Clone(original.locationNames);
    210       distances = cloner.Clone(original.distances);
    211       weights = cloner.Clone(original.weights);
    212       installationCosts = cloner.Clone(original.installationCosts);
    213       demands = cloner.Clone(original.demands);
    214       capacities = cloner.Clone(original.capacities);
    215       transportationCosts = cloner.Clone(original.transportationCosts);
    216       expectedRandomQuality = cloner.Clone(original.expectedRandomQuality);
    217       evaluator = cloner.Clone(original.evaluator);
     71      evaluation = cloner.Clone(original.evaluation);
     72      problemInstance = cloner.Clone(original.problemInstance);
    21873    }
    219     public GQAPAssignment(IntegerVector assignment, DoubleValue quality, DoubleValue flowDistanceQuality, DoubleValue installationQuality, DoubleValue overbookedCapacity, StringArray equipmentNames, StringArray locationNames, DoubleMatrix distances, DoubleMatrix weights, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, DoubleValue transportationCosts, DoubleValue expectedRandomQuality, IGQAPEvaluator evaluator)
     74    public GQAPAssignment(IntegerVector assignment, GQAPInstance problemInstance)
     75      : this(assignment, problemInstance, problemInstance.Evaluate(assignment)) { }
     76    public GQAPAssignment(IntegerVector assignment, GQAPInstance problemInstance, Evaluation evaluation)
    22077      : base() {
    22178      this.assignment = assignment;
    222       this.quality = quality;
    223       this.flowDistanceQuality = flowDistanceQuality;
    224       this.installationQuality = installationQuality;
    225       this.overbookedCapacity = overbookedCapacity;
    226       this.equipmentNames = equipmentNames;
    227       this.locationNames = locationNames;
    228       this.distances = distances;
    229       this.weights = weights;
    230       this.installationCosts = installationCosts;
    231       this.demands = demands;
    232       this.capacities = capacities;
    233       this.transportationCosts = transportationCosts;
    234       this.expectedRandomQuality = expectedRandomQuality;
    235       this.evaluator = evaluator;
     79      this.evaluation = evaluation;
     80      this.problemInstance = problemInstance;
    23681    }
    23782
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPAssignmentArchive.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Data;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2726
     
    3635      get { return solutions; }
    3736      set {
    38         bool changed = (solutions != value);
     37        if (solutions == value) return;
    3938        solutions = value;
    40         if (changed) OnPropertyChanged("Solutions");
     39        OnPropertyChanged(nameof(Solutions));
    4140      }
    4241    }
    4342
    4443    [Storable]
    45     private StringArray equipmentNames;
    46     public StringArray EquipmentNames {
    47       get { return equipmentNames; }
     44    private GQAPInstance problemInstance;
     45    public GQAPInstance ProblemInstance {
     46      get { return problemInstance; }
    4847      set {
    49         bool changed = (equipmentNames != value);
    50         equipmentNames = value;
    51         if (changed) OnPropertyChanged("EquipmentNames");
    52       }
    53     }
    54 
    55     [Storable]
    56     private StringArray locationNames;
    57     public StringArray LocationNames {
    58       get { return locationNames; }
    59       set {
    60         bool changed = (locationNames != value);
    61         locationNames = value;
    62         if (changed) OnPropertyChanged("LocationNames");
    63       }
    64     }
    65 
    66     [Storable]
    67     private DoubleMatrix distances;
    68     public DoubleMatrix Distances {
    69       get { return distances; }
    70       set {
    71         bool changed = (distances != value);
    72         distances = value;
    73         if (changed) OnPropertyChanged("Distances");
    74       }
    75     }
    76 
    77     [Storable]
    78     private DoubleMatrix weights;
    79     public DoubleMatrix Weights {
    80       get { return weights; }
    81       set {
    82         bool changed = (weights != value);
    83         weights = value;
    84         if (changed) OnPropertyChanged("Weights");
    85       }
    86     }
    87 
    88     [Storable]
    89     private DoubleMatrix installationCosts;
    90     public DoubleMatrix InstallationCosts {
    91       get { return installationCosts; }
    92       set {
    93         bool changed = (installationCosts != value);
    94         installationCosts = value;
    95         if (changed) OnPropertyChanged("InstallationCosts");
    96       }
    97     }
    98 
    99     [Storable]
    100     private DoubleArray demands;
    101     public DoubleArray Demands {
    102       get { return demands; }
    103       set {
    104         bool changed = (demands != value);
    105         demands = value;
    106         if (changed) OnPropertyChanged("Demands");
    107       }
    108     }
    109 
    110     [Storable]
    111     private DoubleArray capacities;
    112     public DoubleArray Capacities {
    113       get { return capacities; }
    114       set {
    115         bool changed = (capacities != value);
    116         capacities = value;
    117         if (changed) OnPropertyChanged("Capacities");
    118       }
    119     }
    120 
    121     [Storable]
    122     private DoubleValue transportationCosts;
    123     public DoubleValue TransportationCosts {
    124       get { return transportationCosts; }
    125       set {
    126         bool changed = (transportationCosts != value);
    127         transportationCosts = value;
    128         if (changed) OnPropertyChanged("TransportationCosts");
    129       }
    130     }
    131 
    132     [Storable]
    133     private DoubleValue expectedRandomQuality;
    134     public DoubleValue ExpectedRandomQuality {
    135       get { return expectedRandomQuality; }
    136       set {
    137         bool changed = (expectedRandomQuality != value);
    138         expectedRandomQuality = value;
    139         if (changed) OnPropertyChanged("ExpectedRandomQuality");
    140       }
    141     }
    142 
    143     [Storable]
    144     private IGQAPEvaluator evaluator;
    145     public IGQAPEvaluator Evaluator {
    146       get { return evaluator; }
    147       set {
    148         bool changed = (evaluator != value);
    149         evaluator = value;
    150         if (changed) OnPropertyChanged("Evaluator");
     48        if (problemInstance == value) return;
     49        problemInstance = value;
     50        OnPropertyChanged(nameof(ProblemInstance));
    15151      }
    15252    }
     
    15757      : base(original, cloner) {
    15858      solutions = cloner.Clone(original.solutions);
    159       equipmentNames = cloner.Clone(original.equipmentNames);
    160       locationNames = cloner.Clone(original.locationNames);
    161       distances = cloner.Clone(original.distances);
    162       weights = cloner.Clone(original.weights);
    163       installationCosts = cloner.Clone(original.installationCosts);
    164       demands = cloner.Clone(original.demands);
    165       capacities = cloner.Clone(original.capacities);
    166       transportationCosts = cloner.Clone(original.transportationCosts);
    167       expectedRandomQuality = cloner.Clone(original.expectedRandomQuality);
    168       evaluator = cloner.Clone(original.evaluator);
     59      problemInstance = cloner.Clone(original.problemInstance);
    16960    }
    17061    public GQAPAssignmentArchive()
     
    17263      this.solutions = new ItemList<GQAPSolution>();
    17364    }
    174     public GQAPAssignmentArchive(StringArray equipmentNames, StringArray locationNames, DoubleMatrix distances, DoubleMatrix weights, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, DoubleValue transportationCosts, DoubleValue expectedRandomQuality, IGQAPEvaluator evaluator)
     65    public GQAPAssignmentArchive(GQAPInstance problemInstance)
    17566      : this() {
    176       this.distances = distances;
    177       this.weights = weights;
    178       this.installationCosts = installationCosts;
    179       this.demands = demands;
    180       this.capacities = capacities;
    181       this.transportationCosts = transportationCosts;
    182       this.expectedRandomQuality = expectedRandomQuality;
    183       this.evaluator = evaluator;
     67      this.problemInstance = problemInstance;
    18468    }
    18569
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPSolution.cs

    r7418 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Data;
    2625using HeuristicLab.Encodings.IntegerVectorEncoding;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4443
    4544    [Storable]
    46     private DoubleValue quality;
    47     public DoubleValue Quality {
    48       get { return quality; }
     45    private Evaluation evaluation;
     46    public Evaluation Evaluation {
     47      get { return evaluation; }
    4948      set {
    50         bool changed = (quality != value);
    51         quality = value;
    52         if (changed) OnPropertyChanged("Quality");
    53       }
    54     }
    55 
    56     [Storable]
    57     private DoubleValue flowDistanceQuality;
    58     public DoubleValue FlowDistanceQuality {
    59       get { return flowDistanceQuality; }
    60       set {
    61         bool changed = (flowDistanceQuality != value);
    62         flowDistanceQuality = value;
    63         if (changed) OnPropertyChanged("FlowDistanceQuality");
    64       }
    65     }
    66 
    67     [Storable]
    68     private DoubleValue installationQuality;
    69     public DoubleValue InstallationQuality {
    70       get { return installationQuality; }
    71       set {
    72         bool changed = (installationQuality != value);
    73         installationQuality = value;
    74         if (changed) OnPropertyChanged("InstallationQuality");
    75       }
    76     }
    77 
    78     [Storable]
    79     private DoubleValue overbookedCapacity;
    80     public DoubleValue OverbookedCapacity {
    81       get { return overbookedCapacity; }
    82       set {
    83         bool changed = (overbookedCapacity != value);
    84         overbookedCapacity = value;
    85         if (changed) OnPropertyChanged("OverbookedCapacity");
     49        if (evaluation == value) return;
     50        evaluation = value;
     51        OnPropertyChanged(nameof(Evaluation));
    8652      }
    8753    }
     
    9258      : base(original, cloner) {
    9359      assignment = cloner.Clone(original.assignment);
    94       quality = cloner.Clone(original.quality);
    95       flowDistanceQuality = cloner.Clone(original.flowDistanceQuality);
    96       installationQuality = cloner.Clone(original.installationQuality);
    97       overbookedCapacity = cloner.Clone(original.overbookedCapacity);
     60      evaluation = cloner.Clone(original.evaluation);
    9861    }
    99     public GQAPSolution(IntegerVector assignment, DoubleValue quality, DoubleValue flowDistanceQuality, DoubleValue installationQuality, DoubleValue overbookedCapacity)
     62    public GQAPSolution(IntegerVector assignment, Evaluation evaluation)
    10063      : base() {
    10164      this.assignment = assignment;
    102       this.quality = quality;
    103       this.flowDistanceQuality = flowDistanceQuality;
    104       this.installationQuality = installationQuality;
    105       this.overbookedCapacity = overbookedCapacity;
     65      this.evaluation = evaluation;
    10666    }
    10767
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.csproj

    r15492 r15504  
    9898  </ItemGroup>
    9999  <ItemGroup>
    100     <Compile Include="Analyzers\BestGQAPSolutionAnalyzer.cs" />
    101     <Compile Include="Analyzers\GQAPSolutionArchiveUpdater.cs" />
    102     <Compile Include="Analyzers\GQAPPopulationDiversityAnalyzer.cs" />
    103     <Compile Include="Analyzers\GQAPSolutionArchiveAnalyzer.cs" />
    104     <Compile Include="Evaluators\GQAPPenaltyLevelEvaluator.cs" />
    105     <Compile Include="Evaluators\GQAPEvaluator.cs" />
    106     <Compile Include="Evaluators\GQAPNMoveEvaluator.cs" />
     100    <Compile Include="Evaluation\Evaluation.cs" />
     101    <Compile Include="Evaluation\GQAPNMoveEvaluator.cs" />
    107102    <Compile Include="GQAPAssignment.cs" />
    108     <Compile Include="Interfaces\IEvaluatorAwareGQAPOperator.cs" />
     103    <Compile Include="GQAPInstance.cs" />
    109104    <Compile Include="Operators\Crossovers\CordeauCrossover.cs" />
    110105    <Compile Include="SolutionCreators\SlackMinimizationSolutionCreator.cs" />
     
    113108    <Compile Include="SolutionCreators\GQAPStochasticSolutionCreator.cs" />
    114109    <Compile Include="SolutionCreators\GreedyRandomizedSolutionCreator.cs" />
    115     <Compile Include="SolutionCreators\RandomSolutionCreator.cs" />
    116110    <None Include="Plugin.cs.frame" />
    117     <Compile Include="Evaluators\GQAPAdditivePenaltyEvaluator.cs" />
    118     <Compile Include="GeneralizedQuadraticAssignmentProblem.cs" />
     111    <Compile Include="GQAP.cs" />
    119112    <Compile Include="GQAPAssignmentArchive.cs" />
    120113    <Compile Include="GQAPSolution.cs" />
    121     <Compile Include="Interfaces\IBestKnownSolutionsAwareGQAPOperator.cs" />
    122     <Compile Include="Interfaces\IGQAPManipulator.cs" />
    123     <Compile Include="Interfaces\IQualitiesAwareGQAPOperator.cs" />
    124     <Compile Include="Interfaces\IAssignmentsAwareGQAPOperator.cs" />
    125     <Compile Include="Interfaces\IBestKnownQualityAwareGQAPOperator.cs" />
    126     <Compile Include="Interfaces\IBestKnownSolutionAwareGQAPOperator.cs" />
    127     <Compile Include="Interfaces\ILocationNamesAwareGQAPOperator.cs" />
    128     <Compile Include="Interfaces\IEquipmentNamesAwareGQAPOperator.cs" />
    129     <Compile Include="Interfaces\IMoveQualityAwareGQAPOperator.cs" />
    130     <Compile Include="Interfaces\IGQAPEvaluator.cs" />
    131     <Compile Include="Interfaces\IQualityAwareGQAPOperator.cs" />
    132     <Compile Include="Interfaces\IExpectedRandomQualityAwareGQAPOperator.cs" />
    133     <Compile Include="Interfaces\ITransportationCostsAwareGQAPOperator.cs" />
    134     <Compile Include="Interfaces\IInstallationCostsAwareGQAPOperator.cs" />
    135     <Compile Include="Interfaces\IDistancesAwareGQAPOperator.cs" />
    136     <Compile Include="Interfaces\IWeightsAwareGQAPOperator.cs" />
    137     <Compile Include="Interfaces\IAssignmentAwareGQAPOperator.cs" />
    138     <Compile Include="Interfaces\IGQAPNMoveEvaluator.cs" />
    139     <Compile Include="Interfaces\IDemandsAwareGQAPOperator.cs" />
    140     <Compile Include="Interfaces\IGQAPCrossover.cs" />
    141     <Compile Include="Interfaces\IGQAPLocalImprovementOperator.cs" />
    142     <Compile Include="Interfaces\IGQAPMoveEvaluator.cs" />
    143     <Compile Include="Interfaces\IGQAPMoveOperator.cs" />
    144     <Compile Include="Interfaces\IGQAPNMoveOperator.cs" />
    145     <Compile Include="Interfaces\IGQAPOperator.cs" />
    146     <Compile Include="Interfaces\IGQAPSolutionCreator.cs" />
    147     <Compile Include="Interfaces\ICapacitiesAwareGQAPOperator.cs" />
     114    <Compile Include="Interfaces\Parameter\IBestKnownSolutionsAwareGQAPOperator.cs" />
     115    <Compile Include="Interfaces\Operator\IGQAPManipulator.cs" />
     116    <Compile Include="Interfaces\Parameter\IQualitiesAwareGQAPOperator.cs" />
     117    <Compile Include="Interfaces\Parameter\IBestKnownQualityAwareGQAPOperator.cs" />
     118    <Compile Include="Interfaces\Parameter\IBestKnownSolutionAwareGQAPOperator.cs" />
     119    <Compile Include="Interfaces\Parameter\IMoveQualityAwareGQAPOperator.cs" />
     120    <Compile Include="Interfaces\Parameter\IQualityAwareGQAPOperator.cs" />
     121    <Compile Include="Interfaces\Parameter\IProblemInstanceAwareGQAPOperator.cs" />
     122    <Compile Include="Interfaces\Operator\IGQAPNMoveEvaluator.cs" />
     123    <Compile Include="Interfaces\Operator\IGQAPCrossover.cs" />
     124    <Compile Include="Interfaces\Operator\IGQAPLocalImprovementOperator.cs" />
     125    <Compile Include="Interfaces\Operator\IGQAPMoveEvaluator.cs" />
     126    <Compile Include="Interfaces\Operator\IGQAPMoveOperator.cs" />
     127    <Compile Include="Interfaces\Operator\IGQAPNMoveOperator.cs" />
     128    <Compile Include="Interfaces\Operator\IGQAPOperator.cs" />
     129    <Compile Include="Interfaces\Operator\IGQAPSolutionCreator.cs" />
    148130    <Compile Include="Moves\NMove.cs" />
    149131    <Compile Include="Moves\GQAPMoveGenerator.cs" />
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPCrossover.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPLocalImprovementOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Data;
     24using HeuristicLab.Encodings.IntegerVectorEncoding;
    2425using HeuristicLab.Optimization;
    2526
     
    2728  public interface IGQAPLocalImprovementOperator : ILocalImprovementAlgorithmOperator {
    2829    IValueLookupParameter<IntValue> MaximumCandidateListSizeParameter { get; }
     30    ILookupParameter<IntegerVector> AssignmentParameter { get; }
    2931  }
    3032}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPManipulator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using HeuristicLab.Core;
     23using HeuristicLab.Encodings.IntegerVectorEncoding;
    2224using HeuristicLab.Optimization;
    2325
    2426namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    25   public interface IGQAPManipulator : IAssignmentAwareGQAPOperator, IManipulator { }
     27  public interface IGQAPManipulator : IManipulator {
     28    ILookupParameter<IntegerVector> AssignmentParameter { get; }
     29  }
    2630}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPMoveEvaluator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using HeuristicLab.Core;
    23 using HeuristicLab.Data;
    2423using HeuristicLab.Optimization;
    2524
    2625namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    2726  public interface IGQAPMoveEvaluator : IGQAPMoveOperator, ISingleObjectiveMoveEvaluator {
    28     ILookupParameter<BoolValue> MaximizationParameter { get; }
    29     ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter { get; }
    30     ILookupParameter<DoubleValue> MoveInstallationQualityParameter { get; }
    31     ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter { get; }
     27    ILookupParameter<Evaluation> MoveEvaluationParameter { get; }
    3228  }
    3329}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPMoveOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using HeuristicLab.Core;
     23using HeuristicLab.Encodings.IntegerVectorEncoding;
    2224using HeuristicLab.Optimization;
    2325
    2426namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    25   public interface IGQAPMoveOperator : IMoveOperator { }
     27  public interface IGQAPMoveOperator : IMoveOperator {
     28    ILookupParameter<IntegerVector> AssignmentParameter { get; }
     29  }
    2630}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPNMoveEvaluator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPNMoveOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPSolutionCreator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
    22 using HeuristicLab.Core;
    2322using HeuristicLab.Encodings.IntegerVectorEncoding;
    24 using HeuristicLab.Optimization;
    2523
    2624namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    27   public interface IGQAPSolutionCreator : ISolutionCreator {
    28     ILookupParameter<IntegerVector> AssignmentParameter { get; }
    29   }
     25  public interface IGQAPSolutionCreator : IIntegerVectorCreator {  }
    3026}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IBestKnownQualityAwareGQAPOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IBestKnownSolutionAwareGQAPOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IBestKnownSolutionsAwareGQAPOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IMoveQualityAwareGQAPOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    2626  public interface IMoveQualityAwareGQAPOperator : IGQAPMoveOperator {
    27     ILookupParameter<BoolValue> MaximizationParameter { get; }
    2827    ILookupParameter<DoubleValue> MoveQualityParameter { get; }
    29     ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter { get; }
    30     ILookupParameter<DoubleValue> MoveInstallationQualityParameter { get; }
    31     ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter { get; }
     28    ILookupParameter<Evaluation> MoveEvaluationParameter { get; }
    3229  }
    3330}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IProblemInstanceAwareGQAPOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using HeuristicLab.Core;
    23 using HeuristicLab.Data;
    2423
    2524namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    26   public interface IExpectedRandomQualityAwareGQAPOperator : IGQAPOperator {
    27     IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { get; }
     25  public interface IProblemInstanceAwareGQAPOperator : IGQAPOperator {
     26    ILookupParameter<GQAPInstance> ProblemInstanceParameter { get; }
    2827  }
    2928}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IQualitiesAwareGQAPOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    2626  public interface IQualitiesAwareGQAPOperator : IGQAPOperator {
    27     ILookupParameter<BoolValue> MaximizationParameter { get; }
    2827    IScopeTreeLookupParameter<DoubleValue> QualityParameter { get; }
    29     IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter { get; }
    30     IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter { get; }
    31     IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter { get; }
     28    IScopeTreeLookupParameter<Evaluation> EvaluationParameter { get; }
    3229  }
    3330}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IQualityAwareGQAPOperator.cs

    r15503 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    2626  public interface IQualityAwareGQAPOperator : IGQAPOperator {
    27     ILookupParameter<BoolValue> MaximizationParameter { get; }
    2827    ILookupParameter<DoubleValue> QualityParameter { get; }
    29     ILookupParameter<DoubleValue> FlowDistanceQualityParameter { get; }
    30     ILookupParameter<DoubleValue> InstallationQualityParameter { get; }
    31     ILookupParameter<DoubleValue> OverbookedCapacityParameter { get; }
     28    ILookupParameter<Evaluation> EvaluationParameter { get; }
    3229  }
    3330}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/GQAPMoveGenerator.cs

    r7419 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3131  [Item("GQAPMoveGenerator", "Base class for move generators for the Generalized Quadratic Assignment Problem.")]
    3232  [StorableClass]
    33   public abstract class GQAPMoveGenerator : SingleSuccessorOperator, IAssignmentAwareGQAPOperator, IMoveGenerator, IGQAPMoveOperator {
     33  public abstract class GQAPMoveGenerator : SingleSuccessorOperator, IMoveGenerator, IGQAPMoveOperator,
     34    IProblemInstanceAwareGQAPOperator {
    3435
    3536    public ILookupParameter<IntegerVector> AssignmentParameter {
    3637      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
     38    }
     39
     40
     41    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     42      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
    3743    }
    3844
     
    4349      : base() {
    4450      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
     51      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
    4552    }
    4653  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/GQAPNMoveGenerator.cs

    r7505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    5858      int counter = 0;
    5959      string name = MoveParameter.TranslatedName;
    60       foreach (var move in GenerateMoves(AssignmentParameter.ActualValue, NParameter.ActualValue.Value)) {
     60      foreach (var move in GenerateMoves(AssignmentParameter.ActualValue, NParameter.ActualValue.Value, ProblemInstanceParameter.ActualValue)) {
    6161        scopes.Add(new Scope(counter.ToString()));
    6262        scopes.Last().Variables.Add(new Variable(name, move));
     
    6767    }
    6868
    69     public abstract IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n);
     69    public abstract IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n, GQAPInstance problemInstance);
    7070  }
    7171}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMove.cs

    r7505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveAbsoluteAttribute.cs

    r7505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveMaker.cs

    r7505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3232  [Item("N-Move Maker", "Performs an N-Move.")]
    3333  [StorableClass]
    34   public class NMoveMaker : SingleSuccessorOperator, IAssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {
     34  public class NMoveMaker : SingleSuccessorOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {
    3535
    3636    public ILookupParameter<IntegerVector> AssignmentParameter {
     
    4040      get { return (ILookupParameter<NMove>)Parameters["Move"]; }
    4141    }
    42     ILookupParameter<BoolValue> IQualityAwareGQAPOperator.MaximizationParameter {
    43       get { return MaximizationParameter; }
    44     }
    45     ILookupParameter<BoolValue> IMoveQualityAwareGQAPOperator.MaximizationParameter {
    46       get { return MaximizationParameter; }
    47     }
    48     public ILookupParameter<BoolValue> MaximizationParameter {
    49       get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    50     }
    5142    public ILookupParameter<DoubleValue> QualityParameter {
    5243      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    5344    }
    54     public ILookupParameter<DoubleValue> FlowDistanceQualityParameter {
    55       get { return (ILookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
    56     }
    57     public ILookupParameter<DoubleValue> InstallationQualityParameter {
    58       get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
    59     }
    60     public ILookupParameter<DoubleValue> OverbookedCapacityParameter {
    61       get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
     45    public ILookupParameter<Evaluation> EvaluationParameter {
     46      get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; }
    6247    }
    6348    public ILookupParameter<DoubleValue> MoveQualityParameter {
    6449      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    6550    }
    66     public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter {
    67       get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; }
    68     }
    69     public ILookupParameter<DoubleValue> MoveInstallationQualityParameter {
    70       get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; }
    71     }
    72     public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter {
    73       get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; }
     51    public ILookupParameter<Evaluation> MoveEvaluationParameter {
     52      get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; }
    7453    }
    7554
     
    8160      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
    8261      Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
    83       Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
    84       Parameters.Add(new LookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
    85       Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
    86       Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
    87       Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
     62      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
     63      Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
    8864      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
    89       Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", GQAPNMoveEvaluator.MoveFlowDistanceQualityDescription));
    90       Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", GQAPNMoveEvaluator.MoveInstallationQualityDescription));
    91       Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", GQAPNMoveEvaluator.MoveOverbookedCapacityDescription));
     65      Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription));
    9266    }
    9367
     
    10478      Apply(AssignmentParameter.ActualValue, MoveParameter.ActualValue);
    10579      QualityParameter.ActualValue.Value = MoveQualityParameter.ActualValue.Value;
    106       FlowDistanceQualityParameter.ActualValue.Value = MoveFlowDistanceQualityParameter.ActualValue.Value;
    107       InstallationQualityParameter.ActualValue.Value = MoveInstallationQualityParameter.ActualValue.Value;
    108       OverbookedCapacityParameter.ActualValue.Value = MoveOverbookedCapacityParameter.ActualValue.Value;
     80      EvaluationParameter.ActualValue = MoveEvaluationParameter.ActualValue;
    10981      return base.Apply();
    11082    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveTabuChecker.cs

    r7505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3333  [StorableClass]
    3434  public class NMoveTabuChecker : SingleSuccessorOperator, ITabuChecker,
    35     IAssignmentAwareGQAPOperator, IGQAPNMoveOperator, IMoveQualityAwareGQAPOperator {
     35    IGQAPNMoveOperator, IMoveQualityAwareGQAPOperator {
    3636    public override bool CanChangeName {
    3737      get { return false; }
     38    }
     39    public IValueLookupParameter<BoolValue> MaximizationParameter {
     40      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    3841    }
    3942    public ILookupParameter<NMove> MoveParameter {
     
    4952      get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; }
    5053    }
    51     public IValueLookupParameter<BoolValue> MaximizationParameter {
    52       get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    53     }
    54     ILookupParameter<BoolValue> IMoveQualityAwareGQAPOperator.MaximizationParameter {
    55       get { return MaximizationParameter; }
    56     }
    5754    public ILookupParameter<DoubleValue> MoveQualityParameter {
    5855      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    5956    }
    60     public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter {
    61       get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; }
    62     }
    63     public ILookupParameter<DoubleValue> MoveInstallationQualityParameter {
    64       get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; }
    65     }
    66     public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter {
    67       get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; }
     57    public ILookupParameter<Evaluation> MoveEvaluationParameter {
     58      get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; }
    6859    }
    6960    public IValueParameter<BoolValue> UseAspirationCriterionParameter {
     
    8172    public NMoveTabuChecker()
    8273      : base() {
     74      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", ""));
    8375      Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
    8476      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
    8577      Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list contains previous move attributes."));
    8678      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "Declares if a move is tabu or not."));
    87       Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    8879      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
    89       Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", GQAPNMoveEvaluator.MoveFlowDistanceQualityDescription));
    90       Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", GQAPNMoveEvaluator.MoveInstallationQualityDescription));
    91       Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", GQAPNMoveEvaluator.MoveOverbookedCapacityDescription));
     80      Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription));
    9281      Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether moves can be aspired.", new BoolValue(true)));
    9382    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveTabuMaker.cs

    r7505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.IntegerVectorEncoding;
    2625using HeuristicLab.Optimization.Operators;
     
    3130  [Item("N-Move TabuMaker", "Declares an N-Move tabu.")]
    3231  [StorableClass]
    33   public class NMoveTabuMaker : TabuMaker, IGQAPNMoveOperator, IAssignmentAwareGQAPOperator,
    34     IMoveQualityAwareGQAPOperator {
     32  public class NMoveTabuMaker : TabuMaker, IGQAPNMoveOperator, IMoveQualityAwareGQAPOperator {
    3533
    3634    public ILookupParameter<IntegerVector> AssignmentParameter {
     
    4038      get { return (ILookupParameter<NMove>)Parameters["Move"]; }
    4139    }
    42     ILookupParameter<BoolValue> IMoveQualityAwareGQAPOperator.MaximizationParameter {
    43       get { return (ILookupParameter<BoolValue>)MaximizationParameter; }
    44     }
    45     public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter {
    46       get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; }
    47     }
    48     public ILookupParameter<DoubleValue> MoveInstallationQualityParameter {
    49       get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; }
    50     }
    51     public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter {
    52       get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; }
     40    public ILookupParameter<Evaluation> MoveEvaluationParameter {
     41      get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; }
    5342    }
    5443
     
    6049      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
    6150      Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
    62       Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", GQAPNMoveEvaluator.MoveFlowDistanceQualityDescription));
    63       Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", GQAPNMoveEvaluator.MoveInstallationQualityDescription));
    64       Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", GQAPNMoveEvaluator.MoveOverbookedCapacityDescription));
     51      Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription));
    6552    }
    6653
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/StochasticNMoveMultiMoveGenerator.cs

    r7505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3232  [Item("Stochastic N-Move MultiMoveGenerator", "Randomly samples a number of N-Moves.")]
    3333  [StorableClass]
    34   public class StochasticNMoveMultiMoveGenerator : GQAPNMoveGenerator, ICapacitiesAwareGQAPOperator, IStochasticOperator, IMultiMoveGenerator {
    35 
    36     public ILookupParameter<DoubleArray> CapacitiesParameter {
    37       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    38     }
     34  public class StochasticNMoveMultiMoveGenerator : GQAPNMoveGenerator, IStochasticOperator, IMultiMoveGenerator {
     35   
    3936    public ILookupParameter<IRandom> RandomParameter {
    4037      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     
    5047      : base() {
    5148      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator that should be used."));
    52       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    5349      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
    5450    }
     
    5854    }
    5955
    60     public static IEnumerable<NMove> Generate(IRandom random, IntegerVector assignment, int n, DoubleArray capacities, int sampleSize) {
     56    public static IEnumerable<NMove> Generate(IRandom random, IntegerVector assignment, int n, GQAPInstance problemInstance, int sampleSize) {
    6157      for (int i = 0; i < sampleSize; i++)
    62         yield return StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, n, capacities);
     58        yield return StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, n, problemInstance.Capacities);
    6359    }
    6460
    65     public override IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n) {
    66       return Generate(RandomParameter.ActualValue, assignment, n, CapacitiesParameter.ActualValue, SampleSizeParameter.ActualValue.Value);
     61    public override IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n, GQAPInstance problemInstance) {
     62      return Generate(RandomParameter.ActualValue, assignment, n, problemInstance, SampleSizeParameter.ActualValue.Value);
    6763    }
    6864  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/StochasticNMoveSingleMoveGenerator.cs

    r7505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3232  [Item("Stochastic N-Move SingleMoveGenerator", "Randomly samples a single N-Move.")]
    3333  [StorableClass]
    34   public class StochasticNMoveSingleMoveGenerator : GQAPNMoveGenerator, ICapacitiesAwareGQAPOperator, IStochasticOperator, ISingleMoveGenerator {
    35 
    36     public ILookupParameter<DoubleArray> CapacitiesParameter {
    37       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    38     }
     34  public class StochasticNMoveSingleMoveGenerator : GQAPNMoveGenerator, IStochasticOperator, ISingleMoveGenerator {
     35   
    3936    public ILookupParameter<IRandom> RandomParameter {
    4037      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     
    4744      : base() {
    4845      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator that should be used."));
    49       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    5046    }
    5147
     
    7369    }
    7470
    75     public override IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n) {
    76       yield return GenerateUpToN(RandomParameter.ActualValue, assignment, n, CapacitiesParameter.ActualValue);
     71    public override IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n, GQAPInstance problemInstance) {
     72      yield return GenerateUpToN(RandomParameter.ActualValue, assignment, n, problemInstance.Capacities);
    7773    }
    7874  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/CordeauCrossover.cs

    r15490 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3434  [StorableClass]
    3535  public class CordeauCrossover : GQAPCrossover,
    36     IQualitiesAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator,
    37     IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator,
    38     IExpectedRandomQualityAwareGQAPOperator {
     36    IQualitiesAwareGQAPOperator, IProblemInstanceAwareGQAPOperator {
    3937
    4038    public ILookupParameter<BoolValue> MaximizationParameter {
     
    4442      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    4543    }
    46     public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter {
    47       get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
    48     }
    49     public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter {
    50       get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
    51     }
    52     public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter {
    53       get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
    54     }
    55     public ILookupParameter<DoubleMatrix> WeightsParameter {
    56       get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
    57     }
    58     public ILookupParameter<DoubleMatrix> DistancesParameter {
    59       get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
    60     }
    61     public ILookupParameter<DoubleMatrix> InstallationCostsParameter {
    62       get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
    63     }
    64     public ILookupParameter<DoubleArray> DemandsParameter {
    65       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
    66     }
    67     public ILookupParameter<DoubleArray> CapacitiesParameter {
    68       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    69     }
    70     public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
    71       get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
    72     }
    73     public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter {
    74       get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }
    75     }
    76     public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
    77       get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
     44    public IScopeTreeLookupParameter<Evaluation> EvaluationParameter {
     45      get { return (IScopeTreeLookupParameter<Evaluation>)Parameters["Evaluation"]; }
    7846    }
    7947    public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
     
    8856    public CordeauCrossover()
    8957      : base() {
    90       Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
    91       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription, 1));
    92       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription, 1));
    93       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription, 1));
    94       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription, 1));
    95       Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
    96       Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
    97       Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
    98       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    99       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    100       Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
    101       Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription));
    102       Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator used to evaluate solutions."));
     58      Parameters.Add(new LookupParameter<BoolValue>("Maximization", ""));
     59      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parents", 1));
     60      Parameters.Add(new ScopeTreeLookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription, 1));
    10361      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions."));
    10462    }
     
    10866    }
    10967
    110     public static IntegerVector Apply(IRandom random, BoolValue maximization,
     68    public static IntegerVector Apply(IRandom random, bool maximization,
    11169      IntegerVector parent1, DoubleValue quality1,
    11270      IntegerVector parent2, DoubleValue quality2,
    113       DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts,
    114       DoubleArray demands, DoubleArray capacities,
    115       double transportationCosts, double expectedRandomQuality, IGQAPEvaluator evaluator, IntValue evaluatedSolutions) {
     71      GQAPInstance problemInstance, IntValue evaluatedSolutions) {
     72      var distances = problemInstance.Distances;
     73      var capacities = problemInstance.Capacities;
     74      var demands = problemInstance.Demands;
     75
    11676      var medianDistances = Enumerable.Range(0, distances.Rows).Select(x => distances.GetRow(x).Median()).ToArray();
    11777
     
    12080     
    12181      bool onefound = false;
    122       double fbest, fbestAttempt = maximization.Value ? double.MinValue : double.MaxValue;
     82      double fbest, fbestAttempt = maximization ? double.MinValue : double.MaxValue;
    12383      IntegerVector bestAttempt = null;
    12484      IntegerVector result = null;
    12585
    12686      fbest = quality1.Value;
    127       if (maximization.Value && quality1.Value < quality2.Value
    128         || !maximization.Value && quality1.Value > quality2.Value) {
     87      if (maximization && quality1.Value < quality2.Value
     88        || !maximization && quality1.Value > quality2.Value) {
    12989        var temp = parent1;
    13090        parent1 = parent2;
     
    140100          TryRandomAssignment(random, demands, capacities, m, n, cap, child, ref unassigned);
    141101        if (unassigned == 0) {
    142           var childFit = evaluator.Evaluate(child, weights, distances, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality);
     102          var childFit = problemInstance.ToSingleObjective(problemInstance.Evaluate(child));
    143103          evaluatedSolutions.Value++;
    144           if (maximization.Value && childFit >= fbest
    145             || !maximization.Value && childFit <= fbest) {
     104          if (maximization && childFit >= fbest
     105            || !maximization && childFit <= fbest) {
    146106            fbest = childFit;
    147107            result = child;
    148108            onefound = true;
    149109          }
    150           if (!onefound && (maximization.Value && fbestAttempt < childFit || !maximization.Value && fbestAttempt > childFit)) {
     110          if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) {
    151111            bestAttempt = child;
    152112            fbestAttempt = childFit;
     
    162122        RandomAssignment(random, demands, capacities, m, n, cap, child, ref unassigned);
    163123
    164         var childFit = evaluator.Evaluate(child, weights, distances, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality);
     124        var childFit = problemInstance.ToSingleObjective(problemInstance.Evaluate(child));
    165125        evaluatedSolutions.Value++;
    166126        if (childFit < fbest) {
     
    170130        }
    171131
    172         if (!onefound && (maximization.Value && fbestAttempt < childFit || !maximization.Value && fbestAttempt > childFit)) {
     132        if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) {
    173133          bestAttempt = child;
    174134          fbestAttempt = childFit;
     
    237197    }
    238198
    239     protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) {
     199    protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents,
     200      GQAPInstance problemInstance) {
    240201      if (parents == null) throw new ArgumentNullException("parents");
    241202      if (parents.Length != 2) throw new ArgumentException(Name + " works only with exactly two parents.");
    242203
    243204      var qualities = QualityParameter.ActualValue;
    244       return Apply(random, MaximizationParameter.ActualValue,
     205      return Apply(random, MaximizationParameter.ActualValue.Value,
    245206        parents[0], qualities[0],
    246207        parents[1], qualities[1],
    247         WeightsParameter.ActualValue, DistancesParameter.ActualValue, InstallationCostsParameter.ActualValue,
    248         DemandsParameter.ActualValue, CapacitiesParameter.ActualValue,
    249         TransportationCostsParameter.ActualValue.Value, ExpectedRandomQualityParameter.ActualValue.Value,
    250         EvaluatorParameter.ActualValue, EvaluatedSolutionsParameter.ActualValue);
     208        problemInstance,
     209        EvaluatedSolutionsParameter.ActualValue);
    251210    }
    252211  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/DiscreteLocationCrossover.cs

    r7813 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Encodings.IntegerVectorEncoding;
    28 using HeuristicLab.Parameters;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3029using HeuristicLab.Random;
     
    3332  [Item("DiscreteLocationCrossover", "Combines the assignment to locations from various parents.")]
    3433  [StorableClass]
    35   public class DiscreteLocationCrossover : GQAPCrossover, ICapacitiesAwareGQAPOperator {
    36 
    37     public ILookupParameter<DoubleArray> CapacitiesParameter {
    38       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    39     }
     34  public class DiscreteLocationCrossover : GQAPCrossover {
    4035
    4136    [StorableConstructor]
     
    4540    public DiscreteLocationCrossover()
    4641      : base() {
    47       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    4842    }
    4943
     
    8882    }
    8983
    90     protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) {
    91       return Apply(random, parents, CapacitiesParameter.ActualValue);
     84    protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents,
     85      GQAPInstance problemInstance) {
     86      return Apply(random, parents, problemInstance.Capacities);
    9287    }
    9388  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/GQAPCrossover.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4646      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    4747    }
     48    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     49      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
     50    }
    4851
    4952    [StorableConstructor]
     
    5558      Parameters.Add(new LookupParameter<IntegerVector>("Child", "The child vector resulting from the crossover.", "Assignment"));
    5659      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators."));
     60      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
    5761    }
    5862
    5963    public sealed override IOperation Apply() {
    60       ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
     64      ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue, ProblemInstanceParameter.ActualValue);
    6165      return base.Apply();
    6266    }
    6367
    64     protected abstract IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents);
     68    protected abstract IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents, GQAPInstance problemInstance);
    6569  }
    6670}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/GQAPPathRelinking.cs

    r15492 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3434  [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.")]
    3535  [StorableClass]
    36   public class GQAPPathRelinking : GQAPCrossover, IQualitiesAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator,
    37   IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, ITransportationCostsAwareGQAPOperator,
    38   IExpectedRandomQualityAwareGQAPOperator, IEvaluatorAwareGQAPOperator {
     36  public class GQAPPathRelinking : GQAPCrossover, IQualitiesAwareGQAPOperator {
    3937
    40     public ILookupParameter<BoolValue> MaximizationParameter {
    41       get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    42     }
    4338    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
    4439      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    4540    }
    46     public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter {
    47       get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
    48     }
    49     public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter {
    50       get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
    51     }
    52     public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter {
    53       get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
    54     }
    55     public ILookupParameter<DoubleArray> DemandsParameter {
    56       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
    57     }
    58     public ILookupParameter<DoubleArray> CapacitiesParameter {
    59       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    60     }
    61     public ILookupParameter<DoubleMatrix> WeightsParameter {
    62       get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
    63     }
    64     public ILookupParameter<DoubleMatrix> DistancesParameter {
    65       get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
    66     }
    67     public ILookupParameter<DoubleMatrix> InstallationCostsParameter {
    68       get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
    69     }
    70     public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
    71       get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
    72     }
    73     public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter {
    74       get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }
    75     }
    76     public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
    77       get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
     41    public IScopeTreeLookupParameter<Evaluation> EvaluationParameter {
     42      get { return (IScopeTreeLookupParameter<Evaluation>)Parameters["Evaluation"]; }
    7843    }
    7944
     
    8752    public GQAPPathRelinking()
    8853      : base() {
    89       Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
    90       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
    91       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
    92       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
    93       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
    94       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    95       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    96       Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
    97       Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
    98       Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
    99       Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
    100       Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription));
    101       Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));
     54      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", ""));
     55      Parameters.Add(new ScopeTreeLookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
    10256      Parameters.Add(new ValueParameter<PercentValue>("CandidateSizeFactor", "(η) Determines the size of the set of feasible moves in each path-relinking step relative to the maximum size. A value of 50% means that only half of all possible moves are considered each step.", new PercentValue(0.5)));
    10357    }
     
    10761    }
    10862
    109     public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents, BoolValue maximization, ItemArray<DoubleValue> qualities,
    110       ItemArray<DoubleValue> flowDistanceQualities, ItemArray<DoubleValue> installationQualities, ItemArray<DoubleValue> overbookedCapacities,
    111       DoubleArray demands, DoubleArray capacities, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts,
    112       DoubleValue transportationCosts, DoubleValue expectedRandomQuality, DoubleValue candidateSizeFactor, IGQAPEvaluator evaluator) {
     63    public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents, ItemArray<DoubleValue> qualities,
     64      GQAPInstance problemInstance, double candidateSizeFactor) {
    11365      if (random == null) throw new ArgumentNullException("random", "No IRandom provider is given.");
    11466      if (parents == null || !parents.Any()) throw new ArgumentException("No parents given for path relinking.", "parents");
     
    11769      if (qualities == null || qualities.Length == 0) throw new ArgumentException("The qualities are not given.", "qualities");
    11870      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()));
    119 
     71     
    12072      var source = parents[0];
    12173      var target = parents[1];
    12274      IntegerVector result;
    123       double resultQuality, resultFDQ, resultIQ, resultOC;
     75      double resultQuality;
    12476
    125       int betterParent = 1;
    126       if ((maximization.Value && qualities[0].Value >= qualities[1].Value)
    127         || (!maximization.Value && qualities[0].Value <= qualities[1].Value))
    128         betterParent = 0;
     77      int betterParent = (qualities[0].Value <= qualities[1].Value) ? 0 : 1;
    12978
    13079      result = (IntegerVector)parents[betterParent].Clone();
    13180      resultQuality = qualities[betterParent].Value;
    132       resultFDQ = flowDistanceQualities[betterParent].Value;
    133       resultIQ = installationQualities[betterParent].Value;
    134       resultOC = overbookedCapacities[betterParent].Value;
     81
     82      var demands = problemInstance.Demands;
     83      var capacities = problemInstance.Capacities;
     84
     85      var cmp = new IntegerVectorEqualityComparer();
    13586
    13687      var pi_prime = (IntegerVector)source.Clone();
     
    14091
    14192      while (phi.Any()) {
    142         var B = new List<GQAPSolution>();
     93        var B = new List<Tuple<GQAPSolution, double>>();
    14394        foreach (var v in phi) {
    14495          int oldLocation = pi_prime[v];
    14596          pi_prime[v] = target[v];
    146           var pi2 = makeFeasible(random, pi_prime, v, nonFix, demands, capacities);
     97          var pi2 = MakeFeasible(random, pi_prime, v, nonFix, demands, capacities);
    14798          pi_prime[v] = oldLocation;
    14899
    149           double currentFDQ, currentIQ, currentOC;
    150           evaluator.Evaluate(pi2, weights, distances, installationCosts, demands, capacities,
    151             out currentFDQ, out currentIQ, out currentOC);
     100          var currentEval = problemInstance.Evaluate(pi2);
    152101
    153           if (currentOC <= 0.0) {
    154             var quality = evaluator.GetFitness(currentFDQ, currentIQ, currentOC,
    155               transportationCosts.Value, expectedRandomQuality.Value);
    156             var solution = new GQAPSolution(pi2, new DoubleValue(quality), new DoubleValue(currentFDQ),
    157               new DoubleValue(currentIQ), new DoubleValue(currentOC));
    158             if (B.Count >= candidateSizeFactor.Value * phi.Count) {
     102          if (currentEval.ExcessDemand <= 0.0) {
     103            var quality = problemInstance.ToSingleObjective(currentEval);
     104
     105            var solution = new GQAPSolution(pi2, currentEval);
     106            if (B.Count >= candidateSizeFactor * phi.Count) {
    159107              int mostSimilarIndex = -1;
    160108              double mostSimilarValue = 1.0;
    161109              for (int i = 0; i < B.Count; i++) {
    162                 if (IsBetter(maximization.Value, solution.Quality.Value, B[i].Quality.Value)) {
    163                   var similarity = HammingSimilarityCalculator.CalculateSimilarity(solution.Assignment, B[i].Assignment);
     110                if (quality < B[i].Item2) {
     111                  var similarity = HammingSimilarityCalculator.CalculateSimilarity(solution.Assignment, B[i].Item1.Assignment);
    164112                  if (similarity == 1.0) {
    165113                    mostSimilarIndex = -1;
     
    172120              }
    173121              if (mostSimilarIndex >= 0)
    174                 B[mostSimilarIndex] = solution;
     122                B[mostSimilarIndex] = Tuple.Create(solution, quality);
    175123            } else {
    176124              bool contains = false;
    177125              foreach (var b in B) {
    178                 if (!IntegerVectorEqualityComparer.GetDifferingIndices(solution.Assignment, b.Assignment).Any()) {
     126                if (cmp.Equals(solution.Assignment, b.Item1.Assignment)) {
    179127                  contains = true;
    180128                  break;
    181129                }
    182130              }
    183               if (!contains) B.Add(solution);
     131              if (!contains) B.Add(Tuple.Create(solution, quality));
    184132            }
    185133          }
    186134        }
    187135        if (B.Any()) {
    188           GQAPSolution pi;
    189           if (maximization.Value) pi = B.SampleProportional(random, 1, B.Select(x => x.Quality.Value), false).First();
    190           else pi = B.SampleProportional(random, 1, B.Select(x => 1.0 / x.Quality.Value), false).First();
    191           var diff = IntegerVectorEqualityComparer.GetDifferingIndices(pi.Assignment, target);
     136          var pi = B.SampleProportional(random, 1, B.Select(x => 1.0 / x.Item2), false).First();
     137          var diff = IntegerVectorEqualityComparer.GetDifferingIndices(pi.Item1.Assignment, target);
    192138          var I = phi.Except(diff);
    193139          var i = I.SampleRandom(random);
    194140          fix.Add(i);
    195141          nonFix.Remove(i);
    196           pi_prime = pi.Assignment;
    197           if (IsBetter(maximization.Value, pi.Quality.Value, resultQuality)) {
    198             result = pi.Assignment;
    199             resultQuality = pi.Quality.Value;
    200             resultFDQ = pi.FlowDistanceQuality.Value;
    201             resultIQ = pi.InstallationQuality.Value;
    202             resultOC = pi.OverbookedCapacity.Value;
     142          pi_prime = pi.Item1.Assignment;
     143          if (pi.Item2 < resultQuality) {
     144            result = pi.Item1.Assignment;
     145            resultQuality = pi.Item2;
    203146          }
    204147        } else return result;
     
    209152    }
    210153
    211     protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) {
    212       return Apply(random, parents, MaximizationParameter.ActualValue, QualityParameter.ActualValue, FlowDistanceQualityParameter.ActualValue,
    213         InstallationQualityParameter.ActualValue, OverbookedCapacityParameter.ActualValue, DemandsParameter.ActualValue,
    214         CapacitiesParameter.ActualValue, WeightsParameter.ActualValue, DistancesParameter.ActualValue,
    215         InstallationCostsParameter.ActualValue, TransportationCostsParameter.ActualValue,
    216         ExpectedRandomQualityParameter.ActualValue, CandidateSizeFactorParameter.Value,
    217         EvaluatorParameter.ActualValue);
     154    protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents,
     155      GQAPInstance problemInstance) {
     156      return Apply(random, parents, QualityParameter.ActualValue, problemInstance,
     157        CandidateSizeFactorParameter.Value.Value);
    218158    }
    219159
    220     private static IntegerVector makeFeasible(IRandom random, IntegerVector assignment, int equipment, HashSet<int> nonFix, DoubleArray demands, DoubleArray capacities, int maximumTries = 1000) {
     160    private static IntegerVector MakeFeasible(IRandom random, IntegerVector assignment, int equipment, HashSet<int> nonFix, DoubleArray demands, DoubleArray capacities, int maximumTries = 1000) {
    221161      int l = assignment[equipment];
    222162      var slack = ComputeSlack(assignment, demands, capacities);
     
    250190      return slack;
    251191    }
    252 
    253     private static bool IsBetter(bool maximization, double quality, double otherQuality) {
    254       return maximization && quality > otherQuality || !maximization && quality < otherQuality;
    255     }
    256192  }
    257193}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/MultiGQAPCrossover.cs

    r11505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  [Item("MultiGQAPCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
    3636  [StorableClass]
    37   public class MultiGQAPCrossover : StochasticMultiBranch<IGQAPCrossover>, IGQAPCrossover {
     37  public class MultiGQAPCrossover : StochasticMultiBranch<IGQAPCrossover>, IGQAPCrossover, IProblemInstanceAwareGQAPOperator, IStochasticOperator {
    3838    public override bool CanChangeName {
    3939      get { return false; }
     
    4949      get { return (ILookupParameter<IntegerVector>)Parameters["Child"]; }
    5050    }
     51    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     52      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
     53    }
    5154
    5255    [StorableConstructor]
     
    5760      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Parents", "The parent vectors which should be crossed.", "Assignment"));
    5861      Parameters.Add(new LookupParameter<IntegerVector>("Child", "The child vector resulting from the crossover.", "Assignment"));
     62      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
     63
    5964      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IGQAPCrossover))) {
    6065        if (!typeof(MultiOperator<IGQAPCrossover>).IsAssignableFrom(type))
     
    7984      foreach (var op in Operators.OfType<IGQAPCrossover>()) {
    8085        op.ParentsParameter.ActualName = ParentsParameter.Name;
     86        op.ParentsParameter.Hidden = true;
    8187        op.ChildParameter.ActualName = ChildParameter.Name;
     88        op.ChildParameter.Hidden = true;
    8289      }
    8390      foreach (var op in Operators.OfType<IStochasticOperator>()) {
    8491        op.RandomParameter.ActualName = RandomParameter.Name;
     92        op.RandomParameter.Hidden = true;
     93      }
     94      foreach (var op in Operators.OfType<IProblemInstanceAwareGQAPOperator>()) {
     95        op.ProblemInstanceParameter.ActualName = ProblemInstanceParameter.Name;
     96        op.ProblemInstanceParameter.Hidden = true;
    8597      }
    8698    }
     
    88100    public override IOperation InstrumentedApply() {
    89101      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one crossover to choose from.");
    90       return base.Apply();
     102      return base.InstrumentedApply();
    91103    }
    92104  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/LocalImprovers/ApproximateLocalSearch.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  [Item("ApproximateLocalSearch", "The approximate local search 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.")]
    3636  [StorableClass]
    37   public class ApproximateLocalSearch : SingleSuccessorOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator,
    38     IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator,
    39     ITransportationCostsAwareGQAPOperator, IExpectedRandomQualityAwareGQAPOperator,
    40     IAssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator,
    41     IEvaluatorAwareGQAPOperator, IStochasticOperator {
     37  public class ApproximateLocalSearch : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator,
     38    IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, IStochasticOperator {
    4239    public IProblem Problem { get; set; }
    4340    public Type ProblemType {
    44       get { return typeof(GeneralizedQuadraticAssignmentProblem); }
     41      get { return typeof(GQAP); }
    4542    }
    4643
    47     public ILookupParameter<DoubleArray> DemandsParameter {
    48       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
    49     }
    50     public ILookupParameter<DoubleArray> CapacitiesParameter {
    51       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    52     }
    53     public ILookupParameter<DoubleMatrix> WeightsParameter {
    54       get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
    55     }
    56     public ILookupParameter<DoubleMatrix> DistancesParameter {
    57       get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
    58     }
    59     public ILookupParameter<DoubleMatrix> InstallationCostsParameter {
    60       get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
    61     }
    62     public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
    63       get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
    64     }
    65     public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter {
    66       get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }
     44    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     45      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
    6746    }
    6847    public ILookupParameter<IntegerVector> AssignmentParameter {
    6948      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
    7049    }
    71     public ILookupParameter<BoolValue> MaximizationParameter {
    72       get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    73     }
    7450    public ILookupParameter<DoubleValue> QualityParameter {
    7551      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    7652    }
    77     public ILookupParameter<DoubleValue> FlowDistanceQualityParameter {
    78       get { return (ILookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
    79     }
    80     public ILookupParameter<DoubleValue> InstallationQualityParameter {
    81       get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
    82     }
    83     public ILookupParameter<DoubleValue> OverbookedCapacityParameter {
    84       get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
     53    public ILookupParameter<Evaluation> EvaluationParameter {
     54      get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; }
    8555    }
    8656    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     
    10272      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
    10373    }
    104     public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
    105       get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
    106     }
    10774
    10875    [StorableConstructor]
     
    11178    public ApproximateLocalSearch()
    11279      : base() {
    113       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    114       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    115       Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
    116       Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
    117       Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
    118       Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
    119       Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription));
     80      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
    12081      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
    121       Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
    122       Parameters.Add(new LookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
    123       Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
    124       Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
    125       Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
     82      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
     83      Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
    12684      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations that should be performed."));
    12785      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solution equivalents."));
     
    13088      Parameters.Add(new ValueLookupParameter<PercentValue>("OneMoveProbability", "The probability for performing a 1-move, which is the opposite of performing a 2-move.", new PercentValue(.5)));
    13189      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The result collection that stores the results."));
    132       Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));
    13390    }
    13491
     
    145102    /// <param name="assignment">The equipment-location assignment vector.</param>
    146103    /// <param name="quality">The solution quality.</param>
    147     /// <param name="flowDistanceQuality">The quality regarding the flow-distance criteria.</param>
    148     /// <param name="installationQuality">The quality regarding the installation costs.</param>
    149     /// <param name="overbookedCapacity">The sum of the overbooked capacities relative to the capacity of each location.</param>
     104    /// <param name="evaluation">The evaluation result of the solution.</param>
    150105    /// <param name="maxCLS">The maximum number of candidates that should be found in each step.</param>
    151106    /// <param name="maximumIterations">The maximum number of iterations that should be performed each time the candidate list is generated.</param>
    152     /// <param name="weights">The weights matrix describes the flows between the equipments.</param>
    153     /// <param name="distances">The distances matrix describes the distances between the locations at which the equipment can be installed.</param>
    154     /// <param name="installationCosts">The installation costs matrix describes the installation costs of installing equipment i at location j</param>
    155     /// <param name="demands">The demands vector describes the space requirements of the equipments.</param>
    156     /// <param name="capacities">The capacities vector describes the available space at the locations.</param>
    157     /// <param name="transportationCosts">The transportation cost represents the flow-unit per distance-unit cost factor. This value can also be set to 1 if these costs are factored into the weights matrix already.</param>
    158     /// <param name="overbookedCapacityPenalty"></param>
     107    /// <param name="problemInstance">The problem instance that contains the data.</param>
    159108    /// <param name="oneMoveProbability">The probability for performing a 1-move, which is the opposite of performing a 2-move.</param>
    160109    public static void Apply(IRandom random, IntegerVector assignment,
    161       DoubleValue quality, DoubleValue flowDistanceQuality, DoubleValue installationQuality, DoubleValue overbookedCapacity,
    162       IntValue maxCLS, IntValue maximumIterations,
    163       DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities,
    164       DoubleValue transportationCosts, DoubleValue expectedRandomQuality, PercentValue oneMoveProbability,
    165       IGQAPEvaluator evaluator) {
    166 
     110      DoubleValue quality, ref Evaluation evaluation, IntValue maxCLS, IntValue maximumIterations,
     111      GQAPInstance problemInstance, PercentValue oneMoveProbability) {
     112      var capacities = problemInstance.Capacities;
     113      var demands = problemInstance.Demands;
     114      //var weights = problemInstance.Weights;
     115      //var distances = problemInstance.Distances;
     116      //var installationCosts = problemInstance.InstallationCosts;
    167117      while (true) {
    168118        int count = 0;
    169         var CLS = new List<Tuple<NMove, double, double, double, double>>();
     119        var CLS = new List<Tuple<NMove, double, Evaluation>>();
    170120        double sum = 0.0;
    171121        do {
     
    174124            move = StochasticNMoveSingleMoveGenerator.GenerateExactlyN(random, assignment, 1, capacities);
    175125          else move = StochasticNMoveSingleMoveGenerator.GenerateExactlyN(random, assignment, 2, capacities);
     126         
     127          var moveEval = GQAPNMoveEvaluator.Evaluate(move, assignment, evaluation, problemInstance);
     128          double moveQuality = problemInstance.ToSingleObjective(moveEval);
    176129
    177           double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity;
    178           GQAPNMoveEvaluator.Evaluate(move, assignment, weights, distances, installationCosts,
    179             demands, capacities, evaluator, out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity);
    180           double moveQuality = evaluator.GetFitness(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity,
    181             transportationCosts.Value, expectedRandomQuality.Value);
    182 
    183           if (moveOverbookedCapacity <= 0.0 && moveQuality < 0.0) {
    184             CLS.Add(Tuple.Create(move, moveQuality, moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity));
     130          if (moveEval.ExcessDemand <= 0.0 && moveQuality < 0.0) {
     131            CLS.Add(Tuple.Create(move, moveQuality, moveEval));
    185132            sum += 1.0 / moveQuality;
    186133          }
     
    202149          NMoveMaker.Apply(assignment, selected.Item1);
    203150          quality.Value += selected.Item2;
    204           flowDistanceQuality.Value += selected.Item3;
    205           installationQuality.Value += selected.Item4;
    206           overbookedCapacity.Value += selected.Item5;
     151          evaluation = selected.Item3;
    207152        }
    208153      }
     
    210155
    211156    public override IOperation Apply() {
     157      var evaluation = EvaluationParameter.ActualValue;
    212158      Apply(RandomParameter.ActualValue,
    213159        AssignmentParameter.ActualValue,
    214160        QualityParameter.ActualValue,
    215         FlowDistanceQualityParameter.ActualValue,
    216         InstallationQualityParameter.ActualValue,
    217         OverbookedCapacityParameter.ActualValue,
     161        ref evaluation,
    218162        MaximumCandidateListSizeParameter.ActualValue,
    219163        MaximumIterationsParameter.ActualValue,
    220         WeightsParameter.ActualValue, DistancesParameter.ActualValue,
    221         InstallationCostsParameter.ActualValue,
    222         DemandsParameter.ActualValue, CapacitiesParameter.ActualValue,
    223         TransportationCostsParameter.ActualValue,
    224         ExpectedRandomQualityParameter.ActualValue,
    225         OneMoveProbabilityParameter.ActualValue,
    226         EvaluatorParameter.ActualValue);
     164        ProblemInstanceParameter.ActualValue,
     165        OneMoveProbabilityParameter.ActualValue);
     166      EvaluationParameter.ActualValue = evaluation;
    227167      return base.Apply();
    228168    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/DemandEquivalentSwapEquipmentManipluator.cs

    r7813 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.IntegerVectorEncoding;
    29 using HeuristicLab.Parameters;
    3029using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3130using HeuristicLab.Random;
     
    3534  [Item("DemandEquivalentSwapEquipmentManipluator", "Swaps equipment X from location A with as much equipments from location B that the demand of X is less than or equal to the demand of the swapped equipments in B.")]
    3635  [StorableClass]
    37   public class DemandEquivalentSwapEquipmentManipluator : GQAPManipulator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator {
    38 
    39     public ILookupParameter<DoubleArray> DemandsParameter {
    40       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
    41     }
    42     public ILookupParameter<DoubleArray> CapacitiesParameter {
    43       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    44     }
     36  public class DemandEquivalentSwapEquipmentManipluator : GQAPManipulator {
    4537
    4638    [StorableConstructor]
     
    4941    public DemandEquivalentSwapEquipmentManipluator()
    5042      : base() {
    51       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    52       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    5343    }
    5444
     
    8575    }
    8676
    87     protected override void Manipulate(IRandom random, IntegerVector vector) {
    88       Apply(random, vector, CapacitiesParameter.ActualValue, DemandsParameter.ActualValue);
     77    protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) {
     78      Apply(random, vector, problemInstance.Capacities, problemInstance.Demands);
    8979    }
    9080  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/GQAPManipulator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3131  [Item("GQAPManipulator", "A base class for operators that manipulate assignment vectors of the GeneralizedQuadraticAssignment problems.")]
    3232  [StorableClass]
    33   public abstract class GQAPManipulator : SingleSuccessorOperator, IGQAPManipulator, IAssignmentAwareGQAPOperator, IStochasticOperator {
     33  public abstract class GQAPManipulator : SingleSuccessorOperator, IGQAPManipulator, IProblemInstanceAwareGQAPOperator, IStochasticOperator {
    3434    public override bool CanChangeName {
    3535      get { return false; }
     
    3939      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
    4040    }
     41    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     42      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
     43    }
     44
    4145    public ILookupParameter<IRandom> RandomParameter {
    4246      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     
    4953      : base() {
    5054      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
     55      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
    5156      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    5257    }
    5358
    5459    public sealed override IOperation Apply() {
    55       Manipulate(RandomParameter.ActualValue, AssignmentParameter.ActualValue);
     60      Manipulate(RandomParameter.ActualValue, AssignmentParameter.ActualValue, ProblemInstanceParameter.ActualValue);
    5661      return base.Apply();
    5762    }
    5863
    59     protected abstract void Manipulate(IRandom random, IntegerVector integerVector);
     64    protected abstract void Manipulate(IRandom random, IntegerVector integerVector, GQAPInstance problemInstance);
    6065  }
    6166}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/MultiGQAPManipulator.cs

    r11505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  [Item("MultiGQAPManipulator", "Randomly selects and applies one of its manipulators every time it is called.")]
    3636  [StorableClass]
    37   public class MultiGQAPManipulator : StochasticMultiBranch<IGQAPManipulator>, IGQAPManipulator {
     37  public class MultiGQAPManipulator : StochasticMultiBranch<IGQAPManipulator>, IGQAPManipulator,
     38    IProblemInstanceAwareGQAPOperator {
    3839    public override bool CanChangeName {
    3940      get { return false; }
     
    4647      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
    4748    }
     49    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     50      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
     51    }
    4852
    4953    [StorableConstructor]
     
    5357      : base() {
    5458      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
     59      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
     60
    5561      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IGQAPManipulator))) {
    5662        if (!typeof(MultiOperator<IGQAPManipulator>).IsAssignableFrom(type))
     
    7379
    7480    private void Parameterize() {
    75       foreach (var op in Operators.OfType<IGQAPManipulator>())
     81      foreach (var op in Operators.OfType<IGQAPManipulator>()) {
    7682        op.AssignmentParameter.ActualName = AssignmentParameter.Name;
    77       foreach (var op in Operators.OfType<IStochasticOperator>())
     83        op.AssignmentParameter.Hidden = true;
     84      }
     85      foreach (var op in Operators.OfType<IStochasticOperator>()) {
    7886        op.RandomParameter.ActualName = RandomParameter.Name;
     87        op.RandomParameter.Hidden = true;
     88      }
     89      foreach (var op in Operators.OfType<IProblemInstanceAwareGQAPOperator>()) {
     90        op.ProblemInstanceParameter.ActualName = ProblemInstanceParameter.Name;
     91        op.ProblemInstanceParameter.Hidden = true;
     92      }
    7993    }
    8094
    8195    public override IOperation InstrumentedApply() {
    8296      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one manipulator to choose from.");
    83       return base.Apply();
     97      return base.InstrumentedApply();
    8498    }
    8599  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/RelocateEquipmentManipluator.cs

    r7813 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.IntegerVectorEncoding;
    29 using HeuristicLab.Parameters;
    3029using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3130using HeuristicLab.Random;
     
    3534  [Item("RelocateEquipmentManipluator", "Relocates a random equipment from an overstuffed location to a random one with space or a random equipment if constraints are satisfied.")]
    3635  [StorableClass]
    37   public class RelocateEquipmentManipluator : GQAPManipulator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator {
    38 
    39     public ILookupParameter<DoubleArray> CapacitiesParameter {
    40       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    41     }
    42     public ILookupParameter<DoubleArray> DemandsParameter {
    43       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
    44     }
    45 
     36  public class RelocateEquipmentManipluator : GQAPManipulator {
     37   
    4638    [StorableConstructor]
    4739    protected RelocateEquipmentManipluator(bool deserializing) : base(deserializing) { }
     
    4941    public RelocateEquipmentManipluator()
    5042      : base() {
    51       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    52       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    5343    }
    5444
     
    9282    }
    9383
    94     protected override void Manipulate(IRandom random, IntegerVector vector) {
    95       Apply(random, vector, CapacitiesParameter.ActualValue, DemandsParameter.ActualValue);
     84    protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) {
     85      Apply(random, vector, problemInstance.Capacities, problemInstance.Demands);
    9686    }
    9787  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/SwapEquipmentManipluator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    5656    }
    5757
    58     protected override void Manipulate(IRandom random, IntegerVector vector) {
     58    protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) {
    5959      Apply(random, vector);
    6060    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/SwapLocationManipulator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2726using HeuristicLab.Encodings.IntegerVectorEncoding;
    28 using HeuristicLab.Parameters;
    2927using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3028
     
    3331  [Item("SwapLocationManipluator", "Swaps two locations by exchanging all equipments between the locations.")]
    3432  [StorableClass]
    35   public class SwapLocationManipluator : GQAPManipulator, ICapacitiesAwareGQAPOperator {
    36 
    37     public ILookupParameter<DoubleArray> CapacitiesParameter {
    38       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    39     }
    40 
     33  public class SwapLocationManipluator : GQAPManipulator {
     34   
    4135    [StorableConstructor]
    4236    protected SwapLocationManipluator(bool deserializing) : base(deserializing) { }
     
    4438    public SwapLocationManipluator()
    4539      : base() {
    46       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    4740    }
    4841
     
    7265    }
    7366
    74     protected override void Manipulate(IRandom random, IntegerVector vector) {
    75       Apply(random, vector, CapacitiesParameter.ActualValue.Length);
     67    protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) {
     68      Apply(random, vector, problemInstance.Capacities.Length);
    7669    }
    7770  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/PopulationReducers/GQAPQualitySimilarityReducer.cs

    r15492 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3434  [Item("GQAPQualitySimilarityReducer", "Reduces two populations two one by using quality and similarity information to obtain a population of high quality, but also diverse solutions.")]
    3535  [StorableClass]
    36   public class GQAPQualitySimilarityReducer : SingleSuccessorOperator, IAssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IPopulationReducer {
     36  public class GQAPQualitySimilarityReducer : SingleSuccessorOperator, IQualityAwareGQAPOperator, IPopulationReducer {
    3737    public ILookupParameter<IntegerVector> AssignmentParameter {
    3838      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
    39     }
    40     public ILookupParameter<BoolValue> MaximizationParameter {
    41       get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    4239    }
    4340    public ILookupParameter<DoubleValue> QualityParameter {
    4441      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    4542    }
    46     public ILookupParameter<DoubleValue> FlowDistanceQualityParameter {
    47       get { return (ILookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
    48     }
    49     public ILookupParameter<DoubleValue> InstallationQualityParameter {
    50       get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
    51     }
    52     public ILookupParameter<DoubleValue> OverbookedCapacityParameter {
    53       get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
     43    public ILookupParameter<Evaluation> EvaluationParameter {
     44      get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; }
    5445    }
    5546    public ILookupParameter<IntValue> MinimumPopulationSizeParameter {
     
    6657      : base() {
    6758      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
    68       Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
    69       Parameters.Add(new LookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
    70       Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
    71       Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
    72       Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
     59      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
     60      Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
    7361      Parameters.Add(new LookupParameter<IntValue>("MinimumPopulationSize", "The size of the population that should not be undershot."));
    7462      Parameters.Add(new LookupParameter<IntValue>("MaximumPopulationSize", "The size of the population that should not be surpassed."));
     
    8371      string qualityName = QualityParameter.TranslatedName;
    8472      int populationSize = MaximumPopulationSizeParameter.ActualValue.Value;
    85       bool maximization = MaximizationParameter.ActualValue.Value;
    8673
    8774      IScope remaining = ExecutionContext.Scope.SubScopes[0];
     
    10895        } else {
    10996          var replacement = population.Select((v, i) => new { V = v, Index = i })
    110                                       .Where(x => (maximization && x.V.Quality < candidate.Quality)
    111                                                || (!maximization && x.V.Quality > candidate.Quality));
     97                                      .Where(x => x.V.Quality > candidate.Quality);
    11298          if (replacement.Any()) {
    11399            replacement.OrderBy(x => similarities[x.Index]).ToArray();
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Shakers/NMoveShakingOperator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3232  [Item("NMoveShakingOperator", "Performs a number of shaking operations that increase in strength.")]
    3333  [StorableClass]
    34   public class NMoveShakingOperator : SingleSuccessorOperator, IAssignmentAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator {
     34  public class NMoveShakingOperator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator {
    3535
     36
     37    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     38      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
     39    }
    3640    public ILookupParameter<IntegerVector> AssignmentParameter {
    3741      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
    38     }
    39     public ILookupParameter<DoubleArray> CapacitiesParameter {
    40       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    4142    }
    4243    public IValueLookupParameter<IntValue> CurrentNeighborhoodIndexParameter {
     
    5455    protected NMoveShakingOperator(NMoveShakingOperator original, Cloner cloner) : base(original, cloner) { }
    5556    public NMoveShakingOperator() {
     57      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
    5658      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
    57       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    5859      Parameters.Add(new ValueLookupParameter<IntValue>("CurrentNeighborhoodIndex", "The index of the operator that should be applied (k)."));
    5960      Parameters.Add(new LookupParameter<IntValue>("NeighborhoodCount", "The number of operators that are available."));
     
    6869      var random = RandomParameter.ActualValue;
    6970      var assignment = AssignmentParameter.ActualValue;
    70       var capacities = CapacitiesParameter.ActualValue;
     71      var capacities = ProblemInstanceParameter.ActualValue.Capacities;
    7172
    7273      if (NeighborhoodCountParameter.ActualValue == null)
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Plugin.cs.frame

    r13418 r15504  
    3737  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3838  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    39   [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3")]
    4039  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    4140  [PluginDependency("HeuristicLab.Random", "3.3")]
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Properties/AssemblyInfo.cs.frame

    r7345 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3232[assembly: AssemblyCompany("HEAL")]
    3333[assembly: AssemblyProduct("HeuristicLab")]
    34 [assembly: AssemblyCopyright("(c) 2002-2011 HEAL")]
     34[assembly: AssemblyCopyright("(c) 2002-2017 HEAL")]
    3535[assembly: AssemblyTrademark("")]
    3636[assembly: AssemblyCulture("")]
     
    5555// [assembly: AssemblyVersion("1.0.*")]
    5656[assembly: AssemblyVersion("3.3.0.0")]
    57 [assembly: AssemblyFileVersion("3.3.6.$WCREV$")]
     57[assembly: AssemblyFileVersion("3.3.14.$WCREV$")]
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GQAPSolutionCreator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3131  [Item("GQAPSolutionCreator", "Base class for solution creators of the Generalized Quadratic Assignment Problem.")]
    3232  [StorableClass]
    33   public abstract class GQAPSolutionCreator : SingleSuccessorOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IGQAPSolutionCreator {
     33  public abstract class GQAPSolutionCreator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, IGQAPSolutionCreator {
    3434
    3535    #region Parameter Descriptions
     
    3737    #endregion
    3838
    39     public ILookupParameter<IntegerVector> AssignmentParameter {
    40       get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
     39    public ILookupParameter<IntegerVector> IntegerVectorParameter {
     40      get { return (ILookupParameter<IntegerVector>)Parameters["IntegerVector"]; }
    4141    }
    42     public ILookupParameter<DoubleArray> DemandsParameter {
    43       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
     42    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     43      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
    4444    }
    45     public ILookupParameter<DoubleArray> CapacitiesParameter {
    46       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
     45    public IValueLookupParameter<IntValue> LengthParameter {
     46      get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; }
     47    }
     48    public IValueLookupParameter<IntMatrix> BoundsParameter {
     49      get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
    4750    }
    4851
     
    5356    public GQAPSolutionCreator()
    5457      : base() {
    55       Parameters.Add(new LookupParameter<IntegerVector>("Assignment", AssignmentDescription));
    56       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    57       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
     58      Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", AssignmentDescription));
     59      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
     60      Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the vector.") { Hidden = true });
     61      Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "") { Hidden = true });
    5862    }
    5963
    6064    public override IOperation Apply() {
    61       AssignmentParameter.ActualValue = CreateSolution(DemandsParameter.ActualValue, CapacitiesParameter.ActualValue);
     65      IntegerVectorParameter.ActualValue = CreateSolution(ProblemInstanceParameter.ActualValue);
    6266      return base.Apply();
    6367    }
    6468
    65     protected abstract IntegerVector CreateSolution(DoubleArray demands, DoubleArray capacities);
     69    protected abstract IntegerVector CreateSolution(GQAPInstance problemInstance);
    6670  }
    6771}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GQAPStochasticSolutionCreator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.IntegerVectorEncoding;
    2625using HeuristicLab.Optimization;
     
    4645    }
    4746
    48     protected sealed override IntegerVector CreateSolution(DoubleArray demands, DoubleArray capacities) {
    49       return CreateRandomSolution(RandomParameter.ActualValue, demands, capacities);
     47    protected sealed override IntegerVector CreateSolution(GQAPInstance problemInstance) {
     48      return CreateRandomSolution(RandomParameter.ActualValue, problemInstance);
    5049    }
    5150
    52     protected abstract IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities);
     51    protected abstract IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance);
    5352  }
    5453}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GreedyRandomizedSolutionCreator.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  [Item("GreedyRandomizedSolutionCreator", "Creates a solution according to the procedure 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.")]
    3636  [StorableClass]
    37   public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator,
    38     IEvaluatorAwareGQAPOperator {
     37  public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator {
    3938
    4039    public IValueLookupParameter<IntValue> MaximumTriesParameter {
     
    4342    public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter {
    4443      get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; }
    45     }
    46     public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
    47       get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
    4844    }
    4945
     
    5652      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumTries", "The maximum number of tries to create a feasible solution after which an exception is thrown. If it is set to 0 or a negative value there will be an infinite number of attempts.", new IntValue(100000)));
    5753      Parameters.Add(new ValueLookupParameter<BoolValue>("CreateMostFeasibleSolution", "If this is set to true the operator will always succeed, and outputs the solution with the least violation instead of throwing an exception.", new BoolValue(false)));
    58       Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));
    5954    }
    6055
     
    6358    }
    6459
    65     public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities,
    66       IGQAPEvaluator evaluator,
     60    public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance,
    6761      int maximumTries, bool createMostFeasibleSolution, CancellationToken cancelToken) {
     62      var demands = problemInstance.Demands;
     63      var capacities = problemInstance.Capacities;
    6864      int tries = 0;
    6965      var assignment = new Dictionary<int, int>(demands.Length);
     
    125121            slack[l] -= demands[f];
    126122          }
    127           double violation = evaluator.EvaluateOverbooking(slack, capacities);
     123          double violation = slack.Select(x => x < 0 ? -x : 0).Sum();
    128124          if (violation < minViolation) {
    129125            bestAssignment = assignment;
     
    139135    }
    140136
    141     protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) {
    142       return CreateSolution(random, demands, capacities,
    143         EvaluatorParameter.ActualValue,
     137    protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) {
     138      return CreateSolution(random, problemInstance,
    144139        MaximumTriesParameter.ActualValue.Value,
    145140        CreateMostFeasibleSolutionParameter.ActualValue.Value,
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  [Item("RandomButFeasibleSolutionCreator", "Creates a random, but feasible solution to the Generalized Quadratic Assignment Problem.")]
    3636  [StorableClass]
    37   public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator,
    38     IEvaluatorAwareGQAPOperator {
     37  public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator {
    3938
    4039    public IValueLookupParameter<IntValue> MaximumTriesParameter {
     
    4342    public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter {
    4443      get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; }
    45     }
    46     public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
    47       get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
    4844    }
    4945
     
    5551      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumTries", "The maximum number of tries to create a feasible solution after which an exception is thrown. If it is set to 0 or a negative value there will be an infinite number of attempts.", new IntValue(100000)));
    5652      Parameters.Add(new ValueLookupParameter<BoolValue>("CreateMostFeasibleSolution", "If this is set to true the operator will always succeed, and outputs the solution with the least violation instead of throwing an exception.", new BoolValue(false)));
    57       Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));
    5853    }
    5954
     
    6257    }
    6358
    64     public static IntegerVector CreateSolution(IRandom random, DoubleArray demands,
    65       DoubleArray capacities, IGQAPEvaluator evaluator,
     59    public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance,
    6660      int maximumTries, bool createMostFeasibleSolution, CancellationToken cancel) {
     61      var capacities = problemInstance.Capacities;
     62      var demands = problemInstance.Demands;
    6763      IntegerVector result = null;
    6864      bool isFeasible = false;
     
    8783          slack[assignment[equipment]] -= demands[equipment];
    8884        }
    89         double violation = evaluator.EvaluateOverbooking(slack, capacities);
     85        double violation = slack.Select(x => x < 0 ? -x : 0).Sum();
    9086        isFeasible = violation == 0;
    9187        if (isFeasible || violation < minViolation) {
     
    9793    }
    9894
    99     protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) {
    100       return CreateSolution(random, demands, capacities,
    101         EvaluatorParameter.ActualValue,
     95    protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) {
     96      return CreateSolution(random, problemInstance,
    10297        MaximumTriesParameter.ActualValue.Value,
    10398        CreateMostFeasibleSolutionParameter.ActualValue.Value,
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/SlackMinimizationSolutionCreator.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  [Item("SlackMinimizationSolutionCreator", "A heuristic that creates a solution to the Generalized Quadratic Assignment Problem by minimizing the amount of slack.")]
    3636  [StorableClass]
    37   public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator,
    38     IEvaluatorAwareGQAPOperator {
     37  public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator {
    3938
    4039    public IValueLookupParameter<IntValue> MaximumTriesParameter {
     
    5049      get { return (IValueLookupParameter<IntValue>)Parameters["RandomWalkLength"]; }
    5150    }
    52     public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
    53       get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
    54     }
    5551
    5652    [StorableConstructor]
     
    6359      Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3)));
    6460      Parameters.Add(new ValueLookupParameter<IntValue>("RandomWalkLength", "The length of the random walk in the feasible region that is used to diversify the found assignments.", new IntValue(10)));
    65       Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));
    6661    }
    6762
     
    7065    }
    7166
    72     [StorableHook(HookType.AfterDeserialization)]
    73     private void AfterDeserialization() {
    74       if (!Parameters.ContainsKey("Depth")) {
    75         Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3)));
    76       }
    77       if (!Parameters.ContainsKey("RandomWalkLength")) {
    78         Parameters.Add(new ValueLookupParameter<IntValue>("RandomWalkLength", "The length of the random walk in the feasible region that is used to diversify the found assignments.", new IntValue(10)));
    79       }
    80     }
     67    public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance,
     68      int depth, int maximumTries, bool createMostFeasibleSolution, int randomWalkLength, CancellationToken cancel) {
     69      var capacities = problemInstance.Capacities;
     70      var demands = problemInstance.Demands;
    8171
    82     public static IntegerVector CreateSolution(IRandom random, DoubleArray demands,
    83       DoubleArray capacities, IGQAPEvaluator evaluator,
    84       int depth, int maximumTries, bool createMostFeasibleSolution, int randomWalkLength, CancellationToken cancel) {
    8572      IntegerVector result = null;
    8673      bool isFeasible = false;
     
    125112          }
    126113        } else RandomFeasibleWalk(random, assignment, demands, slack, randomWalkLength);
    127         double violation = evaluator.EvaluateOverbooking(slack, capacities);
     114        double violation = slack.Select(x => x < 0 ? -x : 0).Sum();
    128115        isFeasible = violation == 0;
    129116        if (isFeasible || violation < minViolation) {
     
    182169    }
    183170
    184     protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) {
    185       return CreateSolution(random, demands, capacities,
    186         EvaluatorParameter.ActualValue,
     171    protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) {
     172      return CreateSolution(random, problemInstance,
    187173        DepthParameter.ActualValue.Value,
    188174        MaximumTriesParameter.ActualValue.Value,
  • branches/GeneralizedQAP/UnitTests/CordeauCrossoverTest.cs

    r15490 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535      var provider = new CordeauGQAPInstanceProvider();
    3636      var instance = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name == "20-15-75"));
    37       var gqap = new GeneralizedQuadraticAssignmentProblem();
     37      var gqap = new GQAP();
    3838      gqap.Load(instance);
    3939      var evaluator = gqap.Evaluator;
     
    4141      for (int i = 0; i < 100; i++) {
    4242        var random = new MersenneTwister((uint)i);
    43         var parent1 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap.Demands, gqap.Capacities, gqap.Evaluator, 100, true, CancellationToken.None);
    44         var parent2 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap.Demands, gqap.Capacities, gqap.Evaluator, 100, true, CancellationToken.None);
     43        var parent1 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap.ProblemInstance, 100, true, CancellationToken.None);
     44        var parent2 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap.ProblemInstance, 100, true, CancellationToken.None);
    4545
    4646        try {
    4747          CordeauCrossover.Apply(random, gqap.Maximization,
    4848            parent1,
    49             new DoubleValue(gqap.Evaluator.Evaluate(parent1, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality)),
     49            new DoubleValue(gqap.Evaluate(parent1)),
    5050            parent2,
    51             new DoubleValue(gqap.Evaluator.Evaluate(parent2, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality)),
    52             gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality, gqap.Evaluator,
     51            new DoubleValue(gqap.Evaluate(parent2)),
     52            gqap.ProblemInstance,
    5353            new IntValue(0));
    5454        } catch {
  • branches/GeneralizedQAP/UnitTests/GQAPNMoveEvaluatorTest.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  public class GQAPNMoveEvaluatorTest {
    3636    private const int Equipments = 10, Locations = 5;
    37     private static DoubleMatrix symmetricWeights, asymmetricWeights, nonZeroDiagonalWeights;
    38     private static DoubleMatrix symmetricDistances, asymmetricDistances, nonZeroDiagonalDistances;
    39     private static DoubleMatrix installationCosts;
    40     private static DoubleArray demands, capacities;
    41     private static double transportationCosts, overbookedCapacityPenalty;
     37    private static GQAPInstance symmetricInstance, asymmetricInstance, nonZeroDiagonalInstance;
    4238    private static IntegerVector assignment;
    4339    private static MersenneTwister random;
     
    5854    public static void MyClassInitialize(TestContext testContext) {
    5955      random = new MersenneTwister();
    60       symmetricDistances = new DoubleMatrix(Locations, Locations);
    61       symmetricWeights = new DoubleMatrix(Equipments, Equipments);
    62       asymmetricDistances = new DoubleMatrix(Locations, Locations);
    63       asymmetricWeights = new DoubleMatrix(Equipments, Equipments);
    64       nonZeroDiagonalDistances = new DoubleMatrix(Locations, Locations);
    65       nonZeroDiagonalWeights = new DoubleMatrix(Equipments, Equipments);
     56      var symmetricDistances = new DoubleMatrix(Locations, Locations);
     57      var symmetricWeights = new DoubleMatrix(Equipments, Equipments);
     58      var asymmetricDistances = new DoubleMatrix(Locations, Locations);
     59      var asymmetricWeights = new DoubleMatrix(Equipments, Equipments);
     60      var nonZeroDiagonalDistances = new DoubleMatrix(Locations, Locations);
     61      var nonZeroDiagonalWeights = new DoubleMatrix(Equipments, Equipments);
    6662      for (int i = 0; i < Equipments - 1; i++) {
    6763        for (int j = i + 1; j < Equipments; j++) {
     
    8682        nonZeroDiagonalDistances[i, i] = random.Next(Locations * 100);
    8783      }
    88       installationCosts = new DoubleMatrix(Equipments, Locations);
     84      var installationCosts = new DoubleMatrix(Equipments, Locations);
    8985      for (int i = 0; i < Equipments; i++) {
    9086        for (int j = 0; j < Locations; j++) {
     
    9288        }
    9389      }
    94       demands = new DoubleArray(Equipments);
     90      var demands = new DoubleArray(Equipments);
    9591      for (int i = 0; i < Equipments; i++) {
    9692        demands[i] = random.Next(1, 10);
    9793      }
    98       capacities = new DoubleArray(Locations);
     94      var capacities = new DoubleArray(Locations);
    9995      for (int j = 0; j < Locations; j++) {
    10096        capacities[j] = random.Next(1, 10) * ((double)Equipments / (double)Locations) * 1.5;
     
    107103        nonZeroDiagonalWeights[index, index] = random.Next(1, Equipments * 100);
    108104
    109       transportationCosts = random.NextDouble() * 10;
    110       overbookedCapacityPenalty = 1000 * random.NextDouble() + 100;
     105      var transportationCosts = random.NextDouble() * 10;
     106      var overbookedCapacityPenalty = 1000 * random.NextDouble() + 100;
    111107      assignment = new IntegerVector(Equipments, random, 0, Locations);
     108
     109      symmetricInstance = new GQAPInstance() {
     110        Capacities = capacities,
     111        Demands = demands,
     112        InstallationCosts = installationCosts,
     113        PenaltyLevel = overbookedCapacityPenalty,
     114        TransportationCosts = transportationCosts,
     115        Weights = symmetricWeights,
     116        Distances = symmetricDistances
     117      };
     118      asymmetricInstance = new GQAPInstance() {
     119        Capacities = capacities,
     120        Demands = demands,
     121        InstallationCosts = installationCosts,
     122        PenaltyLevel = overbookedCapacityPenalty,
     123        TransportationCosts = transportationCosts,
     124        Weights = asymmetricWeights,
     125        Distances = asymmetricDistances
     126      };
     127      nonZeroDiagonalInstance = new GQAPInstance() {
     128        Capacities = capacities,
     129        Demands = demands,
     130        InstallationCosts = installationCosts,
     131        PenaltyLevel = overbookedCapacityPenalty,
     132        TransportationCosts = transportationCosts,
     133        Weights = nonZeroDiagonalWeights,
     134        Distances = nonZeroDiagonalDistances
     135      };
    112136    }
    113137    #endregion
     
    119143    [TestMethod()]
    120144    public void EvaluateTest() {
    121       var evaluator = new GQAPAdditivePenaltyEvaluator();
    122145      for (int i = 0; i < 500; i++) {
    123         NMove currentMove = StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, 3, capacities);
     146        NMove currentMove = StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, 3, symmetricInstance.Capacities);
    124147        IntegerVector prevAssignment = (IntegerVector)assignment.Clone();
    125148        NMoveMaker.Apply(assignment, currentMove);
    126         double before = evaluator.Evaluate(prevAssignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0);
    127         double after = evaluator.Evaluate(assignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0);
    128         double moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator);
     149        var beforeEval = symmetricInstance.Evaluate(prevAssignment);
     150        double before = symmetricInstance.ToSingleObjective(beforeEval);
     151        double after = Evaluate(symmetricInstance, assignment);
     152        double moveDiff = symmetricInstance.ToSingleObjective(
     153          GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, symmetricInstance)
     154          ) - symmetricInstance.ToSingleObjective(beforeEval);
    129155        Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on symmetric matrices: " + Environment.NewLine
    130156          + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + ".");
    131157
    132         before = evaluator.Evaluate(prevAssignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0);
    133         after = evaluator.Evaluate(assignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0);
    134         moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator);
     158        beforeEval = asymmetricInstance.Evaluate(prevAssignment);
     159        before = asymmetricInstance.ToSingleObjective(beforeEval);
     160        after = Evaluate(asymmetricInstance, assignment);
     161        moveDiff = asymmetricInstance.ToSingleObjective(
     162          GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, asymmetricInstance)
     163          ) - asymmetricInstance.ToSingleObjective(beforeEval);
    135164        Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on asymmetric matrices: " + Environment.NewLine
    136165          + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + ".");
    137166
    138         before = evaluator.Evaluate(prevAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0);
    139         after = evaluator.Evaluate(assignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0);
    140         moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator);
     167        beforeEval = nonZeroDiagonalInstance.Evaluate(prevAssignment);
     168        before = nonZeroDiagonalInstance.ToSingleObjective(beforeEval);
     169        after = Evaluate(nonZeroDiagonalInstance, assignment);
     170        moveDiff = nonZeroDiagonalInstance.ToSingleObjective(
     171          GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, nonZeroDiagonalInstance)
     172          ) - nonZeroDiagonalInstance.ToSingleObjective(beforeEval);
    141173        Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on non-zero diagonal matrices: " + Environment.NewLine
    142174          + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + ".");
    143175      }
    144176    }
     177
     178    private double Evaluate(GQAPInstance instance, IntegerVector assignment) {
     179      return instance.ToSingleObjective(instance.Evaluate(assignment));
     180    }
    145181  }
    146182}
  • branches/GeneralizedQAP/UnitTests/Properties/AssemblyInfo.cs

    r7412 r15504  
    11using System.Reflection;
    2 using System.Runtime.CompilerServices;
    32using System.Runtime.InteropServices;
    43
     
    98[assembly: AssemblyDescription("")]
    109[assembly: AssemblyConfiguration("")]
    11 [assembly: AssemblyCompany("Microsoft")]
     10[assembly: AssemblyCompany("HEAL")]
    1211[assembly: AssemblyProduct("UnitTests")]
    13 [assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
     12[assembly: AssemblyCopyright("(c) 2002-2017 HEAL")]
    1413[assembly: AssemblyTrademark("")]
    1514[assembly: AssemblyCulture("")]
Note: See TracChangeset for help on using the changeset viewer.