public ClusterItem Add(MarkerWrapper marker) { totalCount++; if (zoom < instance.clusterToZoom) { int mx, my; int z = zoom + 1; marker.GetTilePosition(z, out mx, out my); for (int i = 0; i < count; i++) { ClusterItem item = childs[i]; if (item.CompareTiles(z, mx, my)) { if (item is Cluster) { (item as Cluster).Add(marker); } else { Cluster c = new Cluster(z, item as MarkerWrapper, marker) { parent = this }; childs[i] = c; } return(item); } } } AddChild(marker); return(this); }
protected Tuple <float, float> CalculateAffinity(ClusterItem item, TokenZipNode rootZipNode, ClusteringConfig config, int itemsCount) { Dictionary <int, int[]> itemTokenPlaceMap = item.GetTokenPlacesMap(); Debug.Assert(itemTokenPlaceMap != null); int encounterThreshold = (int)Math.Floor(itemsCount * config.MinClusterAffinity * config.MinClusterAffinity); var itemTokensFound = new HashSet <int>(); Tuple <float, float> matchingAndTotalWeight = CalculateAffinity(0, itemTokenPlaceMap, rootZipNode, itemsCount, encounterThreshold, null, ref itemTokensFound); float foundWeight = 0.0f, notFoundWeight = 0.0f; int seqIndex = 1; foreach (Token token in item.TokenIndex.Tokens) { if (itemTokensFound.Contains(token.Id)) { seqIndex = 1; foundWeight += 1; } else { notFoundWeight += (float)(1 * Math.Pow(seqIndex++, 1.25)); } } return(new Tuple <float, float>(matchingAndTotalWeight.Item1 + foundWeight, matchingAndTotalWeight.Item2 + foundWeight + notFoundWeight)); }
/// <summary> /// TokenZips zip chains are updated when adding an item to include the item's own sequences, extend TokenZips' sequences by an extra token and remote TokenZips chains that can be consolidated /// </summary> protected override void OnAddToCluster(ClusterItem item, float affinity) { this.MaxScore = null; this.TokenZipRoot = this.TokenZipRoot ?? TokenZipNode.CreateRoot(item.TokenIndex.Tokens, this.Vocabulary); this.TokenZipRoot.Append(item.TokenIndex.Tokens.Distinct()); this.TokenZipRoot.Compact(); }
public void OnAddSingleClusterItem() { if (_clusterManager != null) { var latLng = new LatLng(51.5005642, -0.1241729); var clusterItem = new ClusterItem(latLng, "Westminster Bridge", latLng.ToString()); var westminsterBridge = clusterItem; _clusterManager.AddItem(westminsterBridge); } }
public void RemoveAll() { for (int i = 0; i < count; i++) { ClusterItem item = childs[i]; if (item is Cluster) { (item as Cluster).RemoveAll(); } item.Dispose(); } childs = null; count = 0; capacity = 0; totalCount = 0; }
private void ClusterRightMouseClick(object sender, MouseButtonEventArgs e) { FrameworkElement element = sender as FrameworkElement; if (element != null) { ClusterItem cluster = element.DataContext as ClusterItem; if (cluster != null) { cluster.HideExpanded = true; cluster.ClusterState = ClusterState.Expanded; } } e.Handled = true; }
private bool TryRemoveMarker(OnlineMapsMarker marker) { for (int i = 0; i < count; i++) { ClusterItem item = childs[i]; if (item is Cluster) { if ((item as Cluster).TryRemoveMarker(marker)) { return(true); } } else if (item.markerRef == marker) { item.Dispose(); for (int j = i; j < count - 1; j++) { childs[j] = childs[j + 1]; } count--; totalCount--; Cluster p = parent; while (p != null) { p.totalCount--; p.Update(); p = p.parent; } childs[count] = null; if (count == 1 && parent != null) { if (childs[0] is MarkerWrapper) { parent.Replace(this, childs[0] as MarkerWrapper); Dispose(); } } return(true); } } return(false); }
private void AddChild(ClusterItem child) { if (childs == null) { childs = new ClusterItem[2]; capacity = 2; } if (count == capacity) { capacity *= 2; Array.Resize(ref childs, capacity); } child.parent = this; childs[count] = child; count++; }
public void AddIfNotExist(List<ClusterItem> cList, ClusterItem clusterToInsert) { var toRemoveIndices = new List<int>(); #region if empty, insert if (cList.Count == 0) { cList.Add(clusterToInsert); return; } #endregion var cListCopy = new List<ClusterItem>(cList); for (int i = 0; i < cListCopy.Count; i++) { ClusterItem clusterItem = cList.ElementAt(i); var intersect = clusterItem.Cluster.Intersect(clusterToInsert.Cluster); if (intersect.Any()) { if (cList[i].Datum > clusterToInsert.Datum) { toRemoveIndices.Add(i); } else { //wird nicht eingefügt, weil datum älter? //muss man schleife zu ende laufen lassen? return; //continue; } } //} } foreach (int delKey in toRemoveIndices) { cList.RemoveAt(delKey); } cList.Add(clusterToInsert); }
public bool UpdateMarker(OnlineMapsMarker marker) { for (int i = 0; i < count; i++) { ClusterItem item = childs[i]; if (item is Cluster) { if ((item as Cluster).UpdateMarker(marker)) { return(true); } } else if (item.markerRef == marker) { (item as MarkerWrapper).UpdatePosition(); return(true); } } return(false); }
public MarkerWrapper FindMarkerWrapper(OnlineMapsMarker marker) { for (int i = 0; i < count; i++) { ClusterItem item = childs[i]; if (item is Cluster) { MarkerWrapper wrapper = (item as Cluster).FindMarkerWrapper(marker); if (wrapper != null) { return(wrapper); } } else if (item.markerRef == marker) { return(item as MarkerWrapper); } } return(null); }
private void ClusterMouseClick(object sender, MouseButtonEventArgs e) { FrameworkElement element = sender as FrameworkElement; if (element != null) { ClusterItem cluster = element.DataContext as ClusterItem; if (cluster != null) { if (cluster.ClusterState == ClusterState.ExpandedToPolygon || cluster.ClusterState == ClusterState.Expanded) { cluster.ClusterState = ClusterState.Collapsed; } else { cluster.HideExpanded = false; cluster.ClusterState = ClusterState.ExpandedToPolygon; } } } }
/// <summary> /// ZIP-like comparison: the cluster maintains zip chains (TokenZips) which consist of sequences of tokens that are found across several items. /// Getting the affinity for an unknown item checks how many of these chains are encountered in the item /// </summary> protected override float OnGetAffinity(ClusterItem item, float minAffinity) { Tuple <float, float> matchingAndTotalWeight = CalculateAffinity(item, this.TokenZipRoot, this.Config, this.Items.Count); return(matchingAndTotalWeight.Item1 / matchingAndTotalWeight.Item2); }
public RoutePredictionResult PredictEndLocation(double lat, double lon, DateTime time) { var prediction = new RoutePredictionResult(); // check how many start points we have within a cluster // and iterate through the cluster hierachy to get at least 1 location // TODO: filter using time of the day (morning, midday, evening, night), week day, month,... ClusterItem <LocationInstance <TripSummary> > cluster = startLocationRoot.GetLeaf(lat, lon); prediction.ClusterLevel = 0; while (cluster.GetNrOfLocations() == 0) { var parentItem = cluster.GetParentItem(); if (parentItem != null) { if (parentItem is ClusterItem <LocationInstance <TripSummary> > ) { cluster = parentItem as ClusterItem <LocationInstance <TripSummary> >; prediction.ClusterLevel++; } else { // return an empty prediction result return(prediction); } } else { // return an empty prediction result return(prediction); } } Dictionary <ClusterLeaf <TripSummary>, RoutePredictionItem> leafs = new Dictionary <ClusterLeaf <TripSummary>, RoutePredictionItem>(); // create a list of endLocation leafs and count how many times an endlocation is part of the leaf foreach (var location in cluster.GetLocations()) { ClusterLeaf <TripSummary> leaf = location.LocationObject.GetParentItem() as ClusterLeaf <TripSummary>; if (!leafs.ContainsKey(leaf)) { leafs[leaf] = new RoutePredictionItem() { Lat = leaf.CenterLat, Lon = leaf.CenterLon, NrOfEndPoints = 0, NrOfDayMatches = 0, NrOfTimeMatches = 0, NrOfWorkdayMatches = 0 }; } leafs[leaf].NrOfEndPoints++; leafs[leaf].TripIds.Add(location.LocationObject.LocationObject.TripId); if (location.LocationObject.LocationObject.StartTime.DayOfWeek == time.DayOfWeek) { leafs[leaf].NrOfDayMatches++; } ; if (IsWeekend(location.LocationObject.LocationObject.StartTime) == IsWeekend(time)) { leafs[leaf].NrOfWorkdayMatches++; } if (GetTimeSlot(location.LocationObject.LocationObject.StartTime) == GetTimeSlot(time)) { leafs[leaf].NrOfTimeMatches++; } leafs[leaf].CalculateProbability(cluster.GetNrOfLocations()); } prediction.Predictions = leafs.Values.ToList(); prediction.Predictions.Sort(); return(prediction); }