最適化
May 09 2022
問題の範囲次に、上記の条件下で適切な製品ユニットを製造することにより、製品の売上を最大化するための最適なソリューションを見つけましょう。まず、「月光」をインポートします。まだインストールしていない場合— -pip次のようにターミナルからgekkoをインストールします。次に、パッケージをノートブックにインポートし、モデルインスタンスを呼び出します。

問題の範囲

それでは、上記の条件下で適切な製品ユニットを製造することにより、製品の売上を最大化するための最適なソリューションを見つけてみましょう。
まず、「月光」をインポートします。インストールしていない場合— -pip以下に示すように、ターミナルからgekkoをインストールします。

次に、パッケージをノートブックにインポートし、モデルインスタンスを呼び出します。
from gekko import gekko
#Create model instance
m = gekko()
- Tablet_units:いいえ。製造された錠剤の
- smartph_units:いいえ。製造されたスマートフォンの。
- prod_constr:これは各製品の(#units *それらを生成するのにかかる時間)を指定します
- total_sales:会社が最大額として取得する最終的な売上額
#Initiate variables
tablet_units = m.Var(value=1)
smartph_units = m.Var(value=1)
prod_constr = m.Var()
total_sales = m.Var()
#Production time to create each product type
tablet_time = 1.5
smartph_time = 2
#Sale price of each product stored as a constant value
tablet_price = 900
smartph_price = 1100
#Minimum units the stores need for each product
m.Equation(tablet_units>=500)
m.Equation(smartph_units>=200)
<gekko.gekko.EquationObj at 0x184f83a4220>
#Production constraint
m.Equation(prod_constr== (tablet_units*tablet_time)+(smartph_units*smartph_time))
m.Equation(prod_constr<=2999.5)
<gekko.gekko.EquationObj at 0x184f83a4730>
#Total sales
m.Equation(total_sales==(tablet_units*tablet_price)+(smartph_units*smartph_price))
<gekko.gekko.EquationObj at 0x184f83a4e50>
#Setting the objective function
m.Obj(-total_sales)
m.options.SOLVER = 1
m.options.SOLVER:ソルバーをAPOPTに設定して、整数の解を取得します。これは、製品単位が整数のみである必要があるためです。
これですべての設定が完了しました。ソリューションと呼びましょう!
m.solve()
apm 45.114.158.17_gk_model0 <br><pre> ----------------------------------------------------------------
APMonitor, Version 1.0.1
APMonitor Optimization Suite
----------------------------------------------------------------
--------- APM Model Size ------------
Each time step contains
Objects : 0
Constants : 0
Variables : 7
Intermediates: 0
Connections : 0
Equations : 6
Residuals : 6
Number of state variables: 7
Number of total equations: - 5
Number of slack variables: - 3
---------------------------------------
Degrees of freedom : -1
* Warning: DOF <= 0
----------------------------------------------
Steady State Optimization with APOPT Solver
----------------------------------------------
Iter Objective Convergence
0 -6.70000E+05 2.99950E+03
1 -1.72412E+06 0.00000E+00
2 -1.77970E+06 2.22045E-16
3 -1.77970E+06 2.22045E-16
4 -1.77970E+06 2.22045E-16
Successful solution
---------------------------------------------------
Solver : APOPT (v1.0)
Solution time : 1.290000000153668E-002 sec
Objective : -1779700.00000000
Successful solution
---------------------------------------------------
print('Total Tablet Units :' + str(tablet_units.value))
print('Total Smartphone Units:' +str(smartph_units.value))
print('Maximized total sales:' + str(total_sales.value))
Total Tablet Units :[1733.0]
Total Smartphone Units:[200.0]
Maximized total sales:[1779700.0]