# test for game.py

import numpy as np
import random
from game import ChainState, Config
import time

# Configuration
config = Config()
config.num_nodes = 25
np.set_printoptions(formatter={'float': '{: 0.3f}'.format})

histogram_options = np.zeros(20, dtype=np.int)
histogram_distance = np.zeros(30, dtype=np.int)
duration_paretos = 0
duration_minimax = 0
distance_paretos = 0
distance_minimax = 0
matches = 0

for i in range(1000):
    # run the experiment
    config.num_nodes = 20
    state = ChainState(config)
    state.generate_graph()
    state.calculate_results()

    # do the pareto calculation
    start_time = time.time()
    paretos_efficient = state.pareto_defense_actions()
    duration_paretos += time.time() - start_time
Пример #2
0
# tests for the game module

import time
import numpy as np
from game import Config, State, StateReader
from test_state import TestState
from test_reader import TestStateReader

config = Config()
config.num_service = 4
config.num_viruses = 1
config.num_datadir = 1
config.num_nodes = 5
config.sparcity = 0.1
config.att_points = 100
config.def_points = 100

config.ratios = np.array([3, 3, 2], dtype=np.int)

# Generate a graph
test_case1 = TestState(config)

# Write the state to file
test_case2 = TestStateReader()
# test_case2.write_state(test_case1.state)

# Read the graph
# test_case1.state = test_case2.read_state()
test_case1.print_graph()
print(test_case1.state.graph_edges)