mdl.add(minimize(max([end_of(OPS[o[0]]) for o in ops])))


##############################################################################
# Model solving
##############################################################################

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=100000, TimeLimit=10)
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for flexible job-shop " + filename)
    visu.panel("Machines")
    for j in range(nb_mchs):
        visu.sequence(name='M' + str(j))
        for v in MACHS[j]:
            itv = msol.get_var_solution(v)
            if itv.is_present():
                job = Job[v.get_name()]
                visu.interval(itv, job, 'J' + str(job))
    visu.show()
Пример #2
0
        ftardiness[t] = f

# Minimize cost
mdl.add(mdl.minimize(mdl.sum(cost)))

#-----------------------------------------------------------------------------
# Solve the model and display the result
#-----------------------------------------------------------------------------

print("Solving model....")
msol = mdl.solve(TimeLimit=10)
print("Solution: ")
msol.print_solution()

if msol and visu.is_visu_enabled():
    visu.timeline("Solution SchedTime", origin=10, horizon=120)
    visu.panel("Schedule")
    for t in ALL_TASKS:
        visu.interval(msol.get_var_solution(tasks[t.id]), t.id, t.name)
    for t in ALL_TASKS:
        if t.release_date is not None:
            visu.panel('Earliness')
            itvsol = msol.get_var_solution(tasks[t.id])
            cost = fearliness[t].get_value(itvsol.get_start())
            visu.function(segments=[(itvsol, cost, t.name)],
                          color=t.id,
                          style='interval')
            visu.function(segments=fearliness[t], color=t.id)
        if t.due_date is not None:
            visu.panel('Tardiness')
            itvsol = msol.get_var_solution(tasks[t.id])
Пример #3
0
msol.print_solution()


##############################################################################
# Display result
##############################################################################

def compact(name):
    # Example: A31_M1_TP1 -> 31
    task, foo = name.split('_', 1)
    return task[1:]

def showsequence(s, setup):
    seq = msol.get_var_solution(s)
    visu.sequence(name=s.get_name())
    vs = seq.get_value()
    for v in vs:
        nm = v.get_name()
        visu.interval(v, tp[id[nm]], compact(nm))
    for i in range(len(vs) - 1):
        end = vs[i].get_end()
        tp1 = tp[id[vs[i].get_name()]]
        tp2 = tp[id[vs[i + 1].get_name()]]
        visu.transition(end, end + setup.get_value(tp1, tp2))

if msol and visu.is_visu_enabled():
    visu.timeline("Solution for SchedTCost")
    showsequence(s1, setup1)
    showsequence(s2, setup2)
    visu.show()
Пример #4
0
msol.print_solution()

##############################################################################
# Display result
##############################################################################


def compact(name):
    # Example: H3-garden -> G3
    #           ^ ^
    loc, task = name[1:].split('-', 1)
    return task[0].upper() + loc


# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline('Solution SchedOptional', 0, deadline)
    for w in range(nbWorkers):
        visu.sequence(name=workerNames[w])
        for t in worker_tasks[w]:
            wt = msol.get_var_solution(t)
            if wt.is_present():
                if desc[t].skills[w] == max(desc[t].skills):
                    # Green-like color when task is using the most skilled worker
                    color = 'lightgreen'
                else:
                    # Red-like color when task does not use the most skilled worker
                    color = 'salmon'
                visu.interval(wt, color, compact(wt.get_name()))
    visu.show()
        # Add task intervals
        tasks = []
        for task, interval in task_intervals_on_machines[m_id]:
            val = msol.get_value(interval)
            if val != ():
                tasks.append(
                    (msol.get_var_solution(interval), 1, interval.get_name()))
                cost_sum += energy_intervals_array[val[2] - 1].get_value(
                    val[0]) * task['power_consumption']
                # Add segments to cost function
                for i in range(val[0], val[1]):
                    cost_i = energy_prices[i] * task['power_consumption']
                    energy_costs.add_value(i, i + 1, cost_i)
        # Do not show this machine if no task if assigned to it
        if tasks and ons:
            visu.timeline("Machine " + str(m_id), 0, int(TIMESLOTS))
            visu.panel("Tasks")
            visu.sequence(name='Machine', intervals=ons)
            visu.sequence(name='Tasks', intervals=tasks)
            visu.function(name='Cost={}'.format(cost_sum),
                          segments=energy_costs)

            for j in range(NUM_RESOURCES):
                visu.panel('resources_{}'.format(j))
                res = CpoStepFunction()
                for task, interval in task_intervals_on_machines[m_id]:
                    val = msol.get_value(interval)
                    if val != ():
                        res.add_value(val[0], val[1],
                                      task['resource_usage'][j])
                visu.function(segments=res, color=j)
