-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from scioip34/feature/vswrm
Feature/vswrm
- Loading branch information
Showing
36 changed files
with
4,576 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,67 @@ | ||
# Basic simulation parameters | ||
|
||
# Number of agents and resc. patches | ||
N = 3 | ||
N_RESOURCES = 10 | ||
|
||
# Simulation time | ||
T = 1000 | ||
|
||
# Framerate (only matter if visualization is turned on) | ||
INIT_FRAMERATE = 25 | ||
|
||
# Visualization ON/OFF | ||
WITH_VISUALIZATION = 1 | ||
|
||
# Resolution (px) of agents' visual projection fields | ||
VISUAL_FIELD_RESOLUTION = 1200 | ||
|
||
# Enviornment size (width and height in px) | ||
ENV_WIDTH = 600 | ||
ENV_HEIGHT = 600 | ||
|
||
# Agent and Resource sizes | ||
RADIUS_AGENT = 10 | ||
RADIUS_RESOURCE = 45 | ||
MIN_RESOURCE_PER_PATCH = 400 | ||
MAX_RESOURCE_PER_PATCH = 450 | ||
REGENERATE_PATCHES = 1 | ||
PATCH_BORDER_OVERLAP = 1 | ||
|
||
# Exploitation | ||
# max consumption of an agent per timestep | ||
AGENT_CONSUMPTION = 1 | ||
# resource patch quality | ||
MIN_RESOURCE_QUALITY = 0.05 | ||
MAX_RESOURCE_QUALITY = 0.3 | ||
TELEPORT_TO_MIDDLE = 0 | ||
GHOST_WHILE_EXPLOIT = 1 | ||
AGENT_AGENT_COLLISION = 1 | ||
PATCHWISE_SOCIAL_EXCLUSION =1 | ||
|
||
# Vision | ||
# fov is symmetric and defined with percent of pi. e.g | ||
# if 0.6 then fov is (-0.6*pi, 0.6*pi). 1 is full 360 degree vision | ||
AGENT_FOV = 0.45 | ||
VISION_RANGE = 200 | ||
VISUAL_EXCLUSION = 1 | ||
|
||
# Visualize agents' visual field on screen by default or when return is pressed | ||
SHOW_VISUAL_FIELDS = 0 | ||
SHOW_VISUAL_FIELDS_RETURN = 1 | ||
SHOW_VISION_RANGE = 1 | ||
|
||
# Time needed to acquire info from env and initial probability for pooling process | ||
POOLING_TIME = 0 | ||
POOLING_PROBABILITY = 0.05 | ||
|
||
# Monitoring Related parameters (True only tested on Ubuntu machines with | ||
# initialized grafana and ifdb instances as in readme) | ||
# log data in influxdb | ||
USE_IFDB_LOGGING = 0 | ||
# logs data in RAM | ||
USE_RAM_LOGGING = 1 | ||
# using zarr compression | ||
USE_ZARR_FORMAT = 1 | ||
# saves csv files (if ifdb logging is used, json files otherwise) | ||
SAVE_CSV_FILES = 0 | ||
|
||
# Decision process parameters | ||
DEC_TW = 0.5 | ||
DEC_EPSW = 3 | ||
DEC_GW = 0.085 | ||
DEC_BW = 0 | ||
DEC_WMAX = 1 | ||
|
||
DEC_TU = 0.5 | ||
DEC_EPSU = 3 | ||
DEC_GU = 0.085 | ||
DEC_BU = 0 | ||
DEC_UMAX = 1 | ||
|
||
DEC_SWU = 0.25 | ||
DEC_SUW = 0.01 | ||
|
||
DEC_TAU = 10 | ||
DEC_FN = 2 | ||
DEC_FR = 1 | ||
|
||
# Movement parameters | ||
# Exploration | ||
MOV_EXP_VEL_MIN = 1 | ||
MOV_EXP_VEL_MAX = 1 | ||
MOV_EXP_TH_MIN = -0.3 | ||
MOV_EXP_TH_MAX = 0.3 | ||
|
||
# Relocation | ||
MOV_REL_DES_VEL = 1 | ||
MOV_REL_TH_MAX = 0.5 | ||
|
||
# Exploitation | ||
CONS_STOP_RATIO = 0.08 | ||
N=10 | ||
N_RESOURCES=1 | ||
T=5000 | ||
INIT_FRAMERATE=25 | ||
WITH_VISUALIZATION=0 | ||
VISUAL_FIELD_RESOLUTION=320 | ||
ENV_WIDTH=900 | ||
ENV_HEIGHT=900 | ||
RADIUS_AGENT=10 | ||
RADIUS_RESOURCE=20 | ||
MIN_RESOURCE_PER_PATCH=100 | ||
MAX_RESOURCE_PER_PATCH=-1 | ||
REGENERATE_PATCHES=1 | ||
PATCH_BORDER_OVERLAP=1 | ||
MAX_SPEED=1.5 | ||
AGENT_CONSUMPTION=1 | ||
MIN_RESOURCE_QUALITY=0.25 | ||
MAX_RESOURCE_QUALITY=-1 | ||
TELEPORT_TO_MIDDLE=0 | ||
GHOST_WHILE_EXPLOIT=1 | ||
AGENT_AGENT_COLLISION=0 | ||
PATCHWISE_SOCIAL_EXCLUSION=1 | ||
AGENT_FOV=0.5 | ||
VISION_RANGE=2000 | ||
VISUAL_EXCLUSION=0 | ||
SHOW_VISUAL_FIELDS=0 | ||
SHOW_VISUAL_FIELDS_RETURN=0 | ||
SHOW_VISION_RANGE=0 | ||
POOLING_TIME=0 | ||
POOLING_PROBABILITY=0.05 | ||
USE_IFDB_LOGGING=1 | ||
USE_RAM_LOGGING=1 | ||
USE_ZARR_FORMAT=1 | ||
SAVE_CSV_FILES=1 | ||
DEC_TW=0.5 | ||
DEC_EPSW=0 | ||
DEC_GW=0.085 | ||
DEC_BW=0 | ||
DEC_WMAX=1 | ||
DEC_TU=0.5 | ||
DEC_EPSU=1 | ||
DEC_GU=0.085 | ||
DEC_BU=0 | ||
DEC_UMAX=1 | ||
DEC_SWU=0 | ||
DEC_SUW=0 | ||
DEC_TAU=10 | ||
DEC_FN=0.5 | ||
DEC_FR=0.5 | ||
MOV_EXP_VEL_MIN=3 | ||
MOV_EXP_VEL_MAX=3 | ||
MOV_EXP_TH_MIN=-0.5 | ||
MOV_EXP_TH_MAX=0.5 | ||
MOV_REL_DES_VEL=3 | ||
MOV_REL_TH_MAX=1.8 | ||
MEMORY_DEPTH=1 | ||
CONS_STOP_RATIO=0.175 | ||
APP_VERSION=VisualFlocking | ||
VF_GAM=0.1 | ||
VF_V0=1 | ||
VF_ALP0=0 | ||
VF_ALP1=0.0014 | ||
VF_ALP2=0 | ||
VF_BET0=0 | ||
VF_BET1=0.0014 | ||
VF_BET2=0 | ||
SAVE_ROOT_DIR=abm/data/simulation_data/VFinfinite/batch_0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
from contextlib import ExitStack | ||
from dotenv import dotenv_values | ||
|
||
from abm.app import save_isims_env | ||
from abm.projects.visual_flocking.vf_simulation.vf_isims import VFPlaygroundSimulation | ||
from abm.projects.visual_flocking.vf_contrib.vf_playgroundtool import setup_visflock_playground | ||
from abm.projects.visual_flocking.vf_simulation.vf_sims import VFSimulation | ||
|
||
|
||
def setup_environment(): | ||
EXP_NAME = os.getenv("EXPERIMENT_NAME", "visual_flocking") | ||
EXP_NAME_COPY = f"{EXP_NAME}_copy" | ||
os.path.dirname(os.path.realpath(__file__)) | ||
root_abm_dir = Path(__file__).parent.parent | ||
env_file_dir = root_abm_dir / "abm" / "projects" / "visual_flocking" # Path(__file__).parent | ||
env_path = env_file_dir / f"{EXP_NAME}.env" | ||
env_path_copy = env_file_dir / f"{EXP_NAME_COPY}.env" | ||
# make a duplicate of the env file to be used by the playground | ||
shutil.copyfile(env_path, env_path_copy) | ||
envconf = dotenv_values(env_path) | ||
return env_file_dir, EXP_NAME_COPY, envconf | ||
|
||
|
||
def start_playground(): | ||
"""starting simulation with interactive interface""" | ||
env_file_dir, EXP_NAME_COPY, envconf = setup_environment() | ||
# changing env file according to playground default parameters before | ||
# running any component of the SW | ||
pgt = setup_visflock_playground() | ||
save_isims_env(env_file_dir, EXP_NAME_COPY, pgt, envconf) | ||
# Start interactive simulation | ||
sim = VFPlaygroundSimulation() | ||
sim.start() | ||
|
||
|
||
def start(parallel=False, headless=False, agent_behave_param_list=None): | ||
"""starting simulation without interactive interface""" | ||
# Define root abm directory from which env file is read out | ||
root_abm_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
# Finding env file | ||
EXP_NAME = os.getenv("EXPERIMENT_NAME", "") | ||
env_path = os.path.join(root_abm_dir, f"{EXP_NAME}.env") | ||
if os.path.isfile(env_path): | ||
print(f"Read env vars from {env_path}") | ||
envconf = dotenv_values(env_path) | ||
app_version = envconf.get("APP_VERSION", "Base") | ||
if app_version != "VisualFlocking": | ||
raise Exception(".env file was not created for project visual " | ||
"flocking or no APP_VERSION parameter found!") | ||
else: | ||
raise Exception(f"Could not find .env file under path {env_path}") | ||
|
||
# Initializing virtual display | ||
window_pad = 30 | ||
vscreen_width = int(float(envconf["ENV_WIDTH"])) + 2 * window_pad + 10 | ||
vscreen_height = int(float(envconf["ENV_HEIGHT"])) + 2 * window_pad + 10 | ||
|
||
# Running headless simulation on virtual display | ||
if headless: | ||
# required to start pygame in headless mode | ||
os.environ['SDL_VIDEODRIVER'] = 'dummy' | ||
from xvfbwrapper import Xvfb | ||
|
||
with ExitStack() if not headless else Xvfb(width=vscreen_width, height=vscreen_height) as xvfb: | ||
sim = VFSimulation(N=int(float(envconf["N"])), | ||
T=int(float(envconf["T"])), | ||
v_field_res=int(envconf["VISUAL_FIELD_RESOLUTION"]), | ||
agent_fov=float(envconf['AGENT_FOV']), | ||
framerate=int(float(envconf["INIT_FRAMERATE"])), | ||
with_visualization=bool(int(float(envconf["WITH_VISUALIZATION"]))), | ||
width=int(float(envconf["ENV_WIDTH"])), | ||
height=int(float(envconf["ENV_HEIGHT"])), | ||
show_vis_field=bool(int(float(envconf["SHOW_VISUAL_FIELDS"]))), | ||
show_vis_field_return=bool(int(envconf['SHOW_VISUAL_FIELDS_RETURN'])), | ||
pooling_time=int(float(envconf["POOLING_TIME"])), | ||
pooling_prob=float(envconf["POOLING_PROBABILITY"]), | ||
agent_radius=int(float(envconf["RADIUS_AGENT"])), | ||
N_resc=int(float(envconf["N_RESOURCES"])), | ||
allow_border_patch_overlap=bool(int(float(envconf["PATCH_BORDER_OVERLAP"]))), | ||
min_resc_perpatch=int(float(envconf["MIN_RESOURCE_PER_PATCH"])), | ||
max_resc_perpatch=int(float(envconf["MAX_RESOURCE_PER_PATCH"])), | ||
min_resc_quality=float(envconf["MIN_RESOURCE_QUALITY"]), | ||
max_resc_quality=float(envconf["MAX_RESOURCE_QUALITY"]), | ||
patch_radius=int(float(envconf["RADIUS_RESOURCE"])), | ||
regenerate_patches=bool(int(float(envconf["REGENERATE_PATCHES"]))), | ||
agent_consumption=int(float(envconf["AGENT_CONSUMPTION"])), | ||
ghost_mode=bool(int(float(envconf["GHOST_WHILE_EXPLOIT"]))), | ||
patchwise_exclusion=bool(int(float(envconf["PATCHWISE_SOCIAL_EXCLUSION"]))), | ||
teleport_exploit=bool(int(float(envconf["TELEPORT_TO_MIDDLE"]))), | ||
vision_range=int(float(envconf["VISION_RANGE"])), | ||
visual_exclusion=bool(int(float(envconf["VISUAL_EXCLUSION"]))), | ||
show_vision_range=bool(int(float(envconf["SHOW_VISION_RANGE"]))), | ||
use_ifdb_logging=bool(int(float(envconf["USE_IFDB_LOGGING"]))), | ||
use_ram_logging=bool(int(float(envconf["USE_RAM_LOGGING"]))), | ||
save_csv_files=bool(int(float(envconf["SAVE_CSV_FILES"]))), | ||
use_zarr=bool(int(float(envconf["USE_ZARR_FORMAT"]))), | ||
parallel=parallel, | ||
window_pad=window_pad, | ||
agent_behave_param_list=agent_behave_param_list, | ||
collide_agents=bool(int(float(envconf["AGENT_AGENT_COLLISION"]))) | ||
) | ||
sim.write_batch_size = 100 | ||
sim.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.