Changeset 7412 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators
- Timestamp:
- 01/25/12 18:32:44 (13 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP
- Property svn:ignore
-
old new 1 1 *.suo 2 TestResults
-
- Property svn:ignore
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/ApproximateLocalSearch.cs
r7407 r7412 55 55 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 56 56 } 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"]; } 59 65 } 60 66 public ILookupParameter<ResultCollection> ResultsParameter { … … 79 85 get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; } 80 86 } 81 public ILookupParameter<DoubleValue> TransportationCostsParameter {82 get { return (ILookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }83 }84 87 public ILookupParameter<DoubleArray> DemandsParameter { 85 88 get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; } … … 88 91 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 89 92 } 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 } 91 102 92 103 [StorableConstructor] … … 99 110 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solution equivalents.")); 100 111 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.")); 102 115 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The result collection that stores the results.")); 103 116 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumCandidateListSize", "The maximum number of candidates that should be found in each step.", new IntValue(10))); … … 107 120 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The distances matrix describes the distances between the locations at which the equipment can be installed.")); 108 121 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."));110 122 Parameters.Add(new LookupParameter<DoubleArray>("Demands", "The demands vector describes the space requirements of the equipments.")); 111 123 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))); 112 127 } 113 128 … … 124 139 /// <param name="assignment">The equipment-location assignment vector.</param> 125 140 /// <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> 127 144 /// <param name="maxCLS">The maximum number of candidates that should be found in each step.</param> 128 145 /// <param name="maxSampleSize">The maximum number of candidates that should be sampled in each step.</param> 129 146 /// <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>132 147 /// <param name="weights">The weights matrix describes the flows between the equipments.</param> 133 148 /// <param name="distances">The distances matrix describes the distances between the locations at which the equipment can be installed.</param> 134 149 /// <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> 135 152 /// <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 142 161 for (int i = 0; i < maximumIterations.Value; i++) { 143 162 int count = 0; 144 var CLS = new List<Tuple<NMove, DoubleValue, DoubleValue>>();163 var CLS = new List<Tuple<NMove, double, double, double, double>>(); 145 164 double sum = 0.0; 146 165 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; 155 180 } 156 181 count++; 157 182 } while (CLS.Count < maxCLS.Value && count < maxSampleSize.Value); 158 if (CLS.Count == 0) return; // END 183 184 if (CLS.Count == 0) 185 return; // END 159 186 else { 160 187 var ball = random.NextDouble() * sum; 161 188 var selected = CLS.Last(); 162 189 foreach (var candidate in CLS) { 163 ball -= 1.0 / candidate.Item2 .Value;190 ball -= 1.0 / candidate.Item2; 164 191 if (ball <= 0.0) { 165 192 selected = candidate; … … 168 195 } 169 196 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; 172 201 } 173 202 } … … 178 207 AssignmentParameter.ActualValue, 179 208 QualityParameter.ActualValue, 180 InfeasibilityParameter.ActualValue, 209 FlowDistanceQualityParameter.ActualValue, 210 InstallationQualityParameter.ActualValue, 211 OverbookedCapacityParameter.ActualValue, 181 212 MaximumCandidateListSizeParameter.ActualValue, 182 213 MaximumSampleSizeParameter.ActualValue, 183 214 MaximumIterationsParameter.ActualValue, 184 DemandsParameter.ActualValue, CapacitiesParameter.ActualValue,185 215 WeightsParameter.ActualValue, DistancesParameter.ActualValue, 186 216 InstallationCostsParameter.ActualValue, 187 TransportationCostsParameter.ActualValue); 217 DemandsParameter.ActualValue, CapacitiesParameter.ActualValue, 218 TransportationCostsParameter.ActualValue, 219 OverbookedCapacityPenaltyParameter.ActualValue, 220 OneMoveProbabilityParameter.ActualValue); 188 221 return base.Apply(); 189 222 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/GreedyRandomizedSolutionCreator.cs
r7407 r7412 60 60 while (tries < maxTries) { 61 61 assignment.Clear(); 62 demands.Select((v, i) => slack[i] = v).Enumerate();62 capacities.Select((v, i) => slack[i] = v).Enumerate(); 63 63 HashSet<int> CF = new HashSet<int>(), // set of chosen facilities / equipments 64 64 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.