Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ahmad Reza Cheraghi
swarm-sim
Commits
c3a91e1f
Commit
c3a91e1f
authored
Dec 16, 2019
by
Karol Actun
Browse files
merge with master
parents
a7ebadfa
eb1c00fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/vis3d.py
View file @
c3a91e1f
...
@@ -261,6 +261,9 @@ class Visualization:
...
@@ -261,6 +261,9 @@ class Visualization:
self
.
_viewer
.
marker_update_flag
=
True
self
.
_viewer
.
marker_update_flag
=
True
self
.
_viewer
.
marker_offset_data
[
marker
]
=
(
marker
.
coordinates
,
marker
.
color
)
self
.
_viewer
.
marker_offset_data
[
marker
]
=
(
marker
.
coordinates
,
marker
.
color
)
def
update_visualization_data
(
self
):
self
.
_viewer
.
update_data
()
# setters and getters for various variables in the visualization
# setters and getters for various variables in the visualization
def
set_rounds_per_second
(
self
,
rounds_per_second
):
def
set_rounds_per_second
(
self
,
rounds_per_second
):
...
...
lib/world.py
View file @
c3a91e1f
...
@@ -24,25 +24,27 @@ class World:
...
@@ -24,25 +24,27 @@ class World:
self
.
init_particles
=
[]
self
.
init_particles
=
[]
self
.
particle_id_counter
=
0
self
.
particle_id_counter
=
0
self
.
particles
=
[]
self
.
particles
=
[]
self
.
particles_created
=
[]
self
.
particle_rm
=
[]
self
.
particle_map_coordinates
=
{}
self
.
particle_map_coordinates
=
{}
self
.
particle_map_id
=
{}
self
.
particle_map_id
=
{}
self
.
particles_created
=
[]
self
.
particle_rm
=
[]
self
.
__particle_deleted
=
False
self
.
__particle_deleted
=
False
self
.
new_particle
=
None
self
.
new_particle
=
None
self
.
tiles
=
[]
self
.
tiles
=
[]
self
.
tiles_created
=
[]
self
.
tiles_rm
=
[]
self
.
tile_map_coordinates
=
{}
self
.
tile_map_coordinates
=
{}
self
.
tile_map_id
=
{}
self
.
tile_map_id
=
{}
self
.
tiles_created
=
[]
self
.
tiles_rm
=
[]
self
.
__tile_deleted
=
False
self
.
__tile_deleted
=
False
self
.
new_tile
=
None
self
.
new_tile
=
None
self
.
__tile_deleted
=
False
self
.
markers
=
[]
self
.
markers
=
[]
self
.
markers_created
=
[]
self
.
marker_map_coordinates
=
{}
self
.
marker_map_coordinates
=
{}
self
.
marker_map_id
=
{}
self
.
marker_map_id
=
{}
self
.
markers_created
=
[]
self
.
markers_rm
=
[]
self
.
markers_rm
=
[]
self
.
__marker_deleted
=
False
self
.
__marker_deleted
=
False
self
.
new_marker
=
None
self
.
new_marker
=
None
...
@@ -114,7 +116,8 @@ class World:
...
@@ -114,7 +116,8 @@ class World:
# if visualization is on, run the scenario in a separate thread and show that the program runs..
# if visualization is on, run the scenario in a separate thread and show that the program runs..
x
=
threading
.
Thread
(
target
=
mod
.
scenario
,
args
=
(
self
,))
x
=
threading
.
Thread
(
target
=
mod
.
scenario
,
args
=
(
self
,))
self
.
vis
.
wait_for_thread
(
x
,
"loading scenario... please wait."
,
"Loading Scenario"
)
self
.
vis
.
wait_for_thread
(
x
,
"loading scenario... please wait."
,
"Loading Scenario"
)
self
.
vis
.
_viewer
.
update_data
()
self
.
vis
.
update_visualization_data
()
else
:
else
:
# if no vis, just run the scenario on the main thread
# if no vis, just run the scenario on the main thread
mod
.
scenario
(
self
)
mod
.
scenario
(
self
)
...
@@ -340,6 +343,7 @@ class World:
...
@@ -340,6 +343,7 @@ class World:
self
.
new_particle
.
created
=
True
self
.
new_particle
.
created
=
True
logging
.
info
(
"Created particle at %s"
,
self
.
new_particle
.
coordinates
)
logging
.
info
(
"Created particle at %s"
,
self
.
new_particle
.
coordinates
)
return
self
.
new_particle
return
self
.
new_particle
else
:
else
:
logging
.
info
(
"there is already a particle on %s"
%
str
(
coordinates
))
logging
.
info
(
"there is already a particle on %s"
%
str
(
coordinates
))
return
False
return
False
...
@@ -387,7 +391,6 @@ class World:
...
@@ -387,7 +391,6 @@ class World:
def
add_tile
(
self
,
coordinates
,
color
=
None
):
def
add_tile
(
self
,
coordinates
,
color
=
None
):
"""
"""
Adds a tile to the world database
Adds a tile to the world database
:param color: color of the tile (None for config default)
:param color: color of the tile (None for config default)
:param coordinates: the coordinates on which the tile should be added
:param coordinates: the coordinates on which the tile should be added
:return: Successful added matter; False: Unsuccessful
:return: Successful added matter; False: Unsuccessful
...
@@ -410,6 +413,7 @@ class World:
...
@@ -410,6 +413,7 @@ class World:
logging
.
info
(
"Created tile with tile id %s on coordinates %s"
,
logging
.
info
(
"Created tile with tile id %s on coordinates %s"
,
str
(
self
.
new_tile
.
get_id
()),
str
(
coordinates
))
str
(
self
.
new_tile
.
get_id
()),
str
(
coordinates
))
return
self
.
new_tile
return
self
.
new_tile
else
:
else
:
logging
.
info
(
"there is already a tile on %s "
%
str
(
coordinates
))
logging
.
info
(
"there is already a tile on %s "
%
str
(
coordinates
))
return
False
return
False
...
...
swarm-sim.py
View file @
c3a91e1f
...
@@ -6,7 +6,7 @@ import os
...
@@ -6,7 +6,7 @@ import os
import
sys
import
sys
import
time
import
time
import
random
import
random
from
lib
import
world
,
config
from
lib
import
world
,
config
,
vis3d
from
lib.gnuplot_generator
import
gnuplot_generator
from
lib.gnuplot_generator
import
gnuplot_generator
...
@@ -25,16 +25,27 @@ def swarm_sim(argv):
...
@@ -25,16 +25,27 @@ def swarm_sim(argv):
random
.
seed
(
config_data
.
seed_value
)
random
.
seed
(
config_data
.
seed_value
)
swarm_sim_world
=
world
.
World
(
config_data
)
swarm_sim_world
=
world
.
World
(
config_data
)
round_start_timestamp
=
time
.
perf_counter
()
while
(
config_data
.
max_round
==
0
or
swarm_sim_world
.
get_actual_round
()
<=
config_data
.
max_round
)
\
while
(
config_data
.
max_round
==
0
or
swarm_sim_world
.
get_actual_round
()
<=
config_data
.
max_round
)
\
and
swarm_sim_world
.
get_end
()
is
False
:
and
swarm_sim_world
.
get_end
()
is
False
:
round_start_timestamp
=
time
.
perf_counter
()
if
config_data
.
visualization
:
if
config_data
.
visualization
:
swarm_sim_world
.
vis
.
run
(
round_start_timestamp
)
swarm_sim_world
.
vis
.
run
(
round_start_timestamp
)
round_start_timestamp
=
time
.
perf_counter
()
run_solution
(
swarm_sim_world
)
run_solution
(
swarm_sim_world
)
logging
.
info
(
'Finished'
)
logging
.
info
(
'Finished'
)
# generate_data(config_data, swarm_sim_world)
generate_data
(
config_data
,
swarm_sim_world
)
def
draw_scenario
(
config_data
,
swarm_sim_world
):
mod
=
importlib
.
import_module
(
'scenario.'
+
config_data
.
scenario
)
mod
.
scenario
(
swarm_sim_world
)
if
config_data
.
particle_random_order
:
random
.
shuffle
(
swarm_sim_world
.
particles
)
def
read_cmd_args
(
argv
,
config_data
):
def
read_cmd_args
(
argv
,
config_data
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment