Changeset 14607 for branches/OptimizationNetworks/HeuristicLab.Problems.FacilityLocation/3.3/FacilityLocationProblem.cs
- Timestamp:
- 01/25/17 16:20:27 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.