This project demonstrates a Q-Learning implementation to optimize routes between locations in a predefined environment. It uses the principles of reinforcement learning to determine the shortest path between locations while considering rewards for each state transition.
- Environment Definition: States, actions, and reward matrices define the system's environment.
- Reinforcement Learning: Implements the Q-Learning algorithm to learn and optimize routes.
- Shortest Route Calculation: Calculates the shortest route between a starting location, intermediary location, and ending location.
- Python 3.x
- Numpy library (
pip install numpy
)
- Clone the repository:
git clone <repository_url>
- Navigate to the project directory:
cd q-learning-process-optimization
- Run the script:
python q_learning_optimization.py
- Define your starting, intermediary, and ending locations.
- Use the
best_route
function to calculate the optimal route:print(best_route('E', 'K', 'G'))
- Modify the reward matrix (
R
) to represent different environments as needed.
To calculate the optimal route from location E
to K
to G
:
print(best_route('E', 'K', 'G'))
Output:
Route:
['E', 'I', 'J', 'K', 'G']
- Q-Learning Algorithm:
- Randomly explores the environment.
- Updates the Q-Table using the Temporal Difference (TD) formula.
- Route Calculation:
- Starts from the initial state.
- Iteratively selects the next state with the highest Q-value until reaching the destination.
- Adjust
gamma
(discount factor) andalpha
(learning rate) to fine-tune the learning process. - Modify the reward matrix (
R
) to represent different environments.
This project is licensed under the MIT License. See the LICENSE file for details.