예제 #1
0
 def test_throughputs(self):
     # compute and check throughputs for uniform network
     network = MAS.Network(*generate_uniform())
     # check throughputs
     self.assertTrue(is_equal(network.throughputs(), (1.0 / 3) * np.ones((3,))))
     # check availabilities
     self.assertTrue(is_equal(network.availabilities(), np.ones((3,))))
예제 #2
0
 def test_adjacencies(self):
     network = MAS.Network(*generate_uniform(4))
     reachable_1 = np.array([[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]])
     reachable_2 = np.array([[0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]])
     network.adjacency_1 = reachable_1
     self.assertTrue(is_equal(reachable_1.flatten(), network.get_adjacencies(1).flatten()))
     self.assertTrue(is_equal(reachable_2.flatten(), network.get_adjacencies(2).flatten()))
 def test_to_cplex_lp_file(self):
     # same example as above
     network = MAS.Network(*generate_uniform())
     attack_rates = np.array([1., 1., 1.])
     k = 2
     string = AttackRoutingSolver(network, attack_rates, k).to_cplex_lp_file()
     print string
예제 #4
0
 def test_throughputs(self):
     # compute and check throughputs for uniform network
     network = MAS.Network(*generate_uniform())
     # check throughputs
     self.assertTrue(
         is_equal(network.throughputs(), (1. / 3) * np.ones((3, ))))
     # check availabilities
     self.assertTrue(is_equal(network.availabilities(), np.ones((3, ))))
 def test_cplex_attack_routing_small_network(self):
     # see test_attack_routing_solver() above for details on the example
     network = MAS.Network(*generate_uniform())
     attack_rates = np.array([1., 1., 1.])
     k = 2
     a, routing = AttackRoutingSolver(network, attack_rates, k, cplex=True).solve()
     network.update(attack_rates, routing)
     self.assertTrue(abs(np.sum(network.new_availabilities()) - 7./3))
예제 #6
0
 def test_cplex_attack_routing_small_network(self):
     # trying with CPLEX, see test_attack_routing_2() above for more details
     network = MAS.Network(*generate_uniform())
     attack_rates = np.array([1., 1., 0.])
     k = 2
     a, routing = network.opt_attack_routing(attack_rates, k, cplex=True)
     self.assertTrue(is_equal(a, network.new_availabilities()))
     self.assertTrue(abs(np.sum(a) - 5. / 3))
 def test_to_cplex_lp_file(self):
     # same example as above
     network = MAS.Network(*generate_uniform())
     attack_rates = np.array([1., 1., 1.])
     k = 2
     string = AttackRoutingSolver(network, attack_rates,
                                  k).to_cplex_lp_file()
     print string
예제 #8
0
 def test_cplex_attack_routing_small_network(self):
     # trying with CPLEX, see test_attack_routing_2() above for more details
     network = MAS.Network(*generate_uniform())
     attack_rates = np.array([1.0, 1.0, 0.0])
     k = 2
     a, routing = network.opt_attack_routing(attack_rates, k, cplex=True)
     self.assertTrue(is_equal(a, network.new_availabilities()))
     self.assertTrue(abs(np.sum(a) - 5.0 / 3))
 def test_cplex_attack_routing_small_network(self):
     # see test_attack_routing_solver() above for details on the example
     network = MAS.Network(*generate_uniform())
     attack_rates = np.array([1., 1., 1.])
     k = 2
     a, routing = AttackRoutingSolver(network, attack_rates, k,
                                      cplex=True).solve()
     network.update(attack_rates, routing)
     self.assertTrue(abs(np.sum(network.new_availabilities()) - 7. / 3))
예제 #10
0
 def test_ill_defined_MAS_network(self):
     # test network with a rate too small
     rates, routing, travel_times = generate_uniform()
     rates[0] = 0.0
     network = MAS.Network(rates, routing, travel_times)
     try:
         network.check()
         self.assertTrue(False)
     except AssertionError as e:
         self.assertEqual(e.args[0], "rates too small")
