Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decision making #15

Draft
wants to merge 87 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
d2af326
Remove pycache from repo
RensDur Feb 28, 2023
d969ef4
Remove cache files
RensDur Feb 28, 2023
73e7ff2
Add evaluation option to main and implement this in agent
vincentvvliet Mar 7, 2023
09554fc
Add evaluation to output logger
vincentvvliet Mar 7, 2023
107f7df
Clean up code
vincentvvliet Mar 7, 2023
85b93d1
Pass evaluation type to output logger
vincentvvliet Mar 7, 2023
b0da28b
Implement a first version of Trust Mechanism
RensDur Mar 9, 2023
a9f8e7b
Add .idea and logs to gitignore
RensDur Mar 9, 2023
a453cac
Update trust mechanism
RensDur Mar 9, 2023
83d0327
Update .gitignore
RensDur Mar 14, 2023
23920c9
Add state container per received message
RensDur Mar 14, 2023
8e7dd95
Merge pull request #1 from RensDur/evaluation
vincentvvliet Mar 15, 2023
61678c5
Update .gitignore
RensDur Mar 15, 2023
7a75e0c
Merge pull request #3 from RensDur/impl-message-state-connection
RensDur Mar 15, 2023
eb6ec62
Fix merge conflicts
vincentvvliet Mar 15, 2023
03599f4
Merge pull request #2 from RensDur/experiment-trust-mechanism
RensDur Mar 15, 2023
6640e90
added TODO comments at places where decision might be manipulated by …
bstellinga Mar 15, 2023
ea4325b
Start making overview of possible decisions
RensDur Mar 15, 2023
ef2aa13
Update markdown file with useful vars
RensDur Mar 15, 2023
dbab3ac
Update OfficialAgent
RensDur Mar 15, 2023
268086f
Update markdown
RensDur Mar 15, 2023
78ca83d
Implement confidence trust belief
RensDur Mar 16, 2023
4653bb0
Implement functions for comparing trust beliefs
RensDur Mar 16, 2023
845f153
Merge pull request #4 from RensDur/advance-trust-mechanism
bramstellinga Mar 16, 2023
ad8a81e
Finalize trust mechanism for now
RensDur Mar 16, 2023
f1c0c3e
Incorporate confidence in csv file
RensDur Mar 16, 2023
b53958a
Update trust mechanism to incorporate human robot distance
RensDur Mar 16, 2023
4de0fa4
In phase 5, the robot now uses willingness to determine how long to s…
bstellinga Mar 16, 2023
03e7bc7
Competence belief when rescuing alone
RensDur Mar 16, 2023
eadee07
Merge pull request #5 from RensDur/advance-trust-mechanism
RensDur Mar 16, 2023
3aa7d90
Change default confidence level
RensDur Mar 16, 2023
2a494c5
Update CSV-fiels
RensDur Mar 16, 2023
5adc09a
ik decisions gemaakt op basis van will en conp in phase 5, en wat oud…
bstellinga Mar 16, 2023
bb46e08
implemented the use of trust in phase 8
bstellinga Mar 16, 2023
67147fa
implemented usage of trust in phase 8
bstellinga Mar 16, 2023
5251147
fixed small things
bstellinga Mar 17, 2023
55d3c3a
fixed small things
bstellinga Mar 17, 2023
55250c1
Merge pull request #6 from rsverhagen94/CAI2023
RensDur Mar 17, 2023
0633d0a
Add confidence attribution in _trustBeliefs
RensDur Mar 17, 2023
0535396
Implement trust based on robot messages
RensDur Mar 17, 2023
4e0cc53
Merge pull request #7 from RensDur/confidence-attribution
RensDur Mar 17, 2023
7fe4d8f
added print statements describing the decisions made
bstellinga Mar 17, 2023
4974386
Fix weird code
RensDur Mar 17, 2023
05629d6
Merge branch 'decision-making' into implement-decisions
bramstellinga Mar 17, 2023
cd05484
Merge pull request #11 from rsverhagen94/CAI2023
RensDur Mar 17, 2023
69e6738
Merge branch 'main' into decision-making
RensDur Mar 17, 2023
7e2496d
PYC bsht
RensDur Mar 17, 2023
98ce519
Pyc
RensDur Mar 17, 2023
6bf59f1
Fix previous fix
RensDur Mar 17, 2023
2ecf349
Remove new messages
RensDur Mar 17, 2023
9bb5818
Merge pull request #9 from RensDur/implement-decisions
RensDur Mar 17, 2023
89ef9ac
Fix stay_idle function
RensDur Mar 17, 2023
512403c
typo fix
julievm Mar 17, 2023
ad76a8c
Nog een keer
RensDur Mar 17, 2023
629b819
Merge branch 'decision-making' of https://github.com/RensDur/CAI-Grou…
RensDur Mar 17, 2023
03f46a6
Nog een keer
RensDur Mar 17, 2023
f33bc6f
Nog een keer
RensDur Mar 17, 2023
d647bad
Adjust timer
RensDur Mar 17, 2023
1194163
Resolve issue with timers
RensDur Mar 18, 2023
7ba730c
Update willingness decision
RensDur Mar 18, 2023
70331ec
Delete all __pycache__ files
RensDur Mar 18, 2023
120e220
actions
RensDur Mar 18, 2023
ff74dec
Merge pull request #14 from RensDur/CAI2023
RensDur Mar 18, 2023
e6e61d4
Merge main into decision-making
RensDur Mar 18, 2023
e6abb21
Remove pycache
RensDur Mar 18, 2023
ae1419a
Pycache
RensDur Mar 18, 2023
e8dfc53
Update timer
RensDur Mar 18, 2023
da311e1
Fix eval_type mistake
RensDur Mar 18, 2023
43d0dc9
self._waiting = True
RensDur Mar 18, 2023
4fe0aa1
Update actions
RensDur Mar 18, 2023
d10131e
Remove annoying printing statement
RensDur Mar 18, 2023
04d16cc
Add processing messages to trust mechanism
RensDur Mar 18, 2023
16425f6
Implement score console logger
RensDur Mar 18, 2023
65a8b5e
Resolve issue with timers
RensDur Mar 18, 2023
a2e4711
Update outputlogger
RensDur Mar 18, 2023
d750caf
Resolve issue where robot remained idle when instructed 'remove alone'
RensDur Mar 18, 2023
70a0f69
Update OfficialAgent
RensDur Mar 18, 2023
588a0fa
Update
RensDur Mar 18, 2023
8dec740
Update agent
RensDur Mar 18, 2023
747d5f2
Update
RensDur Mar 18, 2023
94308a8
Update
RensDur Mar 18, 2023
95992dc
Update CustomLogger
RensDur Mar 19, 2023
cec765c
Update confidence increase
RensDur Mar 19, 2023
d2d6d17
fixed bug when robot rescues mild victim
bstellinga Mar 20, 2023
e5e5dd1
removed debug message
bstellinga Mar 20, 2023
38d35fb
Make robot move on if human doesn't showup for rescue together
RensDur Mar 20, 2023
2355ed2
removed todos
bstellinga Mar 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed SaR_gui/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added SaR_gui/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified SaR_gui/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified SaR_gui/__pycache__/visualization_server.cpython-38.pyc
Binary file not shown.
Binary file modified actions1/__pycache__/CustomActions.cpython-38.pyc
Binary file not shown.
889 changes: 796 additions & 93 deletions agents1/OfficialAgent.py

