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/optimizerIeco.py
2025-01-26 17:26:49 +08:00

64 lines
1.9 KiB
Python

import csv
import numpy as np
import json
import matplotlib.pyplot as plt
colorList = json.load(open('color/config.json','r'))["color"]
data={}
with open('data/passenger.csv', 'r', encoding='utf-8') as f:
reader = csv.reader(f)
next(reader) # skip header row
for row in reader:
data[int(row[0])] = np.sum(np.array(row[1:4], dtype=int))
dataList = []
for i in range(2015,2020):
# print(data[i]/data[i-1])
dataList.append(data[i]/data[i-1])
# print(data[2023]/data[2022])
dataList.append(data[2023]/data[2022])
dataList = np.array(dataList)
avgGrowth = np.mean(dataList)
prediction = data[2023]*((avgGrowth)**(2025-2023))
print("predicting 2025 total passengers when maintaining current taxation rate:",prediction)
taxShift=0.03
torShift=1-0.054
curTaxationRate=1.0
def predictTotalPassengers(taxationRate):
return (prediction/(torShift**(curTaxationRate/taxShift)))*(torShift**(taxationRate/taxShift))
temp1 = np.log(prediction/(torShift**(curTaxationRate/taxShift)))
temp2 = np.log(torShift)
def tax(x):
return taxShift*(np.log(x)-temp1)/temp2
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
psgRange = predictTotalPassengers(np.arange(0.6,1.4,0.01))
from scipy.optimize import minimize_scalar
result = minimize_scalar(lambda x: -f1(x),bounds=(np.min(psgRange),np.max(psgRange)),method='bounded')
print(result)
plt.plot(psgRange,f1(psgRange),label='Ieco',color=colorList[0])
plt.plot(psgRange,tax(psgRange),label='tax(x)',color=colorList[1])
plt.xlabel('total passengers')
plt.ylabel('Ieco / taxation rate')
plt.plot(predictTotalPassengers(1),1,'o',label='maintain taxation rate',color=colorList[2])
plt.plot(result.x,f1(result.x),'o',label='optimal for Ieco',color=colorList[3])
plt.legend()
plt.savefig('result/taxation-and-f1.png')
plt.show()