#!/usr/bin/env python # coding: utf-8 # # Multi-period Dispatch Simulation # Multi-period dispatch economic dispatch (ED) and unit commitment (UC) is also available. # # In this case, we will show a 24-hour ED simulation. # In[1]: import ams import datetime # In[2]: print("Last run time:", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) print(f'ams:{ams.__version__}') # In[3]: ams.config_logger(stream_level=20) # ## Load Case # In[4]: sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'), setup=True, no_output=True,) # ## Reginonal Design # The disaptch models in AMS has develoepd with regional structure, and it can be inspected in device ``Region``. # In[5]: sp.Region.as_df() # In device ``Bus``, the Param ``zone`` indicates the zone of the bus. # Correspondingly, the region of generator and load are determined by the bus they connected. # In[6]: sp.Bus.as_df() # ## Multi-period Dispatch Base # In AMS, multi-period dispatch involves devices in group ``Horizon``. # This group is developed to provide time-series data for multi-period dispatch. # In[7]: sp.Horizon.models # We can get the idx of StaticGens. # In[8]: sp.StaticGen.get_idx() # In ``EDTSlot``, Param ``sd`` refers the load factors of each region in each time slot, and Param ``ug`` represents the generator commitment status in each time slot. # # To be more specific, EDT1 has ``sd=0.0793,0.0``, which means the load factor of region 1 is 0.0793 in the first time slot, and 0.0 in the second time slot. # # Next, EDT1 has ``ug=1,1,1,1``, and it means the commitment status of generator PV_1, PV_3, PV_5, and Slack_4 are all online. # In[9]: sp.EDTSlot.as_df() # ## Solve and Result # In[10]: sp.ED.init() # In[11]: sp.ED.run(solver='ECOS') # All decision variables are collected in the dict ``vars``. # In[12]: sp.ED.vars # As we can see, the generator output ``pg`` is a 2D array, and the first dimension is the generator index, and the second dimension is the time slot. # In[13]: sp.ED.pg.v # Partial results can be accessed with desired time slot. # In the retrieved result, the first dimension is the generator index, and the second dimension is the time slot. # In[14]: sp.ED.get(src='pg', attr='v', idx='PV_1', horizon=['EDT1']) # Or, get multiple variables in mutliple time slots. # In[15]: sp.ED.get(src='pg', attr='v', idx=['PV_1', 'PV_3'], horizon=['EDT1', 'EDT2', 'EDT3'])