version1 is stabled

This commit is contained in:
zjcOvO 2025-01-26 21:49:59 +08:00
parent fe228a1b93
commit 0868ed487e
4 changed files with 161 additions and 0 deletions

63
optimizerO-series.py Normal file
View File

@ -0,0 +1,63 @@
import numpy as np
import json
import matplotlib.pyplot as plt
colorList = json.load(open('color/config.json','r'))["color_pool"]
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)
for i in range(10):
C3=i*5
plt.plot(psgRange,f(psgRange),label='result, C3=%d'%C3,color=colorList[i])
# 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])
result = minimize_scalar(lambda x: -f(x),bounds=(np.min(psgRange),np.max(psgRange)),method='bounded')
plt.plot(result.x,f(result.x),'o',color=colorList[i])
print(result.x,tax(result.x),f(result.x))
plt.xlabel('total passengers')
plt.ylabel('Optimized objective function')
plt.legend(fontsize=8)
plt.savefig('result/O-ser1.png',dpi=1024,)
plt.show()
print("Optimal total passengers:",result.x)
print("Optimal taxation rate:",tax(result.x))
print("Score",f(result.x))

24
stability-plot.py Normal file
View File

@ -0,0 +1,24 @@
import json
import numpy as np
import matplotlib.pyplot as plt
colorList = json.load(open('color/config.json','r'))["color"]
import csv
with open('stability.csv', 'r') as f:
reader = csv.reader(f)
header = next(reader)
# next(reader)
data = [row for row in reader]
plt.figure(figsize=(6,5))
plt.bar(range(len(data)), [np.log(np.abs(float(row[2]))) for row in data] , color=colorList[0])
plt.plot([-1,len(data)],[0,0],color=colorList[2]) # x axis
plt.margins(0.01)
plt.xticks(range(0,len(data)), [row[3] for row in data], rotation=45)
plt.xlabel('Parameters abbr.',labelpad=-3)
plt.ylabel('Affect on Stability (log scale)')
plt.title('Different Parameters\'s Affect on Stability')
plt.savefig('result/stability-result.png',dpi=1024)
plt.show()

12
stability.csv Normal file
View File

@ -0,0 +1,12 @@
name,algorithm,gradient
Tax influences tourists,torShift**(1/taxShift),-38049184.08,TIT
Passenger influence on revenue,the slope of the passenger-revenue relation curve,87730.21866,R-K
Initial revenue,the interception of the passenger-revenue relation curve,-0.052009008,R-B
Carbon footprint per person,C2,-230200.9189,Cpi
Total Carbon footprint,Cb2,0.002691839,SCpi
social effect per person,C3,-24062.72963,Spi
maximum social effect bearage,Cb3,7.12E-05,SSpi
iceberg contribution,iceberg,0.001602255,IC
influence factor for ecomomy,influenceFactor[0],1574163.139,Weco
influence factor for environment,influenceFactor[1],-432635.705,Wenv
influence factor for society,influenceFactor[2],-100327.8061,Wsoc
1 name,algorithm,gradient
2 Tax influences tourists,torShift**(1/taxShift),-38049184.08,TIT
3 Passenger influence on revenue,the slope of the passenger-revenue relation curve,87730.21866,R-K
4 Initial revenue,the interception of the passenger-revenue relation curve,-0.052009008,R-B
5 Carbon footprint per person,C2,-230200.9189,Cpi
6 Total Carbon footprint,Cb2,0.002691839,SCpi
7 social effect per person,C3,-24062.72963,Spi
8 maximum social effect bearage,Cb3,7.12E-05,SSpi
9 iceberg contribution,iceberg,0.001602255,IC
10 influence factor for ecomomy,influenceFactor[0],1574163.139,Weco
11 influence factor for environment,influenceFactor[1],-432635.705,Wenv
12 influence factor for society,influenceFactor[2],-100327.8061,Wsoc

62
stabilityO.py Normal file
View File

@ -0,0 +1,62 @@
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,dtype=np.float64)
prediction = 2433827
taxShift=0.03
torShift=1-0.054
curTaxationRate=1.0
def tax(x):
temp1 = np.log(prediction/(torShift**(curTaxationRate/taxShift)))
temp2 = np.log(torShift)
return taxShift*(np.log(x)-temp1)/temp2
def predictTotalPassengers(taxationRate):
return (prediction/(torShift**(curTaxationRate/taxShift)))*(torShift**(taxationRate/taxShift))
RNGk = 37.648854
RNGb = 59397421.185785
def f1(x):
temp3=(curTaxationRate*(RNGk*(predictTotalPassengers(curTaxationRate))+RNGb))
return 5*((tax(x))*(RNGk*x+RNGb) / temp3 -1)+1
C2=1
Cb2=1e8
iceberg = -0.2
def f2(x):
return 1 - C2*x/Cb2 + iceberg
C3=1
Cb3=4e8
def f3(x):
return 1 - C3*x/Cb3
influenceFactor = np.array([0.21061,0.54848,0.24091],dtype=np.float64)
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')
plt.plot(psgRange,f(psgRange),color=colorList[0],label='case 0')
cur_x = iceberg
cur_y = result.x
tag = 1e-10
alt_x = iceberg
alt_y = minimize_scalar(lambda x: -f(x),bounds=(np.min(psgRange),np.max(psgRange)),method='bounded').x
while abs(alt_y-cur_y)<10:
iceberg += tag
alt_x = iceberg
alt_y = minimize_scalar(lambda x: -f(x),bounds=(np.min(psgRange),np.max(psgRange)),method='bounded').x
tag *= 2
plt.plot(psgRange,f(psgRange),color=colorList[1],label='case 1')
plt.legend()
plt.show()
print(cur_x,cur_y,alt_x,alt_y)
print((alt_y-cur_y)/(alt_x-cur_x))