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('sap_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 # "global" variables (to be referred as global under def fun(something))
00018 winner_id = 'none'
00019 winner_cost = 0
00020 
00021 role_assigned = False
00022 node_role = 'none'
00023 
00024 
00025 #########################################################################################
00026 ## Create list of neighbour nodes to relay the auction_req
00027 ## (must return a list)
00028 #########################################################################################
00029 def create_neighbour_nodes_list(auction_req):
00030 
00031     neighbour_nodes_string = rospy.get_param('~neighbour_nodes_list')
00032     neighbour_nodes_list = neighbour_nodes_string.split(',')
00033 
00034     ##debug##
00035     #print "1."
00036     #print neighbour_nodes_list
00037     #for node in neighbour_nodes_list:
00038     #    print node
00039     ##debug##
00040 
00041     #print neighbour_nodes_string
00042     #print auction_req.nodes_collected
00043 
00044     #nodes_collected_list = neighbour_nodes_list + auction_req.nodes_collected.split(',')
00045     #print "Collected nodes list:"
00046     #print nodes_collected_list
00047 
00048     # print "Intersection:"
00049     # print list(set(neighbour_nodes_list) & set(auction_req.nodes_collected.split(',')))
00050     # print "Union:"
00051     # print list(set(neighbour_nodes_list) | set(auction_req.nodes_collected.split(',')))
00052     # print "Difference"
00053     # print list(set(neighbour_nodes_list) - set(auction_req.nodes_collected.split(',')))
00054 
00055     nodes_collected_list = list(set(neighbour_nodes_list) - set(auction_req.nodes_collected.split(',')))
00056     
00057 
00058     # remove '' strings
00059     while '' in nodes_collected_list:
00060         nodes_collected_list.remove('')
00061 
00062     # remove duplicates
00063     nodes_collected_list = list(set(nodes_collected_list))
00064     
00065     # remove self-references
00066     while rospy.get_name() in nodes_collected_list:
00067         nodes_collected_list.remove(rospy.get_name())
00068 
00069     # remove references to the sender node
00070     while auction_req.sending_node in nodes_collected_list:
00071         nodes_collected_list.remove(auction_req.sending_node)
00072         
00073 
00074     if nodes_collected_list:
00075 
00076         # convert list to string splited by ','
00077         nodes_collected_string = ','.join(nodes_collected_list)
00078 
00079         ##debug##
00080         #print "\nNodes Collected:"+nodes_collected_string+"\n"
00081         ##debug##
00082 
00083         neighbour_nodes_list = nodes_collected_string.split(',')
00084 
00085     else:
00086         neighbour_nodes_list = []
00087         pass
00088 
00089     return neighbour_nodes_list
00090     #return nodes_collected_list
00091 
00092 ## End create_neighbour_nodes_list


sap_pkg
Author(s): Joao Manuel Leitao Quintas
autogenerated on Mon Jan 6 2014 11:28:15