Skip to content

C++ implementation of the Q-Learning algorithm applied to a simple grid world problem

Notifications You must be signed in to change notification settings

SarahAbuirmeileh/QLearningAlgorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Q-Learning Algorithm ⚙️💻

This repository contains a C++ implementation of the Q-Learning algorithm applied to a simple grid world problem. The grid world consists of states represented by rows and actions represented by columns. The goal is to reach a specific state denoted by F from any staring point.

image



Here is the representation of the environment:

iamge



Here is the Reward Table:

image



Description ⚡️📑

The q_learning.cpp file contains the main implementation of the Q-Learning algorithm. Here's an overview of the key components:

  • printArray: Function to print a 2D array.
  • initializeRewardArray: Function to initialize the reward matrix based on the problem description.
  • getRandomPossibleAction: Function to select a random possible action from a given state.
  • QLearningAlgorithm: Function implementing the Q-Learning algorithm. It updates the Q-table based on the rewards and learns the optimal policy.
  • main: The entry point of the program. It initializes the reward matrix, sets up the Q-table, runs the Q-Learning algorithm, and prints the final Q-table.

Usage ⚙️👩🏻‍💻

You can modify the parameters such as the number of episodes (episode) and the learning rate (y) in the main function to experiment with different settings.

// The # of trials for computer to learn, usually the # is big
int episode = 1000;

// Constant for learning rate
double y = 0.8;



Here is the Q matrix after 1000 episodes:

image

Releases

No releases published

Packages

No packages published

Languages