Large diffs are not rendered by default.

Binary file removed agents1/__pycache__/BaselineAgent.cpython-38.pyc
Binary file not shown.
Binary file modified agents1/__pycache__/OfficialAgent.cpython-38.pyc
Binary file not shown.
Binary file modified agents1/__pycache__/TutorialAgent.cpython-38.pyc
Binary file not shown.
283 changes: 283 additions & 0 deletions agents1/descide_on_actions_useful_vars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
# These are useful variables that we can use to adapt the robot's decisions


## Obviously: the trust beliefs:
I've created two functions that quickly extract the trust-belief values for the human-teammate

Willingness: ```getCurrentWillingnessBelief()``` <Br>
Competence: ```getCurrentCompetenceBelief()```

These are placed inside the scope of ```decide_on_actions()```.


<hr>

## Getters: provide information that we base our decision on

|Variable |Meaning |Possible values|
|---------------------------|-----------------------|---------------|
|```self._searchedRooms``` |Rooms that have been searched by the robot or human | List[~Room]|
|```self._distanceHuman``` |Distance between the robot and the human |'close' or 'far'|
|```self._distanceDrop``` |Distance from the robot to the drop-zone |'close' or 'far' |
|```self._roomVics``` |List of victims in the current room |List[~Victim]|
|```self._recentVic``` |Recently (or currently) considered victim |~Victim|
|```remainingZones``` |Remaining drop zones |List[~Zone-Info] |
|```remainingVics``` |Remaining victims |List[~Victim] |
|```remaining``` |Location of remaining victims|List[~Location]<Br>_indexed by ~Victims_|
| | | |


<hr>

## Setters: means of changing robot's behaviour
|Variable |Meaning |Possible values|
|---------------------------|-----------------------|---------------|
|```self._goalVic``` |Target victim to rescue next| ~Victim|
|```self._goalLoc``` |Target location to move next| ~Location|
|```self._rescue``` |Directive for the robot to start rescuing a victim | None or 'alone' or 'together'|
| | | |




# Decisions that are currently made by the robot

## Phase 1: FIND_NEXT_GOAL

**All areas have been searched, but there's still victims left.**
Define a previously found victim as target
```python
if vic in self._foundVictims and vic in self._todo and len(self._searchedRooms)==0:
```

**Otherwise, if not all areas have been searched and there's still victims left in the 'found' list**
Define a previously found victim as target
```python
if vic in self._foundVictims and vic not in self._todo:
```

**If there are no target victims found (found-list empty)**
Visit an unsearched area to search for victims
```python
if vic not in self._foundVictims or vic in self._foundVictims and vic in self._todo and len(self._searchedRooms)>0:
PHASE -> PICK_UNSEARCHED_ROOM
```

## Phase 2: PICK_UNSEARCHED_ROOM

**If all areas have been searched but the task is not finished**
```python
if self._remainingZones and len(unsearchedRooms) == 0:
PHASE -> FIND_NEXT_GOAL
```

_Start searching areas again_

**Otherwise, if there are still areas to search**
```python
else:
PHASE -> PLAN_PATH_TO_ROOM
```

_Define which one to search next_

## Phase 3: PLAN_PATH_TO_ROOM

**NO IMPORTANT DECISIONS ARE MADE IN THIS PHASE**

## Phase 4: FOLLOW_PATH_TO_ROOM

**NO IMPORTANT DECISIONS ARE MADE IN THIS PHASE**

## Phase 5: REMOVE_OBSTACLE_IF_NEEDED

**If the human tells the agent not to remove the obstacle**
```python
if self.received_messages_content and self.received_messages_content[-1] == 'Continue' and not self._remove:
PHASE -> FIND_NEXT_GOAL
```

_Determine the next area to explore_

**If the human tells the agent to (help) remove the rock**
```python
if self.received_messages_content and self.received_messages_content[-1] == 'Remove' or self._remove:
```

*** OBSTACLE: ROCK ***

_Wait for the human to help removing the obstacle and remove the obstacle together_

*** OBSTACLE: TREE ***

_Remove the obstacle if the human tells the agent to do so_

*** OBSTACLE: STONES ***

_Remove the obstacle alone if the human decides so_

OR:

_Remove the obstacle together if the human decides so_

## Phase 6: ENTER_ROOM

