開始使用免費開始

調整 MILP

禮服與燕尾服公司調整了部分營運內容,需要你依照新的設定來最佳化利潤。

原本的利潤公式是 $545g + 330t$,其中 \(g\) 表示禮服數量,\(t\) 表示燕尾服數量。 限制條件相同:$6g+4t<=40$、$3g+t<=20$。

公司想把燕尾服的利潤提高 10%,而且 S 先生現在每週只能工作 30 小時。

milpLinearConstraintBounds 已為你載入。

本練習屬於課程

Python 最佳化入門

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Adjust the objective
result = milp([____, ____],
              integrality=[1, 1],
              bounds=Bounds([0, 0], [20, 12]), 
              constraints=LinearConstraint([[6, 4], [3, 1]], ub=[40, 20]))

print(result.message)
print(f'The optimal number of gowns produced is: {result.x[0]:.2f}')
print(f'The optimal number of tuxedos produced is: {result.x[1]:.2f}')
print(f'The firm made: ${-result.fun:.2f}')
編輯並執行程式碼