max_dm_kW = 150.0 #Maximum demand(kW)
pf = 0.85 #Average power factor
rate = 90.0 #Cost of maximum demand(Rs/kVA)
E_rate = 0.3 #Cost of energy consumed(Rs)
lf = 0.65 #Annual load factor
max_dm_kVA = max_dm_kW/pf #Maximum demand(kVA)
annual_chg_kVA = rate*max_dm_kVA #Annual fixed charges based on max demand(Rs)
E_kWh = lf*365*24*max_dm_kW #Energy consumed per annum(kWh)
annual_E_chg = E_kWh*E_rate #Annual energy charges(Rs)
annual_elect_charge = annual_chg_kVA + annual_E_chg #Annual electricity charge to be paid(Rs)
print('Annual electricity charges to be paid by consumer = Rs %.2f' %annual_elect_charge)
P = 75.0 #Power(kW)
cost_plant = 3000.0 #Cost of plant(Rs/kW)
cost_td = 30.0*10**5 #Cost of transmission & distribution(Rs)
interest = 0.15 #Interest,insurance charges(/annum)
depreciation = 0.05 #Depreciation(/annum)
cost_fix_mt = 4.0*10**5 #Fixed maintainance(Rs)
cost_var_mt = 6.0*10**5 #Variable maintainance(Rs)
cost_fuel = 10.0*10**6 #Fuel cost(Rs/annum)
cost_opr = 3.0*10**6 #Operation cost(Rs/annum)
max_demand = 70.0 #Maximum demand(MW)
df = 1.6 #Diversity factor b/w consumers
lf = 0.6 #Annual load factor
dividend = 10**6 #Dividend to shareholders(Rs/annum)
per_L = 0.10 #Total energy loss(% of generated energy)
cost = cost_plant*P*1000 #Cost of plant(Rs)
per_value = interest+depreciation #Total interest & depreciation(/annum)
cost_fix_ann = (cost+cost_opr)*per_value+cost_fix_mt+dividend #Total fixed cost(Rs)
cost_var_ann = cost_fuel+cost_opr+cost_var_mt #Total running cost(Rs)
E_gen_ann = max_demand*1000*24*365*lf #Energy generated per annum(kWh)
E_loss = per_L*E_gen_ann #Energy losses(kWh)
E_sold = E_gen_ann - E_loss #Energy sold(kWh)
sum_max_demand = df*max_demand*1000 #Sum of maximum demand of consumers(kW)
charge_max_demand = cost_fix_ann/sum_max_demand #Charge to consumers per kW of max demand per year(Rs)
charge_energy = cost_var_ann/E_sold*100 #Charge for energy(paise per kWh)
print('Two-part tariff is :')
print('Rs %.2f per kW of maximum demand per year + %.1f paise per kWh consumed' %(charge_max_demand,charge_energy))
P_D = 500.0 #Total load(MW)
b_1 = 15.0 #Beta value of controllable thermal plant C1
g_1 = 0.012 #Gamma value of controllable thermal plant C1
b_2 = 16.0 #Beta value of controllable thermal plant C2
g_2 = 0.018 #Gamma value of controllable thermal plant C2
b_3 = 19.0 #Beta value of controllable thermal plant C3
g_3 = 0.020 #Gamma value of controllable thermal plant C3
l = (P_D+((b_1/(2*g_1))+(b_2/(2*g_2))+(b_3/(2*g_3))))/((1/(2*g_1))+(1/(2*g_2))+(1/(2*g_3))) #Lambda value which is a Lagrange multiplier
P_G1 = (l - b_1)/(2*g_1) #(MW)
P_G2 = (l - b_2)/(2*g_2) #(MW)
P_G3 = (l - b_3)/(2*g_3) #(MW)
C1 = 1500.0 + b_1*P_G1 + g_1*P_G1**2 #Fuel cost of plant C1(Rs/hr)
C2 = 2000.0 + b_2*P_G2 + g_2*P_G2**2 #Fuel cost of plant C2(Rs/hr)
C3 = 1000.0 + b_3*P_G3 + g_3*P_G3**2 #Fuel cost of plant C3(Rs/hr)
C = C1 + C2 + C3 #Total fuel cost(Rs/hr)
print('Value of λ from equation(10.14) = %.3f' %l)
print('Optimal scheduling of thermal plant C1 = %.2f MW' %P_G1)
print('Optimal scheduling of thermal plant C2 = %.2f MW' %P_G2)
print('Optimal scheduling of thermal plant C3 = %.2f MW' %P_G3)
print('Total cost , C = Rs %.2f/hr' %C)