Skip to content

Instantly share code, notes, and snippets.

@phabee
Created August 28, 2024 14:13
Show Gist options
  • Save phabee/cd7291f604a0b6b904898ce07be6fa1f to your computer and use it in GitHub Desktop.
Save phabee/cd7291f604a0b6b904898ce07be6fa1f to your computer and use it in GitHub Desktop.
# Problem generator for Production Planning Instances
# Author: Fabian Leuthold
import random
def create_prod_plan_problem(num_machines, num_jobs):
"""
Generate a Production Planning problem instance
:param num_machines: the number of (identical) machines available
:param num_jobs: the number of jobs to assign to the machines
:return:
"""
name = f"PRODPLAN_M{num_machines}_J{num_jobs}"
file_name = f"./data/{name}.ppl"
comment = f"Assign {num_jobs} jobs with given duration to {num_machines} sequences processed on" \
f" {num_machines} (identic) machines (Leuthold)"
random.seed(1)
# Start des Problem-Textformats
problem_text = []
problem_text.append(f"NAME: {name}")
problem_text.append("TYPE: PRODPLAN_PROBLEM")
problem_text.append(f"COMMENT: {comment}")
problem_text.append(f"NUM_MACHINES: {num_machines}")
problem_text.append(f"NUM_JOBS: {num_jobs}")
problem_text.append("JOBS_ID_DURATION")
# Hinzufügen der Job-Dauern
for job_id in range(1, num_jobs + 1):
duration = round(random.uniform(0.5, 10), 1)
problem_text.append(f"{job_id} {duration}")
# EOF
problem_text.append("EOF")
# Schreibe den Textinhalt in die Datei
with open(file_name, "w") as file:
file.write("\n".join(problem_text))
return
def main():
create_prod_plan_problem(num_machines=2, num_jobs=53)
create_prod_plan_problem(num_machines=2, num_jobs=21)
create_prod_plan_problem(num_machines=4, num_jobs=32)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment