Esempio n. 1
0
 def compute_mesh_expanding(self, item_list, length):   
     
     result = item_list
     #1. call find_boundary_points() 
     boundary_points = Map.find_boundary_points(item_list)
     
     #2. 
     for point in boundary_points:
         new_seg_set = self.compute_fixed_expanding(point[0], point[1], point[2], option.MAX_SPEED)
         new_seg_set = EdgeSegmentSet.clean_fixed_expanding(new_seg_set)
         
         result = EdgeSegmentSet.union(result, new_seg_set)
         
     return result
Esempio n. 2
0
    def compute_mesh_expanding(self, item_list, length):

        result = item_list
        #1. call find_boundary_points()
        boundary_points = Map.find_boundary_points(item_list)

        #2.
        for point in boundary_points:
            new_seg_set = self.compute_fixed_expanding(point[0], point[1],
                                                       point[2],
                                                       option.MAX_SPEED)
            new_seg_set = EdgeSegmentSet.clean_fixed_expanding(new_seg_set)

            result = EdgeSegmentSet.union(result, new_seg_set)

        return result
Esempio n. 3
0
    def solve_new_queries(self, timestamp):

        expanding_list = {}  #dict of lists
        query_list = self.query_log.frames[timestamp]  # timestamp

        #0. reset
        self.reset()

        #1. compute expanding_list
        start_time = time.clock()
        for query in query_list:
            seg_list = self.map_data.compute_fixed_expanding(
                query.x, query.y, query.cur_edge_id,
                query.dist)  #old: option.DISTANCE_CONSTRAINT
            seg_list = EdgeSegmentSet.clean_fixed_expanding(seg_list)

            expanding_list[query.obj_id] = seg_list
        print "expanding_list - elapsed : ", (time.clock() - start_time)

        #2. compute mc_set
        #        start_time = time.clock()
        #        num_edges = 0
        #        list_edges = []
        #        for i in range(len(query_list)):
        #            for j in range(i+1,len(query_list)):
        #                if get_distance(query_list[i].x, query_list[i].y, query_list[j].x, query_list[j].y) > \
        #                    option.INIT_GRAPH_DISTANCE:
        #                    continue
        #
        #                if EdgeSegmentSet.is_set_cover(Point(query_list[i]), expanding_list[query_list[j].obj_id]) and \
        #                    EdgeSegmentSet.is_set_cover(Point(query_list[j]), expanding_list[query_list[i].obj_id]):
        #                    num_edges += 1
        #                    list_edges.append((query_list[i].obj_id, query_list[j].obj_id))
        #
        #        print "num_edges=", num_edges
        #        print "list_edges OLD - elapsed : ", (time.clock() - start_time)

        start_time = time.clock()
        (num_edges,
         list_edges) = self.compute_edge_list(expanding_list, query_list)
        print "num_edges=", num_edges
        print "list_edges NEW - elapsed : ", (time.clock() - start_time)

        # write list_edges[] to file
        self.write_list_edges(list_edges)
        #

        start_time = time.clock()
        #        # (OLD)
        #        graph.add_to_mc_set(list_edges)

        # (NEW)
        call([
            option.MACE_EXECUTABLE, "M", option.MAXIMAL_CLIQUE_FILE_IN,
            option.MAXIMAL_CLIQUE_FILE_OUT
        ],
             shell=False)

        f = open(option.MAXIMAL_CLIQUE_FILE_OUT, "r")
        fstr = f.read()
        f.close()
        for line in fstr.split("\n"):
            node_list = line.split(" ")
            if len(node_list) < 2:
                continue
            self.mc_set.append(set([int(node) for node in node_list]))

        print len(self.mc_set)

        print "add_to_mc_set - elapsed : ", (time.clock() - start_time)
        #        print "mc_set =", self.mc_set

        #3.
        start_time = time.clock()
        self.find_cloaking_sets(timestamp, expanding_list)

        print "find_cloaking_sets - elapsed : ", (time.clock() - start_time)

        #4. 'Set Cover Problem' (from weighted_set_cover.py)
        start_time = time.clock()

        num_element = max(
            query_list,
            key=lambda query: query.obj_id).obj_id + 1  # avoid out of range
        if timestamp == 0:
            self.cover_set, num_cloaked_users = find_init_cover(
                self.positive_mc_set, num_element)
            self.new_cover_set = self.cover_set  # for compute CLOAKING MESH
        else:
            self.new_cover_set, num_cloaked_users, checking_pairs = find_next_cover(
                self.positive_mc_set, num_element, self.cover_set,
                option.K_GLOBAL)

        print "Success rate =", float(num_cloaked_users) / len(query_list)
        print "compute cover_set - elapsed : ", (time.clock() - start_time)

        #5. compute CLOAKING MESH
        start_time = time.clock()

        total_mesh_length = 0
        total_query = 0
        self.new_cover_mesh = []  # NEW
        for clique_id in range(len(self.new_cover_set)):
            clique = self.new_cover_set[clique_id]
            #compute length of mesh
            mesh = []
            for obj_id in clique:
                mesh = EdgeSegmentSet.union(mesh, expanding_list[obj_id])

            self.new_cover_mesh.append(mesh)  #NEW

            total_mesh_length += EdgeSegmentSet.length(mesh)
            total_query += len(clique)

        average_mesh_query = total_mesh_length / total_query

        print "total_mesh_length =", total_mesh_length
        print "average_mesh_query =", average_mesh_query
        print "Compute CLOAKING MBR - elapsed : ", (time.clock() - start_time)
        #        print "user_mesh = ", self.user_mesh

        #5.2 Check MMB/MAB
        #        self.new_cover_mesh_mmb = self.compute_cover_mesh_mmb(self.new_cover_mesh, expanding_list)
        #
        #        if timestamp > 0:
        #            start_time = time.clock()
        #
        #            self.check_MMB_MAB(checking_pairs, self.cover_mesh, self.cover_mesh_mmb, self.new_cover_mesh, self.new_cover_mesh_mmb)
        #
        #            print "check_MMB_MAB() - elapsed : ", (time.clock() - start_time)

        # UPDATE
        self.cover_set = self.new_cover_set
        self.cover_mesh = self.new_cover_mesh
        #        self.cover_mesh_mmb = self.new_cover_mesh_mmb

        #6. compute user_mc_set (max clique for each obj_id), replace self.positive_mc_set by self.cover_set
        start_time = time.clock()
        self.user_mc_set = {}
        for clique_id in range(len(self.cover_set)):
            clique = self.cover_set[clique_id]

            for obj_id in clique:
                #
                if not self.user_mc_set.has_key(obj_id):
                    self.user_mc_set[obj_id] = clique_id  #use id
                elif len(self.cover_set[self.user_mc_set[obj_id]]) < len(
                        clique):
                    self.user_mc_set[obj_id] = clique_id  #store the maximum
            #
            for obj_id in clique:
                if self.user_mc_set[
                        obj_id] == clique_id:  #clique id comparison
                    self.user_mesh[obj_id] = self.cover_mesh[clique_id]

        print "Compute user_mc_set - elapsed : ", (time.clock() - start_time)
        #        print "user_mc_set = ", self.user_mc_set

        #7. publish MBRs (write to file)
        start_time = time.clock()
        self.write_results_to_files(timestamp)

        print "write_results_to_files - elapsed : ", (time.clock() -
                                                      start_time)
    def solve_new_queries(self, timestamp):
        
        expanding_list = {}                                 #dict of lists
        query_list = self.query_log.frames[timestamp]       # timestamp
        
        
        #0. reset
        self.reset()
        
        #1. compute expanding_list
        start_time = time.clock()    
        for query in query_list:
            seg_list = self.map_data.compute_fixed_expanding(query.x, query.y, 
                                            query.cur_edge_id, query.dist)  #old: option.DISTANCE_CONSTRAINT
            seg_list = EdgeSegmentSet.clean_fixed_expanding(seg_list)
            
            expanding_list[query.obj_id] = seg_list
        print "expanding_list - elapsed : ", (time.clock() - start_time)       
        
        #2. compute mc_set