예제 #11
0
 def test_ill_defined_MAS_network(self):
     # test network with a rate too small
     rates, routing, travel_times = generate_uniform()
     rates[0] = 0.
     network = MAS.Network(rates, routing, travel_times)
     try:
         network.check()
         self.assertTrue(False)
     except AssertionError as e:
         self.assertEqual(e.args[0], 'rates too small')
예제 #12
0
 def test_attack_routing_2(self):
     # test if the routing of attacks works given fixed attack rates
     network = MAS.Network(*generate_uniform())
     # attack rates are fixed
     attack_rates = np.array([1.0, 1.0, 0.0])
     # find routing minimizing the weighted sum of availabilities
     # fix the availability at station 2 to be equal to 1
     k = 2
     # get the availabilities 'a' and routing that led to 'a'
     a, routing = network.opt_attack_routing(attack_rates, k)
     self.assertTrue(is_equal(a, network.new_availabilities(), 1e-7))
     self.assertTrue(abs(np.sum(a) - 5.0 / 3))
예제 #13
0
 def test_attack_routing_2(self):
     # test if the routing of attacks works given fixed attack rates
     network = MAS.Network(*generate_uniform())
     # attack rates are fixed
     attack_rates = np.array([1., 1., 0.])
     # find routing minimizing the weighted sum of availabilities
     # fix the availability at station 2 to be equal to 1
     k = 2
     # get the availabilities 'a' and routing that led to 'a'
     a, routing = network.opt_attack_routing(attack_rates, k)
     self.assertTrue(is_equal(a, network.new_availabilities(), 1e-7))
     self.assertTrue(abs(np.sum(a) - 5. / 3))
예제 #14
0
 def test_adjacencies(self):
     network = MAS.Network(*generate_uniform(4))
     reachable_1 = np.array([[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1],
                             [0, 1, 1, 0]])
     reachable_2 = np.array([[0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1],
                             [1, 1, 1, 0]])
     network.adjacency_1 = reachable_1
     self.assertTrue(
         is_equal(reachable_1.flatten(),
                  network.get_adjacencies(1).flatten()))
     self.assertTrue(
         is_equal(reachable_2.flatten(),
                  network.get_adjacencies(2).flatten()))
 def test_attack_routing_solver(self):
     # generate symmetric network with availabilities = [1., 1., 1.]
     # weight on the availabilities are [1., 1., 1.]
     network = MAS.Network(*generate_uniform())
     # attack rates are fixed
     attack_rates = np.array([1., 1., 1.])
     # find routing minimizing the weighted weighted sum of availabilities
     # fix the availability at station 2 to be equal to 1
     k = 2 
     # get the availabilities 'a' and routing that led to 'a'
     a, routing = AttackRoutingSolver(network, attack_rates, k).solve()
     network.update(attack_rates, routing)
     self.assertTrue(abs(np.sum(network.new_availabilities()) - 7./3))
 def test_attack_routing_solver(self):
     # generate symmetric network with availabilities = [1., 1., 1.]
     # weight on the availabilities are [1., 1., 1.]
     network = MAS.Network(*generate_uniform())
     # attack rates are fixed
     attack_rates = np.array([1., 1., 1.])
     # find routing minimizing the weighted weighted sum of availabilities
     # fix the availability at station 2 to be equal to 1
     k = 2
     # get the availabilities 'a' and routing that led to 'a'
     a, routing = AttackRoutingSolver(network, attack_rates, k).solve()
     network.update(attack_rates, routing)
     self.assertTrue(abs(np.sum(network.new_availabilities()) - 7. / 3))
예제 #17
0
 def test_mean_travel_time(self):
     network = MAS.Network(*generate_uniform())
     self.assertTrue(network.mean_travel_time == 20.0 / 3)
예제 #18
0
 def test_MAS_network(self):
     # test valid network
     network = MAS.Network(*generate_uniform())
     network.check()
예제 #19
0
 def test_mean_travel_time(self):
     network = MAS.Network(*generate_uniform())
     self.assertTrue(network.mean_travel_time == 20. / 3)
예제 #20
0
 def test_MAS_network(self):
     # test valid network
     network = MAS.Network(*generate_uniform())
     network.check()