public static IEnumerable<Coordinate> ApproximateTrajectoryPartition(Trajectory trajectory) { var characteristicPoints = new List<Coordinate> (); characteristicPoints.Add (trajectory.Coordinates.First ()); int startIndex = 0; int length = 0; while (startIndex + length < trajectory.Count) { int currentIndex = startIndex + length; int costPar = minimumDescriptionLengthPar (trajectory, startIndex, currentIndex); int costNoPar = minimumDescriptionLengthNoPar (trajectory, startIndex, currentIndex); if (costPar > costNoPar) { characteristicPoints.Add (trajectory.Coordinates.ElementAt (currentIndex - 1)); startIndex = currentIndex - 1; length = 1; } else { length++; } } cw++; Console.WriteLine("Progress: Trajectory " + cw + "/100000"); return characteristicPoints; }
public static Trajectory ParseTrajectory(String polyline) { var trajectory = new Trajectory(); var sep = new char[] { ']' }; var split = polyline.Split(sep, options:StringSplitOptions.RemoveEmptyEntries); IEnumerable<string> points = split.Take(split.Count() - 1).Select(p => p.Remove(0, 3)); foreach(var point in points) { var coordinate = ParseCoordinate (point); if (trajectory.Coordinates.LastOrDefault () == null || isFarEnough (trajectory.Coordinates.LastOrDefault (), coordinate)) { trajectory.Add (coordinate); } } return trajectory; }
public static int minimumDescriptionLengthNoPar(Trajectory trajectory, int startIndex, int endIndex) { return descriptionCost (trajectory, startIndex, endIndex); }
private static int encodingCost(Trajectory trajectory, int startIndex, int endIndex) { double perpendicularDist; double angleDist; int encodingCost = 0; Coordinate startComponent = trajectory.Coordinates.ElementAt (startIndex); Coordinate endComponent = trajectory.Coordinates.ElementAt (endIndex); //TODO correct this if(startComponent.Vector == endComponent.Vector) return 0; for (int i = startIndex; i < endIndex; i++) { Coordinate startSegment = trajectory.Coordinates.ElementAt (i); Coordinate endSegment = trajectory.Coordinates.ElementAt (i + 1); perpendicularDist = perpendicularDistance(startComponent, endComponent, startSegment, endSegment); angleDist = angleDistance(startComponent, endComponent, startSegment, endSegment); if (perpendicularDist< 1.0) perpendicularDist = 1.0f; if (angleDist < 1.0) angleDist = 1.0f; encodingCost += (int)Math.Ceiling(Math.Log(perpendicularDist, 2)) + (int)Math.Ceiling(Math.Log(angleDist, 2)); } return encodingCost; }
private static int descriptionCost(Trajectory trajectory, int startIndex, int endIndex) { Coordinate startSegment = trajectory.Coordinates.ElementAt (startIndex); Coordinate endSegment = trajectory.Coordinates.ElementAt (endIndex); double distance = euclidianDistance (startSegment.Vector, endSegment.Vector); if (distance < 1.0) distance = 1.0f; return (int)Math.Ceiling (Math.Log (distance, 2)); }