from .OfficialAgent import BaselineAgent
import csv
import numpy as np
class MyAgent(BaselineAgent):
def __init__(self, slowdown, condition, name, folder):
super().__init__(slowdown, condition, name, folder)
self.processedMessages = []
def decide_on_actions(self, state, trustBeliefs, receivedMessages):
for message in receivedMessages:
if message in self.processedMessages:
continue
#robot checks the competence and willingness when doing certain tasks
#if the competence/willingness is too low it will just do it alone but if it is above a threshold it will ask to work together
#carrying a mildly injured victim can either do alone or working together
#rescue a found mildly injured victim
if self.message[-1] == 'Rescue together' and 'mild' in self._recentVic:
#check the comptence/willingness, below threshold then do it alone
if ((trustBeliefs[self._humanName]['competence'] + trustBeliefs[self._humanName]['willingness']) / 2 ) < 0.6:
self._rescue = 'alone'
self._answered = True
self._waiting = False
self._sendMessage(
'Picking up ' + self._recentVic + ' in ' + self._door['room_name'] + '.',
'RescueBot')
#above the threshold work together
else:
self._rescue = 'together'
self._answered = True
self._waiting = False
self._sendMessage('Lets carry ' + str(
self._recentVic) + ' together! Please wait until I moved on top of ' + str(
self._recentVic) + '.', 'RescueBot')
objects = []
#removing a small stone it can either do alone or working together
for info in state.values():
if 'class_inheritance' in info and 'ObstacleObject' in info['class_inheritance'] and 'stone' in info['obj_id']:
objects.append(info)
#remove the obstacle alone
if ((trustBeliefs[self._humanName]['competence'] + trustBeliefs[self._humanName]['willingness']) / 2 ) < 0.6:
self._rescue = 'alone'
self._answered = True
self._waiting = False
self._sendMessage(
'Removing stones blocking ' + str(self._door['room_name']) + '.',
'RescueBot')
#remove the obstacle together
else:
self._rescue = 'together'
self._answered = True
self._waiting = False
self._sendMessage(
'Lets remove stones blocking ' + str(self._door['room_name']) + '!',
'RescueBot')
# def _trustBelief(self, members, trustBeliefs, folder, receivedMessages):
# for message in receivedMessages:
# if message in self.processedMessages:
# continue
#
# if 'Collect' in message:
# object_collected = message.split(":")[1].split(" in ")[0].strip()
#
# if object_collected not in self._collectedVictims:
# # Increase agent trust in a team member that rescued a victim
# trustBeliefs[self._humanName]['competence']+=0.10
# else:
# trustBeliefs[self._humanName]['competence']-=0.10
#
# self.processedMessages.append(message)
#
# if 'Search' in message:
# area = message.split()[-1]
#
# if area not in self._searchedRooms:
# # Increase agent trust in a team member that searched the room
# trustBeliefs[self._humanName]['competence'] += 0.10
# else:
# trustBeliefs[self._humanName]['competence'] -= 0.10
#
# self.processedMessages.append(message)
#
# if 'Found' in message:
# # Identify which victim and area it concerns
# if len(message.split()) == 6:
# foundVic = ' '.join(message.split()[1:4])
# else:
# foundVic = ' '.join(message.split()[1:5])
#
# if foundVic in self._foundVictims:
# # Increase agent trust in a team member if victims is in the drop zone
# trustBeliefs[self._humanName]['competence'] += 0.10
# else:
# trustBeliefs[self._humanName]['competence'] -= 0.10
#
# if 'Remove' in message:
# area = message.split()[-1]
#
# if area in self._searchedRooms:
# trustBeliefs[self._humanName]['competence'] += 0.10
# else:
# trustBeliefs[self._humanName]['competence'] -= 0.10
# self.processedMessages.append(message)
#
# # Restrict the competence belief to a range of -1 to 1
# trustBeliefs[self._humanName]['competence'] = np.clip(trustBeliefs[self._humanName]['competence'], -1, 1)
# trustBeliefs[self._humanName]['willingness'] = np.clip(trustBeliefs[self._humanName]['willingness'], -1, 1)
# Save current trust belief values so we can later use and retrieve them to add to a csv file with all the logged trust belief values
with open(folder + '/beliefs/allTrustBeliefs.csv', mode='w') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(['name','competence','willingness'])
csv_writer.writerow([self._humanName,trustBeliefs[self._humanName]['competence'],trustBeliefs[self._humanName]['willingness']])
print("Messages", receivedMessages)
print("Members", members)
print("Trust Beliefs",trustBeliefs)
print("Distance", self._distanceHuman)
print("Collected", self._collectedVictims)
print("Found", self._foundVictims)