def __init__(self, args): # initial setup of network model variables super(NetworkModel, self).__init__(args) self.last_action_scan = False self.fresh = True # Collected Data # self.unique_nodes_scanned = [] self.num_scans = 0 # Network Configuration Data # self.network_config = json.load(open(config_parser.network_cfg, "r")) # read in reward values for 4 vulns self.sql_reward = int(self.network_config['sql_reward']) self.ftp_reward = int(self.network_config['ftp_reward']) self.smtp_reward = int(self.network_config['smtp_reward']) self.vnc_reward = int(self.network_config['vnc_reward']) self.scan_reward = int(self.network_config['scan_reward']) self.move_reward = int(self.network_config['move_reward']) self.exit_reward = int(self.network_config['exit_reward']) self.illegal_move_penalty = int(self.network_config['illegal_move_penalty']) self.map_text, _ = config_parser.parse_map(self.network_config['layout_file']) self.node_list = {} # read in raw text and build network based on it state = 0 for item in self.map_text: if state == 0: if item == 'Node Type': state = 1 continue if state == 1: if item == 'Adjacency': state = 2 continue else: stuff = item.split(':') if stuff[0] not in self.node_list.keys(): self.node_list[stuff[0]] = NodeData(stuff[0], [], stuff[1], []) if state == 2: if item == 'end': break else: adj = item.split(' ') for node in self.node_list.values(): if node.name == adj[0]: node.update_adj_list(adj[1:])
def __init__(self, args): super(CyberModel, self).__init__(args) # logging utility self.logger = logging.getLogger('POMDPy.CyberModel') self.cyber_config = json.load(open(config_parser.cyber_cfg, "r")) # -------- Model configurations -------- # # The reward for sampling a good self.good_cyber_reward = self.cyber_config['good_cyber_reward'] # The penalty for sampling a bad self.bad_cyber_penalty = self.cyber_config['bad_cyber_penalty'] # The reward for exiting the map self.exit_reward = self.cyber_config['exit_reward'] # The penalty for an illegal move. self.illegal_move_penalty = self.cyber_config['illegal_move_penalty'] # penalty for finishing without sampling a cyber self.half_efficiency_distance = self.cyber_config[ 'half_efficiency_distance'] # ------------- Flags --------------- # # Flag that checks whether the agent has yet to successfully sample self.sampled_cyber_yet = False # Flag that keeps track of whether the agent currently believes there are still good self.any_good_cybers = False # ------------- Data Collection ---------- # self.unique_cybers_sampled = [] self.num_times_sampled = 0.0 self.good_samples = 0.0 self.num_reused_nodes = 0 self.num_bad_cybers_sampled = 0 self.num_good_checks = 0 self.num_bad_checks = 0 # -------------- Map data ---------------- # # The number of rows in the map. self.n_rows = 0 # The number of columns in the map self.n_cols = 0 # The number of cybers on the map. self.n_cybers = 0 self.num_states = 0 self.min_val = 0 self.max_val = 0 self.start_position = GridPosition() # The coordinates of the cybers. self.cyber_positions = [] # The coordinates of the goal squares. self.goal_positions = [] # The environment map in vector form. # List of lists of RSCellTypes self.env_map = [] # The distance from each cell to the nearest goal square. self.goal_distances = [] # The distance from each cell to each cyber. self.cyber_distances = [] # Smart cyber data self.all_cyber_data = [] # Actual cyber states self.actual_cyber_states = [] # The environment map in text form. self.map_text, dimensions = config_parser.parse_map( self.cyber_config['map_file']) self.n_rows = int(dimensions[0]) self.n_cols = int(dimensions[1]) self.initialize()