**NO INTERESTING DECISIONS ARE MADE IN THIS PHASE**

## Phase 7: PLAN_ROOM_SEARCH_PATH

**NO INTERESTING DECISIONS ARE MADE IN THIS PHASE**

## Phase 8: FOLLOW_ROOM_SEARCH_PATH

**The robot has found a mildly- or critically-injured victim**

_Describe the action that the robot takes accordingly_

```python
if 'mild' in vic and self._answered == False and not self._waiting:
self._sendMessage('Found ' + vic + ' in ' + self._door['room_name'] + '. Please decide whether to "Rescue together", "Rescue alone", or "Continue" searching. \n \n \
Important features to consider are: \n safe - victims rescued: ' + str(self._collectedVictims) + '\n explore - areas searched: area ' + str(self._searchedRooms).replace('area ','') + '\n \
clock - extra time when rescuing alone: 15 seconds \n afstand - distance between us: ' + self._distanceHuman,'RescueBot')
self._waiting = True

if 'critical' in vic and self._answered == False and not self._waiting:
self._sendMessage('Found ' + vic + ' in ' + self._door['room_name'] + '. Please decide whether to "Rescue" or "Continue" searching. \n\n \
Important features to consider are: \n explore - areas searched: area ' + str(self._searchedRooms).replace('area','') + ' \n safe - victims rescued: ' + str(self._collectedVictims) + '\n \
afstand - distance between us: ' + self._distanceHuman,'RescueBot')
self._waiting = True
```


<hr>

**The robot discovered that the victim, about which it learned it was located in room A, is in fact not there**

_Communicate that the agent did not find the target victim in the are, while the human previously communicted the victim was located there._

```python
if self._goalVic in self._foundVictims and self._goalVic not in self._roomVics and self._foundVictimLocs[self._goalVic]['room'] == self._door['room_name']:
```

<hr>

**The RescueBot received a message from the human saying it wants to rescue a critically injured victim**

_Rescue the victim, together with the human_

```python
if self.received_messages_content and self.received_messages_content[-1] == 'Rescue' and 'critical' in self._recentVic:
self._rescue = 'together'
```

<hr>

**The RescueBot received a message from the human saying it wants to rescue a mildly injured victim, together**

_Rescue the victim, together with the human_

```python
if self.received_messages_content and self.received_messages_content[-1] == 'Rescue together' and 'mild' in self._recentVic:
self._rescue = 'together'
```

<hr>

**The RescueBot received a message from the human saying it should rescue a mildly injured victim alone.**

_Rescue the victim, without help from the human_

```python
if self.received_messages_content and self.received_messages_content[-1] == 'Rescue alone' and 'mild' in self._recentVic:
[...]
self._rescue = 'alone'
```

<hr>

**The human says that the robot should continue searching rooms**

_Do as the human instructed_

```python
if self.received_messages_content and self.received_messages_content[-1] == 'Continue':
[...]
self._todo.append(self._recentVic)
self._recentVic = None
PHASE -> FIND_NEXT_GOAL
```

<hr>

**The robot hasn't heard from the human yet, about whether to rescue the victim or not**

_Wait indefinetely_

```python
if self.received_messages_content and self._waiting and self.received_messages_content[-1] != 'Rescue' and self.received_messages_content[-1] != 'Continue':
return None, {}
```


## Phase 9: PLAN_PATH_TO_VICTIM

**NO INTERESTING DECISIONS ARE MADE IN THIS PHASE**

## Phase 10: FOLLOW_PATH_TO_VICTIM

**NO INTERESTING DECISIONS ARE MADE IN THIS PHASE**

## Phase 11: TAKE_VICTIM

_Some interesting decisions are made, but I don't think we should take these into consideration_ ~Rens

## Phase 12: PLAN_PATH_TO_DROPPOINT

**NO INTERESTING DECISIONS ARE MADE IN THIS PHASE**

## Phase 13: FOLLOW_PATH_TO_DROPPOINT

