Giter VIP home page Giter VIP logo

py_plan's Introduction

py_plan's People

Contributors

cmaclell avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

afcarl

py_plan's Issues

Circular options to act?

Cool and understandable approach!

I tried to change the book ordering example in a way, that it starts with owning a book 1, selling it for 10 and then it should buy the book 2 nine:

from operator import ge, add
from operator import sub
from functools import partial

from py_search.utils import compare_searches
from py_search.uninformed import depth_first_search

from py_plan.total_order import StateSpacePlanningProblem
from py_plan.base import Operator

buy = Operator('buy',
               [('Book', '?b'),
                ('Cost', '?b', '?c'),
                ('Money', '?m'),
                (ge, '?m', '?c')],
               [('Own', '?b'),
                ('not', ('Money', '?m')),
                ('Money', (sub, '?m', '?c'))], cost=2)

sell = Operator('sell',
               [('Book', '?b'),
                ('Cost', '?b', '?c'),
                ('Own', '?b'),
                ('Money', '?m'),
                ],
               [('Own', '?b'),
                ('Money', (add, '?m', '?c'))], cost=1)

start = [('Money', 0), ('Own', 'book1')]
for i in range(10):
    book = "book%s" % i
    start += [('Book', book), ('Cost', book, 10-i)]

goal = [('Own', 'book2')]

p = StateSpacePlanningProblem(start, goal, [buy, sell])


def progression(problem):
    return partial(depth_first_search, forward=True, backward=False)(problem)


def regression(problem):
    return partial(depth_first_search, forward=False, backward=True)(problem)

def bidirectional(problem):
    return partial(depth_first_search, forward=True, backward=True)(problem)


compare_searches([p], [progression,
                       regression,
                       bidirectional
                       ])
                       
                       
print(next(progression(p)).path())
path = next(regression(p)).path()

print(path[0][0])      

This seems to run from my perspective, but does not stop, maybe it is evaluating all the time selling and buying the same item again and again over and over and there should be a guard to prevent such circles?

Or what is happening now, when the script does not stop?

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.