Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/25/12 18:32:44 (13 years ago)
Author:
abeham
Message:

#1614: worked on GQAP and GRASP+PR

Location:
branches/GeneralizedQAP
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP

    • Property svn:ignore
      •  

        old new  
        11*.suo
         2TestResults
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/ApproximateLocalSearch.cs

    r7407 r7412  
    5555      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    5656    }
    57     public ILookupParameter<DoubleValue> InfeasibilityParameter {
    58       get { return (ILookupParameter<DoubleValue>)Parameters["Infeasibility"]; }
     57    public ILookupParameter<DoubleValue> FlowDistanceQualityParameter {
     58      get { return (ILookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
     59    }
     60    public ILookupParameter<DoubleValue> InstallationQualityParameter {
     61      get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
     62    }
     63    public ILookupParameter<DoubleValue> OverbookedCapacityParameter {
     64      get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
    5965    }
    6066    public ILookupParameter<ResultCollection> ResultsParameter {
     
    7985      get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
    8086    }
    81     public ILookupParameter<DoubleValue> TransportationCostsParameter {
    82       get { return (ILookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
    83     }
    8487    public ILookupParameter<DoubleArray> DemandsParameter {
    8588      get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
     
    8891      get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    8992    }
    90 
     93    public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
     94      get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
     95    }
     96    public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {
     97      get { return (IValueLookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; }
     98    }
     99    public IValueLookupParameter<PercentValue> OneMoveProbabilityParameter {
     100      get { return (IValueLookupParameter<PercentValue>)Parameters["OneMoveProbability"]; }
     101    }
    91102
    92103    [StorableConstructor]
     
    99110      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solution equivalents."));
    100111      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The solution quality."));
    101       Parameters.Add(new LookupParameter<DoubleValue>("Infeasibility", "The infeasibility describes the sum of the overbooked capacities."));
     112      Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", "The quality regarding the flow-distance criteria."));
     113      Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", "The quality regarding the installation costs."));
     114      Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", "The sum of the overbooked capacities relative to the capacity of each location."));
    102115      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The result collection that stores the results."));
    103116      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumCandidateListSize", "The maximum number of candidates that should be found in each step.", new IntValue(10)));
     
    107120      Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The distances matrix describes the distances between the locations at which the equipment can be installed."));
    108121      Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", "The installation costs matrix describes the installation costs of installing equipment i at location j."));
    109       Parameters.Add(new LookupParameter<DoubleValue>("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."));
    110122      Parameters.Add(new LookupParameter<DoubleArray>("Demands", "The demands vector describes the space requirements of the equipments."));
    111123      Parameters.Add(new LookupParameter<DoubleArray>("Capacities", "The capacities vector describes the available space at the locations."));
     124      Parameters.Add(new ValueLookupParameter<DoubleValue>("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."));
     125      Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", "The multiplier for the constraint violation when added to the quality."));
     126      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)));
    112127    }
    113128
     
    124139    /// <param name="assignment">The equipment-location assignment vector.</param>
    125140    /// <param name="quality">The solution quality.</param>
    126     /// <param name="infeasibility">The infeasibility describes the sum of the overbooked capacities.</param>
     141    /// <param name="flowDistanceQuality">The quality regarding the flow-distance criteria.</param>
     142    /// <param name="installationQuality">The quality regarding the installation costs.</param>
     143    /// <param name="overbookedCapacity">The sum of the overbooked capacities relative to the capacity of each location.</param>
    127144    /// <param name="maxCLS">The maximum number of candidates that should be found in each step.</param>
    128145    /// <param name="maxSampleSize">The maximum number of candidates that should be sampled in each step.</param>
    129146    /// <param name="maximumIterations">The maximum number of iterations that should be performed.</param>
    130     /// <param name="demands">The demands vector describes the space requirements of the equipments.</param>
    131     /// <param name="capacities">The capacities vector describes the available space at the locations.</param>
    132147    /// <param name="weights">The weights matrix describes the flows between the equipments.</param>
    133148    /// <param name="distances">The distances matrix describes the distances between the locations at which the equipment can be installed.</param>
    134149    /// <param name="installationCosts">The installation costs matrix describes the installation costs of installing equipment i at location j</param>
     150    /// <param name="demands">The demands vector describes the space requirements of the equipments.</param>
     151    /// <param name="capacities">The capacities vector describes the available space at the locations.</param>
    135152    /// <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>
    136     public static void Apply(IRandom random, IntegerVector assignment, DoubleValue quality, DoubleValue infeasibility,
    137                              IntValue maxCLS, IntValue maxSampleSize, IntValue maximumIterations,
    138                              DoubleArray demands, DoubleArray capacities,
    139                              DoubleMatrix weights, DoubleMatrix distances,
    140                              DoubleMatrix installationCosts,
    141                              DoubleValue transportationCosts) {
     153    /// <param name="overbookedCapacityPenalty"></param>
     154    /// <param name="oneMoveProbability">The probability for performing a 1-move, which is the opposite of performing a 2-move.</param>
     155    public static void Apply(IRandom random, IntegerVector assignment,
     156      DoubleValue quality, DoubleValue flowDistanceQuality, DoubleValue installationQuality, DoubleValue overbookedCapacity,
     157      IntValue maxCLS, IntValue maxSampleSize, IntValue maximumIterations,
     158      DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities,
     159      DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty, PercentValue oneMoveProbability) {
     160
    142161      for (int i = 0; i < maximumIterations.Value; i++) {
    143162        int count = 0;
    144         var CLS = new List<Tuple<NMove, DoubleValue, DoubleValue>>();
     163        var CLS = new List<Tuple<NMove, double, double, double, double>>();
    145164        double sum = 0.0;
    146165        do {
    147           var move = StochasticNMoveSingleMoveGenerator.Generate(random, assignment, 2, capacities);
    148           DoubleValue moveInfeasibility;
    149           var moveQuality = GQAPNMoveEvaluator.Evaluate(move, assignment, quality,
    150             demands, capacities, weights, distances,
    151             installationCosts, transportationCosts, out moveInfeasibility);
    152           if (moveInfeasibility.Value <= 0.0 && moveQuality.Value < quality.Value) {
    153             CLS.Add(Tuple.Create(move, moveQuality, moveInfeasibility));
    154             sum += 1.0 / moveQuality.Value;
     166          NMove move;
     167          if (random.NextDouble() < oneMoveProbability.Value)
     168            move = StochasticNMoveSingleMoveGenerator.GenerateExactlyN(random, assignment, 1, capacities);
     169          else move = StochasticNMoveSingleMoveGenerator.GenerateExactlyN(random, assignment, 2, capacities);
     170
     171          double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity;
     172          GQAPNMoveEvaluator.Evaluate(move, assignment, weights, distances, installationCosts,
     173            demands, capacities, out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity);
     174          double moveQuality = GQAPEvaluator.GetCombinedQuality(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity,
     175            transportationCosts.Value, overbookedCapacityPenalty.Value);
     176
     177          if (moveOverbookedCapacity <= 0.0 && moveQuality < 0.0) {
     178            CLS.Add(Tuple.Create(move, moveQuality, moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity));
     179            sum += 1.0 / moveQuality;
    155180          }
    156181          count++;
    157182        } while (CLS.Count < maxCLS.Value && count < maxSampleSize.Value);
    158         if (CLS.Count == 0) return; // END
     183
     184        if (CLS.Count == 0)
     185          return; // END
    159186        else {
    160187          var ball = random.NextDouble() * sum;
    161188          var selected = CLS.Last();
    162189          foreach (var candidate in CLS) {
    163             ball -= 1.0 / candidate.Item2.Value;
     190            ball -= 1.0 / candidate.Item2;
    164191            if (ball <= 0.0) {
    165192              selected = candidate;
     
    168195          }
    169196          NMoveMaker.Apply(assignment, selected.Item1);
    170           quality.Value = selected.Item2.Value;
    171           infeasibility.Value = selected.Item3.Value;
     197          quality.Value += selected.Item2;
     198          flowDistanceQuality.Value += selected.Item3;
     199          installationQuality.Value += selected.Item4;
     200          overbookedCapacity.Value += selected.Item5;
    172201        }
    173202      }
     
    178207        AssignmentParameter.ActualValue,
    179208        QualityParameter.ActualValue,
    180         InfeasibilityParameter.ActualValue,
     209        FlowDistanceQualityParameter.ActualValue,
     210        InstallationQualityParameter.ActualValue,
     211        OverbookedCapacityParameter.ActualValue,
    181212        MaximumCandidateListSizeParameter.ActualValue,
    182213        MaximumSampleSizeParameter.ActualValue,
    183214        MaximumIterationsParameter.ActualValue,
    184         DemandsParameter.ActualValue, CapacitiesParameter.ActualValue,
    185215        WeightsParameter.ActualValue, DistancesParameter.ActualValue,
    186216        InstallationCostsParameter.ActualValue,
    187         TransportationCostsParameter.ActualValue);
     217        DemandsParameter.ActualValue, CapacitiesParameter.ActualValue,
     218        TransportationCostsParameter.ActualValue,
     219        OverbookedCapacityPenaltyParameter.ActualValue,
     220        OneMoveProbabilityParameter.ActualValue);
    188221      return base.Apply();
    189222    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/GreedyRandomizedSolutionCreator.cs

    r7407 r7412  
    6060      while (tries < maxTries) {
    6161        assignment.Clear();
    62         demands.Select((v, i) => slack[i] = v).Enumerate();
     62        capacities.Select((v, i) => slack[i] = v).Enumerate();
    6363        HashSet<int> CF = new HashSet<int>(), // set of chosen facilities / equipments
    6464          T = new HashSet<int>(), // set of facilities / equpiments that can be assigned to the set of chosen locations (CL)
Note: See TracChangeset for help on using the changeset viewer.