[英]Is there a docplex function for getting solution of more than one variables for using in lazy cut?
我的代碼的優化問題在Python(docplex)基礎上, 在這里,但我的切口是類似的東西sum(X) <= N + M*sum(Y, Z)
X, Y and Z
是決定瓦爾。 我不知道如何將X, Y, Z
的解傳遞給self.get_cpx_unsatisfied_cts([ct],
solution
, tolerance=1e-6)
。 當我使用self.get_values()
,我收到此錯誤: Error: Internal error in CPLEX solve: AttributeError: 'list' object has no attribute '_get_var_value'
有人可以幫忙嗎?
在 [here] 示例中( 使用延遲約束回調實現 TSP ),回調通過混合類MosdelCallbackMixin
連接到MosdelCallbackMixin
。 這個類有一個make_complete_solution
方法,它從回調內部返回一個解決方案對象(參見 docplex.mp.SolveSolution 的文檔)。
在第二步中, get_cpx_unsatisfied_cts
從給定的約束列表中返回未滿足的約束列表。 在您的情況下,如果您只需要檢查一個約束,使用is_satisfied
方法進行約束會更簡單,它需要一個解決方案和一個容差(默認為 1e-6,即:
if not myct.is_satisfied(sol, tolerance):
print(f" constraint {myct} is violated")
總結一下:
make_complete_solution
生成解決方案對象ct.is_satisfied
檢查是否滿足。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.