#        start_time = time.clock()    
#        num_edges = 0 
#        list_edges = []
#        for i in range(len(query_list)):
#            for j in range(i+1,len(query_list)):
#                if get_distance(query_list[i].x, query_list[i].y, query_list[j].x, query_list[j].y) > \
#                    option.INIT_GRAPH_DISTANCE:
#                    continue
#                
#                if EdgeSegmentSet.is_set_cover(Point(query_list[i]), expanding_list[query_list[j].obj_id]) and \
#                    EdgeSegmentSet.is_set_cover(Point(query_list[j]), expanding_list[query_list[i].obj_id]):
#                    num_edges += 1
#                    list_edges.append((query_list[i].obj_id, query_list[j].obj_id))
#                    
#        print "num_edges=", num_edges
#        print "list_edges OLD - elapsed : ", (time.clock() - start_time)  
        
        start_time = time.clock()
        (num_edges, list_edges) = self.compute_edge_list(expanding_list, query_list)
        print "num_edges=", num_edges
        print "list_edges NEW - elapsed : ", (time.clock() - start_time)       
        
        # write list_edges[] to file
        self.write_list_edges(list_edges)
        #
    
        start_time = time.clock()        
#        # (OLD)    
#        graph.add_to_mc_set(list_edges)
         
        # (NEW)
        call([option.MACE_EXECUTABLE, "M", option.MAXIMAL_CLIQUE_FILE_IN, option.MAXIMAL_CLIQUE_FILE_OUT], 
             shell=False)

        f = open(option.MAXIMAL_CLIQUE_FILE_OUT, "r")
        fstr = f.read()
        f.close()
        for line in fstr.split("\n"):
            node_list = line.split(" ")
            if len(node_list) < 2:
                continue
            self.mc_set.append(set([int(node) for node in node_list]))
            
        print len(self.mc_set) 
        
        print "add_to_mc_set - elapsed : ", (time.clock() - start_time)   
