Example #1
0
        public static GreedyGridWorldPolicy Create(
            GridWorld world,
            GridWorldValueTable gridWorldValueTable,
            IGridWorldRewarder gridWorldRewarder)
        {
            var greedyPolicy = new GreedyGridWorldPolicy();

            foreach (var state in world.AllStates())
            {
                greedyPolicy._actions[state] = FindBestAction(world, state, gridWorldValueTable, gridWorldRewarder);
            }

            return(greedyPolicy);
        }
Example #2
0
        private static GridWorldAction FindBestAction(
            GridWorld world,
            GridWorldState state,
            GridWorldValueTable gridWorldValueTable,
            IGridWorldRewarder gridWorldRewarder)
        {
            var max       = double.MinValue;
            var maxAction = GridWorldAction.Down;

            foreach (var action in world.AvailableActions(state))
            {
                var nextState      = world.NextState(state, action);
                var nextStateValue = gridWorldValueTable.Value(nextState);
                var reward         = gridWorldRewarder.Reward(state, action);

                if (reward + nextStateValue > max)
                {
                    max       = reward + nextStateValue;
                    maxAction = action;
                }
            }

            return(maxAction);
        }
Example #3
0
 public GridWorldValueTable(GridWorld world)
 {
     _world  = world;
     _values = new double[world.AllStates().Count()];
 }