MHOD: skipping iterations when no new utilization values have been added
This commit is contained in:
parent
e237609e37
commit
81cb7165f8
@ -77,6 +77,7 @@ def init_state(history_size, window_sizes, number_of_states):
|
||||
"""
|
||||
return {
|
||||
'previous_state': 0,
|
||||
'previous_utilization': [],
|
||||
'time_in_states': 0,
|
||||
'time_in_state_n': 0,
|
||||
'request_windows': estimation.init_request_windows(
|
||||
@ -121,8 +122,14 @@ def mhod(state_config, otf, window_sizes, bruteforce_step, learning_steps,
|
||||
:return: The updated state and decision of the algorithm.
|
||||
:rtype: tuple(bool, dict)
|
||||
"""
|
||||
if len(utilization) == state['time_in_states'] and \
|
||||
utilization == state['previous_utilization']:
|
||||
# No new utilization values
|
||||
return False, state
|
||||
|
||||
number_of_states = len(state_config) + 1
|
||||
previous_state = 0
|
||||
state['previous_utilization'] = utilization
|
||||
state['request_windows'] = estimation.init_request_windows(
|
||||
number_of_states, max(window_sizes))
|
||||
state['estimate_windows'] = estimation.init_deque_structure(
|
||||
|
@ -27,6 +27,7 @@ class Core(TestCase):
|
||||
def test_init_state(self):
|
||||
state = c.init_state(100, [20, 40], 2)
|
||||
self.assertEquals(state['previous_state'], 0)
|
||||
self.assertEquals(state['previous_utilization'], [])
|
||||
self.assertEquals(state['time_in_states'], 0)
|
||||
self.assertEquals(state['time_in_state_n'], 0)
|
||||
self.assertTrue('request_windows' in state)
|
||||
@ -120,6 +121,7 @@ class Core(TestCase):
|
||||
state = c.init_state(10, window_sizes, 2)
|
||||
|
||||
with MockTransaction:
|
||||
state['previous_utilization'] = []
|
||||
expect(estimation).select_best_estimates.and_return([[0., 0.], [0., 0.]])
|
||||
expect(c).get_current_state.and_return(1).once()
|
||||
decision, _ = c.mhod(state_config, otf, window_sizes, bruteforce_step,
|
||||
@ -127,6 +129,7 @@ class Core(TestCase):
|
||||
self.assertFalse(decision)
|
||||
|
||||
with MockTransaction:
|
||||
state['previous_utilization'] = []
|
||||
expect(estimation).select_best_estimates.and_return([[0., 0.], [0., 0.]])
|
||||
expect(c).get_current_state.and_return(0).once()
|
||||
decision, _ = c.mhod(state_config, otf, window_sizes, bruteforce_step,
|
||||
@ -134,6 +137,7 @@ class Core(TestCase):
|
||||
self.assertFalse(decision)
|
||||
|
||||
with MockTransaction:
|
||||
state['previous_utilization'] = []
|
||||
expect(estimation).select_best_estimates.and_return([[0., 1.], [0., 1.]])
|
||||
expect(c).get_current_state.and_return(0).once()
|
||||
decision, _ = c.mhod(state_config, otf, window_sizes, bruteforce_step,
|
||||
@ -141,12 +145,22 @@ class Core(TestCase):
|
||||
self.assertFalse(decision)
|
||||
|
||||
with MockTransaction:
|
||||
state['previous_utilization'] = []
|
||||
expect(estimation).select_best_estimates.and_return([[0., 1.], [0., 1.]])
|
||||
expect(c).get_current_state.and_return(1).once()
|
||||
decision, _ = c.mhod(state_config, otf, window_sizes, bruteforce_step,
|
||||
learning_steps, time_step, migration_time, utilization, state)
|
||||
self.assertTrue(decision)
|
||||
|
||||
with MockTransaction:
|
||||
utilization = [1.0, 1.0]
|
||||
state['previous_utilization'] = [1.0, 1.0]
|
||||
state['time_in_states'] = 2
|
||||
expect(estimation).select_best_estimates.never()
|
||||
decision, _ = c.mhod(state_config, otf, window_sizes, bruteforce_step,
|
||||
learning_steps, time_step, migration_time, utilization, state)
|
||||
self.assertFalse(decision)
|
||||
|
||||
|
||||
def deque_maxlen(coll):
|
||||
return int(re.sub("\)$", "", re.sub(".*=", "", coll.__repr__())))
|
||||
|
Loading…
x
Reference in New Issue
Block a user