This repository has been archived on 2025-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
Files_for_MM/optimizerO.py
2025-01-26 17:26:49 +08:00

59 lines
1.7 KiB
Python

import numpy as np
import json
import matplotlib.pyplot as plt
colorList = json.load(open('color/config.json','r'))["color"]
psgRange=np.arange(1e6,5e6,1e5)
prediction = 2433827
taxShift=0.03
torShift=1-0.054
curTaxationRate=1.0
temp1 = np.log(prediction/(torShift**(curTaxationRate/taxShift)))
temp2 = np.log(torShift)
def tax(x):
return taxShift*(np.log(x)-temp1)/temp2
def predictTotalPassengers(taxationRate):
return (prediction/(torShift**(curTaxationRate/taxShift)))*(torShift**(taxationRate/taxShift))
RNGk = 37.648854
RNGb = 59397421.185785
temp3=(curTaxationRate*(RNGk*(predictTotalPassengers(curTaxationRate))+RNGb))
def f1(x):
return 5*((tax(x))*(RNGk*x+RNGb) / temp3 -1)+1
C2=1
Cb2=1e8
def f2(x):
return 1 - C2*x/Cb2 - 0.2
C3=1
Cb3=4e8
def f3(x):
return 1 - C3*x/Cb3
influenceFactor = np.array([0.21061,0.54848,0.24091])
def f(x):
return f1(x)*influenceFactor[0] + f2(x)*influenceFactor[1] + f3(x)*influenceFactor[2]
from scipy.optimize import minimize_scalar
result = minimize_scalar(lambda x: -f(x),bounds=(np.min(psgRange),np.max(psgRange)),method='bounded')
print(result)
plt.plot(psgRange,f(psgRange),label='result',color=colorList[0])
plt.plot(psgRange,f1(psgRange),label='Ieco',color=colorList[1])
plt.plot(psgRange,f2(psgRange),label='Ienv',color=colorList[2])
plt.plot(psgRange,f3(psgRange),label='Isoc',color=colorList[3])
plt.plot(result.x,f(result.x),'o',label='optimal',color=colorList[4])
plt.xlabel('total passengers')
plt.ylabel('Optimized objective function')
plt.legend()
plt.savefig('result/O.png')
plt.show()
print("Optimal total passengers:",result.x)
print("Optimal taxation rate:",tax(result.x))
print("Score",f(result.x))