예제 #1
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()
예제 #2
0
#-----------------------------------------------------------------------------

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])
            cost = ftardiness[t].get_value(itvsol.get_end())
            visu.function(segments=[(itvsol, cost, t.name)],
                          color=t.id,
                          style='interval')
            visu.function(segments=ftardiness[t], color=t.id)
    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()
예제 #4
0
##############################################################################

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


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

if msol and visu.is_visu_enabled():
    load = [CpoStepFunction() for j in range(nbResources)]
    for i in range(nbTasks):
        itv = msol.get_var_solution(tasks[i])
        for j in range(nbResources):
            if 0 < demands[i][j]:
                load[j].add_value(itv.get_start(), itv.get_end(), demands[i][j])

    visu.timeline("Solution for RCPSP " + filename)
    visu.panel("Tasks")
    for i in range(nbTasks):
        visu.interval(msol.get_var_solution(tasks[i]), i, tasks[i].get_name())
    for j in range(nbResources):
        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()
예제 #5
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()
##############################################################################

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


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

if msol and visu.is_visu_enabled():
    load = [CpoStepFunction() for j in range(nbResources)]
    for i in range(nbTasks):
        itv = msol.get_var_solution(tasks[i])
        for j in range(nbResources):
            if 0 < demands[i][j]:
                load[j].add_value(itv.get_start(), itv.get_end(), demands[i][j])

    visu.timeline("Solution for RCPSP " + filename)
    visu.panel("Tasks")
    for i in range(nbTasks):
        visu.interval(msol.get_var_solution(tasks[i]), i, tasks[i].get_name())
    for j in range(nbResources):
        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

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()
            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)

    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()
# 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()
예제 #11
0
    # 전체 인력 사용 수준 그래프
    print("workforce level for" + str(team))
    rcParams['figure.figsize'] = 15, 3
    workforce=CpoStepFunction()
    workforce_standard=CpoStepFunction()
    workforce_whole=CpoStepFunction()
    for key, value in acts.items():
        wf=sol.get_var_solution(act_var[key])
        workforce.add_value(wf.get_start(),wf.get_end(), acts[key].worker)

    workforce_whole.add_value(0, last_end, sum(worker))
    workforce_standard.add_value(0,last_end ,standard)

    # 공종 별 인력 사용 수준 그래프
    visu.panel(name="Workers")
    visu.function(segments=workforce, style='area', origin=0, horizon=last_end, color='lightgreen')
    visu.function(segments=workforce_standard, style='line', origin=0, horizon=last_end)
    visu.function(segments=workforce_whole, style='line', origin=0, horizon=last_end, color='blue')
    visu.show(pngfile="overall_workforce")

    print(worker)
    for i in range(len(worker)):
        workforce_bywork = CpoStepFunction()
        workforce_limit = CpoStepFunction()
        visu.panel(name="Work " + str(i + 1))

        for key, value in acts.items():
            if acts[key].process == "W" + str(i + 1):
                itv = sol.get_var_solution(act_var[key])
                workforce_bywork.add_value(itv.get_start(), itv.get_end(), acts[key].worker)
        workforce_limit.add_value(0, last_end, worker[i])
##############################################################################

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")
            visu.function(segments=ftardiness[t], color=t.id)
    visu.show()