Free cookie consent management tool by TermsFeed Policy Generator

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

#1614:

  • Fixed bugs in view
  • Made Evaluation object immutable
  • Fixed bug in Analyze
  • Fixed operators
Location:
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • 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.