Skip to content

Commit 2ad9273

Browse files
authored
Merge pull request #355 from Limmen/tolerance_tests
csle tolerance tests
2 parents 10c0cd4 + 36b2a72 commit 2ad9273

14 files changed

+2213
-65
lines changed

simulation-system/libs/csle-tolerance/src/csle_tolerance/dao/intrusion_recovery_game_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __str__(self) -> str:
5858
"""
5959
:return: a string representation of the DTO
6060
"""
61-
return (f"eta: {self.eta}, p_a: {self.p_a}, p_c_1: {self.p_c_1},"
61+
return (f"eta: {self.eta}, p_a: {self.p_a}, p_c_1: {self.p_c_1}, "
6262
f"BTR: {self.BTR}, negate_costs: {self.negate_costs}, seed: {self.seed}, "
6363
f"discount_factor: {self.discount_factor}, states: {self.states}, actions: {self.actions}, "
6464
f"observations: {self.observation_tensor}, cost_tensor: {self.cost_tensor}, "
@@ -105,7 +105,7 @@ def to_dict(self) -> Dict[str, Any]:
105105
d["b1"] = self.b1
106106
d["T"] = self.T
107107
d["simulation_env_name"] = self.simulation_env_name
108-
d["gym_env_name"] = self.simulation_env_name
108+
d["gym_env_name"] = self.gym_env_name
109109
return d
110110

111111
@staticmethod

simulation-system/libs/csle-tolerance/src/csle_tolerance/dao/intrusion_recovery_pomdp_config.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from typing import List, Dict, Any
22
import numpy as np
3+
import logging
4+
import io
5+
import json
36
from csle_common.dao.simulation_config.simulation_env_input_config import SimulationEnvInputConfig
47

58

@@ -111,7 +114,7 @@ def to_dict(self) -> Dict[str, Any]:
111114
d["b1"] = self.b1
112115
d["T"] = self.T
113116
d["simulation_env_name"] = self.simulation_env_name
114-
d["gym_env_name"] = self.simulation_env_name
117+
d["gym_env_name"] = self.gym_env_name
115118
return d
116119

117120
@staticmethod
@@ -122,8 +125,8 @@ def from_json_file(json_file_path: str) -> "IntrusionRecoveryPomdpConfig":
122125
:param json_file_path: the json file path
123126
:return: the converted DTO
124127
"""
125-
import io
126-
import json
128+
logging.info(msg="msg")
127129
with io.open(json_file_path, 'r') as f:
128130
json_str = f.read()
131+
print(json_str)
129132
return IntrusionRecoveryPomdpConfig.from_dict(json.loads(json_str))

simulation-system/libs/csle-tolerance/src/csle_tolerance/util/general_util.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from typing import List
2-
from gymnasium.envs.registration import register
32
import math
43
import numpy as np
54

@@ -22,9 +21,14 @@ def threshold_probability(b1: float, threshold: float, k=-20) -> float:
2221
return 1.0
2322
if round(b1, 2) == 0:
2423
return 0.0
25-
if (threshold * (1 - b1)) > 0 and (b1 * (1 - threshold)) / (threshold * (1 - b1)) > 0:
24+
if (threshold * (1 - b1)) > 0 and (b1 * (1 - threshold)) / (
25+
threshold * (1 - b1)
26+
) > 0:
2627
try:
27-
return math.pow(1 + math.pow(((b1 * (1 - threshold)) / (threshold * (1 - b1))), k), -1)
28+
return math.pow(
29+
1 + math.pow(((b1 * (1 - threshold)) / (threshold * (1 - b1))), k),
30+
-1,
31+
)
2832
except Exception:
2933
return 0.0
3034
else:
@@ -51,7 +55,9 @@ def inverse_sigmoid(y) -> float:
5155
return math.log(y / (1 - y), math.e)
5256

5357
@staticmethod
54-
def sample_next_state(transition_tensor: List[List[List[float]]], s: int, a: int, states: List[int]) -> int:
58+
def sample_next_state(
59+
transition_tensor: List[List[List[float]]], s: int, a: int, states: List[int]
60+
) -> int:
5561
"""
5662
Samples the next state of a MDP or POMDP
5763
@@ -73,13 +79,15 @@ def register_envs() -> None:
7379
7480
:return: None
7581
"""
82+
from gymnasium.envs.registration import register
83+
7684
register(
77-
id='csle-tolerance-intrusion-recovery-pomdp-v1',
78-
entry_point='csle_tolerance.envs.intrusion_recovery_pomdp_env:IntrusionRecoveryPomdpEnv',
79-
kwargs={'config': None}
85+
id="csle-tolerance-intrusion-recovery-pomdp-v1",
86+
entry_point="csle_tolerance.envs.intrusion_recovery_pomdp_env:IntrusionRecoveryPomdpEnv",
87+
kwargs={"config": None},
8088
)
8189
register(
82-
id='csle-tolerance-intrusion-response-cmdp-v1',
83-
entry_point='csle_tolerance.envs.intrusion_response_cmdp_env:IntrusionResponseCmdpEnv',
84-
kwargs={'config': None}
90+
id="csle-tolerance-intrusion-response-cmdp-v1",
91+
entry_point="csle_tolerance.envs.intrusion_response_cmdp_env:IntrusionResponseCmdpEnv",
92+
kwargs={"config": None},
8593
)

0 commit comments

Comments
 (0)