Priority Model: Penalty for non-consideration of job priority -> Indicator if difference is positive or negativ
ユーザーの入力を待っています。Dear Ladies and Gentleman,
I am trying to build a simple priorisation model, which i later want to include into an multi-objective model i do already have.
The simple priorization approach shall be like this. I consider multiple jobs. Each job has a priority p_i and each job has a makespan C_i.
The problem is that in some situations everything is fine, in others the model is infeasable, which I do not understand.
Also I did carefully had a look to this post: https://support.gurobi.com/hc/en-us/community/posts/360078062211-Conditional-statement-in-Gurobi
I did append further information here:
I would be very thankful for any help. I also appended the model code.
Kind regards
Armin
from gurobipy import *
import numpy as np
#### Author: bch
#### This model adds a penalty to not respected priorities
#### The less the priority is respected, the higher the penalty.
m = Model('01_simple_priority_approach')
########################################################
# Sets
########################################################
jobs = {'o1', 'o2', 'o3'}
########################################################
# Parameters
########################################################
job_cmakes = {
('o1'): 10,
('o2'): 11,
('o3'): 8
}
job_priority = {
('o1'): 1,
('o2'): 2,
('o3'): 3
}
########################################################
# Decision Variables
########################################################
diff = {}
for i in jobs:
for j in jobs:
if i != j:
diff[i, j] = m.addVar(vtype= GRB.CONTINUOUS, name='difference_%s_%s'%(i,j))
s = {}
for i in jobs:
for j in jobs:
if i != j:
s[i, j] = m.addVar(vtype= GRB.BINARY, name='aux_%s_%s'%(i,j))
z = {}
for i in jobs:
for j in jobs:
if i != j:
z[i, j] = m.addVar(vtype= GRB.BINARY, name='z_%s_%s'%(i,j))
########################################################
# Objective Function
########################################################
objective_exp = LinExpr()
for i in jobs:
for j in jobs:
if i != j:
objective_exp = objective_exp + z[i,j] * abs(job_priority[i]-job_priority[j])
m.ModelSense=GRB.MINIMIZE
m.setObjective(objective_exp)
print()
print("###################################")
print("########### Priorities #############")
print(job_priority)
print()
print()
print("###################################")
print("############ Cmakes ###############")
print(job_cmakes)
print()
########################################################
# Constraints
########################################################
print()
print("###################################")
print("######### Constraints #############")
print()
for i in jobs:
for j in jobs:
if i != j:
if job_priority[j]<=job_priority[i]:
print("-----")
print("i:", i, "j:", j)
m.addConstr(diff[i,j] == (job_cmakes[i] - job_cmakes[j])) #diff[i,j]
m.addConstr((s[i,j]==0) >> (diff[i,j]<=0), name = 'indicator0_%s_%s' % (i,j))
#m.addConstr((s[i,j]==1) >> (diff[i,j] >=0), name = 'indicator1_%s_%s' % (i,j))
for i in jobs:
for j in jobs:
if i != j:
m.addConstr((s[i,j]>=0), name = 's_basic_%s_%s' % (i,j))
m.addConstr((z[i,j]>=s[i,j]), name = 'z_basic_%s_%s' % (i,j))
########################################################
# Solve
########################################################
m.optimize()
# export model
m.write('01_simple_priority_approach.lp')
########################################################
# Output
########################################################
if m.SolCount > 0:
print('The count of found solutions is %i' % (m.SolCount))
m.printAttr('X')
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Armin,
The reason why the script above leads to an infeasible model is that continuous variables have a default lower bound of 0, i.e., your diff variables are not allowed to have negative values. You can just add
..., lb=-GRB.INFINITY, ...
to your addVar() call for the diff variables. Then, a solution of 1 is found for the model.
Is that correct?Best regards,
Mario0
投稿コメントは受け付けていません。
コメント
2件のコメント