#        print "mc_set =", self.mc_set
        
        #3.
        start_time = time.clock() 
        self.find_cloaking_sets(timestamp, expanding_list)
        
        print "find_cloaking_sets - elapsed : ", (time.clock() - start_time)
        
        
        #4. 'Set Cover Problem' (from weighted_set_cover.py)
        start_time = time.clock() 
        
        num_element = max(query_list, key=lambda query: query.obj_id).obj_id + 1  # avoid out of range  
        if timestamp == 0:
            self.cover_set, num_cloaked_users = find_init_cover(self.positive_mc_set, num_element)
            self.new_cover_set = self.cover_set     # for compute CLOAKING MESH
        else:
            self.new_cover_set, num_cloaked_users, checking_pairs = find_next_cover(self.positive_mc_set, num_element, self.cover_set, option.K_GLOBAL)
        
        print "Success rate =", float(num_cloaked_users)/len(query_list)    
        print "compute cover_set - elapsed : ", (time.clock() - start_time)
        
        
        #5. compute CLOAKING MESH
        start_time = time.clock()   
        
        total_mesh_length = 0
        total_query = 0
        self.new_cover_mesh = []    # NEW
        for clique_id in range(len(self.new_cover_set)):
            clique = self.new_cover_set[clique_id]
            #compute length of mesh
            mesh = []
            for obj_id in clique:
                mesh = EdgeSegmentSet.union(mesh, expanding_list[obj_id])
            
            self.new_cover_mesh.append(mesh)    #NEW           
            
            total_mesh_length += EdgeSegmentSet.length(mesh)
            total_query += len(clique)    
            
        
        average_mesh_query = total_mesh_length/total_query
        
        print "total_mesh_length =", total_mesh_length    
        print "average_mesh_query =", average_mesh_query    
        print "Compute CLOAKING MBR - elapsed : ", (time.clock() - start_time)  
#        print "user_mesh = ", self.user_mesh
                
                
        #5.2 Check MMB/MAB
#        self.new_cover_mesh_mmb = self.compute_cover_mesh_mmb(self.new_cover_mesh, expanding_list)
#            
#        if timestamp > 0:
#            start_time = time.clock() 
#            
#            self.check_MMB_MAB(checking_pairs, self.cover_mesh, self.cover_mesh_mmb, self.new_cover_mesh, self.new_cover_mesh_mmb)
#            
#            print "check_MMB_MAB() - elapsed : ", (time.clock() - start_time)
        
        # UPDATE
        self.cover_set = self.new_cover_set
        self.cover_mesh = self.new_cover_mesh
#        self.cover_mesh_mmb = self.new_cover_mesh_mmb        
        
        
        #6. compute user_mc_set (max clique for each obj_id), replace self.positive_mc_set by self.cover_set
        start_time = time.clock()   
        self.user_mc_set = {}
        for clique_id in range(len(self.cover_set)):
            clique = self.cover_set[clique_id]
            
            for obj_id in clique:
                #
                if not self.user_mc_set.has_key(obj_id):
                    self.user_mc_set[obj_id] = clique_id            #use id
                elif len(self.cover_set[self.user_mc_set[obj_id]]) < len(clique):
                    self.user_mc_set[obj_id] = clique_id               #store the maximum
            #
            for obj_id in clique:
                if self.user_mc_set[obj_id] == clique_id:  #clique id comparison
                    self.user_mesh[obj_id] = self.cover_mesh[clique_id]        
        
        print "Compute user_mc_set - elapsed : ", (time.clock() - start_time)   
#        print "user_mc_set = ", self.user_mc_set
        
                
        #7. publish MBRs (write to file)   
        start_time = time.clock()   
        self.write_results_to_files(timestamp)
        
        print "write_results_to_files - elapsed : ", (time.clock() - start_time)  
Esempio n. 5
0
    def process_existing_clique(self, clique, timestamp):

        free_nodes = []
        satisfied = True  #new clique satisfied or not

        #1. get new_loc
        expanding_list = {}  #dict of lists
        query_list = []

        for node in clique:
            query = self.query_log.trajs[node][timestamp]
            query_list.append(query)

        for query in query_list:
            seg_list = self.map_data.compute_fixed_expanding(
                query.x, query.y, query.cur_edge_id, option.INIT_DISTANCE)
            seg_list = EdgeSegmentSet.clean_fixed_expanding(seg_list)
            expanding_list[query.obj_id] = seg_list

        #2. build graph
        degree = {}
        adj = {}
        for query in query_list:
            degree[query.obj_id] = 0

        for i in range(len(query_list)):
            for j in range(i + 1, len(query_list)):
                if EdgeSegmentSet.is_set_cover(Point(query_list[i]), expanding_list[query_list[j].obj_id]) and \
                    EdgeSegmentSet.is_set_cover(Point(query_list[j]), expanding_list[query_list[i].obj_id]):
                    adj[(query_list[i].obj_id, query_list[j].obj_id)] = 1
                    adj[(query_list[j].obj_id, query_list[i].obj_id)] = 1
        for pair in adj.iterkeys():
            degree[pair[0]] += 1
            degree[pair[1]] += 1

        for node in clique:
            if degree[node] == 0:
                free_nodes.append(node)
                del expanding_list[node]
                satisfied = False

        #3. compute union (mesh) and ...
        mesh = []
        for seg_list in expanding_list.itervalues():
            mesh = EdgeSegmentSet.union(mesh, seg_list)

        #3.2 check total_len
        if EdgeSegmentSet.length(mesh) > option.MAX_MESH_LENGTH:
            satisfied = False
            # remove (heuristically) nodes which have low degrees
            while True:
                node = min(degree, degree.get)

                free_nodes.append(node)
                del degree[node]

                for node_2 in clique:
                    if adj.has_key((node, node_2)):
                        del adj[(node, node_2)]
                        del adj[(node_2, node)]
                        degree[node_2] = degree[node_2] - 1

                #re-compute union (mesh) and check total_len
                mesh = []
                for seg_list in expanding_list.itervalues():
                    mesh = EdgeSegmentSet.union(mesh, seg_list)
                if EdgeSegmentSet.length(mesh) <= option.MAX_MESH_LENGTH:
                    break

        #4. return
        return (satisfied, free_nodes, mesh)
Esempio n. 6
0
    def init_mc_set(self):
        start_time = time.clock()

        expanding_list = {}  #[[]] * option.MAX_USER   #dict of lists
        query_list = self.query_log.frames[0]  #init timestamp
        min_obj_id = option.MAX_USER
        max_obj_id = 0

        #1. compute expanding_list
        for query in query_list:
            if max_obj_id < query.obj_id:
                max_obj_id = query.obj_id
            if min_obj_id > query.obj_id:
                min_obj_id = query.obj_id
            #
            self.num_user = max(self.num_user, query.obj_id)
            seg_list = self.map_data.compute_fixed_expanding(
                query.x, query.y, query.cur_edge_id, option.INIT_DISTANCE)
            seg_list = EdgeSegmentSet.clean_fixed_expanding(seg_list)

            expanding_list[query.obj_id] = seg_list

        #1.2 check connectivity of each seg_list --> OK
