auction_common.py
Go to the documentation of this file.
00001 # configuring PYTHONPATH (By default, this will add the src and lib directory for each of your dependencies to your PYTHONPATH)
00002 import roslib; roslib.load_manifest('k-saap_pkg')
00003 
00004 # import client library
00005 import rospy
00006 
00007 # import messages
00008 import auction_msgs.msg
00009 
00010 # import services
00011 import auction_srvs.srv
00012 
00013 # import auxiliar libraries
00014 import random
00015 import math
00016 
00017 
00018 #########################################################################################
00019 ## Create list of neighbour nodes to relay the auction_req
00020 ## (must return a list)
00021 #########################################################################################
00022 def create_neighbour_nodes_list(auction_req):
00023 
00024     neighbour_nodes_string = rospy.get_param('~neighbour_nodes_list')
00025     neighbour_nodes_list = neighbour_nodes_string.split(',')
00026 
00027     ##debug##
00028     #print "1."
00029     #print neighbour_nodes_list
00030     #for node in neighbour_nodes_list:
00031     #    print node
00032     ##debug##
00033 
00034     #print neighbour_nodes_string
00035     #print auction_req.nodes_collected
00036 
00037     #nodes_collected_list = neighbour_nodes_list + auction_req.nodes_collected.split(',')
00038     #print "Collected nodes list:"
00039     #print nodes_collected_list
00040 
00041     # print "Intersection:"
00042     # print list(set(neighbour_nodes_list) & set(auction_req.nodes_collected.split(',')))
00043     # print "Union:"
00044     # print list(set(neighbour_nodes_list) | set(auction_req.nodes_collected.split(',')))
00045     # print "Difference"
00046     # print list(set(neighbour_nodes_list) - set(auction_req.nodes_collected.split(',')))
00047 
00048     nodes_collected_list = list(set(neighbour_nodes_list) - set(auction_req.nodes_collected.split(',')))
00049     
00050 
00051     # remove '' strings
00052     while '' in nodes_collected_list:
00053         nodes_collected_list.remove('')
00054 
00055     # remove duplicates
00056     nodes_collected_list = list(set(nodes_collected_list))
00057     
00058     # remove self-references
00059     while rospy.get_name() in nodes_collected_list:
00060         nodes_collected_list.remove(rospy.get_name())
00061 
00062     # remove references to the sender node
00063     while auction_req.sending_node in nodes_collected_list:
00064         nodes_collected_list.remove(auction_req.sending_node)
00065         
00066 
00067     if nodes_collected_list:
00068 
00069         # convert list to string splited by ','
00070         nodes_collected_string = ','.join(nodes_collected_list)
00071 
00072         ##debug##
00073         #print "\nNodes Collected:"+nodes_collected_string+"\n"
00074         ##debug##
00075 
00076         neighbour_nodes_list = nodes_collected_string.split(',')
00077 
00078     else:
00079         neighbour_nodes_list = []
00080         pass
00081 
00082     return neighbour_nodes_list
00083     #return nodes_collected_list
00084 
00085 ## End create_neighbour_nodes_list


k-saap_pkg
Author(s): Joao Manuel Leitao Quintas
autogenerated on Mon Jan 6 2014 11:29:06