This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
methode_exacte.py
75 lines (60 loc) · 2.07 KB
/
methode_exacte.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import argparse
import sys
import numpy as np
import os
from script.data import loader, separate
from docplex.cp.model import CpoModel
from config import setup
def main(argv):
"""
:param argv: parser
:return: None
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--instance",
default="ft06",
type=str,
help="Nom de l'instance", )
parser.add_argument(
"--temps",
default=10,
type=int,
help="Temps de recherche", )
args = parser.parse_args()
setup()
recherche_exact(args.instance, args.temps)
def recherche_exact(instance, temps):
'''
:param temps: int, temps de recherche
:param instance: nom de l'instance str
:return: None
'''
problem_data, optimum = loader(instance)
nb_machine = problem_data["nb_machine"]
nb_jobs = problem_data["nb_jobs"]
problem = problem_data["problem"]
machine, durations = separate(problem)
model = CpoModel(name='Scheduling')
# Variable
job_operations = [[model.interval_var(size=durations[j][m],
name="O{}-{}".format(j, m)) for m in range(nb_machine)] for j in
range(nb_jobs)]
# chaque opération doit commencer aprés la fin de la précedente
for j in range(nb_jobs):
for s in range(1, nb_machine):
model.add(model.end_before_start(job_operations[j][s - 1], job_operations[j][s]))
# Pas d'overlap pour les operations executées sur une même machine
machine_operations = [[] for m in range(nb_machine)]
for j in range(nb_jobs):
for s in range(0, nb_machine):
machine_operations[machine[j][s]].append(job_operations[j][s])
for lops in machine_operations:
model.add(model.no_overlap(lops))
# Minimiser la date de fin
model.add(model.minimize(model.max([model.end_of(job_operations[i][nb_machine - 1]) for i in range(nb_jobs)])))
# Solve model
print("Solving model....")
msol = model.solve(TimeLimit=temps)
if __name__ == '__main__':
main(sys.argv)