- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以使用 python 上的 pymoo 运行3 个目标、16 个约束、12 个变量问题,如果还有其他程序可以提供帮助,请告知?我使用了 pymoo 代码,但它一直提供此错误。
File "C:\Users\omar.elfarouk\Anaconda3\lib\sitepackages\pymoo\model\problem.py", line 286, in evaluate
CV = Problem.calc_constraint_violation(out["G"])
KeyError: 'G'
代码如下
```#from pyomo.environ import *
from pymoo.algorithms.nsga2 import NSGA2
from pymoo.factory import get_problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter
from pymoo.factory import get_termination
from pymoo.util import plotting
import autograd.numpy as anp
import numpy as np
from pymoo.util.misc import stack
from pymoo.model.problem import Problem
import numpy as np
import math```
```#Factors for the third party in the supply chain%%
U_Demand = 12000#normrnd(mn,std)%Monte carlo simulation mean 12000 unit%
alpha = 0.1#Percentage of rate of return of products from third party%
lamda = alpha * U_Demand
miu =0.1#Probability of havieng a returned product in a good working condition%
gamma=0.7#Probability of having a rerurned part after disassembly with good working condition%
Q_TP=(lamda*(miu))+(lamda*(1-miu)*gamma)#Quantity of the third party%
std = 200 # 10000 runslamda and %
#for daikin australia
pd_1 = 600#round(random('Normal',600,24.49));q
pd_2 = 60#round(random('Normal',60,7.749));
Z_var = U_Demand - pd_1-pd_2
#Transportation Costs#
TS_s = 5000 #Transportation cost for the supplier(From alexandria road to downtown cairo)%
TS_m = 5000 #Transportation cost for the manufacturer(Assumed to be almost fixed due to practicallity)%
TS_d = 5000 #Transportation cost for the distributer%
TS_rt = 5000 #Transportation cost for the retailer%
TS_tp = 5000 #Transportation cost for the third party%
#collection Costs%%
C_tp = 5.1 #collection cost of recovering used product from the customer%
#facility opening Costs%%
F_rt = 10000000 #facility opening cost for the recovery center(Assumed to be 10 million Egyptian pound)%
#Ordering Costs%%
S_s = 5.1
S_ms = 58.956
S_m1 = 700
S_m2 = 800
S_m3 = 850
S_d = 173.4
S_r = 204
S_tp = 42.5
#Holding Costs%%
H_s = 50.126
H_ms = 589.56
H_m = 1473.9
H_dr = 1734
H_rt = 2040
H_tp = 425.9571
#Production Rates%%
P_m1=200 #Production Rates assumed to be 200 unit per day for the power plant %%
P_m2=210
P_m3=220
#U_Demand = 400000 #Demand rate is asumed to be 400,000 unit per month%
P_m = P_m1+P_m2+P_m3 # Production rate of the manufacuter
#i_m #conunting of manufacturer%
#i_mp
#i_d #Counting of Distributer
##Factors for the third party in the supply chain##
alpha = 0.1 #Percentage of rate of return of products from third party%
lamda =(alpha*U_Demand)
miu =0.1 #Probability of havieng a returned product in a good working condition%
gamma=0.7 #Probability of having a rerurned part after disassembly with good working condition%
Q_TP =(lamda*(miu))+(lamda*(1-miu)*gamma) #Quantity of the third party%
#Values of supplied chain quantities
n_s = 5
n_m = 1 #1:2
n_d = 1
定义Pyomo 问题和约束
class MyProblem(Problem):
def __init__(self):
super().__init__(n_var=12,
n_obj=3,
n_constr=16,
xl=anp.array([0,0,0,0,0,0,0,0,0,0,0,0]),
xu=anp.array([12800000000000,12800000000000,12800000000000,12800000000000,12800000000000,12800000000000,12800000000000,12800000000000,12800000000000,12800000000000,12800000000000,12800000000000]))
def _evaluate(self, x, out, *args, **kwargs): #Defining the Objective and constrains#
Q_rt1 = x[:,0] # quantity of the retailer in the forward cycle
Q_rt2 = x[:,1] # quantity of the retailer in the forward cycle
Q_rt3 = x[:,2] # quantity of the retailer in the forward cycle
Q_d1 = x[:,3] # Quantity of the distributer
Q_d2 = x[:,4] # Quantity of the distributer
Q_d3 = x[:,5] # Quantity of the distributer
Q_m1 = x[:,6] # Quantity of the Manufacturer
Q_m2 = x[:,7] # Quantity of the Manufacturer
Q_m3 = x[:,8] # Quantity of the Manufacturer
Q_s1 = x[:,9] #Quantity of Supplied Parts
Q_s2 = x[:,10] #Quantity of Supplied Parts
Q_s3 = x[:,11] #Quantity of Supplied Parts
t_r= (U_Demand)/(x[:,0]) #Cycle time of the supply chain# #cycle time of the retailer
t_d = n_d * t_r #cycle time of the Distribiter
t_m = (n_m * n_d* t_r) #cycle time of the Manufacturer
t_s = n_s *n_m *n_d *t_r #cycle time of the supplier
t_tp = t_s #cycle time of the third party
S_jfS=30 #Job Index factor number of fixed jobs at the supplier assumed to be 30 fixed employees %
S_jfM=30 #Job index for the number of fixed jobs by Mamufacturer assumed to be 30 fixed employees %
S_jfD=30 #Job index for the number of fixed jobs by distributer assumed to be 30 fixed employees%
S_jfRT=30 #Job index for the number of fixed jobs by retialer assumed to be 30 fixed employees%
S_jfTP=20 #Job index for the number of fixed jobs by third party recovery assumed to be 20 fixed employees%
S_jvS=270 #Job Index factor number of variable jobs at the supplier assumed to be 270 workers per facility%
S_jvM=270 #Job index for the number of variable jobs by Mamufacturer 270 workers per facility%
S_jvD=270 #Job index for the number of variable jobs by distributer 270 workers per facility%
S_jvRT=270#Job index for the number of variable jobs by retialer 270 workers per facility%
S_jvTP=100#Job index for the number of variable jobs by third party recovery 100 workers per facility%
S_u=20 #Employee satisfaction factor of the refurbrished parts for the third party disassembler%
S_rt=30 #Customer satisfaction factor of the refurbrished parts%
S_ds=5 #Number of lost days at work% # Number of lost days from injuries or work damage at the suppliers / month%
S_dm=5 #Number of lost days from injuries or work damage at the manufactuer%
S_dd=5 #Number of lost days from injuries or work damage at the distributer%
S_drt=5 #Number of lost days from injuries or work damage at the retailer%
S_dtp=5 #Number of lost days from injuries or work damage at the third party%
#Enviromental Aspect of the supply chain (Emissions calculated from carbon footprint)%
E_q=10 #Emission factor from production line
E_tp=10 #Emission from wastes removal%
#Transportation emission cost%
E_ts=20 #Emission from Transportation made by the supplier%
E_tm=20 #Emission from Transportation made by the manufacturer%
E_td=20 #Emission from Transportation made by the distributer%
E_trt=20 #Emission from Transportation made by the retailer%
E_ttp=20 #Emission from Transportation made by the third party
i_s = 1
i_ss=np.arange(i_s,n_s+1,1)
tc_s1= list(range(i_s,n_s+1))
for i_s in i_ss:
tc_s1 = np.sum(((i_ss)/n_s)*Q_s1*t_s)
i_s=i_s + 1 # Adding value of Supplier integer#
tc_s4 = (tc_s1)
TC_s1 = (S_s*(1/(n_s*t_s)))+(((H_s+TS_s)/(n_s*(t_s)))*tc_s4) #cost of the supplier for component 1%
i_s= 1 #starting of the loop#
i_ss=np.arange(i_s,n_s+1,1)
#for w1 in w11:
tc_s2= list(range(i_s,n_s+1))
for i_s in i_ss:
tc_s2=np.sum((i_ss/n_s)*Q_s2*t_s) #((x(11)) +Q_TP#
i_s = i_s + 1 #Adding value of Supplier integer
tc_s5 = (tc_s2)
TC_s2 = (S_s*(1/(n_s*t_s)))+(((H_s+TS_s)/(n_s*(t_s)))*tc_s5)
i_s=1 #starting of the loop#
tc_s3= list(range(i_s,n_s+1))
for i_s in i_ss:
tc_s3=np.sum((i_ss/n_s)*Q_s3*t_s) #((x(12)+ Q_TP))%
i_s = i_s + 1 #Adding value of Supplier integer
tc_s6 = tc_s3
TC_s3 = (S_s*(1/(n_s*t_s)))+(((H_s+TS_s)/(n_s*(t_s)))*tc_s6)
i_m = 1 #starting of the loop#
i_mm=np.arange(i_m,n_m+1,1)
#for w1 in w11:
tc_m2= list(range(i_m,n_m+1))
for i_m in i_mm:
tc_m1 =np.arange(1,n_m,1) #Defining range with starting and ending point
tc_m2 = np.sum((1-((i_mm)/(n_m)))*((Q_m1)+Q_TP)) #Defining range with start & ending point#
i_m=i_m + 1 # Adding value of manufacturer integer#
tc_m3=(tc_m2)
tc_s7 =np.arange(1,n_s,1)
#Total cost of manufacturer#
tc_m = sum(tc_m1)
tc_s8 = sum(tc_s7)
TC_m =(H_m*((0.5*(Q_m1**2)*(1/P_m1))\
+(tc_m*(Q_m1*t_m*(1/(n_m**2))))))\
+((S_m1+TS_m)*(1/t_m))+((S_ms+TS_tp)*(1/t_s))\
+(H_ms*(1/t_s)*(((((Q_s1+Q_TP)*Q_m1)/P_m1))\
+(tc_s8*(((Q_s1)+Q_TP)/n_s)*(t_m-(Q_m1/P_m1)))))
TC_m2 =(H_m*((0.5*(Q_m2**2)*(1/P_m2))\
+(tc_m*(Q_m2*t_m*(1/(n_m**2))))))\
+((S_m2+TS_m)*(1/t_m))+((S_ms+TS_tp)*(1/t_s))\
+(H_ms*(1/t_s)*(((((Q_s2+Q_TP)*Q_m2)/P_m2))\
+(tc_s8*(((Q_s2)+Q_TP)/n_s)*(t_m-(Q_m2/P_m2)))))
TC_m3 =(H_m*((0.5*(Q_m3**2)*(1/P_m3))\
+(tc_m*(Q_m3*t_m*(1/(n_m**2))))))\
+((S_m3+TS_m)*(1/t_m))+((S_ms+TS_tp)*(1/t_s))\
+(H_ms*(1/t_s)*(((((Q_s3+Q_TP)*Q_m3)/P_m3))\
+(tc_s8*(((Q_s3)+Q_TP)/n_s)*(t_m-(Q_m3/P_m3)))))
i_d = 1
i_dd=np.arange(i_d,n_d+1,1)
#for w1 in w11:
tc_d1= list(range(i_d,n_d+1))
tc_d2= list(range(i_d,n_d+1))
tc_d3= list(range(i_d,n_d+1))
for i_d in i_dd:
tc_d1=np.sum(((i_dd)/(n_d))*(Q_d1)) #Cost of the Distributer for Product 1%%
tc_d2=np.sum(((i_dd)/(n_d))*(Q_d2)) #Cost of the Distributer for Product 2%%
tc_d3=np.sum(((i_d)/(n_d))*(Q_d3)) #Cost of the Distributer for Product 3%%
i_d = i_d + 1
tc_d_f = (tc_d1)+(tc_d2)+(tc_d3)
TC_d = (H_dr*(tc_d_f/n_d))+((S_d+TS_d)*(1/t_d)) #Total cost of the distributer of the supply chain%
#Total cost of retailer
TC_rt = (H_rt*((Q_rt1)/2))+((S_r+TS_rt)*(1/t_r)) #Cost of the retailer%%
TC_rt2 = (H_rt*(Q_rt2/2))+((S_r+TS_rt)*(1/t_r)) #Cost of the retailer for product 2%%
TC_rt3 = (H_rt*((Q_rt3)/2))+((S_r+TS_rt)*(1/t_r)) #Cost of the retailer for product 3%%
#Total cost of third party recovery
TC_tp = ((H_tp/2)*Q_TP)+((S_tp+TS_tp)*(1/t_tp))
S_jfS=30 #Job Index factor number of fixed jobs at the supplier assumed to be 30 fixed employees %
S_jfM=30 #Job index for the number of fixed jobs by Mamufacturer assumed to be 30 fixed employees %
S_jfD=30 #Job index for the number of fixed jobs by distributer assumed to be 30 fixed employees%
S_jfRT=30 #Job index for the number of fixed jobs by retialer assumed to be 30 fixed employees%
S_jfTP=20 #Job index for the number of fixed jobs by third party recovery assumed to be 20 fixed employees%
S_jvS=270 #Job Index factor number of variable jobs at the supplier assumed to be 270 workers per facility%
S_jvM=270 #Job index for the number of variable jobs by Mamufacturer 270 workers per facility%
S_jvD=270 #Job index for the number of variable jobs by distributer 270 workers per facility%
S_jvRT=270#Job index for the number of variable jobs by retialer 270 workers per facility%
S_jvTP=100#Job index for the number of variable jobs by third party recovery 100 workers per facility%
S_u=20 #Employee satisfaction factor of the refurbrished parts for the third party disassembler%
S_rt=30 #Customer satisfaction factor of the refurbrished parts%
#Number of lost days at work%
S_ds=5 # Number of lost days from injuries or work damage at the suppliers / month%
S_dm=5 #Number of lost days from injuries or work damage at the manufactuer%
S_dd=5 #Number of lost days from injuries or work damage at the distributer%
S_drt=5 #Number of lost days from injuries or work damage at the retailer%
S_dtp=5 #Number of lost days from injuries or work damage at the third party%
#Enviromental Aspect of the supply chain (Emissions calculated from carbon footprint)%
E_q=10 #Emission factor from production line
E_tp=10 #Emission from wastes removal%
#Transportation emission cost%
E_ts=20 #Emission from Transportation made by the supplier%
E_tm=20 #Emission from Transportation made by the manufacturer%
E_td=20 #Emission from Transportation made by the distributer%
E_trt=20 #Emission from Transportation made by the retailer%
E_ttp=20 #Emission from Transportation made by the third party%
#Cycle time%
EQO = TC_s1+TC_s2+TC_s3+TC_m+TC_m2+TC_m3+TC_d+TC_rt\
+TC_rt2+TC_rt3+TC_tp
# Economical aspect#
LSC =(S_jfS+S_jfM+S_jfD+S_jfRT+S_jfTP)\
+((S_jvS*Q_s1)+(S_jvD*Q_d1)+(S_jvM*Q_m1)\
+(S_jvRT*Q_rt1)+(S_jvTP*Q_TP))\
+(S_u*(U_Demand))+(S_rt*Q_rt1)-(S_ds*Q_s1)\
+(S_dd*Q_d1)+(S_dm*Q_m1)+(S_drt*Q_rt1)\
+(S_dtp*Q_TP)#Social aspect equation%
ESC=(E_q*(Q_s1+Q_d1+Q_m1+Q_rt1))\
+(E_ts*(1/t_s))+(E_td*(1/t_d))\
+(E_tm*(1/t_m))+(E_trt*(1/t_r))\
+(E_ts*(1/t_tp))+(E_tp*Q_TP) #Enviromental aspect
w1 = 1
w2 = 1
w3 = 1
f1 = EQO*w1
f2 = LSC*w2
f3 = ESC*w3
g1 = -x[:,0]+U_Demand
g2 = -x[:,1]+U_Demand
g3 = -x[:,2]+U_Demand
g4 = -f1-f2-f3
g5 = -((x[:,9])+Q_TP)+(n_s*x[:,6])
g6 =-((x[:,10])+Q_TP)+(n_s*x[:,7])
g7 =-((x[:,11])+Q_TP)+(n_s*x[:,8])
g8 =(n_m*(x[:,3]))-x[:,6]
g9 =(n_m*(x[:,4]))-x[:,7]
g10 = (n_m*(x[:,5]))-x[:,8]
g11 = -x[:,3]+(n_d*x[:,0])
g12 = -x[:,4]+ (n_d*x[:,1])
g13 = -x[:,5]+ (n_d*x[:,2])
g14 = -x[:,0]
g15 = -x[:,1]
g16 = -x[:,2]
out["F"] = anp.column_stack([f1, f2, f3])
out["G"] = anp.column_stack([g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12,\
g13, g14, g15, g16])
problem = MyProblem()
```
使用 NSGA
运行 算法```
#print(res)
from pymoo.algorithms.nsga2 import NSGA2
algorithm = NSGA2()
#from pymoo.factory import get_algorithm
algorithm = NSGA2(pop_size=100)
termination = get_termination("f_tol", tol=0.001, n_last=20, n_max_gen=1000, nth_gen=10)
algorithm = NSGA2(pop_size=100, eliminate_duplicates=True)
res = minimize(MyProblem(),
algorithm,
termination,
seed=1,
pf=problem.pareto_front(use_cache=False),
save_history=True,
verbose=True)
#res = minimize(objective,x0,algorithm,bounds=bnds,constraints=cons('n_gen', 200))
#minimize(objective,x0,method='COBYLA',bounds=bnds,constraints=cons)
plot = Scatter()
plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7)
plot.add(res.F, color="red")
plot.show()
```
可以使用 Pymoo 优化工具运行模型,或者如果有另一个 Python 中的工具 可以支持多目标 (3 objective , 16 约束和 12 变量类型的问题)
最佳答案
免责声明:我是 pymoo 的主要开发人员。
我刚刚看了你的代码。请下次尝试发布一个最小的例子。这让我和其他人更容易帮助你。另外,我想提一下 pyomo 和 pymoo 是两个不同的框架。
问题不在于 pymoo 本身,而在于您如何定义 _evaluate
方法。如果仔细查看 __init__
方法,您会发现您没有覆盖 _evaluate
方法,而是在构造函数中定义它。如果您在 def _evaluate(self, x, out, *args, **kwargs):
行之后删除了代码中的所有内容,那么您的方法实际上被调用了(实际情况并非如此现在)。
请查看我们的入门指南,了解如何正确定义问题: https://pymoo.org/getting_started.html
关于python - pymoo 运行多目标函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59444909/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!