Class: FiniteMDP::ArrayModel::OrderedStateActionMap

Inherits:
StateActionMap show all
Defined in:
lib/finite_mdp/array_model.rb

Overview

A StateActionMap for states that support ordering. Lookups are more efficient than for an ordinary StateActionMap, which does not assume that states can be ordered.

Instance Attribute Summary

Attributes inherited from StateActionMap

#map

Instance Method Summary collapse

Methods inherited from StateActionMap

#actions, from_model, #initialize, #state, #state_action_index, #states

Constructor Details

This class inherits a constructor from FiniteMDP::ArrayModel::StateActionMap

Instance Method Details

#add(state, actions) ⇒ Object


80
81
82
83
# File 'lib/finite_mdp/array_model.rb', line 80

def add(state, actions)
  index = state_index(state)
  @map.insert(index || @map.size, [state, actions])
end

#state_index(state) ⇒ Object


85
86
87
# File 'lib/finite_mdp/array_model.rb', line 85

def state_index(state)
  (0...@map.size).bsearch { |i| @map[i][0] >= state }
end