Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/VRPProblemAnalyzer/DepotExcentricityCalculator.cs @ 13660

Last change on this file since 13660 was 7315, checked in by epitzer, 13 years ago

#1696: Add VRP depot excentricity metrics

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace VRPProblemAnalyzer {
7
8  public class DepotExcentricityCalculator {
9
10    public static double Geographic(double[,] vertices) {
11      var customers = Utils.MatrixToPointList(vertices);
12      var depot = customers[0];
13      customers.RemoveAt(0);
14      var minX = customers.Min(c => c.X);
15      var minY = customers.Min(c => c.Y);
16      var maxX = customers.Max(c => c.X);
17      var maxY = customers.Max(c => c.Y);
18      var rangeX = maxX - minX;
19      var rangeY = maxY - minY;
20      var center = new PointD(minX + rangeX/2, minY + rangeY/2);
21      Console.WriteLine("Geographic {0} -> {1} = {2}", depot, center, depot.DistanceTo(center));
22      return depot.DistanceTo(center);
23    }
24
25    public static double DistanceCentroid(double[,] vertices) {
26      var customers = Utils.MatrixToPointList(vertices);
27      var depot = customers[0];
28      customers.RemoveAt(0);
29      var center = new PointD(
30        customers.Select(c => c.X).Average(),
31        customers.Select(c => c.Y).Average());
32      Console.WriteLine("Distance {0} -> {1} = {2}", depot, center, depot.DistanceTo(center));
33      return depot.DistanceTo(center);
34    }
35
36    public static double DemandDistanceCentroid(double[,] vertices, double[] demands) {
37      var factor = demands.Sum()/demands.Length;
38      var customers = Utils.MatrixToPointList(vertices).Zip(demands, (c, d) => new {c.X, c.Y, D = d/factor}).ToList();
39      var depot = customers[0];
40      customers.RemoveAt(0);
41      var center = new PointD(
42        customers.Select(c => c.X*c.D).Average(),
43        customers.Select(c => c.Y*c.D).Average());
44      Console.WriteLine("Demand {0} -> {1} = {2}", depot, center, new PointD(depot.X, depot.Y).DistanceTo(center));
45      return new PointD(depot.X, depot.Y).DistanceTo(center);
46    }
47  }
48}
Note: See TracBrowser for help on using the repository browser.