mdl.add(minimize(max([end_of(ITVS[i][nbMchs - 1]) for i in range(nbJobs)])))


##############################################################################
# Model solving
##############################################################################

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for permutation flow-shop " + filename)
    visu.panel("Jobs")
    for i in range(nbJobs):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'M' + str(j)) for j in range(nbMchs)])
    visu.panel("Machines")
    for j in range(nbMchs):
        visu.sequence(name='M' + str(j),
                      intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'J' + str(i)) for i in range(nbJobs)])
    visu.show()
Пример #7
0
# Solve model
print("Solving model....")
msol = mdl.solve(TimeLimit=10, FailLimit=250000)
print("Solution: ")
msol.print_solution()

if msol and visu.is_visu_enabled():
    import docplex.cp.utils_visu as visu
    import matplotlib.pyplot as plt

    makespan_values = [msol.get_var_solution(m).get_value() for m in makespans]
    plt.hist(makespan_values, color='skyblue')
    plt.axvline(msol.get_objective_values()[0],
                color='navy',
                linestyle='dashed',
                linewidth=2)
    plt.title("Makespan histogram")
    plt.xlabel("Value")
    plt.ylabel("Frequency")

    visu.timeline("Solution sequencing for stochastic job-shop " + filename)
    visu.panel("Machines")
    for j in range(NB_MACHINES):
        visu.sequence(name='M' + str(j))
        itvs = msol.get_var_solution(ref_sequences[j]).get_value()
        for v in itvs:
            k, i, m = v.get_name().split('-')
            visu.interval(v, int(i), 'O' + i + '-' + m)
    visu.show()
# Viewing the results of sequencing problems in a Gantt chart
# (double click on the gantt to see details)
import docplex.cp.utils_visu as visu
import matplotlib.pyplot as plt
#matplotlib inline
#Change the plot size
from pylab import rcParams
rcParams['figure.figsize'] = 15, 3


def showsequence(msol, s, setup, tp):
    seq = msol.get_var_solution(s)
    visu.sequence(name=s.get_name())
    vs = seq.get_value()
    for v in vs:
        nm = v.get_name()
        visu.interval(v, tp[TaskNames_ids[nm]], nm)
    for i in range(len(vs) - 1):
        end = vs[i].get_end()
        tp1 = tp[TaskNames_ids[vs[i].get_name()]]
        tp2 = tp[TaskNames_ids[vs[i + 1].get_name()]]
        visu.transition(end, end + setup.get_value(tp1, tp2))


if msol2:
    visu.timeline("Solution for SchedSetup")
    for w in WorkerNames:
        types = [h for h in Houses for t in TaskNames if Worker[t] == w]
        showsequence(msol2, workers[w], transitionTimes, types)
    visu.show()
Пример #9
0
        mdl.max([
            mdl.end_of(job_operations[i][j]) for i in range(NB_JOBS)
            for j in range(NB_MACHINES)
        ])))

#-----------------------------------------------------------------------------
# Solve the model and display the result
#-----------------------------------------------------------------------------

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
print("Solution: ")
msol.print_solution()

# Display solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for open-shop " + filename)
    visu.panel("Jobs")
    for i in range(NB_JOBS):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(job_operations[i][j]),
                                  j, 'M' + str(j))
                                 for j in range(NB_MACHINES)])
    visu.panel("Machines")
    for j in range(NB_MACHINES):
        visu.sequence(name='M' + str(j),
                      intervals=[(msol.get_var_solution(job_operations[i][j]),
                                  j, 'J' + str(i)) for i in range(NB_JOBS)])
    visu.show()
Пример #10
0
rcParams['figure.figsize'] = 15, 3

now = datetime.datetime.now().strftime("%Y-%m-%d ")

df = [
    dict(Task     = Buses[b].Name, 
         Start    = now + s(sol.get_var_solution(outwardTrip[b][i]).start),
         Finish   = now + s(sol.get_var_solution(outwardTrip[b][i]).end), 
         Seats    = str(Buses[b].Seats) + " Seats")
    for b in range(NbBuses) for i in range(NbMaxTrips) if (sol.get_var_solution(outwardTrip[b][i]).is_present())
]

for i in df:
  print(i)

visu.timeline('Buses')
visu.panel(name="Schedule")
for b in range(NbBuses):
  for i in range(NbMaxTrips):
    if (sol.get_var_solution(outwardTrip[b][i]).is_present()):
        visu.interval(sol.get_var_solution(outwardTrip[b][i]), int(Buses[b].Seats), sol.get_var_solution(outwardTrip[b][i]).length)
visu.show()        

"""

which gives

{'Task': 'A40', 'Start': '2021-03-22 09:30', 'Finish': '2021-03-22 10:00', 'Seats': '40 Seats'}
{'Task': 'D40', 'Start': '2021-03-22 09:30', 'Finish': '2021-03-22 10:00', 'Seats': '40 Seats'}
{'Task': 'E40', 'Start': '2021-03-22 09:30', 'Finish': '2021-03-22 10:00', 'Seats': '40 Seats'}
{'Task': 'F30', 'Start': '2021-03-22 08:45', 'Finish': '2021-03-22 09:10', 'Seats': '30 Seats'}
msol.print_solution()


##############################################################################
# Display result
##############################################################################

def compact(name):
    # Example: A31_M1_TP1 -> 31
    task, foo = name.split('_', 1)
    return task[1:]

def showsequence(s, setup):
    seq = msol.get_var_solution(s)
    visu.sequence(name=s.get_name())
    vs = seq.get_value()
    for v in vs:
        nm = v.get_name()
        visu.interval(v, tp[id[nm]], compact(nm))
    for i in range(len(vs) - 1):
        end = vs[i].get_end()
        tp1 = tp[id[vs[i].get_name()]]
        tp2 = tp[id[vs[i + 1].get_name()]]
        visu.transition(end, end + setup.get_value(tp1, tp2))

if msol and visu.is_visu_enabled():
    visu.timeline("Solution for SchedSetup")
    showsequence(s1, setup1)
    showsequence(s2, setup2)
    visu.show()
##############################################################################
# Solving
##############################################################################

print("Solving model....")
msol = mdl.solve(TimeLimit=10)
print("Solution: ")
msol.print_solution()

##############################################################################
# Display result
##############################################################################

if msol and visu.is_visu_enabled():
    visu.timeline("Solution SchedTime", origin=10, horizon=120)
    visu.panel("Schedule")
    for t in ALL_TASKS:
        visu.interval(msol.get_var_solution(tasks[t.id]), t.id, t.name)
    for t in ALL_TASKS:
        if t.release_date is not None:
            visu.panel("Earliness")
            itvsol = msol.get_var_solution(tasks[t.id])
            cost = fearliness[t].get_value(itvsol.get_start())
            visu.function(segments=[(itvsol, cost, t.name)], color=t.id, style="interval")
            visu.function(segments=fearliness[t], color=t.id)
        if t.due_date is not None:
            visu.panel("Tardiness")
            itvsol = msol.get_var_solution(tasks[t.id])
            cost = ftardiness[t].get_value(itvsol.get_end())
            visu.function(segments=[(itvsol, cost, t.name)], color=t.id, style="interval")
Пример #13
0
pe_idx = {p: i for i, p in enumerate(PEs)}
#print(pe_idx)
pe_tasks_real = [[] for p in range(nbPEs)]  # Tasks assigned to a given worker
#print(pe_tasks_real)
for d in Dags:
    for f in Functionality:
        pe = f[0]
        pe_t = pe_tasks[(d, f)]
        pe_tasks_real[pe_idx[pe]].append(pe_t)

#print(len(pe_tasks_real[0]))
#print(len(pe_tasks_real[1]))
#print(pe_idx)

colors = ['blue', 'red', 'green']
visu.timeline('Solution SchedOptional', 0, 75)
for i, p in enumerate(PEs):
    visu.sequence(name=p)
    for t in pe_tasks_real[pe_idx[p]]:
        wt = msol_2.get_var_solution(t)
        if wt.is_present():
            #if desc[t].skills[w] == max(desc[t].skills):
            # Green-like color when task is using the most skilled worker
            #    color = 'lightgreen'
            #else:
            # Red-like color when task does not use the most skilled worker
            #    color = 'salmon'
            #color = colors[i]
            color = 'y'
            visu.interval(wt, color, wt.get_name())
            print(t)
Пример #14
0
        mdl.max([
            mdl.end_of(job_operations[i][NB_MACHINES - 1])
            for i in range(NB_JOBS)
        ])))

#-----------------------------------------------------------------------------
# Solve the model and display the result
#-----------------------------------------------------------------------------

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
print("Solution: ")
msol.print_solution()

# Display solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for flow-shop " + filename)
    visu.panel("Jobs")
    for i in range(NB_JOBS):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(job_operations[i][j]),
                                  j, 'M' + str(j))
                                 for j in range(NB_MACHINES)])
    visu.panel("Machines")
    for j in range(NB_MACHINES):
        visu.sequence(name='M' + str(j),
                      intervals=[(msol.get_var_solution(job_operations[i][j]),
                                  j, 'J' + str(i)) for i in range(NB_JOBS)])
    visu.show()
mdl.add(minimize(max([end_of(ITVS[i][nbMchs - 1]) for i in range(nbJobs)])))


##############################################################################
# Model solving
##############################################################################

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

# Display solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for flow-shop " + filename)
    visu.panel("Jobs")
    for i in range(nbJobs):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'M' + str(j)) for j in range(nbMchs)])
    visu.panel("Machines")
    for j in range(nbMchs):
        visu.sequence(name='M' + str(j),
                      intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'J' + str(i)) for i in range(nbJobs)])
    visu.show()
Пример #16
0
            for i in range(NB_JOBS)
        ])))

# -----------------------------------------------------------------------------
# Solve the model and display the result
# -----------------------------------------------------------------------------

# Solve model
print("Resolution...")
msol = mdl.solve(TimeLimit=15)
print("Solution : ")
msol.print_solution()

# Draw solution
if msol and visu.is_visu_enabled() and display == 1:
    visu.timeline("Solution pour le fichier  " + path_file)
    visu.panel("Jobs")
    for i in range(NB_JOBS):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(job_operations[i][j]),
                                  MACHINES[i][j], 'M' + str(MACHINES[i][j]))
                                 for j in range(NB_MACHINES)])
    visu.panel("Machines")
    for k in range(NB_MACHINES):
        visu.sequence(name='M' + str(k),
                      intervals=[
                          (msol.get_var_solution(machine_operations[k][i]), k,
                           'J' + str(i)) for i in range(NB_JOBS)
                      ])
    visu.show()
Пример #17
0
# -----------------------------------------------------------------------------
# Решение solver'ом и вывод
# -----------------------------------------------------------------------------

print("Solving model....")
msol = mdl.solve(FailLimit=100000, TimeLimit=10)
print("Solution: ")
msol.print_solution()
# mdl.export_as_cpo()
#
if msol and visu.is_visu_enabled():
    load = [CpoStepFunction() for j in range(NB_RESOURCES)]
    for i in range(NB_TASKS):
        itv = msol.get_var_solution(tasks[i])
        for j in range(NB_RESOURCES):
            if 0 < DEMANDS[i][j]:
                load[j].add_value(itv.get_start(), itv.get_end(),
                                  DEMANDS[i][j])

    visu.timeline("Solution for R'n'D problem")
    visu.panel("Tasks")
    for i in range(NB_TASKS):
        visu.interval(msol.get_var_solution(tasks[i]), i, tasks[i].get_name())
    for j in range(NB_RESOURCES):
        visu.panel("R " + str(j + 1))
        visu.function(segments=[(INTERVAL_MIN, INTERVAL_MAX, CAPACITIES[j])],
                      style='area',
                      color='lightgrey')
        visu.function(segments=load[j], style='area', color=j)
    visu.show()
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

def compact(name):
    # Example: H3-garden -> G3
    #           ^ ^
    loc, task = name[1:].split('-', 1)
    return task[0].upper() + loc

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline('Solution SchedOptional', 0, deadline)
    for w in range(nbWorkers):
        visu.sequence(name=workerNames[w])
        for t in worker_tasks[w]:
            wt = msol.get_var_solution(t)
            if wt.is_present():
                if desc[t].skills[w] == max(desc[t].skills):
                    # Green-like color when task is using the most skilled worker
                    color = 'lightgreen'
                else:
                    # Red-like color when task does not use the most skilled worker
                    color = 'salmon'
                visu.interval(wt, color, compact(wt.get_name()))
    visu.show()
Пример #19
0
        mdl.max([
            mdl.end_of(job_operations[i][NB_MACHINES - 1])
            for i in range(NB_JOBS)
        ])))

#-----------------------------------------------------------------------------
# Solve the model and display the result
#-----------------------------------------------------------------------------

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
print("Solution: ")
msol.print_solution()

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for permutation flow-shop " + filename)
    visu.panel("Jobs")
    for i in range(NB_JOBS):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(job_operations[i][j]),
                                  j, 'M' + str(j))
                                 for j in range(NB_MACHINES)])
    visu.panel("Machines")
    for j in range(NB_MACHINES):
        visu.sequence(name='M' + str(j),
                      intervals=[(msol.get_var_solution(job_operations[i][j]),
                                  j, 'J' + str(i)) for i in range(NB_JOBS)])
    visu.show()
Пример #20
0
##############################################################################
# Model solving
##############################################################################

# Solve model
print("Solving model....")
msol = mdl.solve(TimeLimit=10)
print("Solution: ")
msol.print_solution()

##############################################################################
# Display result
##############################################################################

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for job-shop " + filename)
    visu.panel("Jobs")
    for i in range(nb_jobs):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(ITVS[i][j]), mch[i][j],
                                  'M' + str(mch[i][j]))
                                 for j in range(nb_mchs)])
    visu.panel("Machines")
    for k in range(nb_mchs):
        visu.sequence(name='M' + str(k),
                      intervals=[(msol.get_var_solution(MACH[k][i]), k,
                                  'J' + str(i)) for i in range(nb_jobs)])
    visu.show()
# 1. Calling the solve
print("\nSolving model....")
msol = mdl.solve(url=None, key=None, FailLimit=30000)
print("done")

# 2. Displaying the objective and solution
print("Cost will be " + str(msol.get_objective_values()[0]))

# 3. Viewing the results of sequencing problems in a Gantt chart
rcParams['figure.figsize'] = 15, 3

workers_function = CpoStepFunction()
for h in Houses:
    for t in TaskNames:
        itv = msol.get_var_solution(task[h, t])
        workers_function.add_value(itv.get_start(), itv.get_end(), 1)

visu.timeline('Solution SchedState')
visu.panel(name="Schedule")
for h in Houses:
    for t in TaskNames:
        visu.interval(msol.get_var_solution(task[h, t]), h, t)

visu.panel(name="Houses state")
for h in Houses:
    f = state[h]
    visu.sequence(name=f.get_name(), segments=msol.get_var_solution(f))
visu.panel(name="Nb of workers")
visu.function(segments=workers_function, style='line')
visu.show()
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

def compact(name):
    # Example: H3-garden -> G3
    #           ^ ^
    loc, task = name[1:].split('-', 1)
    return task[0].upper() + loc

if msol and visu.is_visu_enabled():
    workers_function = CpoStepFunction()
    for v in all_tasks:
        itv = msol.get_var_solution(v)
        workers_function.add_value(itv.get_start(), itv.get_end(), 1)

    visu.timeline('Solution SchedState')
    visu.panel(name="Schedule")
    for v in all_tasks:
        visu.interval(msol.get_var_solution(v), house[v], compact(v.get_name()))
    visu.panel(name="Houses state")
    for f in all_state_functions:
        visu.sequence(name=f.get_name(), segments=msol.get_var_solution(f))
    visu.panel(name="Nb of workers")
    visu.function(segments=workers_function, style='line')
    visu.show()
##############################################################################
# Display result
##############################################################################

def compact(name):
    # Example: H3-garden -> G3
    #           ^ ^
    loc, task = name[1:].split('-', 1)
    return task[0].upper() + loc

if msol and visu.is_visu_enabled():
    workersF = CpoStepFunction()
    cashF = CpoStepFunction()
    for p in range(5):
        cashF.add_value(60 * p, INT_MAX, 30000)
    for task in all_tasks:
        itv = msol.get_var_solution(task)
        workersF.add_value(itv.get_start(), itv.get_end(), 1)
        cashF.add_value(itv.start, INT_MAX, -200 * desc[task].duration)

    visu.timeline('Solution SchedCumul')
    visu.panel(name="Schedule")
    for task in all_tasks:
        visu.interval(msol.get_var_solution(task), house[task], compact(task.get_name()))
    visu.panel(name="Workers")
    visu.function(segments=workersF, style='area')
    visu.panel(name="Cash")
    visu.function(segments=cashF, style='area', color='gold')
    visu.show()
print("\nSolving model....")
msol3 = mdl3.solve(FailLimit=30000)
print("done")

if msol3:
    print("Cost will be " +
          str(msol3.get_objective_values()[0]))  # Allocate tasks to workers
    tasks = {w: [] for w in WorkerNames}
    for k, v in Worker.items():
        tasks[v].append(k)

    types = {t: i for i, t in enumerate(TaskNames)}

    import docplex.cp.utils_visu as visu
    import matplotlib.pyplot as plt
    #matplotlib inline
    #Change the plot size
    from pylab import rcParams
    rcParams['figure.figsize'] = 15, 3

    visu.timeline('Solution SchedCalendar')
    for w in WorkerNames:
        visu.panel()
        visu.pause(Calendar[w])
        visu.sequence(name=w,
                      intervals=[(msol3.get_var_solution(itvs[h,
                                                              t]), types[t], t)
                                 for t in tasks[w] for h in Houses])
    visu.show()
else:
    print("No solution found")
mdl.add(minimize(max([end_of(ITVS[i][j]) for i in range(nbJobs) for j in range(nbMchs)])))


##############################################################################
# Model solving
##############################################################################

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for open-shop " + filename)
    visu.panel("Jobs")
    for i in range(nbJobs):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'M' + str(j)) for j in range(nbMchs)])
    visu.panel("Machines")
    for j in range(nbMchs):
        visu.sequence(name='M' + str(j),
                      intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'J' + str(i)) for i in range(nbJobs)])
    visu.show()
Пример #26
0
# Add minimization objective
mdl.add(minimize(max([end_of(OPS[o[0]]) for o in ops])))

##############################################################################
# Model solving
##############################################################################

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=100000, TimeLimit=10)
print("Solution: ")
msol.print_solution()

##############################################################################
# Display result
##############################################################################

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for flexible job-shop " + filename)
    visu.panel("Machines")
    for j in range(nb_mchs):
        visu.sequence(name='M' + str(j))
        for v in MACHS[j]:
            itv = msol.get_var_solution(v)
            if itv.is_present():
                job = Job[v.get_name()]
                visu.interval(itv, job, 'J' + str(job))
    visu.show()

##############################################################################
# Model solving
##############################################################################

# Solve model
print("Solving model....")
msol = mdl.solve(TimeLimit=10)
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline("Solution for job-shop " + filename)
    visu.panel("Jobs")
    for i in range(nb_jobs):
        visu.sequence(name='J' + str(i),
                      intervals=[(msol.get_var_solution(ITVS[i][j]), mch[i][j], 'M' + str(mch[i][j])) for j in
                                 range(nb_mchs)])
    visu.panel("Machines")
    for k in range(nb_mchs):
        visu.sequence(name='M' + str(k),
                      intervals=[(msol.get_var_solution(MACH[k][i]), k, 'J' + str(i)) for i in range(nb_jobs)])
    visu.show()
Пример #28
0
    return task[0].upper() + loc


# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
print("Solution: ")
msol.print_solution()

# Display result
if msol and visu.is_visu_enabled():
    workersF = CpoStepFunction()
    cashF = CpoStepFunction()
    for p in range(5):
        cashF.add_value(60 * p, INT_MAX, 30000)
    for task in all_tasks:
        itv = msol.get_var_solution(task)
        workersF.add_value(itv.get_start(), itv.get_end(), 1)
        cashF.add_value(itv.start, INT_MAX, -200 * desc[task].duration)

    visu.timeline('Solution SchedCumul')
    visu.panel(name="Schedule")
    for task in all_tasks:
        visu.interval(msol.get_var_solution(task), house[task],
                      compact(task.get_name()))
    visu.panel(name="Workers")
    visu.function(segments=workersF, style='area')
    visu.panel(name="Cash")
    visu.function(segments=cashF, style='area', color='gold')
    visu.show()
print("Solving model....")
msol = mdl.solve(TimeLimit=10, FailLimit=250000)
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

if msol and visu.is_visu_enabled():
    import docplex.cp.utils_visu as visu
    import matplotlib.pyplot as plt

    makespan_values = [msol.get_var_solution(m).get_value() for m in makespans]
    plt.hist(makespan_values, color='skyblue')
    plt.axvline(msol.get_objective_values()[0], color='navy', linestyle='dashed', linewidth=2)
    plt.title("Makespan histogram")
    plt.xlabel("Value")
    plt.ylabel("Frequency")

    visu.timeline("Solution sequencing for stochastic job-shop " + filename)
    visu.panel("Machines")
    for j in range(nb_machines):
        visu.sequence(name='M' + str(j))
        itvs = msol.get_var_solution(ref_sequences[j]).get_value()
        for v in itvs:
            k, i, m = v.get_name().split('-')
            visu.interval(v, int(i), 'O' + i + '-' + m)
    visu.show()
# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=30000, TimeLimit=10)
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

if msol and visu.is_visu_enabled():
    load = [CpoStepFunction() for j in range(nb_renewable)]
    for m in modes_data:
        itv = msol.get_var_solution(modes[m])
        if itv.is_present():
            for j in range(nb_renewable):
                if 0 < m.demand_renewable[j]:
                    load[j].add_value(itv.get_start(), itv.get_end(), m.demand_renewable[j])

    visu.timeline("Solution for RCPSPMM " + filename)
    visu.panel("Tasks")
    for t in tasks_data:
        visu.interval(msol.get_var_solution(tasks[t]), int(t.name[1:]), t.name)
    for j in range(nb_renewable):
        visu.panel("R " + str(j + 1))
        visu.function(segments=[(INTERVAL_MIN, INTERVAL_MAX, cap_renewables[j])], style='area', color='lightgrey')
        visu.function(segments=load[j], style='area', color=j)
    visu.show()
# mdl.export_as_cpo()

# Solve model
print("Solving model....")
msol = mdl.solve(TimeLimit=10)
print("Solution: ")
msol.print_solution()


##############################################################################
# Display result
##############################################################################

def compact(name):
    # Example: H3-garden -> G3
    #           ^ ^
    loc, task = name[1:].split('-', 1)
    return task[0].upper() + loc

if msol and visu.is_visu_enabled():
    visu.timeline('Solution SchedCalendar')
    visu.panel()
    visu.pause(joe_calendar)
    visu.sequence(name='Joe',
                  intervals=[(msol.get_var_solution(t), type[t], compact(t.name)) for t in joe_tasks])
    visu.panel()
    visu.pause(jim_calendar)
    visu.sequence(name='Jim',
                  intervals=[(msol.get_var_solution(t), type[t], compact(t.name)) for t in jim_tasks])
    visu.show()
Пример #32
0
#-----------------------------------------------------------------------------
# Solve the model and display the result
#-----------------------------------------------------------------------------

# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=30000, TimeLimit=10)
print("Solution: ")
msol.print_solution()

if msol and visu.is_visu_enabled():
    load = [CpoStepFunction() for j in range(NB_RENEWABLE)]
    for m in MODES:
        itv = msol.get_var_solution(modes[m['id']])
        if itv.is_present():
            for j in range(NB_RENEWABLE):
                dem = m['demandRenewable'][j]
                if dem > 0:
                    load[j].add_value(itv.get_start(), itv.get_end(), dem)

    visu.timeline("Solution for RCPSPMM " + filename)
    visu.panel("Tasks")
    for t in TASKS:
        tid = t['id']
        visu.interval(msol.get_var_solution(tasks[tid]), tid, str(tid))
    for j in range(NB_RENEWABLE):
        visu.panel("R " + str(j + 1))
        visu.function(segments=[(INTERVAL_MIN, INTERVAL_MAX, CAPACITIES_RENEWABLE[j])], style='area', color='lightgrey')
        visu.function(segments=load[j], style='area', color=j)
    visu.show()
def compact(name):
    # Example: H3-garden -> G3
    #           ^ ^
    loc, task = name[1:].split('-', 1)
    return task[0].upper() + loc


# Solve model
print("Solving model....")
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
print("Solution: ")
msol.print_solution()

# Draw solution
if msol and visu.is_visu_enabled():
    visu.timeline('Solution SchedOptional', 0, DEADLINE)
    for w in range(NB_WORKERS):
        visu.sequence(name=WORKER_NAMES[w])
        for t in worker_tasks[w]:
            wt = msol.get_var_solution(t)
            if wt.is_present():
                if desc[t].skills[w] == max(desc[t].skills):
                    # Green-like color when task is using the most skilled worker
                    color = 'lightgreen'
                else:
                    # Red-like color when task does not use the most skilled worker
                    color = 'salmon'
                visu.interval(wt, color, compact(wt.get_name()))
    visu.show()