#        print "Connectivity check: STARTED"
#        for query in query_list:
#            if not Map.check_connected_expanding(expanding_list[query.obj_id]):
#                print "error found at obj_id=", query.obj_id
#        print "Connectivity check: DONE"

#2. init self.mc_set
        self.reset()
        for query in query_list:
            self.mc_set.append(set([query.obj_id]))

        #3. compute mc_set
        num_edges = 0
        list_edges = []
        for i in range(len(query_list)):
            for j in range(i + 1, len(query_list)):
                if get_distance(query_list[i].x, query_list[i].y, query_list[j].x, query_list[j].y) > \
                    option.INIT_DISTANCE:
                    continue

                if EdgeSegmentSet.is_set_cover(Point(query_list[i]), expanding_list[query_list[j].obj_id]) and \
                    EdgeSegmentSet.is_set_cover(Point(query_list[j]), expanding_list[query_list[i].obj_id]):
                    num_edges += 1
                    list_edges.append(
                        (query_list[i].obj_id, query_list[j].obj_id))
        print "num_edges=", num_edges
        print "list_edges - elapsed : ", (time.clock() - start_time)

        start_time = time.clock()
        graph.add_to_mc_set(list_edges)

        print "add_to_mc_set - elapsed : ", (time.clock() - start_time)
        print "mc_set =", self.mc_set

        #4. compute user_mc_set, max clique for each obj_id
        self.user_mc_set = {}
        for clique in self.mc_set:
            if len(clique) >= option.K_ANONYMITY:
                for obj_id in clique:
                    if not self.user_mc_set.has_key(obj_id):
                        self.user_mc_set[obj_id] = clique
                    elif len(self.user_mc_set[obj_id]) < len(clique):
                        self.user_mc_set[obj_id] = clique
        print "Compute user_mc_set: DONE"
        print "user_mc_set = ", self.user_mc_set

        #5. compute MMBs (CLOAKING MESHES) and self.user_set
        max_mesh_len = 0
        min_mesh_len = 1000000
        for clique in self.mc_set:
            if len(clique) >= option.K_ANONYMITY:
                mesh = []
                for obj_id in clique:
                    mesh = EdgeSegmentSet.union(mesh, expanding_list[obj_id])

                #
                temp_len = EdgeSegmentSet.length(mesh)
                if max_mesh_len < temp_len:
                    max_mesh_len = temp_len
                if min_mesh_len > temp_len:
                    min_mesh_len = temp_len

                # assign mesh to all obj_id in 'clique'
                for obj_id in clique:
                    self.user_mesh[obj_id] = mesh

                #
                for obj_id in clique:
                    self.user_set = self.user_set | set([obj_id])

        print "self.user_set = ", self.user_set

        print "Compute CLOAKING MESH: DONE"
        print "max_mesh_len =", max_mesh_len
        print "min_mesh_len =", min_mesh_len

        #5.2 check connectivity of each user_mesh --> OK
        #        start_time = time.clock()
        #        print "MMB Connectivity check: STARTED"
        #        for clique in self.mc_set:
        #            for obj_id in clique:
        #                if not Map.check_connected_expanding(self.user_mesh[obj_id]):
        #                    print "error found at clique=", clique
        #                continue
        #        print "MMB Connectivity check: DONE"
        #        print "elapsed : ", (time.clock() - start_time)

        #DEBUG
        print "len(graph.mc_set) = ", len(graph.mc_set)
        print graph.mc_set
