Esempio n. 1
0
	def __init__(self, delta, energy, ID, x, y, theta, red, green, blue, state):
		self.about_me_wm = AboutMe_WM(delta, energy, ID, x, y, theta, red, green, blue, state)
		self.Alive = 20
	
		self.old_state = 1

		#From the list of services select 30% (this number can be modified) for the agent to be providing - at random
		#[id time energy reward ...] ... -> dependencies on other services for instance 4 5 2 1
		#active_servs format: [[5, 100, 3705, 42], [6, 97, 5736, 19], [9, 96, 9156, 4]]

		self.active_servs = simulation_functions.select_services()

		self.changed_servs = 1
		self.iteration = 1
		self.task_idx = 0
		self.service = self.active_servs[self.task_idx] 

		self.message = Message_Type()
		self.message.id = self.about_me_wm.ID
		self.message.rank = 10
		self.message.group = 1

		self.message.content = []
		self.message.content.append([x[0] for x in self.active_servs])

		self.message.timestamp = time.strftime('%X', time.gmtime())

		print self.message

		rospy.init_node('agent', anonymous=True)
		self.publish_global = rospy.Publisher('msgs', Message_Type, queue_size=200)
		rospy.Subscriber('trigger', StateTrigger, self.callback)
Esempio n. 2
0
	def __init__(self, delta, energy, ID, x, y, theta, red, green, blue, state):
		self.about_me_wm = AboutMe_WM(delta, energy, ID, x, y, theta, red, green, blue, state)
		self.Alive = 20
		
		#From the list of services select 30% (this number can be modified) for the agent to be providing - at random
		#[id time energy reward]
		#active_servs format: [[5, 100, 3705, 42], [6, 97, 5736, 19], [9, 96, 9156, 4]]

		active_servs = simulation_functions.select_services()
		rospy.init_node('agent', anonymous=True)
		rospy.Subscriber('trigger', StateTrigger, self.callback)
    def __init__(self, delta, energy, ID, x, y, theta, red, green, blue, state,
                 depend_nr, popSize, provaNr):

        self.TIME = time.time()
        self.DURATION = 3600  # 20min
        ## The attributes below serve as a timestamp for each function called ######
        self.handle = 0
        self.call = 0
        self.callback_bc = 0
        self.w = 0
        self.a = 0
        self.run_step = 0
        self.fsm = 0
        self.helping = False
        ############################################################################
        # use this variable to count the instances in which an agent asks for help the same agent who asked it for help in the first place
        self.count_posReq = 0
        self.COUNT_noones = 0
        self.count_loops = 0

        self.steps_b4_equilibrium = 100

        self.lock = Lock()

        self.stdout_log = 'RESULT/pop_size.' + str(popSize) + '/prova.' + str(
            provaNr) + '/stdout_' + str(ID) + '_' + str(delta) + '_' + str(
                depend_nr)
        self.stdout_callback = 'RESULT/pop_size.' + str(
            popSize) + '/prova.' + str(provaNr) + '/stdout_callback' + str(
                ID) + '_' + str(delta) + '_' + str(depend_nr)
        self.stdout_handle = 'RESULT/pop_size.' + str(
            popSize) + '/prova.' + str(provaNr) + '/stdout_handle' + str(
                ID) + '_' + str(delta) + '_' + str(depend_nr)

        self.about_me_wm = AboutMe_WM(delta, energy, ID, x, y, theta, red,
                                      green, blue, state)
        self.Alive = 20000

        self.attempted_jobs = 0
        self.completed_jobs = 0
        self.attempted_jobs_depend = 0
        self.completed_jobs_depend = 0
        self.depend_myself = 0
        self.collected_reward = 0

        self.old_state = 1

        ## These vars are manipulated by multiple threads ###
        self.adaptive_state = []
        self.current_client = []
        self.service_req = []
        self.service_resp = []
        self.service_resp_content = []
        #####################################################

        self.client_index = -1
        self.old_client_index = -1

        #follows the indexing of known_people
        self.helping_interactions = []
        self.total_interactions = []

        # example format [[[e1-pos-inter, e1-tot-inter], [e2-pos-inter, e2-tot-inter] ...], ..], for serv1, serv2.... for the first guy in known_people
        self.capability_expertise = []

        self.timeouts = 0

        self.timeouts_xinteract = []

        #From the list of services select 30% (this number can be modified) for the agent to be providing - at random
        #[id time energy reward ...] ... -> dependencies on other services for instance 4 5 2 1
        #active_servs format: [[5, 100, 3705, 42], [6, 97, 5736, 19], [9, 96, 9156, 4]]
        self.active_servs = simulation_functions.select_services(
            self.about_me_wm.ID, depend_nr)
        print self.active_servs

        self.write_log_file(
            self.stdout_log,
            '[INIT] active_servs: ' + str(self.active_servs) + '\n')

        self.service = []

        self.changed_servs = 1
        self.iteration = 1

        self.message = Message_Type()
        self.message.id = self.about_me_wm.ID
        self.message.rank = 10
        self.message.group = 1
        self.message.content = ''
        for x in self.active_servs:
            self.message.content = self.message.content + str(x[0]) + '|'
        self.message.timestamp = time.strftime('%X', time.gmtime())

        ## ROS Topics and Services ################################################
        ###########################################################################
        self.conn_reset = 0
        rospy.init_node('agent', anonymous=True)

        myservice = '/robot' + str(self.about_me_wm.ID) + '/serve'
        srv = rospy.Service(myservice, Service_One, self.handle_serve)

        self.publish_global = rospy.Publisher('msgs',
                                              Message_Type,
                                              queue_size=200)
        rospy.Subscriber('trigger', Message_Type, self.callback)

        rospy.sleep(10)