- Timestamp:
- 01/25/17 16:20:27 (8 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.LocationRouting/3.3/LrpOrchestratorNode1.cs
r14606 r14607 278 278 279 279 var bestFlpSolution = (IntegerVector)flpResults["Best Solution"].Value; 280 var bestFlpQuality = FlpParameter.Value.Evaluate(bestFlpSolution); 281 var flpCustomerDemands = (DoubleArray)FlpParameter.Value.CustomerDemandsParameter.Value.Clone(); 282 var flpDeliveryCosts = (DoubleMatrix)FlpParameter.Value.DeliveryCostsParameter.Value.Clone(); 283 var flpDepotCapacities = (DoubleArray)FlpParameter.Value.DepotCapacitiesParameter.Value.Clone(); 284 var flpOpeningCosts = (DoubleArray)FlpParameter.Value.OpeningCostsParameter.Value.Clone(); 285 double totalOpeningCosts, totalDeliveryCosts; double[] depotUsage; 286 FacilityLocationProblem.Evaluate(bestFlpSolution.ToArray(), flpOpeningCosts, flpDepotCapacities, flpCustomerDemands, flpDeliveryCosts, out totalOpeningCosts, out totalDeliveryCosts, out depotUsage); 287 var flpSolution = new FacilityLocationSolution { 288 OpeningCosts = flpOpeningCosts, 289 DepotCapacities = flpDepotCapacities, 290 CustomerDemands = flpCustomerDemands, 291 DeliveryCosts = flpDeliveryCosts 292 }; 293 flpSolution.CustomerToDepotAssignmentParameter.Value = bestFlpSolution; 294 flpSolution.FitnessValueParameter.Value = new DoubleValue(bestFlpQuality); 295 flpSolution.TotalOpeningCostsParameter.Value = new DoubleValue(totalOpeningCosts); 296 flpSolution.TotalDeliveryCostsParameter.Value = new DoubleValue(totalDeliveryCosts); 297 flpSolution.TotalOverbookedCapacityParameter.Value = new DoubleValue(bestFlpQuality - totalOpeningCosts - totalDeliveryCosts); 298 280 var flpSolution = FlpParameter.Value.GetSolution(bestFlpSolution); 281 299 282 var depots = bestFlpSolution.Select((x, i) => Tuple.Create(x, i)).GroupBy(x => x.Item1, x => x.Item2); 300 283 var vrpSolutions = new ResultCollection(depots.Count()); … … 305 288 var vrp = (VehicleRoutingProblem)VrpParameter.Value.Clone(); 306 289 var vrpInstance = (CVRPProblemInstance)vrp.ProblemInstance; 307 var coordinates = LrpUtils.GetVrpCoordinates(depotCoordinates, customerCoordinates, depot .Key, customers);290 var coordinates = LrpUtils.GetVrpCoordinates(depotCoordinates, customerCoordinates, depotIdx, customers); 308 291 var distances = LrpUtils.GetVrpDistances(coordinates, distanceType); 309 292 vrpInstance.Coordinates = new DoubleMatrix(coordinates); -
branches/OptimizationNetworks/HeuristicLab.Problems.FacilityLocation/3.3/FacilityLocationProblem.cs
r14587 r14607 37 37 [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 230)] 38 38 [StorableClass] 39 public class FacilityLocationProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding> {39 public sealed class FacilityLocationProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding> { 40 40 public override bool Maximization { 41 41 get { return false; } … … 67 67 68 68 [StorableConstructor] 69 pr otectedFacilityLocationProblem(bool deserializing) : base(deserializing) { }70 pr otectedFacilityLocationProblem(FacilityLocationProblem original, Cloner cloner)69 private FacilityLocationProblem(bool deserializing) : base(deserializing) { } 70 private FacilityLocationProblem(FacilityLocationProblem original, Cloner cloner) 71 71 : base(original, cloner) { 72 72 openingCostsParameter = cloner.Clone(original.openingCostsParameter); … … 153 153 } 154 154 155 public virtualdouble Evaluate(IntegerVector depotAssignment) {155 public double Evaluate(IntegerVector depotAssignment) { 156 156 var openingCosts = OpeningCostsParameter.Value; 157 157 var capacities = DepotCapacitiesParameter.Value; … … 163 163 164 164 try { 165 Evaluate(depotAssignment, openingCosts, capacities, demands, deliveryCosts, out totalOpeningCosts, out totalDeliveryCosts, out depotUsage);165 return Evaluate(depotAssignment, openingCosts, capacities, demands, deliveryCosts, out totalOpeningCosts, out totalDeliveryCosts, out depotUsage); 166 166 } catch (IndexOutOfRangeException) { 167 167 throw new ArgumentException("The solution contains more customers than there are problem data for."); 168 168 } 169 } 170 171 public FacilityLocationSolution GetSolution(IntegerVector depotAssignment) { 172 var openingCosts = OpeningCostsParameter.Value; 173 var capacities = DepotCapacitiesParameter.Value; 174 var demands = CustomerDemandsParameter.Value; 175 var deliveryCosts = DeliveryCostsParameter.Value; 176 177 double totalOpeningCosts, totalDeliveryCosts, fitness; 178 double[] depotUsage; 179 180 try { 181 fitness = Evaluate(depotAssignment, openingCosts, capacities, demands, deliveryCosts, out totalOpeningCosts, out totalDeliveryCosts, out depotUsage); 182 } catch (IndexOutOfRangeException) { 183 throw new ArgumentException("The solution contains more customers than there are problem data for."); 184 } 169 185 170 186 var overbooking = depotUsage.Zip(capacities, (a, b) => a > b ? a - b : 0).Sum(); 171 if (overbooking > 0) // infeasible 172 return openingCosts.Sum() + deliveryCosts.Sum() + overbooking; 173 174 return totalOpeningCosts + totalDeliveryCosts; 175 } 176 177 public static void Evaluate(IEnumerable<int> customer2Depot, DoubleArray openingCosts, DoubleArray capacities, DoubleArray demands, DoubleMatrix deliveryCosts, out double totalOpeningCosts, out double totalDeliveryCosts, out double[] capacityDemandsPerDepot) { 187 188 return new FacilityLocationSolution() { 189 OpeningCosts = (DoubleArray)openingCosts.Clone(), 190 DepotCapacities = (DoubleArray)capacities.Clone(), 191 CustomerDemands = (DoubleArray)demands.Clone(), 192 DeliveryCosts = (DoubleMatrix)deliveryCosts.Clone(), 193 CustomerToDepotAssignmentParameter = { Value = (IntegerVector)depotAssignment.Clone() }, 194 FitnessValueParameter = { Value = new DoubleValue(fitness) }, 195 TotalOpeningCostsParameter = { Value = new DoubleValue(totalOpeningCosts) }, 196 TotalDeliveryCostsParameter = { Value = new DoubleValue(totalDeliveryCosts) }, 197 TotalOverbookedCapacityParameter = { Value = new DoubleValue(overbooking) } 198 }; 199 } 200 201 public static double Evaluate(IEnumerable<int> customer2Depot, DoubleArray openingCosts, DoubleArray capacities, DoubleArray demands, DoubleMatrix deliveryCosts, out double totalOpeningCosts, out double totalDeliveryCosts, out double[] capacityDemandsPerDepot) { 178 202 var D = capacities.Length; 179 203 … … 189 213 customer++; 190 214 } 215 216 217 var overbooking = capacityDemandsPerDepot.Zip(capacities, (a, b) => a > b ? a - b : 0).Sum(); 218 if (overbooking > 0) // infeasible 219 return openingCosts.Sum() + deliveryCosts.Sum() + overbooking; 220 221 return totalOpeningCosts + totalDeliveryCosts; 191 222 } 192 223
Note: See TracChangeset
for help on using the changeset viewer.