59 lines
1.1 KiB
Python
59 lines
1.1 KiB
Python
import math
|
|
import json
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
colorList = json.load(open('color/config.json','r'))["color"]
|
|
|
|
p=3
|
|
p1=100
|
|
d=0.5
|
|
p2=25
|
|
p3=25
|
|
cp=500
|
|
c=15
|
|
cmax=400
|
|
cb=200
|
|
m=0.01
|
|
r=0.85
|
|
|
|
fac1=0.0625
|
|
fac2=0.1875*0.2
|
|
fac3=0.4375
|
|
|
|
def t(x):
|
|
return max(0,500-2.2*x)
|
|
def f1(x):
|
|
return x*t(x)+x/d*p1+x*(1-r)*p2+x*r*p3
|
|
def f2(x):
|
|
return x*c+cp*x/d
|
|
def f3(x):
|
|
return x/cb+x/(x+p)+m*x
|
|
def f(x):
|
|
return fac1*f1(x)-fac2*f2(x)-fac3*f3(x)
|
|
|
|
for x in np.arange(0.2,cb,0.2):
|
|
if (f2(x)>cmax):
|
|
cb = x
|
|
break
|
|
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
ranging=np.arange(0.01,cb,0.01)
|
|
plt.plot(ranging,[f(x) for x in ranging],color=colorList[0],label='f(x)')
|
|
# plt.plot(ranging,[f1(x) for x in ranging],color=colorList[1],label='f1(x)')
|
|
# plt.plot(ranging,[f2(x) for x in ranging],color=colorList[2],label='f2(x)')
|
|
# plt.plot(ranging,[f3(x) for x in ranging],color=colorList[3],label='f3(x)')
|
|
|
|
plt.xlabel('x')
|
|
plt.ylabel('f(x)')
|
|
plt.legend()
|
|
plt.savefig('result/optimized1.png')
|
|
plt.show()
|
|
|
|
from scipy.optimize import minimize
|
|
|
|
res = minimize(lambda x: -f(x), 0.2)
|
|
print(res)
|
|
print(res.x,f(res.x)) |