how to modify function to account for technology specific discount rate

33 Views Asked by At

I need to modify this function so that it can deal with a discount_rate that is now defined for all technologies while before it was equal for all technologies.

This is the original function: `def _calc_regional_cost_planning(self):

    self.totalcost_allregions = np.zeros((len(self.model_data.settings.years), 1))
    self.inv_allregions = 0
    years = -1 * np.arange(len(self.model_data.settings.years))

    for reg in self.model_data.settings.regions:

        totalcost_regional = np.zeros((len(self.model_data.settings.years), 1))

        for ctgry in self.model_data.settings.technologies[reg].keys():

            if ctgry != "Demand":

                totalcost_regional += cp.sum(
                    self.cost_inv_tax[reg][ctgry]
                    - self.cost_inv_sub[reg][ctgry]
                    + self.cost_fix[reg][ctgry]
                    + self.cost_fix_tax[reg][ctgry]
                    - self.cost_fix_sub[reg][ctgry]
                    + self.cost_variable[reg][ctgry]
                    + self.cost_decom[reg][ctgry]
                    - self.salvage_inv[reg][ctgry],
                    axis=1,
                )

                self.inv_allregions += self.cost_inv_fvalue[reg][ctgry]

                if ctgry != "Transmission" and ctgry != "Storage":
                    for emission_type in get_emission_types(self.model_data.settings.global_settings):
                        totalcost_regional += cp.sum(
                            self.emission_cost_by_region[reg][emission_type][ctgry], axis=1
                        )
                        
        for carr in self.unmetdemandbycarrier[reg].keys():
                        
            totalcost_regional += cp.sum(self.cost_unmet_demand[reg][carr],axis=1)

        discount_factor = (
            1 + self.model_data.regional_parameters[reg]["discount_rate"]["Annual Discount Rate"].values
        )

        totalcost_regional_discounted = cp.multiply(
            totalcost_regional, np.power(discount_factor, years)
        )
        self.totalcost_allregions += totalcost_regional_discounted`

this is part of an energy planning optimization model.

if I modify the discount_factor and the years to account for all the new values then i have a problem of dimensions in totalcost_regional_discounted = cp.multiply( totalcost_regional, np.power(discount_factor, years) ) because totalcost_regional_discounted has dimension (years+1,) while discount_rate is (years+1, number of techs).

I have also tried to modify it in a loop, it runs but then the result of the optimization model is wrong. `for ctgry in self.model_data.settings.technologies[reg].keys():

            for tech in self.model_data.settings.technologies[reg][ctgry]:
                
                if ctgry != "Demand":

                    discount_rate = self.model_data.regional_parameters[reg]["discount_rate"][ctgry]
                    discount_rate_reshaped = discount_rate.loc[:, tech].values
                    
                    discount_factor = (
                        1 + discount_rate_reshaped 
                    )
                                            
                    totalcost_reg_tech_discounted = cp.multiply(
                        totalcost_regional, np.power(discount_factor, years)
                    )
                    
                    self.totalcost_allregions += totalcost_reg_tech_discounted`

what i would like to get as an output is a totalcost_regional_discounted that is discounted based on the different discount rates for each technology

0

There are 0 best solutions below