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
a343f212
Commit
a343f212
authored
4 years ago
by
shinedday
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://gitlab.com/be-pyamak/pyamak-noyau
parents
5ae57124
3170b6fb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pyAmakCore/classes/amas.py
+22
-5
22 additions, 5 deletions
pyAmakCore/classes/amas.py
pyAmakCore/classes/tools/loggable.py
+16
-2
16 additions, 2 deletions
pyAmakCore/classes/tools/loggable.py
pyAmakCore/tests/test_amas/test_agent.py
+20
-4
20 additions, 4 deletions
pyAmakCore/tests/test_amas/test_agent.py
with
58 additions
and
11 deletions
pyAmakCore/classes/amas.py
+
22
−
5
View file @
a343f212
...
...
@@ -30,6 +30,9 @@ class Amas(Schedulable, Loggable):
Loggable
.
__init__
(
self
)
self
.
__environment
:
Environment
=
environment
self
.
__agents
:
List
[
Agent
]
=
[]
self
.
__agent_to_add
:
List
[
Agent
]
=
[]
self
.
__agent_to_remove
:
List
[
Agent
]
=
[]
self
.
__nbrcycle
:
int
=
0
self
.
__scheduler
:
Scheduler
=
Scheduler
()
...
...
@@ -40,6 +43,11 @@ class Amas(Schedulable, Loggable):
self
.
on_initial_agents_creation
()
for
agent
in
self
.
__agent_to_add
:
if
agent
not
in
self
.
__agents
:
self
.
__agents
.
append
(
agent
)
self
.
__agent_to_add
=
[]
for
agent
in
self
.
__agents
:
agent
.
compute_criticality
()
...
...
@@ -52,9 +60,9 @@ class Amas(Schedulable, Loggable):
"""
add agent in the amas agents list without duplicate
"""
if
agent
in
self
.
__agents
:
if
agent
in
self
.
__agents
or
agent
in
self
.
__agent_to_add
:
return
self
.
__agent
s
.
append
(
agent
)
self
.
__agent
_to_add
.
append
(
agent
)
def
add_agents
(
self
,
agents
:
List
[
Agent
])
->
None
:
"""
...
...
@@ -67,9 +75,7 @@ class Amas(Schedulable, Loggable):
"""
remove agent from amas
"""
if
agent
not
in
self
.
__agents
:
return
self
.
__agents
.
remove
(
agent
)
self
.
__agent_to_remove
.
append
(
agent
)
def
get_environment
(
self
)
->
Environment
:
"""
...
...
@@ -120,6 +126,11 @@ class Amas(Schedulable, Loggable):
"""
print
(
"
Cycle :
"
,
self
.
__nbrcycle
)
for
agent
in
self
.
__agent_to_add
:
if
agent
not
in
self
.
__agents
:
self
.
__agents
.
append
(
agent
)
self
.
__agent_to_add
=
[]
self
.
on_cycle_begin
()
self
.
synchronization
()
...
...
@@ -146,6 +157,12 @@ class Amas(Schedulable, Loggable):
self
.
synchronization
()
self
.
on_cycle_end
()
for
agent
in
self
.
__agent_to_remove
:
if
agent
in
self
.
__agents
:
self
.
__agents
.
remove
(
agent
)
self
.
__agent_to_remove
=
[]
self
.
to_csv
(
self
.
get_cycle
(),
self
.
get_agents
())
self
.
__nbrcycle
+=
1
...
...
This diff is collapsed.
Click to expand it.
pyAmakCore/classes/tools/loggable.py
+
16
−
2
View file @
a343f212
...
...
@@ -14,6 +14,7 @@ class Loggable:
def
__init__
(
self
):
self
.
__do_log
=
False
self
.
__file_path
=
None
self
.
__ignore_attribute
=
[
"
_Agent__amas
"
,
"
_Agent__environment
"
]
def
to_csv
(
self
,
cycle
:
int
,
var_list
:
List
[
'
Agent
'
])
->
None
:
"""
...
...
@@ -22,8 +23,7 @@ class Loggable:
if
not
self
.
__do_log
:
return
ignore_attribute
=
[
"
_Agent__amas
"
,
"
_Agent__environment
"
]
table
=
[{
**
{
e
:
x
[
e
]
for
e
in
x
if
e
not
in
ignore_attribute
},
table
=
[{
**
{
e
:
x
[
e
]
for
e
in
x
if
e
not
in
self
.
__ignore_attribute
},
**
{
'
nombre_cycle
'
:
cycle
}}
for
x
in
map
(
vars
,
var_list
)]
dataframe
=
DataFrame
(
table
)
...
...
@@ -46,3 +46,17 @@ class Loggable:
specify path to csv
"""
self
.
__file_path
=
path_to_file
def
add_ignore_attribute
(
self
,
attribute
:
str
)
->
None
:
"""
add attribute in ignored attribute
"""
self
.
__ignore_attribute
.
append
(
attribute
)
def
remove_ignore_attribute
(
self
,
attribute
:
str
)
->
None
:
"""
remove attribute in ignored attribute
"""
if
attribute
not
in
self
.
__ignore_attribute
:
return
self
.
__ignore_attribute
.
remove
(
attribute
)
This diff is collapsed.
Click to expand it.
pyAmakCore/tests/test_amas/test_agent.py
+
20
−
4
View file @
a343f212
...
...
@@ -8,6 +8,11 @@ from pyAmakCore.classes.amas import Amas
from
pyAmakCore.classes.environment
import
Environment
from
pyAmakCore.classes.agent
import
Agent
class
SimplerAmas
(
Amas
):
def
synchronization
(
self
):
self
.
_Amas__scheduler
.
give_amas_token
()
super
().
synchronization
()
class
TestAmasAgents
(
TestCase
):
"""
...
...
@@ -33,27 +38,31 @@ class TestAmasAgents(TestCase):
"""
environment
=
Environment
()
amas
=
Amas
(
environment
)
amas
=
Simpler
Amas
(
environment
)
agent1
=
Agent
(
amas
)
agent2
=
Agent
(
amas
)
agent3
=
Agent
(
amas
)
# add 1 agent
amas
.
add_agent
(
agent1
)
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
])
# don't remove previous agent
amas
.
add_agent
(
agent2
)
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
,
agent2
])
# add agent in good order
amas
.
add_agent
(
agent3
)
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
,
agent2
,
agent3
])
# don't add duplicate
amas
.
add_agent
(
agent1
)
amas
.
add_agent
(
agent2
)
amas
.
add_agent
(
agent3
)
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
,
agent2
,
agent3
])
def
test_add_agents
(
self
)
->
None
:
...
...
@@ -62,7 +71,7 @@ class TestAmasAgents(TestCase):
"""
environment
=
Environment
()
amas
=
Amas
(
environment
)
amas
=
Simpler
Amas
(
environment
)
agent1
=
Agent
(
amas
)
agent2
=
Agent
(
amas
)
...
...
@@ -71,36 +80,43 @@ class TestAmasAgents(TestCase):
agent5
=
Agent
(
amas
)
amas
.
add_agents
([
agent1
,
agent2
,
agent3
,
agent4
,
agent5
])
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
,
agent2
,
agent3
,
agent4
,
agent5
])
amas
=
Amas
(
environment
)
amas
=
Simpler
Amas
(
environment
)
amas
.
add_agents
([
agent1
,
agent2
])
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
,
agent2
])
amas
.
add_agents
([
agent1
,
agent2
,
agent4
,
agent2
,
agent3
])
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
,
agent2
,
agent4
,
agent3
])
def
test_remove_agent
(
self
)
->
None
:
environment
=
Environment
()
amas
=
Amas
(
environment
)
amas
=
Simpler
Amas
(
environment
)
agent1
=
Agent
(
amas
)
agent2
=
Agent
(
amas
)
agent3
=
Agent
(
amas
)
amas
.
remove_agent
(
agent2
)
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[])
amas
.
add_agents
([
agent1
,
agent2
,
agent3
])
amas
.
remove_agent
(
agent2
)
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
,
agent3
])
amas
.
remove_agent
(
agent2
)
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[
agent1
,
agent3
])
amas
.
remove_agent
(
agent1
)
amas
.
remove_agent
(
agent3
)
amas
.
cycle
()
self
.
assertEqual
(
amas
.
get_agents
(),
[])
...
...
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