Skip to content

Commit

Permalink
Bug fixed in OpenShop implementation of ct(), edit_tag() function add…
Browse files Browse the repository at this point in the history
…ed in util
  • Loading branch information
framinan committed Mar 25, 2022
1 parent b367555 commit 42d353f
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 61 deletions.
2 changes: 1 addition & 1 deletion build/lib/scheptk/scheptk.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def ct(self, sequence):
index_machine = find_index_min(next_ct)
# increases the completion time of the corresponding machine (and sets the completion time of the job)
ct_machines[index_machine] = max(ct_machines[index_machine], self.r[sequence[j]]) + self.pt[index_machine][sequence[j]]
ct[index_machine][sequence[j]] = ct_machines[index_machine]
ct[index_machine][j] = ct_machines[index_machine]

return ct, sequence

Expand Down
3 changes: 2 additions & 1 deletion build/lib/scheptk/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def read_tag(filename, tag):
# create the proper data structure
# scalar
if(tag_value.find(",") ==-1):
return int(tag_value)
#return int(tag_value)
return get_proper_type(tag_value)
else:
if(tag_value.find(";") !=-1):
values = []
Expand Down
31 changes: 17 additions & 14 deletions scheptk.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
Metadata-Version: 2.1
Name: scheptk
Version: 0.0.4
Version: 0.0.5
Summary: Python scheduling package
Home-page: https://github.com/framinan/scheptk
Author: Jose M Framinan
Author-email: framinan@us.es
License: UNKNOWN
Description: ## `scheptk` - Scheduling Python ToolKit

`scheptk` is a collection of classes and functions to model and solve machine scheduling problems using Python. It is intended basically for teaching purposes, even if the algorithms can be integrated with MOIST, a more advanced scheduling tool.

# How to use it

In order to use `scheptk` you can install it as a Python package using `pip`:

`pip install scheptk`

At this point, the clasess and functions of `scheptk` should be available. You might want to have a look at the [wiki pages](https://github.com/framinan/scheptk/wiki) to get a handle on the documentation.


Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.7
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Description-Content-Type: text/markdown
License-File: LICENSE

## `scheptk` - Scheduling Python ToolKit

`scheptk` is a collection of classes and functions to model and solve machine scheduling problems using Python. It is intended basically for teaching purposes, even if the algorithms can be integrated with MOIST, a more advanced scheduling tool.

# How to use it

In order to use `scheptk` you can install it as a Python package using `pip`:

`pip install scheptk`

At this point, the clasess and functions of `scheptk` should be available. You might want to have a look at the [wiki pages](https://github.com/framinan/scheptk/wiki) to get a handle on the documentation.



1 change: 1 addition & 0 deletions scheptk.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LICENSE
README.md
setup.py
scheptk/__init__.py
Expand Down
Binary file modified scheptk/__pycache__/scheptk.cpython-37.pyc
Binary file not shown.
13 changes: 11 additions & 2 deletions scheptk/scheptk.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,9 @@ def random_solution(self):
# implementation of the completion times of each job on each machine for OpenShop
# it has to be a full sequence
def ct(self, sequence):

# job order to be returned
job_order = []

# completion times of jobs and machines
ct_jobs = [self.r[j] for j in range(self.jobs)]
Expand All @@ -865,6 +868,10 @@ def ct(self, sequence):

# obtain decoded_job
decoded_job = job % self.jobs

# 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)
Expand All @@ -874,9 +881,11 @@ def ct(self, sequence):
ct_jobs[decoded_job]= curr_completion_time
ct_machines[decoded_machine] = curr_completion_time

ct[decoded_machine][decoded_job] = curr_completion_time
# puts the completion time in the proper position the completion times matrix
order_decoded_job = job_order.index(decoded_job)
ct[decoded_machine][order_decoded_job] = curr_completion_time

return ct, ct_jobs
return ct, job_order



Expand Down
122 changes: 80 additions & 42 deletions scheptk/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,57 @@
import operator # for sorted functions
from random import randint # generation of random integer numbers


# utility function to edit the value of a tag in a file
# returns -1 if the tag is not found, the line in the file where the tag is found otherwise
def edit_tag(tag, value, filename):
# obtiene el valor de la etiqueta en formato lista
string_value = ''
if isinstance(value,list):
if isinstance(value[0],list):
# es una matriz
string_value = matrix_to_string(value)
else:
# es una lista
string_value = vector_to_string(value)
else:
string_value = str(value)

found_at = -1
# loading all tags
with open(filename,'r') as file:
list_lines = file.readlines()
# search the specific tag
for x, line in enumerate(list_lines):
if line.find('[' + tag + '=')!= -1:
found_at = x
# if found, changes the line
if found_at != -1:
# gets the part before the [
start = list_lines[found_at].index('=')
#new line
new_line = list_lines[found_at][:start] + '='+ string_value + "]\n"
list_lines[found_at] = new_line
# writes the file with the new value of the tag
with open(filename,'w') as file:
file.writelines(list_lines)
return found_at



# find_index_max() returns the index where the maximum value is found
def find_index_max(list):
tuple = enumerate(list)
sorted_tuple = sorted(tuple, key=operator.itemgetter(1), reverse=True)
return sorted_tuple[0][0]

# find_index_min() returns the index where the minimum value is found
def find_index_min(list):
tuple = enumerate(list)
sorted_tuple = sorted(tuple, key=operator.itemgetter(1), reverse=False)
return sorted_tuple[0][0]


# utility function to get the proper type (int, string, float) of an argument
def get_proper_type(x):
if isinstance(ast.literal_eval(x), int):
Expand All @@ -14,6 +65,20 @@ def get_proper_type(x):
return x


# utility function to map a matrix into a string (mostly to be used internally)
def matrix_to_string(matrix):
cadena = ''
for i in range(len(matrix)-1):
for j in range(len(matrix[i]) - 1):
cadena = cadena + str(matrix[i][j]) + ","
cadena = cadena + str(matrix[i][len(matrix[i])-1]) + ";"
# last row
for j in range(len(matrix[0])-1):
cadena = cadena + str(matrix[len(matrix)-1][j]) + ","
# last col of last row
return cadena + str(matrix[len(matrix)-1][len(matrix[0])-1])


# utility function to print the content of val (escalar, vector, matrix) with a tag
def print_tag(tag, value):
# if it is a list
Expand All @@ -28,28 +93,17 @@ def print_tag(tag, value):
# it is an scalar
print("[" + tag + "=" + str(value) + "]")


# utility function to map a vector into a string (mostly to be used internally)
def vector_to_string(vector):
cadena = ''
for i in range(len(vector)-1):
cadena = cadena + str(vector[i]) + ","
return cadena + str(vector[len(vector)-1])
# utility function to generate a random sequence of length size
def random_sequence(size):
sequence = []
for i in range(size):
number = randint(0, size-1)
while( sequence.count(number)!= 0):
number = randint(0, size-1)
sequence.append(number)
return sequence


# utility function to map a matrix into a string (mostly to be used internally)
def matrix_to_string(matrix):
cadena = ''
for i in range(len(matrix)-1):
for j in range(len(matrix[i]) - 1):
cadena = cadena + str(matrix[i][j]) + ","
cadena = cadena + str(matrix[i][len(matrix[i])-1]) + ";"
# last row
for j in range(len(matrix[0])-1):
cadena = cadena + str(matrix[len(matrix)-1][j]) + ","
# last col of last row
return cadena + str(matrix[len(matrix)-1][len(matrix[0])-1])


# utility function to read a tag
def read_tag(filename, tag):
Expand Down Expand Up @@ -112,28 +166,12 @@ def sorted_value_asc(list):
def sorted_value_desc(list):
return sorted_value(list, True)

# utility function to generate a random sequence of length size
def random_sequence(size):
sequence = []
for i in range(size):
number = randint(0, size-1)
while( sequence.count(number)!= 0):
number = randint(0, size-1)
sequence.append(number)
return sequence


# find_index_max() returns the index where the maximum value is found
def find_index_max(list):
tuple = enumerate(list)
sorted_tuple = sorted(tuple, key=operator.itemgetter(1), reverse=True)
return sorted_tuple[0][0]

# find_index_min() returns the index where the minimum value is found
def find_index_min(list):
tuple = enumerate(list)
sorted_tuple = sorted(tuple, key=operator.itemgetter(1), reverse=False)
return sorted_tuple[0][0]
# utility function to map a vector into a string (mostly to be used internally)
def vector_to_string(vector):
cadena = ''
for i in range(len(vector)-1):
cadena = cadena + str(vector[i]) + ","
return cadena + str(vector[len(vector)-1])

# utility function to write a tag (scalar, vector, matrix) and its value into a file
def write_tag(tag, value, filename):
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.0.4",
version="0.0.5",
author="Jose M Framinan",
author_email="framinan@us.es",
description="Python scheduling package",
Expand Down

0 comments on commit 42d353f

Please sign in to comment.