Skip to content
Snippets Groups Projects
Commit 83d5193a authored by MasterScrat's avatar MasterScrat
Browse files

Merge branch 'fix_malfunction_prob' into 'master'

Fixed malfunction probability

See merge request flatland/flatland!297
parents ba41f476 9a35f2a9
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ import numpy as np ...@@ -6,7 +6,7 @@ import numpy as np
from numpy.random.mtrand import RandomState from numpy.random.mtrand import RandomState
from flatland.envs.agent_utils import EnvAgent, RailAgentStatus from flatland.envs.agent_utils import EnvAgent, RailAgentStatus
from flatland.envs import persistence from flatland.envs import persistence
Malfunction = NamedTuple('Malfunction', [('num_broken_steps', int)]) Malfunction = NamedTuple('Malfunction', [('num_broken_steps', int)])
MalfunctionParameters = NamedTuple('MalfunctionParameters', MalfunctionParameters = NamedTuple('MalfunctionParameters',
...@@ -25,7 +25,7 @@ def _malfunction_prob(rate: float) -> float: ...@@ -25,7 +25,7 @@ def _malfunction_prob(rate: float) -> float:
if rate <= 0: if rate <= 0:
return 0. return 0.
else: else:
return 1 - np.exp(- (1 / rate)) return 1 - np.exp(-rate)
def malfunction_from_file(filename: str, load_from_package=None) -> Tuple[MalfunctionGenerator, MalfunctionProcessData]: def malfunction_from_file(filename: str, load_from_package=None) -> Tuple[MalfunctionGenerator, MalfunctionProcessData]:
...@@ -42,7 +42,7 @@ def malfunction_from_file(filename: str, load_from_package=None) -> Tuple[Malfun ...@@ -42,7 +42,7 @@ def malfunction_from_file(filename: str, load_from_package=None) -> Tuple[Malfun
""" """
# with open(filename, "rb") as file_in: # with open(filename, "rb") as file_in:
# load_data = file_in.read() # load_data = file_in.read()
# if filename.endswith("mpk"): # if filename.endswith("mpk"):
# data = msgpack.unpackb(load_data, use_list=False, encoding='utf-8') # data = msgpack.unpackb(load_data, use_list=False, encoding='utf-8')
# elif filename.endswith("pkl"): # elif filename.endswith("pkl"):
...@@ -52,7 +52,7 @@ def malfunction_from_file(filename: str, load_from_package=None) -> Tuple[Malfun ...@@ -52,7 +52,7 @@ def malfunction_from_file(filename: str, load_from_package=None) -> Tuple[Malfun
if "malfunction" in env_dict: if "malfunction" in env_dict:
env_dict['malfunction'] = oMPD = MalfunctionProcessData._make(env_dict['malfunction']) env_dict['malfunction'] = oMPD = MalfunctionProcessData._make(env_dict['malfunction'])
else: else:
oMPD=None oMPD = None
if oMPD is not None: if oMPD is not None:
# Mean malfunction in number of time steps # Mean malfunction in number of time steps
mean_malfunction_rate = oMPD.malfunction_rate mean_malfunction_rate = oMPD.malfunction_rate
......
...@@ -119,9 +119,9 @@ def test_malfunction_process(): ...@@ -119,9 +119,9 @@ def test_malfunction_process():
def test_malfunction_process_statistically(): def test_malfunction_process_statistically():
"""Tests hat malfunctions are produced by stochastic_data!""" """Tests that malfunctions are produced by stochastic_data!"""
# Set fixed malfunction duration for this test # Set fixed malfunction duration for this test
stochastic_data = MalfunctionParameters(malfunction_rate=5, # Rate of malfunction occurence stochastic_data = MalfunctionParameters(malfunction_rate=1/5, # Rate of malfunction occurence
min_duration=5, # Minimal duration of malfunction min_duration=5, # Minimal duration of malfunction
max_duration=5 # Max duration of malfunction max_duration=5 # Max duration of malfunction
) )
...@@ -168,7 +168,7 @@ def test_malfunction_process_statistically(): ...@@ -168,7 +168,7 @@ def test_malfunction_process_statistically():
def test_malfunction_before_entry(): def test_malfunction_before_entry():
"""Tests that malfunctions are working properly for agents before entering the environment!""" """Tests that malfunctions are working properly for agents before entering the environment!"""
# Set fixed malfunction duration for this test # Set fixed malfunction duration for this test
stochastic_data = MalfunctionParameters(malfunction_rate=2, # Rate of malfunction occurence stochastic_data = MalfunctionParameters(malfunction_rate=1/2, # Rate of malfunction occurrence
min_duration=10, # Minimal duration of malfunction min_duration=10, # Minimal duration of malfunction
max_duration=10 # Max duration of malfunction max_duration=10 # Max duration of malfunction
) )
...@@ -215,7 +215,7 @@ def test_malfunction_values_and_behavior(): ...@@ -215,7 +215,7 @@ def test_malfunction_values_and_behavior():
rail, rail_map = make_simple_rail2() rail, rail_map = make_simple_rail2()
action_dict: Dict[int, RailEnvActions] = {} action_dict: Dict[int, RailEnvActions] = {}
stochastic_data = MalfunctionParameters(malfunction_rate=0.001, # Rate of malfunction occurence stochastic_data = MalfunctionParameters(malfunction_rate=1/0.001, # Rate of malfunction occurence
min_duration=10, # Minimal duration of malfunction min_duration=10, # Minimal duration of malfunction
max_duration=10 # Max duration of malfunction max_duration=10 # Max duration of malfunction
) )
...@@ -241,7 +241,7 @@ def test_malfunction_values_and_behavior(): ...@@ -241,7 +241,7 @@ def test_malfunction_values_and_behavior():
def test_initial_malfunction(): def test_initial_malfunction():
stochastic_data = MalfunctionParameters(malfunction_rate=1000, # Rate of malfunction occurence stochastic_data = MalfunctionParameters(malfunction_rate=1/1000, # Rate of malfunction occurence
min_duration=2, # Minimal duration of malfunction min_duration=2, # Minimal duration of malfunction
max_duration=5 # Max duration of malfunction max_duration=5 # Max duration of malfunction
) )
...@@ -390,7 +390,7 @@ def test_initial_malfunction_stop_moving(): ...@@ -390,7 +390,7 @@ def test_initial_malfunction_stop_moving():
def test_initial_malfunction_do_nothing(): def test_initial_malfunction_do_nothing():
stochastic_data = MalfunctionParameters(malfunction_rate=70, # Rate of malfunction occurence stochastic_data = MalfunctionParameters(malfunction_rate=1/70, # Rate of malfunction occurence
min_duration=2, # Minimal duration of malfunction min_duration=2, # Minimal duration of malfunction
max_duration=5 # Max duration of malfunction max_duration=5 # Max duration of malfunction
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment