-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
221 additions
and
66 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
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
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
64 changes: 64 additions & 0 deletions
64
simulation-system/libs/gym-csle-cyborg/src/gym_csle_cyborg/dao/csle_cyborg_wrapper_config.py
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,64 @@ | ||
from typing import Dict, Any | ||
from csle_common.dao.simulation_config.simulation_env_input_config import SimulationEnvInputConfig | ||
|
||
|
||
class CSLECyborgWrapperConfig(SimulationEnvInputConfig): | ||
""" | ||
DTO representing the input configuration to a gym-csle-cyborg environment | ||
""" | ||
|
||
def __init__(self, maximum_steps: int, gym_env_name: str, save_trace: bool = False): | ||
""" | ||
Initializes the DTO | ||
:param maximum_steps: the maximum number of steps in the environment | ||
:param gym_env_name: the name of the gym environment | ||
:param save_trace: boolean flag indicating whether traces should be saved | ||
""" | ||
self.maximum_steps = maximum_steps | ||
self.gym_env_name = gym_env_name | ||
self.save_trace = save_trace | ||
|
||
def to_dict(self) -> Dict[str, Any]: | ||
""" | ||
Converts the object to a dict representation | ||
:return: a dict representation of the object | ||
""" | ||
d: Dict[str, Any] = {} | ||
d["baseline_red_agents"] = self.maximum_steps | ||
d["gym_env_name"] = self.gym_env_name | ||
d["save_trace"] = self.save_trace | ||
return d | ||
|
||
@staticmethod | ||
def from_dict(d: Dict[str, Any]) -> "CSLECyborgWrapperConfig": | ||
""" | ||
Converts a dict representation to an instance | ||
:param d: the dict to convert | ||
:return: the created instance | ||
""" | ||
obj = CSLECyborgWrapperConfig(gym_env_name=d["gym_env_name"], maximum_steps=d["maximum_steps"], | ||
save_trace=d["save_trace"]) | ||
return obj | ||
|
||
def __str__(self) -> str: | ||
""" | ||
:return: a string representation of the object | ||
""" | ||
return f"gym_env_name: {self.gym_env_name}, maximum_steps: {self.maximum_steps}, save_trace: {self.save_trace}" | ||
|
||
@staticmethod | ||
def from_json_file(json_file_path: str) -> "CSLECyborgWrapperConfig": | ||
""" | ||
Reads a json file and converts it to a DTO | ||
:param json_file_path: the json file path | ||
:return: the converted DTO | ||
""" | ||
import io | ||
import json | ||
with io.open(json_file_path, 'r') as f: | ||
json_str = f.read() | ||
return CSLECyborgWrapperConfig.from_dict(json.loads(json_str)) |
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.