Skip to content

Implemented 11.1 Job-Shop-Problem #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
added docstrings
  • Loading branch information
KaiRawal committed Mar 26, 2017
commit ed38d8c48f98887c9f2f862c801ff683ee9aaa02
44 changes: 44 additions & 0 deletions planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ class HLA(Action):

def __init__(self, action, precond=[None, None], effect=[None, None], duration=0,
consume={}, use={}):
"""
As opposed to actions, to define HLA, we have added constraints.
duration holds the amount of time required to execute the task
consumes holds a dictionary representing the resources the task consumes
uses holds a dictionary representing the resources the task uses
"""
super().__init__(action, precond, effect)
self.duration = duration
self.consumes = consume
Expand All @@ -594,6 +600,10 @@ def __init__(self, action, precond=[None, None], effect=[None, None], duration=0
# self.job_group = -1 # must be assigned in relation to other HLAs

def do_action(self, job_order, available_resources, kb, args):
"""
An HLA based version of act - along with knowledge base updation, it handles
resource checks, and ensures the actions are executed in the correct order.
"""
# print(self.name)
if not self.has_usable_resource(available_resources):
raise Exception('Not enough usable resources to execute {}'.format(self.name))
Expand All @@ -608,6 +618,9 @@ def do_action(self, job_order, available_resources, kb, args):
self.completed = True # set the task status to complete

def has_consumable_resource(self, available_resources):
"""
Ensure there are enough consumable resources for this action to execute.
"""
for resource in self.consumes:
if available_resources.get(resource) is None:
return False
Expand All @@ -616,6 +629,9 @@ def has_consumable_resource(self, available_resources):
return True

def has_usable_resource(self, available_resources):
"""
Ensure there are enough usable resources for this action to execute.
"""
for resource in self.uses:
if available_resources.get(resource) is None:
return False
Expand All @@ -624,6 +640,10 @@ def has_usable_resource(self, available_resources):
return True

def inorder(self, job_order):
"""
Ensure that all the jobs that had to be executed before the current one have been
successfully executed.
"""
for jobs in job_order:
if self in jobs:
for job in jobs:
Expand Down Expand Up @@ -661,9 +681,33 @@ def act(self, action):
if list_action is None:
raise Exception("Action '{}' not found".format(action.name))
list_action.do_action(self.jobs, self.resources, self.kb, args)
print(self.resources)


def job_shop_problem():
"""
[figure 11.1] JOB-SHOP-PROBLEM

A job-shop scheduling problem for assembling two cars,
with resource and ordering constraints.

Example:
>>> from planning import *
>>> p = job_shop_problem()
>>> p.goal_test()
False
>>> p.act(p.jobs[1][0])
>>> p.act(p.jobs[1][1])
>>> p.act(p.jobs[1][2])
>>> p.act(p.jobs[0][0])
>>> p.act(p.jobs[0][1])
>>> p.goal_test()
False
>>> p.act(p.jobs[0][2])
>>> p.goal_test()
True
>>>
"""
init = [expr('Car(C1)'),
expr('Car(C2)'),
expr('Wheels(W1)'),
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy