/// <summary> /// Calculates observation probability /// </summary> /// <param name="original">GPS track point</param> /// <param name="candidate">Candidate point</param> /// <returns>double representing probability that GPS track point corresponds with Candidate point</returns> double CalculateObservationProbability(GPXPoint original, IPointGeo candidate) { double sigma = 30; double distance = Calculations.GetDistance2D(original, candidate); return(Math.Exp(-distance * distance / (2 * sigma * sigma)) / (sigma * Math.Sqrt(Math.PI * 2))); }
public GPXTrackSegment Filter(TimeSpan minInterval, GPXTrackSegment track) { GPXTrackSegment result = new GPXTrackSegment(); if (track.Nodes.Count == 0) { return(result); } GPXPoint last = track.Nodes[0]; result.Nodes.Add(last); int index = 1; while (index < track.Nodes.Count) { if (track.Nodes[index].Time - last.Time >= minInterval) { last = track.Nodes[index]; result.Nodes.Add(last); } index++; } if (last.Time != track.Nodes.Last().Time) { result.Nodes.Add(track.Nodes.Last()); } return(result); }
/// <summary> /// Finds all candidates points for given GPS track point /// </summary> /// <param name="gpxPt">GPS point</param> /// <returns>Collection of points candidate points on road segments</returns> public IEnumerable <CandidatePoint> FindCandidatePoints(GPXPoint gpxPt) { List <CandidatePoint> result = new List <CandidatePoint>(); BBox gpxBbox = new BBox(new IPointGeo[] { gpxPt }); gpxBbox.Inflate(0.0007, 0.0011); foreach (var road in _trackCutout) { if (Topology.Intersects(gpxBbox, road.BBox)) { Segment <IPointGeo> roadSegment; IPointGeo projectedPoint = Topology.ProjectPoint(gpxPt, road, out roadSegment); result.Add(new CandidatePoint() { MapPoint = projectedPoint, Road = road, RoadSegment = roadSegment, ObservationProbability = CalculateObservationProbability(gpxPt, projectedPoint) }); } } if (result.Count == 0) { throw new Exception(string.Format("Can not find any candidate point for {0}", gpxPt)); } return(result); }
public double getTimeInRH(TrafficLight t) { double timeAvgSegments = 0; foreach (var segment in _segments) { GPXPoint firstPoint = segment.Nodes.First(); GPXPoint lastPoint = segment.Nodes.Last(); if (segment.Nodes.Contains(t)) { if (firstPoint == t) { break; } } var distance = Calculations.GetDistance2D(firstPoint, lastPoint); double timeAvgSegment = distance / segment.AvgSpeed; timeAvgSegments += timeAvgSegment; if (segment.Nodes.Contains(t)) { break; } } return(timeAvgSegments); }
/// <summary> /// Raises the WaypointRead event /// </summary> /// <param name="node">The waypoint read from the xml</param> protected void OnWaypointRead(GPXPoint waypoint) { GPXWaypointReadHandler temp = WaypointRead; if (temp != null) { temp(waypoint); } }
/// <summary> /// Creates a new layer in the CandidatesGraph /// </summary> /// <param name="originalPoint">GPX track point</param> /// <param name="candidates">Candidate points for the original point</param> public void CreateLayer(GPXPoint originalPoint, IEnumerable <CandidatePoint> candidates) { CandidateGraphLayer result = new CandidateGraphLayer() { TrackPoint = originalPoint }; result.Candidates.AddRange(candidates); foreach (var candidate in candidates) { candidate.Layer = result; } _layers.Add(result); }
static void Main(string[] args) { string gpxPath = ""; bool showHelp = false; OptionSet parameters = new OptionSet() { { "gpx=", "path to the map file", v => gpxPath = v }, { "h|?|help", v => showHelp = v != null }, }; try { parameters.Parse(args); } catch (OptionException e) { Console.Write("TRoute: "); Console.WriteLine(e.Message); Console.WriteLine("Try `TRoute --help' for more information."); return; } if (showHelp || string.IsNullOrEmpty(gpxPath)) { ShowHelp(parameters); return; } HRDocument hr = new HRDocument(); hr.Load(gpxPath); hr.Webster(); GPXPoint bucketInfo = null; foreach (var track in hr.Tracks) { foreach (var seg in track.Segments) { bucketInfo = seg.Nodes.ToList().Find(x => x.Id == 0); } } Solve(hr.getListProcessor(), hr.getJobTime(), hr.getJobId(), bucketInfo, hr.cycleTime); }
/// <summary> /// Writes point data to the specific tag to the output /// </summary> /// <param name="point">The point that's data should be written</param> /// <param name="tag">The name of the output tag</param> /// <example> /// //writes waypoint /// WritePointData(waypoint, "wpt"); /// </example> protected void WritePointData(GPXPoint point, string tag) { _xmlWriter.WriteStartElement(tag); // writing id _xmlWriter.WriteAttributeString("id", point.Id.ToString(System.Globalization.CultureInfo.InvariantCulture)); _xmlWriter.WriteAttributeString("lat", point.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture)); _xmlWriter.WriteAttributeString("lon", point.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (point.Elevation != 0) { _xmlWriter.WriteElementString("ele", point.Elevation.ToString(System.Globalization.CultureInfo.InvariantCulture)); } if (point.Time != DateTime.MinValue) { _xmlWriter.WriteElementString("time", point.Time.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'")); } if (string.IsNullOrEmpty(point.Name) == false) { _xmlWriter.WriteElementString("name", point.Name); } if (string.IsNullOrEmpty(point.Description) == false) { _xmlWriter.WriteElementString("desc", point.Description); } if (string.IsNullOrEmpty(point.Commenet) == false) { _xmlWriter.WriteElementString("cmt", point.Commenet); } if (point.TrafficSignal != false) { _xmlWriter.WriteAttributeString("traffic_signal", point.TrafficSignal.ToString()); } if (point.StartBucket >= TimeSpan.Zero && point.EndBucket != TimeSpan.Zero) { _xmlWriter.WriteAttributeString("startBucket", point.StartBucket.ToString()); _xmlWriter.WriteAttributeString("endBucket", point.EndBucket.ToString()); } _xmlWriter.WriteEndElement(); }
static void GenerateGpxFiles(List <Bucket> buckets, string file, int positionFile) { foreach (var b in buckets) { if (b.Paths.Any()) { // Saving the Map to GPX instead of OSM - START var tracks = new List <GPXTrack>(); foreach (var p in b.Paths) { GPXTrack track = new GPXTrack(p.Key); foreach (var t in p.Value) { List <GPXPoint> list = new List <GPXPoint>(); foreach (var s in t.Segments) { GPXPoint start = new GPXPoint() { Latitude = s.StartPoint.Latitude, Longitude = s.StartPoint.Longitude }; GPXPoint end = new GPXPoint() { Latitude = s.EndPoint.Latitude, Longitude = s.EndPoint.Longitude }; list.Add(start); list.Add(end); } GPXTrackSegment gpxTrack = new GPXTrackSegment(list); track.Segments.Add(gpxTrack); } tracks.Add(track); } var gpx = new GPXDocument() { Tracks = tracks }; gpx.Save("mapGpx" + positionFile + ".gpx"); // END } } }
public double getTotalTimeRoute() { double timeAvgSegments = 0; foreach (var s in _segments) { GPXPoint firstPoint = s.Nodes.First(); GPXPoint lastPoint = s.Nodes.Last(); var distance = Calculations.GetDistance2D(firstPoint, lastPoint); if (s.AvgSpeed != 0) { double timeAvgSegment = distance / s.AvgSpeed; timeAvgSegments += timeAvgSegment; } } return(timeAvgSegments); }
static void Main(string[] args) { string osmPath = ""; int eps = -1; int minTraffic = -1; bool showHelp = false; OptionSet parameters = new OptionSet() { { "osm=", "path to the map file", v => osmPath = v }, { "eps=", "size of the eps-neighborhood to be considered (integer)", v => eps = Convert.ToInt32(v) }, { "minTraffic=", "minimum traffic considered (integer)", v => minTraffic = Convert.ToInt32(v) }, { "h|?|help", v => showHelp = v != null }, }; try { parameters.Parse(args); } catch (OptionException e) { Console.Write("TRoute: "); Console.WriteLine(e.Message); Console.WriteLine("Try `TRoute --help' for more information."); return; } if (showHelp || string.IsNullOrEmpty(osmPath) || eps < 0 || minTraffic < 0) { ShowHelp(parameters); return; } var osmFile = new OSMDB(); osmFile.Load(osmPath); var roadGraph = new RoadGraph(); roadGraph.Build(osmFile); // Getting all the nodes with traffic signals Dictionary <double, OSMNode> tagsNodes = new Dictionary <double, OSMNode>(); foreach (var node in osmFile.Nodes) { foreach (var tag in node.Tags) { if (tag.Value.Equals("traffic_signals")) { if (!tagsNodes.Keys.Contains(node.Latitude + node.Longitude)) { tagsNodes.Add(node.Latitude + node.Longitude, node); } } } } var hotRoutes = new FlowScan().Run(roadGraph, eps, minTraffic); // Saving GPX file of the Hot Route HashSet <GPXPoint> listPoints; HashSet <GPXTrackSegment> listSegments; GPXTrackSegment segTrack; List <GPXTrack> track = new List <GPXTrack>(); GPXTrack tr; //Console.WriteLine(hotRoutes.Count); foreach (var hr in hotRoutes) { //Console.WriteLine("Number segs: " + hr.Segments.Count); listSegments = new HashSet <GPXTrackSegment>(); foreach (var seg in hr.Segments) { listPoints = new HashSet <GPXPoint>(); foreach (var segInner in seg.Geometry.Segments) { GPXPoint start; if (tagsNodes.Keys.Contains(segInner.StartPoint.Latitude + segInner.StartPoint.Longitude)) { OSMNode osmNode = tagsNodes[segInner.StartPoint.Latitude + segInner.StartPoint.Longitude]; start = new GPXPoint() { Id = osmNode.ID, Latitude = segInner.StartPoint.Latitude, Longitude = segInner.StartPoint.Longitude, TrafficSignal = true }; } else { OSMNode osmNode = osmFile.Nodes.ToList().First(x => x.Latitude == segInner.StartPoint.Latitude && x.Longitude == segInner.StartPoint.Longitude); start = new GPXPoint() { Id = osmNode.ID, Latitude = segInner.StartPoint.Latitude, Longitude = segInner.StartPoint.Longitude, TrafficSignal = false }; } GPXPoint end; if (tagsNodes.Keys.Contains(segInner.EndPoint.Latitude + segInner.EndPoint.Longitude)) { OSMNode osmNode = tagsNodes[segInner.EndPoint.Latitude + segInner.EndPoint.Longitude]; end = new GPXPoint() { Id = osmNode.ID, Latitude = segInner.EndPoint.Latitude, Longitude = segInner.EndPoint.Longitude, TrafficSignal = true }; } else { OSMNode osmNode = osmFile.Nodes.ToList().First(x => x.Latitude == segInner.EndPoint.Latitude && x.Longitude == segInner.EndPoint.Longitude); end = new GPXPoint() { Id = osmNode.ID, Latitude = segInner.EndPoint.Latitude, Longitude = segInner.EndPoint.Longitude, TrafficSignal = false }; } listPoints.Add(start); listPoints.Add(end); } segTrack = new GPXTrackSegment(listPoints, seg.AvgSpeed, seg.Speed, seg.Id); // passing the traffic segTrack.Traffic = seg.Traffic; listSegments.Add(segTrack); } tr = new GPXTrack(); tr.Segments.AddRange(listSegments); track.Add(tr); } // Bucket Information GPXTrack tBucket = new GPXTrack(); GPXPoint pBucket = new GPXPoint(0, 0, 0, false); GPXTrackSegment sBucket = new GPXTrackSegment(); var bucketInfo = osmFile.Nodes.ToList().Find(x => x.ID == 0); if (bucketInfo != null) { pBucket.StartBucket = TimeSpan.Parse(bucketInfo.Tags.First().Value); pBucket.EndBucket = TimeSpan.Parse(bucketInfo.Tags.Last().Value); } sBucket.Nodes.Add(pBucket); tBucket.Segments.Add(sBucket); var gpx = new GPXDocument() { Tracks = track }; gpx.Tracks.Add(tBucket); gpx.Save("mapWithHotRoutes.gpx"); }
// Constructor public JobShop(List <List <int> > machines, List <List <int> > processingTime, List <List <int> > jobIds, GPXPoint bucketInfo, int cycleTime) { this.machinesCount = machines.Count; this.jobsCount = processingTime.Count; this.bucketInfo = bucketInfo; this.cycleTime = cycleTime; this.jobIds = jobIds; Console.WriteLine("machinesCount: " + this.machinesCount); Console.WriteLine("jobsCount: " + jobsCount); this.allMachines = new List <int>(); for (var i = 0; i < this.machinesCount; i++) { this.allMachines.Add(i); } this.allJobs = new List <int>(); for (var i = 0; i < this.jobsCount; i++) { this.allJobs.Add(i); } // Define data. this.machines = machines; this.processingTimes = processingTime; // Computes horizon for (var i = 0; i < allMachines.Count; i++) { this.horizon += processingTimes.ElementAt(i).Sum(); } Console.WriteLine("Horizon: " + this.horizon); }
/// <summary> /// Writes point data to the specific tag to the output /// </summary> /// <param name="point">The point that's data should be written</param> /// <param name="tag">The name of the output tag</param> /// <example> /// //writes waypoint /// WritePointData(waypoint, "wpt"); /// </example> protected void WritePointData(GPXPoint point, string tag) { _xmlWriter.WriteStartElement(tag); _xmlWriter.WriteAttributeString("lat", point.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture)); _xmlWriter.WriteAttributeString("lon", point.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (point.Elevation != 0) { _xmlWriter.WriteElementString("ele", point.Elevation.ToString(System.Globalization.CultureInfo.InvariantCulture)); } if (point.Time != DateTime.MinValue) { _xmlWriter.WriteElementString("time", point.Time.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'")); } if (string.IsNullOrEmpty(point.Name) == false) { _xmlWriter.WriteElementString("name", point.Name); } if (string.IsNullOrEmpty(point.Description) == false) { _xmlWriter.WriteElementString("desc", point.Description); } if (string.IsNullOrEmpty(point.Commenet) == false) { _xmlWriter.WriteElementString("cmt", point.Commenet); } _xmlWriter.WriteEndElement(); }
/// <summary> /// Writes the specific waypoint to the output /// </summary> /// <param name="waypoint">The waypoint to be written</param> public void WriteWaypoint(GPXPoint waypoint) { WritePointData(waypoint, "wpt"); }
/// <summary> /// Reads a point from gpx document /// </summary> private GPXPoint ReadPoint() { // latitude attribute string lat = _xmlReader.GetAttribute("lat"); if (string.IsNullOrEmpty(lat)) { throw new XmlException("Attribute 'lat' is missing."); } double pointLat = double.Parse(lat, System.Globalization.CultureInfo.InvariantCulture); // longitude attribute string lon = _xmlReader.GetAttribute("lon"); if (string.IsNullOrEmpty(lon)) { throw new XmlException("Attribute 'lon' is missing."); } // longitude attribute string trafficSignal = _xmlReader.GetAttribute("traffic_signal"); double pointLon = double.Parse(lon, System.Globalization.CultureInfo.InvariantCulture); GPXPoint parsedPoint = new GPXPoint(pointLat, pointLon); // Id if (_xmlReader.GetAttribute("id") != null) { parsedPoint.Id = long.Parse(_xmlReader.GetAttribute("id")); } if (trafficSignal != null) { parsedPoint.TrafficSignal = bool.Parse(trafficSignal); } // Reading bucket info if (_xmlReader.GetAttribute("startBucket") != null && _xmlReader.GetAttribute("endBucket") != null) { parsedPoint.StartBucket = TimeSpan.Parse(_xmlReader.GetAttribute("startBucket")); parsedPoint.EndBucket = TimeSpan.Parse(_xmlReader.GetAttribute("endBucket")); } if (_xmlReader.IsEmptyElement == false) { _xmlReader.Read(); while (_xmlReader.NodeType != XmlNodeType.EndElement) { if (_xmlReader.NodeType == XmlNodeType.Element) { switch (_xmlReader.Name) { case "ele": string ele = _xmlReader.ReadString(); parsedPoint.Elevation = double.Parse(ele, System.Globalization.CultureInfo.InvariantCulture); _xmlReader.Skip(); break; case "time": string time = _xmlReader.ReadString(); parsedPoint.Time = DateTime.Parse(time, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal); //parsedPoint.Time = TimeSpan.ParseExact(time, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal); _xmlReader.Skip(); break; case "name": parsedPoint.Name = _xmlReader.ReadString(); _xmlReader.Skip(); break; case "desc": parsedPoint.Description = _xmlReader.ReadString(); _xmlReader.Skip(); break; case "cmt": parsedPoint.Commenet = _xmlReader.ReadString(); _xmlReader.Skip(); break; default: _xmlReader.Skip(); break; } } else { _xmlReader.Skip(); } } } _xmlReader.Skip(); return(parsedPoint); }
static void ProcessCSVFile(string path, string outputPath, int samplingPeriod) { double max_lat = -3.691978693, min_lat = -3.8881242275, max_lon = -38.4018707275, min_lon = -38.6374359131; //geo-bounding box for Fortaleza GPXDocument gpx = new GPXDocument(); Console.Write("Parsing {0} ...", Path.GetFileName(path)); string line; char[] seps = { ';', ',', '\t' }; char sep = '.'; String[] fields = { }; long last_id = -1; int id_field = 0; int lat_field = 1; int lon_field = 2; int time_field = 7; int uf1_field = 3; int uf2_field = 4; int uf3_field = 5; int uf4_field = 6; Boolean header = true; GPXTrack trk = null; List <long> ids = new List <long>(); if (samplingPeriod > 0) { DateTime dt = File.GetLastWriteTime(path); if ((DateTime.Now - dt).Days > samplingPeriod) { Console.WriteLine("skiping"); return; } } // Read the file and display it line by line. System.IO.StreamReader csv = new System.IO.StreamReader(path); line = csv.ReadLine(); if (line != null) { for (int i = 0; i < seps.Length; i++) { if ((fields = line.Split(seps[i])).Length > 1) { sep = seps[i]; break; } } if (sep == '.') { throw new Exception(string.Format("Can not find any known separators.{';',',','TAB'}")); } for (int i = 0; i < fields.Length; i++) { if (fields[i] == "id") { id_field = i; } else if (fields[i] == "lat") { lat_field = i; } else if (fields[i] == "lon") { lon_field = i; } else if (fields[i] == "time") { time_field = i; } else if (fields[i] == "uf1") { uf1_field = i; } else if (fields[i] == "uf2") { uf2_field = i; } else if (fields[i] == "uf3") { uf3_field = i; } else if (fields[i] == "uf4") { uf4_field = i; } else { header = false; Console.WriteLine(string.Format("Can not find header line.(id, lat, lon, time)")); csv.Close(); csv = new System.IO.StreamReader(path); break; } } } if (!header) { line = csv.ReadLine(); } while ((line = csv.ReadLine()) != null) { fields = line.Split(sep); long id = Convert.ToInt64(fields[id_field]); if (id != last_id) { if (ids.Find(item => item == id) == 0) { ids.Add(id); } last_id = id; //break; } } csv.Close(); foreach (long next_id in ids) { Console.Write(next_id); int count = 0; csv = new System.IO.StreamReader(path); trk = new GPXTrack(); GPXTrackSegment trkseg = new GPXTrackSegment(); gpx.Tracks.Add(trk); trk.Name = "trk_" + next_id; line = csv.ReadLine(); while ((line = csv.ReadLine()) != null) { fields = line.Split(sep); long id = Convert.ToInt64(fields[id_field]); if (id == next_id) { if (!(fields[lat_field] == "null" && fields[lon_field] == "null")) { var lat = Double.Parse(fields[lat_field], System.Globalization.CultureInfo.InvariantCulture); var lon = Double.Parse(fields[lon_field], System.Globalization.CultureInfo.InvariantCulture); if (lat > min_lat && lat < max_lat && lon > min_lon && lon < max_lon) { GPXPoint p = new GPXPoint(); p.Latitude = lat; p.Longitude = lon; p.Time = DateTime.ParseExact(fields[time_field], "ddd MMM dd yyyy HH:mm:ss 'GMT-0300 (BRT)'", System.Globalization.CultureInfo.InvariantCulture); trkseg.Nodes.Add(p); count++; } } } } trk.Segments.Add(trkseg); csv.Close(); Console.WriteLine("[" + count + "]"); } String fileout = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(path) + ".gpx"); Console.WriteLine(fileout); gpx.Save(fileout); Console.WriteLine("\tDone."); }
static void Solve(List <List <int> > machines, List <List <int> > processingTimes, List <List <int> > jobIds, GPXPoint bucketInfo, int cycleTime) { Console.WriteLine("\n---- Job shop Scheduling Program ----"); JobShop jobShop = new JobShop(machines, processingTimes, jobIds, bucketInfo, cycleTime); jobShop.RunJobShopScheduling("Jobshop"); }