Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15510 for branches


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

#1614:

  • Fixed bugs in view
  • Made Evaluation object immutable
  • Fixed bug in Analyze
  • Fixed operators
Location:
branches/GeneralizedQAP
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs

    r15504 r15510  
    6161    protected override void OnContentChanged() {
    6262      base.OnContentChanged();
    63       UpdateQuality();
    64       UpdateFlowDistanceQuality();
    65       UpdateInstallationQuality();
    66       UpdateOverbookedCapacity();
     63      UpdateEvaluation();
    6764      UpdateAssignment();
    6865      if (Content != null) assignmentView.Content = Content.Assignment;
     
    7774    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    7875      switch (e.PropertyName) {
    79         case "Quality": UpdateQuality(); break;
    80         case "FlowDistanceQuality": UpdateFlowDistanceQuality(); break;
    81         case "InstallationQuality": UpdateInstallationQuality(); break;
    82         case "OverbookedCapacity": UpdateOverbookedCapacity(); break;
    83         case "Assignment": UpdateAssignment(); break;
    84         case "EquipmentNames": UpdateAssignment(); break;
    85         case "LocationNames": UpdateAssignment(); break;
     76        case nameof(Content.Evaluation): UpdateEvaluation(); break;
     77        case nameof(Content.Assignment): UpdateAssignment(); break;
     78        case nameof(Content.ProblemInstance): UpdateEvaluation(); UpdateAssignment(); break;
    8679        default: break;
    8780      }
     
    124117
    125118    #region Helpers
    126     private void UpdateQuality() {
    127       if (InvokeRequired) Invoke((Action)UpdateQuality);
     119    private void UpdateEvaluation() {
     120      if (InvokeRequired) Invoke((Action)UpdateEvaluation);
    128121      else {
    129122        if (Content == null) {
    130123          qualityLabel.Text = "-";
     124          flowDistanceQualityLabel.Text = "-";
     125          installationQualityLabel.Text = "-";
     126          overbookedCapacityLabel.Text = "-";
    131127        } else {
    132128          qualityLabel.Text = Content.ProblemInstance.ToSingleObjective(Content.Evaluation).ToString();
    133         }
    134       }
    135     }
    136 
    137     private void UpdateFlowDistanceQuality() {
    138       if (InvokeRequired) Invoke((Action)UpdateFlowDistanceQuality);
    139       else {
    140         if (Content == null || Content.Evaluation == null) {
    141           flowDistanceQualityLabel.Text = "-";
    142         } else {
    143129          flowDistanceQualityLabel.Text = Content.Evaluation.FlowCosts.ToString();
    144         }
    145       }
    146     }
    147 
    148     private void UpdateInstallationQuality() {
    149       if (InvokeRequired) Invoke((Action)UpdateInstallationQuality);
    150       else {
    151         if (Content == null || Content.Evaluation == null) {
    152           installationQualityLabel.Text = "-";
    153         } else {
    154130          installationQualityLabel.Text = Content.Evaluation.InstallationCosts.ToString();
    155         }
    156       }
    157     }
    158 
    159     private void UpdateOverbookedCapacity() {
    160       if (InvokeRequired) Invoke((Action)UpdateOverbookedCapacity);
    161       else {
    162         if (Content == null || Content.Evaluation == null) {
    163           overbookedCapacityLabel.Text = "-";
    164         } else {
    165131          overbookedCapacityLabel.Text = Content.Evaluation.ExcessDemand.ToString();
    166132        }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3

    • Property svn:ignore
      •  

        old new  
         1*.user
        12Plugin.cs
         3bin
        24obj
        3 bin
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluation/Evaluation.cs

    r15504 r15510  
    1 using System.Linq;
     1using System.Collections.Generic;
     2using System.Linq;
    23using HeuristicLab.Common;
    34using HeuristicLab.Core;
     
    1819    /// </summary>
    1920    [Storable]
    20     public double ExcessDemand { get; set; }
     21    public double ExcessDemand { get; private set; }
    2122    /// <summary>
    2223    /// The amount of slack at each location, is negative in case of excess demand.
     
    2627    /// </remarks>
    2728    [Storable]
    28     public double[] Slack { get; set; }
     29    private double[] slack;
     30    public IReadOnlyList<double> Slack {
     31      get { return slack; }
     32    }
    2933    /// <summary>
    3034    /// The quadratic part of the fitness function that represents the flow or transportation costs.
    3135    /// </summary>
    3236    [Storable]
    33     public double FlowCosts { get; set; }
     37    public double FlowCosts { get; private set; }
    3438    /// <summary>
    3539    /// The linear part of the fitness function that represents the installation costs.
    3640    /// </summary>
    3741    [Storable]
    38     public double InstallationCosts { get; set; }
     42    public double InstallationCosts { get; private set; }
    3943   
    4044    [StorableConstructor]
     
    4347      : base(original, cloner) {
    4448      ExcessDemand = original.ExcessDemand;
    45       if (original.Slack != null)
    46         Slack = original.Slack.ToArray();
     49      if (original.slack != null)
     50        slack = original.slack.ToArray();
    4751      FlowCosts = original.FlowCosts;
    4852      InstallationCosts = original.InstallationCosts;
    4953    }
    50     public Evaluation() { }
     54    public Evaluation(double flowCosts, double installationCosts, double excessDemand, double[] slack) {
     55      FlowCosts = flowCosts;
     56      InstallationCosts = installationCosts;
     57      ExcessDemand = excessDemand;
     58      this.slack = slack;
     59    }
    5160
    5261    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluation/GQAPNMoveEvaluator.cs

    r15507 r15510  
    8585    public static Evaluation Evaluate(NMove move, IntegerVector assignment, Evaluation evaluation, GQAPInstance problemInstance) {
    8686      int moves = move.N;
    87       var newEvaluation = new Evaluation() {
    88         ExcessDemand = evaluation.ExcessDemand,
    89         FlowCosts = evaluation.FlowCosts,
    90         InstallationCosts = evaluation.InstallationCosts,
    91         Slack = evaluation.Slack.ToArray()
    92       };
     87      var excessDemand = evaluation.ExcessDemand;
     88      var flowCosts = evaluation.FlowCosts;
     89      var installationCosts = evaluation.InstallationCosts;
     90      var slack = evaluation.Slack.ToArray();
     91
    9392      foreach (var kvp in move.NewAssignments) {
    9493        int equip = kvp.Key;
     
    9695        int oldLoc = assignment[equip];
    9796        var equipDemand = problemInstance.Demands[equip];
    98         newEvaluation.InstallationCosts -= problemInstance.InstallationCosts[equip, oldLoc];
    99         newEvaluation.InstallationCosts += problemInstance.InstallationCosts[equip, newLoc];
     97        installationCosts -= problemInstance.InstallationCosts[equip, oldLoc];
     98        installationCosts += problemInstance.InstallationCosts[equip, newLoc];
    10099        for (int j = 0; j < assignment.Length; j++) {
    101100          if (!move.NewAssignments.ContainsKey(j)) {
    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];
     101            flowCosts += problemInstance.Weights[equip, j] * problemInstance.Distances[newLoc, assignment[j]];
     102            flowCosts -= problemInstance.Weights[equip, j] * problemInstance.Distances[oldLoc, assignment[j]];
     103            flowCosts += problemInstance.Weights[j, equip] * problemInstance.Distances[assignment[j], newLoc];
     104            flowCosts -= problemInstance.Weights[j, equip] * problemInstance.Distances[assignment[j], oldLoc];
    106105          } else {
    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]];
     106            flowCosts += problemInstance.Weights[equip, j] * problemInstance.Distances[newLoc, move.NewAssignments[j]];
     107            flowCosts -= problemInstance.Weights[equip, j] * problemInstance.Distances[oldLoc, assignment[j]];
    109108          }
    110109        }
    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]);
     110        slack[oldLoc] += equipDemand;
     111        if (slack[oldLoc] < equipDemand)
     112          excessDemand -= Math.Min(equipDemand, equipDemand - slack[oldLoc]);
     113        slack[newLoc] -= equipDemand;
     114        if (slack[newLoc] < 0)
     115          excessDemand += Math.Min(equipDemand, -slack[newLoc]);
    117116      }
    118117
    119       return newEvaluation;
     118      return new Evaluation(flowCosts, installationCosts, excessDemand, slack);
    120119    }
    121120
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAP.cs

    r15506 r15510  
    154154      }
    155155      var archive = archiveResult.Value as GQAPAssignmentArchive;
    156       if (archive == null) archive = new GQAPAssignmentArchive(ProblemInstance);
    157       else archive.ProblemInstance = ProblemInstance;
     156      if (archive == null) {
     157        archive = new GQAPAssignmentArchive(ProblemInstance);
     158        archiveResult.Value = archive;
     159      } else archive.ProblemInstance = ProblemInstance;
    158160     
    159161      var combinedArchive = solutions
     
    401403
    402404    private void InitializeOperators() {
    403       Operators.Clear();
     405      Operators.RemoveAll(x => x is ISingleObjectiveMoveOperator);
     406      Operators.RemoveAll(x => x is SingleObjectiveImprover);
    404407      Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPOperator>());
    405       Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
    406408      Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>());
    407409      Operators.Add(new HammingSimilarityCalculator() { SolutionVariableName = Encoding.Name, QualityVariableName = Evaluator.QualityParameter.ActualName });
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPInstance.cs

    r15504 r15510  
    214214        slack[assignI] -= demands[i];
    215215      }
    216       return new Evaluation() {
    217         ExcessDemand = overbookedCapacity,
    218         FlowCosts = flowDistanceQuality,
    219         InstallationCosts = installationQuality,
    220         Slack = slack
    221       };
     216      return new Evaluation(flowDistanceQuality, installationQuality, overbookedCapacity, slack);
    222217    }
    223218
Note: See TracChangeset for help on using the changeset viewer.