Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyAmak - noyau
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMAC
AMAK
Python
PyAMAK
pyAmak - noyau
Commits
27d2dc38
Commit
27d2dc38
authored
4 years ago
by
shinedday
Browse files
Options
Downloads
Patches
Plain Diff
Add classes mail & mailbox
parent
3b3dd420
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyAmakCore/classes/communicating_agent.py
+72
-0
72 additions, 0 deletions
pyAmakCore/classes/communicating_agent.py
with
72 additions
and
0 deletions
pyAmakCore/classes/communicating_agent.py
0 → 100644
+
72
−
0
View file @
27d2dc38
from
typing
import
Any
,
List
class
Mail
:
def
__init__
(
self
,
id_sender
:
int
,
id_receiver
:
int
,
message
:
Any
)
->
None
:
self
.
id_sender
=
id_sender
self
.
id_receiver
=
id_receiver
self
.
message
=
message
#set getter & setter
class
Mailbox
:
def
__init__
(
self
,
owner_id
:
int
,
amas
:
'
Amas
'
)
->
None
:
self
.
__mail_list
:
List
[
'
Mail
'
]
=
[]
self
.
__owner_id
:
int
=
owner_id
self
.
__amas
:
'
Amas
'
=
amas
def
get_mail
(
self
)
->
'
Mail
'
:
#check si pas empty
mail
=
self
.
__mail_list
.
pop
()
if
mail
.
id_receiver
!=
self
.
__owner_id
:
# pas normal
return
None
return
mail
def
receive_mail
(
self
,
mail
:
'
Mail
'
):
self
.
__mail_list
.
append
(
mail
)
def
send_message
(
self
,
message
:
Any
,
id_receiver
:
int
)
->
None
:
mail
=
Mail
(
self
.
__owner_id
,
id_receiver
,
message
)
for
agent
in
self
.
__amas
.
get_agents
():
if
agent
.
get_id
()
==
id
:
return
agent
.
receive_mail
(
mail
)
# error, id not found
class
CommunicatingAgent
(
Agent
):
def
__init__
(
self
,
amas
:
'
Amas
'
)
->
None
:
super
().
__init__
(
amas
)
self
.
__mailbox
:
'
Mailbox
'
=
Mailbox
(
self
.
get_id
())
def
send_message
(
self
,
message
,
id_receiver
):
self
.
__mailbox
.
send_message
(
message
,
id_receiver
)
def
receive_mail
(
self
,
mail
):
self
.
__mailbox
.
receive_mail
(
mail
)
def
__phase1
(
self
):
"""
this is the first phase of a cycle
"""
self
.
read_mails
()
self
.
on_perceive
()
self
.
compute_criticality
()
self
.
__next_phase
()
def
read_mails
(
self
):
mail
=
self
.
__mailbox
.
get_mail
()
while
mail
is
not
None
:
self
.
read_mail
(
mail
)
mail
=
self
.
__mailbox
.
get_mail
()
def
read_mail
(
self
,
mail
):
"""
TO OVERRIDE
"""
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment