Giter Club home page Giter Club logo

wolf-goat-gabbage-problem-q_learning-py-gym's Introduction

Wolf-Goat-Gabbage-problem-Q_learning-py-gym (๐Ÿฅฆ - ๐Ÿ - ๐Ÿบ - ๐Ÿšฃ๐Ÿฝ)

Description

This is a simple implementation of Q-learning algorithm to solve the wolf-goat-cabbage problem. The problem is a well-known puzzle in artificial intelligence, and it is used to illustrate the power of state-space search algorithms. The problem can be stated as follows: A farmer with a wolf, a goat, and a cabbage come to the edge of a river they wish to cross. There is a boat at the river's edge that only the farmer can row. The farmer can take at most one other object besides himself on a crossing, but if the wolf is ever left with the goat, the wolf will eat the goat; similarly, if the goat is left with the cabbage, the goat will eat the cabbage. Devise a sequence of crossings of the river so that all four characters arrive safely on the other side of the river.

Requirements

  • Python 3.6
  • gym
  • numpy

Installation

pip3 install gym
pip3 install numpy

Usage

python3 main.py

Analysis

The Q-learning algorithm is a model-free, online, off-policy reinforcement learning method. The main idea of Q-learning is to use the Bellman equation as an iterative update rule for action-value pairs. The algorithm in Wolf-Goat-Cabbage problem is as follows:

  • Initialize Q(s,a) arbitrarily
  • Repeat (for each episode):
    • Initialize s
    • Repeat (for each step of episode):
      • Choose a from s using policy derived from Q (e.g., epsilon-greedy)
      • Take action a, observe r, s'
      • Q(s,a) <- Q(s,a) + alpha[r + gamma * max(Q(s',a')) - Q(s,a)]
      • s <- s'
    • until s is terminal

wolf-goat-gabbage-problem-q_learning-py-gym's People

Contributors

codeone45 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.