**NO INTERESTING DECISIONS ARE MADE IN THIS PHASE**

## Phase 14: DROP_VICTIM

**NO INTERESTING DECISIONS ARE MADE IN THIS PHASE**



Willingness = eigen initiatief | beschikbaarbaarheid voor hulp | motivatie om de taak te voltooien
Competence = goed geheugen | snelste route kiezen | weak/normal/strong |



self._sendMessage('Our score is ' + str(state['rescuebot']['score']) + '.', 'RescueBot')
If you are ready to begin our mission, you can simply start moving.', 'RescueBot')
self._sendMessage('Moving to ' + self._foundVictimLocs[vic]['room'] + ' to pick up ' + self._goalVic +'. Please come there as well to help me carry ' + self._goalVic + ' to the drop zone.', 'RescueBot')
self._sendMessage('Going to re-search all areas.', 'RescueBot')
self._sendMessage('Moving to ' + str(self._door['room_name']) + ' to pick up ' + self._goalVic + ' together with you.', 'RescueBot')
self._sendMessage('Moving to ' + str(self._door['room_name']) + ' to pick up ' + self._goalVic + '.', 'RescueBot')
self._sendMessage('Moving to ' + str(self._door['room_name']) + ' because it is the closest unsearched area.', 'RescueBot')
self._sendMessage('Reaching ' + str(self._door['room_name']) + ' will take a bit longer because I found stones blocking my path.', 'RescueBot')
\n clock - removal time: 5 seconds \n afstand - distance between us: ' + self._distanceHuman ,'RescueBot')
self._sendMessage('Please come to ' + str(self._door['room_name']) + ' to remove rock.','RescueBot')
self._sendMessage('Lets remove rock blocking ' + str(self._door['room_name']) + '!','RescueBot')
\n clock - removal time: 10 seconds','RescueBot')
self._sendMessage('Removing tree blocking ' + str(self._door['room_name']) + '.','RescueBot')
self._sendMessage('Removing tree blocking ' + str(self._door['room_name']) + ' because you asked me to.', 'RescueBot')
\n clock - removal time together: 3 seconds \n afstand - distance between us: ' + self._distanceHuman + '\n clock - removal time alone: 20 seconds','RescueBot')
self._sendMessage('Removing stones blocking ' + str(self._door['room_name']) + '.','RescueBot')
self._sendMessage('Please come to ' + str(self._door['room_name']) + ' to remove stones together.','RescueBot')
self._sendMessage('Lets remove stones blocking ' + str(self._door['room_name']) + '!','RescueBot')
self._sendMessage('Found ' + vic + ' in ' + self._door['room_name'] + ' because you told me ' + vic + ' was located here.','RescueBot')
clock - extra time when rescuing alone: 15 seconds \n afstand - distance between us: ' + self._distanceHuman,'RescueBot')
afstand - distance between us: ' + self._distanceHuman,'RescueBot')
self._sendMessage(self._goalVic + ' not present in ' + str(self._door['room_name']) + ' because I searched the whole area without finding ' + self._goalVic + '.','RescueBot')
self._sendMessage('Please come to ' + str(self._door['room_name']) + ' to carry ' + str(self._recentVic) + ' together.', 'RescueBot')
self._sendMessage('Lets carry ' + str(self._recentVic) + ' together! Please wait until I moved on top of ' + str(self._recentVic) + '.', 'RescueBot')
self._sendMessage('Please come to ' + str(self._door['room_name']) + ' to carry ' + str(self._recentVic) + ' together.', 'RescueBot')
self._sendMessage('Lets carry ' + str(self._recentVic) + ' together! Please wait until I moved on top of ' + str(self._recentVic) + '.', 'RescueBot')
self._sendMessage('Picking up ' + self._recentVic + ' in ' + self._door['room_name'] + '.','RescueBot')
self._sendMessage('Transporting ' + self._goalVic + ' to the drop zone.', 'RescueBot')
self._sendMessage('Delivered ' + self._goalVic + ' at the drop zone.', 'RescueBot')
self._sendMessage('Moving to ' + str(self._door['room_name']) + ' to help you remove an obstacle.','RescueBot')
self._sendMessage('Will come to ' + area + ' after dropping ' + self._goalVic + '.','RescueBot')
2 changes: 1 addition & 1 deletion beliefs/allTrustBeliefs.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name;competence;willingness
name;competence;willingness;confidence
;;;
4 changes: 2 additions & 2 deletions beliefs/currentTrustBelief.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name;competence;willingness
rens;0.5;0.5
name;competence;willingness;confidence
Alice;0.5;0.5975;0.545
3 changes: 2 additions & 1 deletion brains1/ArtificialBrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ class ArtificialBrain(ArtificialAgentBrain, ABC):
This class is the obligatory base class for the agents.
Agents must implement decide_on_action
"""
def __init__(self, slowdown, condition, name, folder):
def __init__(self, slowdown, condition, name, eval_type, folder):
'''
@param slowdown an integer. Basically this sets action_duration
field to the given slowdown. 1 implies normal speed
Expand All @@ -626,6 +626,7 @@ def __init__(self, slowdown, condition, name, folder):
self.__condition = condition
self.__name = name
self.__folder = folder
self.__eval_type = eval_type
super().__init__()

def decide_on_action(self, state:State):
Expand Down
Binary file modified brains1/__pycache__/ArtificialBrain.cpython-38.pyc
Binary file not shown.
Binary file modified brains1/__pycache__/HumanBrain.cpython-38.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions classes/ReceivedMessageState.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class ReceivedMessageState:

def __init__(self, msg="", time=0, dist='', robot_msg=[], found_vic=[], collected_vic=[]):
# The message itself
self.message = msg

# Record time
self.time = time

# Store the distance between the human and the robot at the moment the message was received
self.distanceHumanRobot = dist

# Store the messages sent by the robot at the moment the message was received
self.messagesSentByRobot = robot_msg

# Store lists of found and collected victims at the moment this message was received
self.foundVictims = found_vic
self.collectedVictims = collected_vic
Binary file not shown.
39 changes: 39 additions & 0 deletions loggers/CustomLogger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

import csv

action_file = "/Users/rensdur/Documents/TU Delft/BSc Computer Science and Engineering/Year 3/CSE3210 Collaborative Artificial Intelligence/Project 2/GitHub/CAI-Group38-Project2/logs/exp_strong_at_time_10h-31m-45s_date_19d-03m-2023y/world_1/actions__2023-03-19_103146.csv"

action_header = []
action_contents=[]
trustfile_header = []
trustfile_contents = []
# Calculate the unique human and agent actions
unique_agent_actions = []
unique_human_actions = []
with open(action_file) as csvfile:
reader = csv.reader(csvfile, delimiter=';', quotechar="'")
for row in reader:
if action_header==[]:
action_header=row
continue
if row[2:4] not in unique_agent_actions and row[2]!="":
unique_agent_actions.append(row[2:4])
if row[4:6] not in unique_human_actions and row[4]!="":
unique_human_actions.append(row[4:6])
if row[4] == 'RemoveObjectTogether' or row[4] == 'CarryObjectTogether' or row[4] == 'DropObjectTogether':
if row[4:6] not in unique_agent_actions:
unique_agent_actions.append(row[4:6])
res = {action_header[i]: row[i] for i in range(len(action_header))}
action_contents.append(res)

no_ticks = action_contents[-1]['tick_nr']
score = action_contents[-1]['score']
completeness = action_contents[-1]['completeness']

print("\n\n=====OUPUT=====")
print("Completeness: " + str(completeness))
print("Score: " + str(score))
print("No_ticks: " + str(no_ticks))
print("Agent_actions: " + str(len(unique_agent_actions)))
print("Human_actions: " + str(len(unique_human_actions)))
print()
Loading