Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
floor_simulation
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
Container registry
Model registry
Operate
Environments
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
Maximilian Gruber
floor_simulation
Commits
69b13b36
Commit
69b13b36
authored
5 years ago
by
Maximilian Gruber
Browse files
Options
Downloads
Patches
Plain Diff
WIP
parent
74220392
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
run_agents.py
+59
-17
59 additions, 17 deletions
run_agents.py
with
59 additions
and
17 deletions
run_agents.py
+
59
−
17
View file @
69b13b36
...
...
@@ -6,40 +6,82 @@ import pandas as pd
# import directly from git folder
import
sys
sys
.
path
.
append
(
"
../agentMET4FOF
"
)
from
agentMET4FOF.agents
import
AgentMET4FOF
,
AgentNetwork
,
MonitorAgent
from
agentMET4FOF.agents
import
DataStreamAgent
,
AgentNetwork
,
MonitorAgent
from
agentMET4FOF.streams
import
DataStreamMET4FOF
class
SensorAgent
(
AgentMET4FOF
):
def
init_parameters
(
self
,
sampling_period
=
1.0
):
self
.
sampling_period
=
sampling_period
def
on_received_message
(
self
,
message
):
# do something
self
.
send_output
(
1.0
)
# adjust existing agent definitions
class
SensorAgent
(
DataStreamAgent
):
pass
#def agent_loop(self):
# if self.current_state == "Running":
# data = self.stream.next_sample(self.batch_size)
# self.send_output(data['x'], channel="default")
class
SensorStream
(
DataStreamMET4FOF
):
def
__init__
(
self
,
sensor_id
=
""
):
def
generate_data
(
self
):
x
=
np
.
random
.
random
(
300
)
y
=
None
self
.
set_data_source
(
x
,
y
)
def
read_data
(
self
,
df
,
col_index
):
df_column
=
df
.
iloc
[
col_index
]
x
=
df_column
.
values
y
=
df
.
index
self
.
set_data_source
(
x
,
None
)
class
BufferAgent
(
DataStreamAgent
):
def
update_data_memory
(
self
,
message
,
buffer
=
10
):
md
=
message
[
"
data
"
]
mf
=
message
[
"
from
"
]
if
not
isinstance
(
md
,
np
.
ndarray
)
or
mf
not
in
self
.
plots
.
keys
():
self
.
memory
[
mf
]
=
md
else
:
#self.plots[mf].update({key: md[key]})
pmf
=
self
.
plots
[
mf
]
pmf
=
np
.
append
(
pmf
,
md
)
if
len
(
pmf
)
>
buffer
:
pmf
=
pmf
[
-
buffer
:]
self
.
plots
.
update
({
mf
:
pmf
})
self
.
log_info
(
"
PLOTS:
"
+
str
(
self
.
plots
))
def
main
():
# data to initilize from
file_name
=
"
2019-11-28__15:44:39_output.csv
"
df
=
pd
.
read_csv
(
file_name
)
# start agent network server
agentNetwork
=
AgentNetwork
([
SensorAgent
,
SensorStream
])
agentNetwork
=
AgentNetwork
(
dashboard_modules
=
[
SensorAgent
,
SensorStream
])
# init agents
monitor_agent
=
agentNetwork
.
add_agent
(
agentType
=
MonitorAgent
)
sensor_agent
=
agentNetwork
.
add_agent
(
agentType
=
SensorAgent
)
monitor_agent
=
agentNetwork
.
add_agent
(
"
monitor
"
,
agentType
=
_MonitorAgent
)
sensor_agents
=
[]
for
i
in
range
(
3
):
# spawn the sensor agenet
sensor_agent
=
agentNetwork
.
add_agent
(
"
sensor_{N}
"
.
format
(
N
=
i
),
agentType
=
SensorAgent
)
# add a stream of data to agent
sensor_stream
=
SensorStream
()
#sensor_stream.generate_data()
sensor_stream
.
read_data
(
df
,
i
)
sensor_agent
.
init_parameters
(
stream
=
sensor_stream
)
# add to sensor collection
sensor_agents
.
append
(
sensor_agent
)
# connect
agentNetwork
.
bind_agents
(
sensor_agent
,
monitor_agent
)
for
sensor_agent
in
sensor_agents
:
agentNetwork
.
bind_agents
(
sensor_agent
,
monitor_agent
)
# set all agents states to "Running"
agentNetwork
.
set_running_state
()
...
...
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