Ejemplo n.º 1
0
# Associate plant openness to its load
for p in range(nbLocation):
      mdl.add(open[p] == (load[p] > 0))

# Add constraints
mdl.add(mdl.pack(load, cust, demand))

# Add objective
obj = mdl.scal_prod(fixedCost, open)
for c in range(nbCustomer):
    obj += mdl.element(cust[c], cost[c])
mdl.add(mdl.minimize(obj))

# Add KPIs
if compare_natural(context.model.version, '12.9') >= 0:
    mdl.add_kpi(mdl.sum(demand) / mdl.scal_prod(open, capacity), "Average Occupancy")
    mdl.add_kpi(mdl.min([load[l] / capacity[l] + (1 - open[l]) for l in range(nbLocation)]), "Min occupancy")


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

if context.visu_enabled:
    mdl.add_solver_listener(SolverProgressPanelListener(parse_log=True))

# Solve the model
print("Solve the model")
msol = mdl.solve(TimeLimit=20, LogPeriod=1000)
msol.write()
Ejemplo n.º 2
0
# Non-overlapping constraints. Avoid overlapping between tasks of each worker.
for worker_id, assignments in worker_tasks.items():
    mdl.add(modeler.no_overlap(assignments))


#  Create the Decision Optimization objective¶
# In this case, the sum of the skills of the assigned workers to each task will be maximized.

makespan = mdl.max(
    [
        modeler.end_of(assignment)
        for assignment in assignments
        for worker_id, assignments in worker_tasks.items()
    ]
)
mdl.add_kpi(makespan, "makespan")

total_skill = 0
for worker_id, assignments in worker_tasks.items():
    for a in assignments:
        total_skill += modeler.presence_of(a)


mdl.add(mdl.maximize(total_skill))
mdl.print_information()


msol = mdl.solve(TimeLimit=10)
msol.print_solution()