Issues when modelling the BEST-WORST criteria weight extraction method
回答済みHello everyone,
I am trying to model the best-worst criteria weight extraction method (BWM)
which is very simple. The BWM looks like this:
where m is the number of criteria, and the wj are the continuous variables that I am trying to find. ejw and ebj are numeric values.
The issue is somewhere with the constraints with absolute values. I have created auxiliary variables to store the terms inside the absolute values but to no avail. The program still returns "TypeError: must be real number, not GenExprAbs". My code looks like this:
BWM = Model()
a = {}
num_criteria = 16
for criterion in range(1,num_criteria+1):
a[f"w_C{criterion}"] = BWM.addVar(vtype = gp.GRB.CONTINUOUS, name = f"w_C{criterion}")
a[f"wb - ebj*w_C{criterion}"] = BWM.addVar(vtype = gp.GRB.CONTINUOUS, name = f"wb - ebj*w_C{criterion}")
a[f"w_C{criterion} - ejw*ww"] = BWM.addVar(vtype = gp.GRB.CONTINUOUS, name = f"wb - ebj*w_C{criterion}")
X = BWM.addVar(vtype = gp.GRB.CONTINUOUS, name = "X")
BWM.update()
BWM.setObjective(X)
BWM.ModelSense = gp.GRB.MINIMIZE
Wb = "C9"
Ww = "C12"
for criterion in range(1,num_criteria+1):
ebj = df_criteria.loc[df_criteria["Criteria"] == f"C{criterion}"]["Best over Other"].values[0]
ejw = df_criteria.loc[df_criteria["Criteria"] == f"C{criterion}"]["Other over Worst"].values[0]
BWM.addConstr(lhs = gp.abs_(a[f"wb - ebj*w_C{criterion}"]), sense = gp.GRB.LESS_EQUAL, rhs = X)
BWM.addConstr(lhs = gp.abs_(a[f"w_C{criterion} - ejw*ww"]), sense = gp.GRB.LESS_EQUAL, rhs = X)
BWM.addConstr(lhs = a[f"wb - ebj*w_C{criterion}"], sense = gp.GRB.EQUAL,
rhs = a[f"w_{Wb}"]- ebj*a[f"w_C{criterion}"])
BWM.addConstr(lhs = a[f"w_C{criterion} - ejw*ww"], sense = gp.GRB.EQUAL,
rhs = a[f"w_C{criterion}"] - ejw*a[f"w_{Ww}"])
Any help is welcome.
Best regards,
Milovan
-
正式なコメント
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Milovan,
Note that the addGenConstrAbs method has slightly different arguments compared to the addConstr method.
You should try
BWM.addConstr(X == gp.abs_(a[f"wb - ebj*w_C{criterion}"]))
BWM.addConstr(X == gp.abs_(a[f"w_C{criterion} - ejw*ww"]))Note that it is not possible to directly model \(X \leq |a|\). To model an inequality with the absolute function, you have to introduce an additional auxiliary variable \(Y\) to model \(X \leq Y\) and \(Y = |a|\).
On a side note, it is strongly recommended to avoid using names with whitespaces. If possible, you should replace whitespaces by, e.g., '_' or any character you prefer.
Best regards,
Jaromił0 -
Thank you Jaromił. This clarified some things for me.
Now my model works as intended.Best regards,
Milovan0
投稿コメントは受け付けていません。

コメント
3件のコメント