agpl_1.0.0_b5da3320/src/agpl-stochastics-mdp-value_function.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
 

--  Root package for MDP solvers.

with Agpl.Stochastics.Mdp.Action;
with Agpl.Stochastics.Mdp.State;

with Ada.Containers.Indefinite_Hashed_Maps;

package Agpl.Stochastics.Mdp.Value_Function is

   pragma Preelaborate;

   Unknown_Value : exception;

   type Object is private;

   function Contains
     (This : in Object;
      S    : in State.Object'Class) return Boolean;

   function Contains
     (This : in Object;
      S    : in State.Object_Id) return Boolean;

   function Get_Action
     (This : in Object;
      S    : in State.Object'Class) return Action.Object'Class;

   function Get_Action
     (This : in Object;
      S    : in State.Object_Id) return Action.Object'Class;

   function Get_Value
     (This : in Object;
      S    : in State.Object'Class) return Rewards;

   function Get_Value
     (This : in Object;
      S    : in State.Object_Id) return Rewards;

   procedure Set_Value
     (This  : in out Object;
      S     : in     State.Object'Class;
      Value : in     Rewards;
      A     : in     Action.Object'Class);

   procedure Summary (This : in Object);
   --  Stderr dump of State id -> Rewards

   -----------------
   -- Enumeration --
   -----------------

   type Cursor is private;

   function First (This : in Object) return Cursor;

   function Is_Valid (This : in Cursor) return Boolean;

   procedure Next (This : in out Cursor);
   --  May render invalid a cursor.

   function Get_Action
     (This : in Object; I : in Cursor) return Action.Object'Class;

   function Get_Reward
     (This : in Object; I : in Cursor) return Rewards;

   function Get_State
     (This : in Object; I : in Cursor) return State.Object'Class;

   function Get_State_Id
     (This : in Object; I : in Cursor) return State.Object_Id;

private

   package Value_Maps is new Ada.Containers.Indefinite_Hashed_Maps
     (State.Object_Id, Rewards, State.Hash, State."=");

   package Action_Maps is new Ada.Containers.Indefinite_Hashed_Maps
     (State.Object_Id,
      Action.Object'Class,
      State.Hash,
      State."=",
      Action."=");

   type Object is record
      Values  : Value_Maps.Map;
      --  This holds the best reward attainable from a given state.

      Actions : Action_Maps.Map;
      --  This holds the action which yields such reward.

      States  : State.Object_Maps.Map;
      --  This holds the states.
   end record;

   type Cursor is record
      Valid : Boolean := False;
      Pos   : Value_Maps.Cursor;
   end record;

end Agpl.Stochastics.Mdp.Value_Function;