An error with the copy model
回答済みTo whom it may interest,
I am coding an algorithm which I must change a model's objective in the copied model. I tried a lot. however I cannot find a way to handle the problem below.
PS C:\Users\90554> & C:/ProgramData/anaconda3/python.exe d:/Github/docentlik_jcp/stoc_trial_3.py
Enter the scenario number50
Set parameter Username
Academic license - for non-commercial use only - expires 2025-03-05
fstage 5
Traceback (most recent call last):
File "d:\Github\docentlik_jcp\stoc_trial_3.py", line 462, in <module>
res,elapsed,cg_values =stoc_chang(S,pval,7200)
File "d:\Github\docentlik_jcp\stoc_trial_3.py", line 339, in stoc_chang
obj_lagrangian1 = gp.LinExpr(sum(xlambda[i, t] * (-p[i,t,s] + Cg_hat[i, t] + sum(subprob1.getVarByName(f"q_in[{b}, {i}, {t}]") / dist for b in range(B)) - sum(subprob1.getVarByName(f"q_out[{b}, {i}, {t}]") / dist for b in range(B)) + L * prod1[i,t] - sum(subprob1.getVarByName(f"f{j}.{i}.{t}")for j in range(n) if i != j) + subprob1.getVarByName(f"Pg{i}.{t}")+ subprob1.getVarByName(f"delta{i}.{t}")+ sum(subprob1.getVarByName(f"f{i}.{j}.{t}") for j in range(n) if i != j)) for i in range(n) for t in range(1, T)))
File "d:\Github\docentlik_jcp\stoc_trial_3.py", line 339, in <genexpr>
obj_lagrangian1 = gp.LinExpr(sum(xlambda[i, t] * (-p[i,t,s] + Cg_hat[i, t] + sum(subprob1.getVarByName(f"q_in[{b}, {i}, {t}]") / dist for b in range(B)) - sum(subprob1.getVarByName(f"q_out[{b}, {i}, {t}]") / dist for b in range(B)) + L * prod1[i,t] - sum(subprob1.getVarByName(f"f{j}.{i}.{t}")for j in range(n) if i != j) + subprob1.getVarByName(f"Pg{i}.{t}")+ subprob1.getVarByName(f"delta{i}.{t}")+ sum(subprob1.getVarByName(f"f{i}.{j}.{t}") for j in range(n) if i != j)) for i in range(n) for t in range(1, T)))
File "d:\Github\docentlik_jcp\stoc_trial_3.py", line 339, in <genexpr>
obj_lagrangian1 = gp.LinExpr(sum(xlambda[i, t] * (-p[i,t,s] + Cg_hat[i, t] + sum(subprob1.getVarByName(f"q_in[{b}, {i}, {t}]") / dist for b in range(B)) - sum(subprob1.getVarByName(f"q_out[{b}, {i}, {t}]") / dist for b in range(B)) + L * prod1[i,t] - sum(subprob1.getVarByName(f"f{j}.{i}.{t}")for j in range(n) if i != j) + subprob1.getVarByName(f"Pg{i}.{t}")+ subprob1.getVarByName(f"delta{i}.{t}")+ sum(subprob1.getVarByName(f"f{i}.{j}.{t}") for j in range(n) if i != j)) for i in range(n) for t in range(1, T)))
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
I want to add a minimal working example. However it does not work for my model. So that I add a link of my code.
https://drive.google.com/file/d/1tBy18ugTEek918h8h5L-LqGIul7aCYSq/view?usp=drive_link
I appeciate all kind of helps,
Cheers,
Nazmi
-
正式なコメント
This post is more than two 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 Nazmi,
The error message:
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
is telling you that you are trying to divide ( "/" ) None by a float, and it shows you the line that it is happening:
obj_lagrangian1 = gp.LinExpr(sum(xlambda[i, t] * (-p[i,t,s] + Cg_hat[i, t] + sum(subprob1.getVarByName(f"q_in[{b}, {i}, {t}]") / dist for b in range(B)) - sum(subprob1.getVarByName(f"q_out[{b}, {i}, {t}]") / dist for b in range(B)) + L * prod1[i,t] - sum(subprob1.getVarByName(f"f{j}.{i}.{t}")for j in range(n) if i != j) + subprob1.getVarByName(f"Pg{i}.{t}")+ subprob1.getVarByName(f"delta{i}.{t}")+ sum(subprob1.getVarByName(f"f{i}.{j}.{t}") for j in range(n) if i != j)) for i in range(n) for t in range(1, T)))
In this line you are using division here:
subprob1.getVarByName(f"q_in[{b}, {i}, {t}]") / distand here
subprob1.getVarByName(f"q_out[{b}, {i}, {t}]") / distIf a variable doesn't exist with the name given as an argument to Model.getVarByName then this function returns none. To debug try and discover which names are returning None, and why.
- Riley
0
投稿コメントは受け付けていません。
コメント
2件のコメント