def allow_shedding(self, times, resolve=False): self.shedding_mode = True self._set_load_shedding(True) if not user_config.economic_wind_shed: logging.debug('allowing non-controllable generation shedding') self._set_gen_shedding(True) const_times = times.non_overlap() if resolve else times # make load power into a variable instead of a param for load in self.loads(): try: load.create_variables(times) # need all for the .set attrib load.create_constraints(const_times) except RuntimeError: # load already has a power variable and shedding constraint pass if not user_config.economic_wind_shed: for gen in filter(lambda gen: gen.shedding_mode, self.get_generators_noncontrollable()): # create only the power_used var, don't reset the power param gen.create_variables_shedding(times) gen.create_constraints(const_times) # recalc the power balance constraint for bus in self.buses: for time in const_times: bus._remove_component('power balance', time) bus.create_constraints(const_times, self.Bmatrix, self.buses, include_children=False) # reset objective self.reset_objective() self.create_objective(const_times) # re-create system cost constraints self._remove_component('system_cost_first_stage') self._remove_component('system_cost_second_stage') if self._has_reserve: self._remove_component('reserve') self.create_constraints(const_times, include_children=False) # recreating all constraints would be simpler # but would take a bit longer # self.create_constraints(const_times, include_children=True) if self.is_stochastic: # need to recreate the scenario tree variable links stochastic.define_stage_variables(self, times) # and the stochastic instance stochastic.create_problem_with_scenarios(self, times)
def create_problem(power_system, times, scenario_tree=None, stage_number=None, rerun=False): """Create an optimization problem.""" logging.debug('initialized problem') power_system.create_variables(times) logging.debug('created variables') power_system.create_objective(times) logging.debug('created objective') power_system.create_constraints(times) logging.debug('created constraints') if scenario_tree is not None and sum(scenario_tree.shape) > 0 and not rerun: stochastic.construct_simple_scenario_tree( power_system, times, time_stage=stage_number) stochastic.define_stage_variables(power_system, times) stochastic.create_problem_with_scenarios(power_system, times) return
def create_problem(power_system, times, scenario_tree=None, stage_number=None, rerun=False): """Create an optimization problem.""" logging.debug('initialized problem') power_system.create_variables(times) logging.debug('created variables') power_system.create_objective(times) logging.debug('created objective') power_system.create_constraints(times) logging.debug('created constraints') if scenario_tree is not None and sum( scenario_tree.shape) > 0 and not rerun: stochastic.construct_simple_scenario_tree(power_system, times, time_stage=stage_number) stochastic.define_stage_variables(power_system, times) stochastic.create_problem_with_scenarios(power_system, times) return