Esempio n. 7
0
 def process_existing_clique(self, clique, timestamp):
     
     free_nodes = []
     satisfied = True        #new clique satisfied or not
     
     #1. get new_loc
     expanding_list = {}     #dict of lists
     query_list = []
     
     for node in clique:
         query = self.query_log.trajs[node][timestamp]
         query_list.append(query)
         
     for query in query_list:
         seg_list = self.map_data.compute_fixed_expanding(query.x, query.y, 
                                         query.cur_edge_id, option.INIT_DISTANCE)
         seg_list = EdgeSegmentSet.clean_fixed_expanding(seg_list)
         expanding_list[query.obj_id] = seg_list
         
         
     #2. build graph
     degree = {}
     adj = {}
     for query in query_list:
         degree[query.obj_id] = 0
         
     for i in range(len(query_list)):
         for j in range(i+1,len(query_list)):
             if EdgeSegmentSet.is_set_cover(Point(query_list[i]), expanding_list[query_list[j].obj_id]) and \
                 EdgeSegmentSet.is_set_cover(Point(query_list[j]), expanding_list[query_list[i].obj_id]):
                 adj[(query_list[i].obj_id, query_list[j].obj_id)] = 1
                 adj[(query_list[j].obj_id, query_list[i].obj_id)] = 1
     for pair in adj.iterkeys():
         degree[pair[0]] += 1
         degree[pair[1]] += 1            
     
     for node in clique:
         if degree[node] == 0:
             free_nodes.append(node)
             del expanding_list[node]
             satisfied = False
                 
     #3. compute union (mesh) and ...
     mesh = []
     for seg_list in expanding_list.itervalues():
         mesh = EdgeSegmentSet.union(mesh, seg_list)
     
     #3.2 check total_len
     if EdgeSegmentSet.length(mesh) > option.MAX_MESH_LENGTH:
         satisfied = False
         # remove (heuristically) nodes which have low degrees
         while True:
             node = min(degree, degree.get)
             
             free_nodes.append(node)
             del degree[node]
             
             for node_2 in clique:
                 if adj.has_key((node, node_2)):
                     del adj[(node, node_2)]
                     del adj[(node_2, node)]
                     degree[node_2] = degree[node_2] - 1 
             
             #re-compute union (mesh) and check total_len
             mesh = []
             for seg_list in expanding_list.itervalues():
                 mesh = EdgeSegmentSet.union(mesh, seg_list)
             if EdgeSegmentSet.length(mesh) <= option.MAX_MESH_LENGTH:
                 break    
      
     #4. return
     return (satisfied, free_nodes, mesh)   
Esempio n. 8
0
    def init_mc_set(self):         
        start_time = time.clock()
        
        expanding_list = {} #[[]] * option.MAX_USER   #dict of lists
        query_list = self.query_log.frames[0]   #init timestamp
        min_obj_id = option.MAX_USER
        max_obj_id = 0
        
        #1. compute expanding_list
        for query in query_list:
            if max_obj_id < query.obj_id:
                max_obj_id = query.obj_id
            if min_obj_id > query.obj_id:
                min_obj_id = query.obj_id
            #        
            self.num_user = max(self.num_user, query.obj_id)
            seg_list = self.map_data.compute_fixed_expanding(query.x, query.y, 
                                            query.cur_edge_id, option.INIT_DISTANCE)
            seg_list = EdgeSegmentSet.clean_fixed_expanding(seg_list)
            
            expanding_list[query.obj_id] = seg_list
            
            
        #1.2 check connectivity of each seg_list --> OK
