public AnonymizedLocation Anonymize(OriginalLocation msc) { SimulateOtherUsers(msc); //Only for the purpose of this prototype. Remove for video var n = AddMessage(msc); var gmMark = _gm.SubGraph(n); var m = LocalKSearch(msc.K, msc, gmMark).ToList(); if (!m.Any()) { return(null); } _im.Remove(msc); _hm.Remove(msc); _gm.RemoveNode(msc); var bbox = Mbr(m); //TODO: Remove for video _im = new MultidimensionalIndex(); _hm = new ExpirationHeap(); _gm = new ConstraintGraph(); return(new AnonymizedLocation { Id = msc.Id, LatMin = bbox.MinX, LatMax = bbox.MaxX, LonMin = bbox.MinY, LonMax = bbox.MaxY }); }
private static IEnumerable <OriginalLocation> LocalKSearch(int k, OriginalLocation msc, ConstraintGraph gmMark) { var u = gmMark.Nbr(msc).Where(ms => ms.K <= k).ToList(); if (u.Count() < k - 1) { return(new List <OriginalLocation>()); } var l = 0; while (l != u.Count()) { l = u.Count(); foreach (var ms in new List <OriginalLocation>(u)) { if (gmMark.Nbr(ms).Count() < k - 2) { u.Remove(ms); gmMark.RemoveNode(ms); } } } return(gmMark.FindClique(msc, k)); }
private static BoundingBox Bcn(OriginalLocation m) { return(new BoundingBox { MinX = m.Lat - m.Dx, MaxX = m.Lat + m.Dx, MinY = m.Lon - m.Dy, MaxY = m.Lon + m.Dy }); }
public void RemoveNode(OriginalLocation message) { //Remove all edges going into the node foreach (var node in _nodes) { node.Edges = node.Edges.Where(edge => edge.To != message).ToList(); } //Remove the node itself _nodes.Remove(_nodes.Find(node => node.Message == message)); }
//On a real anonymization server, this method would obviously not exist private void SimulateOtherUsers(OriginalLocation msc) { var rng = new Random(); for (var i = 0; i < rng.Next(10, 21); i++) { var location = new OriginalLocation { Lat = msc.Lat + (rng.NextDouble() - 0.5) * msc.Dx * 2, Lon = msc.Lon + (rng.NextDouble() - 0.5) * msc.Dy * 2, K = msc.K - 1, Dx = msc.Dx * 1.2, Dy = msc.Dy * 1.2, Timestamp = 1000, Id = $"{i}" }; AddMessage(location); } }
//Credit to myself for this one :P public IEnumerable <OriginalLocation> FindClique(OriginalLocation msc, int k) { var mscNode = _nodes.Find(node => node.Message == msc); var clique = new List <OriginalLocation>(); foreach (var mscNeighbor in mscNode.Edges.Select(mscEdge => mscEdge.To)) { clique.Clear(); clique.Add(msc); clique.Add(mscNeighbor); ConsiderNeighborsTo(mscNeighbor, clique); if (clique.Count >= k) { return(clique); } } return(new List <OriginalLocation>()); }
private void ConsiderNeighborsTo(OriginalLocation ms, List <OriginalLocation> clique) { var msNode = _nodes.Find(node => node.Message == ms); foreach (var msNeighbor in msNode.Edges.Select(mscEdge => mscEdge.To)) { if (clique.Contains(msNeighbor)) { continue; } var msNeighborNode = _nodes.Find(node => node.Message == msNeighbor); if (clique.Any(c => !msNeighborNode.Edges.Select(e => e.To).Contains(c))) { continue; } clique.Add(msNeighbor); ConsiderNeighborsTo(msNeighbor, clique); } }
public IEnumerable <OriginalLocation> AddMessage(OriginalLocation msc) { _im.Add(msc); _hm.Add(msc); _gm.AddNode(msc); var n = _im.RangeSearch(Bcn(msc)).ToList(); foreach (var ms in n.Where(ms => ms != msc)) { if (Bcn(ms).Contains(new Point { X = msc.Lat, Y = msc.Lon })) { //Add two edges to simulate a unidirectional graph _gm.AddEdge(msc, ms); _gm.AddEdge(ms, msc); } } return(n); }
public void Add(OriginalLocation location) { _messages.Add(location); }
public void Remove(OriginalLocation location) { _messages.Remove(location); }
public void AddNode(OriginalLocation message) { _nodes.Add(new Node(message)); }
public IEnumerable <OriginalLocation> Nbr(OriginalLocation ms) { return(_nodes.Find(m => m.Message == ms).Edges.Select(edge => edge.To).ToList()); }
public void AddEdge(OriginalLocation from, OriginalLocation to) { var node = _nodes.Find(n => n.Message.Equals(from)); node.Edges.Add(new Edge(from, to)); }
public Edge(OriginalLocation from, OriginalLocation to) { From = from; To = to; }
public Node(OriginalLocation message) { Message = message; Edges = new List <Edge>(); }