- Timestamp:
- 02/03/12 16:19:24 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs
r7443 r7445 201 201 } 202 202 203 public void LoadFrom(IQAPInstance format) {204 Weights = new DoubleMatrix( format.Weights);205 Distances = new DoubleMatrix( format.Distances);206 InstallationCosts = new DoubleMatrix(Weights.Rows, Distances.Columns); 203 public void LoadFrom(IQAPInstance instance) { 204 Weights = new DoubleMatrix(instance.Weights); 205 Distances = new DoubleMatrix(instance.Distances); 206 InstallationCosts = new DoubleMatrix(Weights.Rows, Distances.Columns); // all zero 207 207 Capacities = new DoubleArray(Enumerable.Range(0, Distances.Rows).Select(x => 1.0).ToArray()); 208 208 Demands = new DoubleArray(Enumerable.Range(0, Weights.Rows).Select(x => 1.0).ToArray()); 209 209 210 if (format.BestKnownAssignment != null) { 211 var assignment = new IntegerVector(format.BestKnownAssignment); 212 double flowDistanceQuality, installationQuality, overbookedCapacity; 213 GQAPEvaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities, 214 out flowDistanceQuality, out installationQuality, out overbookedCapacity); 215 double quality = GQAPEvaluator.GetCombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts.Value, OverbookedCapacityPenalty.Value); 216 BestKnownSolution = new GQAPSolution(assignment, new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity)); 217 BestKnownQuality = new DoubleValue(quality); 218 } 210 TransportationCosts.Value = 1; 211 212 if (instance.BestKnownAssignment != null) { 213 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 214 } 215 } 216 217 public void LoadFrom(ICTAPInstance instance) { 218 Capacities = new DoubleArray(instance.MemoryCapacities); 219 Demands = new DoubleArray(instance.MemoryRequirements); 220 Weights = new DoubleMatrix(instance.CommunicationCosts); 221 InstallationCosts = new DoubleMatrix(instance.ExecutionCosts); 222 Distances = new DoubleMatrix(Capacities.Length, Capacities.Length); // all one, except diagonal 223 for (int i = 0; i < Capacities.Length - 1; i++) 224 for (int j = i + 1; j < Capacities.Length; j++) { 225 Distances[i, j] = 1; 226 Distances[j, i] = 1; 227 } 228 229 TransportationCosts.Value = 1; 230 231 if (instance.BestKnownAssignment != null) { 232 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 233 } 234 } 235 236 private void EvaluateAndLoadAssignment(int[] vector) { 237 var assignment = new IntegerVector(vector); 238 double flowDistanceQuality, installationQuality, overbookedCapacity; 239 GQAPEvaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities, 240 out flowDistanceQuality, out installationQuality, out overbookedCapacity); 241 double quality = GQAPEvaluator.GetCombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts.Value, OverbookedCapacityPenalty.Value); 242 BestKnownSolution = new GQAPSolution(assignment, new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity)); 243 BestKnownQuality = new DoubleValue(quality); 219 244 } 220 245
Note: See TracChangeset
for help on using the changeset viewer.