#        print "Connectivity check: STARTED"
#        for query in query_list:
#            if not Map.check_connected_expanding(expanding_list[query.obj_id]):   
#                print "error found at obj_id=", query.obj_id
#        print "Connectivity check: DONE"    
                
        #2. init self.mc_set
        self.reset()
        for query in query_list:
            self.mc_set.append(set([query.obj_id]))
            
        #3. compute mc_set
        num_edges = 0 
        list_edges = []
        for i in range(len(query_list)):
            for j in range(i+1,len(query_list)):
                if get_distance(query_list[i].x, query_list[i].y, query_list[j].x, query_list[j].y) > \
                    option.INIT_DISTANCE:
                    continue
                
                if EdgeSegmentSet.is_set_cover(Point(query_list[i]), expanding_list[query_list[j].obj_id]) and \
                    EdgeSegmentSet.is_set_cover(Point(query_list[j]), expanding_list[query_list[i].obj_id]):
                    num_edges += 1
                    list_edges.append((query_list[i].obj_id, query_list[j].obj_id))
        print "num_edges=", num_edges
        print "list_edges - elapsed : ", (time.clock() - start_time)               
                 
        start_time = time.clock()            
        graph.add_to_mc_set(list_edges) 
        
        print "add_to_mc_set - elapsed : ", (time.clock() - start_time)   
        print "mc_set =", self.mc_set
        
        #4. compute user_mc_set, max clique for each obj_id
        self.user_mc_set = {}
        for clique in self.mc_set:
            if len(clique) >= option.K_ANONYMITY:
                for obj_id in clique:
                    if not self.user_mc_set.has_key(obj_id):
                        self.user_mc_set[obj_id] = clique
                    elif len(self.user_mc_set[obj_id]) < len(clique):
                        self.user_mc_set[obj_id] = clique
        print "Compute user_mc_set: DONE"
        print "user_mc_set = ", self.user_mc_set
                    
        #5. compute MMBs (CLOAKING MESHES) and self.user_set
        max_mesh_len = 0
        min_mesh_len = 1000000
        for clique in self.mc_set:
            if len(clique) >= option.K_ANONYMITY:
                mesh = []
                for obj_id in clique:
                    mesh = EdgeSegmentSet.union(mesh, expanding_list[obj_id])
                
                #    
                temp_len = EdgeSegmentSet.length(mesh)
                if max_mesh_len < temp_len:
                    max_mesh_len = temp_len
                if min_mesh_len > temp_len:
                    min_mesh_len = temp_len    
                     
                # assign mesh to all obj_id in 'clique'
                for obj_id in clique:
                    self.user_mesh[obj_id] = mesh
                    
                # 
                for obj_id in clique:
                    self.user_set = self.user_set | set([obj_id])
        
        print "self.user_set = ", self.user_set        
                
        print "Compute CLOAKING MESH: DONE"
        print "max_mesh_len =", max_mesh_len
        print "min_mesh_len =", min_mesh_len
        
        
        
        #5.2 check connectivity of each user_mesh --> OK
#        start_time = time.clock()
#        print "MMB Connectivity check: STARTED"
#        for clique in self.mc_set:
#            for obj_id in clique:
#                if not Map.check_connected_expanding(self.user_mesh[obj_id]):   
#                    print "error found at clique=", clique
#                continue
#        print "MMB Connectivity check: DONE"      
#        print "elapsed : ", (time.clock() - start_time)                
                    
        
            
        #DEBUG
        print "len(graph.mc_set) = ", len(graph.mc_set)
        print graph.mc_set
        
        print "Compute user_mc_set - elapsed : ", (time.clock() - start_time)   
        print "user_mc_set - Now: ", datetime.now() 
        
#        print "user_mc_set = ", self.user_mc_set
                    
        # 6. COMPUTE CLOAKING MESH
        start_time = time.clock()   
        total_mesh_length = 0
        total_query = 0
        for clique_id in range(len(graph.cover_set)):
            clique = graph.cover_set[clique_id]
            #compute length of mesh
            mesh = []
            for obj_id in clique:
                mesh = edge_segment_set.union(mesh, expanding_list[obj_id])
            
            total_mesh_length += edge_segment_set.length(mesh)
            total_query += len(clique)    
            #
            for obj_id in clique:
                if graph.user_mc_set[obj_id] == clique_id:  #clique id comparison
                    graph.user_mesh[obj_id] = mesh
        
        average_mesh_query = total_mesh_length/total_query
        
        print "total_mesh_length =", total_mesh_length    
        print "average_mesh_query =", average_mesh_query    
        print "Compute CLOAKING MBR - elapsed : ", (time.clock() - start_time)  
        print "CLOAKING MBR - Now: ", datetime.now() 
