Skip to content

Commit

Permalink
get_sequence() for JobShop and OpenShop, get_job() and get_machine() …
Browse files Browse the repository at this point in the history
…for OpenShop
  • Loading branch information
framinan committed Nov 25, 2023
1 parent f1e3e71 commit 89e474b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 14 deletions.
46 changes: 40 additions & 6 deletions build/lib/scheptk/scheptk.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,16 @@ def ct(self, solution):

return ct, jobs_involved


# get the order of the jobs in a given solution (according to the time in which they are processed in the first machine)
def get_sequence(self, solution):

# get the jobs involved in the solution in the order they are processed
jobs_involved = list(dict.fromkeys(solution))

return jobs_involved



# implementation of a random solution of the instance
def random_solution(self):
solution = []
Expand Down Expand Up @@ -1002,10 +1011,20 @@ def __init__(self, filename):
# implementation of random_solution()
def random_solution(self):
return random_sequence(self.jobs * self.machines)


# get_job: obtains the job corresponding to an operation
def get_job(self, op):
return op % self.jobs

# get_machine: obtains the machine corresponding to an operation
def get_machine(self, op):
return int((op - self.get_job(op)) / self.jobs)


# implementation of the completion times of each job on each machine for OpenShop
# it has to be a full sequence
def ct(self, sequence):
def ct(self, solution):

# job order to be returned
job_order = []
Expand All @@ -1017,18 +1036,17 @@ def ct(self, sequence):
# completion time of each job on each machine
ct = [[0 for j in range(self.jobs)] for i in range(self.machines)]

for job in sequence:
for op in solution:

# obtain decoded_job
decoded_job = job % self.jobs
decoded_job = self.get_job(op)

# if it is a new job, it is appended to the job_order
if len([e for e in job_order if e == decoded_job]) == 0:
job_order.append(decoded_job)

# obtain decoded machine
decoded_machine = int((job - decoded_job) / self.jobs)

decoded_machine = self.get_machine(op)
# compute completion time
curr_completion_time = max(ct_jobs[decoded_job], ct_machines[decoded_machine]) + self.pt[decoded_machine][decoded_job]
ct_jobs[decoded_job]= curr_completion_time
Expand All @@ -1040,6 +1058,22 @@ def ct(self, sequence):

return ct, job_order

# returns the sequence of jobs in a given solution. It is useful e.g. to check job-level measures
def get_sequence(self, solution):

# job order to be returned
job_order = []

for op in solution:

# obtain decoded_job
decoded_job = self.get_job(op)

# if it is a new job, it is appended to the job_order
if len([e for e in job_order if e == decoded_job]) == 0:
job_order.append(decoded_job)

return job_order



Expand Down
2 changes: 1 addition & 1 deletion scheptk.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: scheptk
Version: 0.1.2
Version: 0.1.3
Summary: Python scheduling package
Home-page: https://github.com/framinan/scheptk
Author: Jose M Framinan
Expand Down
Binary file modified scheptk/__pycache__/scheptk.cpython-39.pyc
Binary file not shown.
46 changes: 40 additions & 6 deletions scheptk/scheptk.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,16 @@ def ct(self, solution):

return ct, jobs_involved


# get the order of the jobs in a given solution (according to the time in which they are processed in the first machine)
def get_sequence(self, solution):

# get the jobs involved in the solution in the order they are processed
jobs_involved = list(dict.fromkeys(solution))

return jobs_involved



# implementation of a random solution of the instance
def random_solution(self):
solution = []
Expand Down Expand Up @@ -1002,10 +1011,20 @@ def __init__(self, filename):
# implementation of random_solution()
def random_solution(self):
return random_sequence(self.jobs * self.machines)


# get_job: obtains the job corresponding to an operation
def get_job(self, op):
return op % self.jobs

# get_machine: obtains the machine corresponding to an operation
def get_machine(self, op):
return int((op - self.get_job(op)) / self.jobs)


# implementation of the completion times of each job on each machine for OpenShop
# it has to be a full sequence
def ct(self, sequence):
def ct(self, solution):

# job order to be returned
job_order = []
Expand All @@ -1017,18 +1036,17 @@ def ct(self, sequence):
# completion time of each job on each machine
ct = [[0 for j in range(self.jobs)] for i in range(self.machines)]

for job in sequence:
for op in solution:

# obtain decoded_job
decoded_job = job % self.jobs
decoded_job = self.get_job(op)

# if it is a new job, it is appended to the job_order
if len([e for e in job_order if e == decoded_job]) == 0:
job_order.append(decoded_job)

# obtain decoded machine
decoded_machine = int((job - decoded_job) / self.jobs)

decoded_machine = self.get_machine(op)
# compute completion time
curr_completion_time = max(ct_jobs[decoded_job], ct_machines[decoded_machine]) + self.pt[decoded_machine][decoded_job]
ct_jobs[decoded_job]= curr_completion_time
Expand All @@ -1040,6 +1058,22 @@ def ct(self, sequence):

return ct, job_order

# returns the sequence of jobs in a given solution. It is useful e.g. to check job-level measures
def get_sequence(self, solution):

# job order to be returned
job_order = []

for op in solution:

# obtain decoded_job
decoded_job = self.get_job(op)

# if it is a new job, it is appended to the job_order
if len([e for e in job_order if e == decoded_job]) == 0:
job_order.append(decoded_job)

return job_order



Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="scheptk",
version="0.1.2",
version="0.1.3",
author="Jose M Framinan",
author_email="[email protected]",
description="Python scheduling package",
Expand Down

0 comments on commit 89e474b

Please sign in to comment.