Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/24/12 17:23:21 (12 years ago)
Author:
abeham
Message:

#1614: worked on GQAP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators/GQAPEvaluator.cs

    r7319 r7407  
    8787    }
    8888
     89    public static DoubleValue Evaluate(IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances,
     90      DoubleMatrix installCosts, double transportCosts, DoubleArray demands, DoubleArray capacities,
     91      out double infeasibility) {
     92      double quality = 0;
     93      int len = assignment.Length;
     94      var slack = (DoubleArray)capacities.Clone();
     95      for (int i = 0; i < len; i++) {
     96        quality += installCosts[i, assignment[i]];
     97        for (int j = 0; j < len; j++) {
     98          quality += transportCosts * weights[i, j] * distances[assignment[i], assignment[j]];
     99        }
     100        slack[assignment[i]] -= demands[i];
     101      }
     102
     103      infeasibility = -slack.Where(x => x < 0).Sum();
     104      return new DoubleValue(quality);
     105    }
     106
    89107    public override IOperation Apply() {
    90108      IntegerVector assignment = AssignmentParameter.ActualValue;
     
    96114      DoubleArray capacities = (DoubleArray)CapacitiesParameter.ActualValue.Clone();
    97115      double penalty = PenaltyParameter.ActualValue.Value;
    98       double quality = 0;
    99       double infeasibility = 0;
    100116
    101117      if (weights.Rows != weights.Columns || distances.Rows != distances.Columns
     
    104120        throw new InvalidOperationException("ERROR: The problem configuration is not valid! Check the sizes of the weights (NxN), distances (MxM) and installation costs (NxM) matrices as well as the length of the demand (N) and capacities (M) vectors.");
    105121
    106       int len = assignment.Length;
    107       for (int i = 0; i < len; i++) {
    108         quality += installCosts[i, assignment[i]];
    109         for (int j = 0; j < len; j++) {
    110           quality += transportCosts * weights[i, j] * distances[assignment[i], assignment[j]];
    111         }
    112         capacities[assignment[i]] -= demands[i];
    113       }
    114 
    115       infeasibility = -capacities.Where(x => x < 0).Sum();
     122      double infeasibility;
     123      var quality = Evaluate(assignment, weights, distances, installCosts, transportCosts, demands, capacities, out infeasibility);
    116124
    117125      InfeasibilityParameter.ActualValue = new DoubleValue(infeasibility);
    118       QualityParameter.ActualValue = new DoubleValue(quality + penalty * infeasibility);
     126      QualityParameter.ActualValue = new DoubleValue(quality.Value + penalty * infeasibility);
    119127      return base.Apply();
    120128    }
Note: See TracChangeset for help on using the changeset viewer.