#        print "user_mesh = ", self.user_mesh
     #
     max_min_area = 0
     max_k_anom = 0
     query_list = []
     for obj_id in clique:
         query = query_log.trajs[obj_id][timestamp]
         query_list.append(query)
         if max_min_area < query.min_area:
             max_min_area = query.min_area
         if max_k_anom < query.k_anom:
             max_k_anom = query.k_anom
             
     #compute length of mesh
     mesh = []
     for obj_id in clique:
         mesh = edge_segment_set.union(mesh, expanding_list[obj_id])
     clique_len = edge_segment_set.length(mesh)
     
     #
     if len(clique) >= max_k_anom and \
             clique_len >= math.sqrt(max_min_area) * map_data.total_map_len * option.MAP_RATIO:
         positive_mc_set_2.append(clique) 
     elif len(clique) > 2:
         negative_mc_set_2.append(clique)
 
 print "len(positive_mc_set_2)", len(positive_mc_set_2)
 print "len(negative_mc_set_2)", len(negative_mc_set_2)
         
 #2.convert negative cliques (heuristically)
 new_negative_mc_set = []
 
Esempio n. 11
0
    def solve_new_queries(self, timestamp):
        start_time = time.clock()

        expanding_list = {}  #dict of lists
        query_list = self.query_log.frames[timestamp]  # timestamp
        min_obj_id = option.MAX_USER
        max_obj_id = 0

        #1. compute expanding_list
        for query in query_list:
            if max_obj_id < query.obj_id:
                max_obj_id = query.obj_id
            if min_obj_id > query.obj_id:
                min_obj_id = query.obj_id
            #
            seg_list = self.map_data.compute_fixed_expanding(
                query.x, query.y, query.cur_edge_id, option.INIT_DISTANCE)
            seg_list = EdgeSegmentSet.clean_fixed_expanding(seg_list)

            expanding_list[query.obj_id] = seg_list

        #2. init self.mc_set
        self.reset()
        for query in query_list:
            self.mc_set.append(set([query.obj_id]))

        #3. compute mc_set
        start_time = time.clock()
        num_edges = 0
        list_edges = []
        for i in range(len(query_list)):
            for j in range(i + 1, len(query_list)):
                if get_distance(query_list[i].x, query_list[i].y, query_list[j].x, query_list[j].y) > \
                    option.INIT_DISTANCE:
                    continue

                if EdgeSegmentSet.is_set_cover(Point(query_list[i]), expanding_list[query_list[j].obj_id]) and \
                    EdgeSegmentSet.is_set_cover(Point(query_list[j]), expanding_list[query_list[i].obj_id]):
                    num_edges += 1
                    list_edges.append(
                        (query_list[i].obj_id, query_list[j].obj_id))
        print "num_edges=", num_edges
        print "list_edges - elapsed : ", (time.clock() - start_time)

        start_time = time.clock()
        graph.add_to_mc_set(list_edges)

        print "add_to_mc_set - elapsed : ", (time.clock() - start_time)
        print "mc_set =", self.mc_set

        #4. compute user_mc_set, max clique for each obj_id
        start_time = time.clock()
        self.user_mc_set = {}
        for clique in self.mc_set:
            if len(clique) >= option.K_ANONYMITY:
                for obj_id in clique:
                    if not self.user_mc_set.has_key(obj_id):
                        self.user_mc_set[obj_id] = clique
                    elif len(self.user_mc_set[obj_id]) < len(clique):
                        self.user_mc_set[obj_id] = clique
        print "Compute user_mc_set - elapsed : ", (time.clock() - start_time)
        print "user_mc_set = ", self.user_mc_set

        #5. compute MMBs (CLOAKING MESHES) and self.user_set
        start_time = time.clock()
        max_mesh_len = 0
        min_mesh_len = 1000000
        for clique in self.mc_set:
            if len(clique) >= option.K_ANONYMITY:
                mesh = []
                for obj_id in clique:
                    mesh = EdgeSegmentSet.union(mesh, expanding_list[obj_id])

                #
                temp_len = EdgeSegmentSet.length(mesh)
                if max_mesh_len < temp_len:
                    max_mesh_len = temp_len
                if min_mesh_len > temp_len:
                    min_mesh_len = temp_len

                # assign mesh to all obj_id in 'clique'
                for obj_id in clique:
                    self.user_mesh[obj_id] = mesh

                #
                for obj_id in clique:
                    self.user_set = self.user_set | set([obj_id])

        #print "self.user_set = ", self.user_set
        print "Compute CLOAKING MESH - elapsed : ", (time.clock() - start_time)

        print "max_mesh_len =", max_mesh_len
        print "min_mesh_len =", min_mesh_len