-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(shock): derive shock-paraeter registry from PDL (#14) #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hackatro
wants to merge
2
commits into
main
Choose a base branch
from
14-derive-shock-parameter-registry-dynamically-from-pdl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,12 +109,12 @@ def step(self): | |
| # cap at capacity, compute all-in unit_price (commodity + freight) | ||
| # ------------------------------------------------------------------ | ||
|
|
||
| def _move(self, upstream, scenario_param: str = ""): | ||
| def _move(self, upstream, shock_key: tuple[str, str] | None = None): | ||
| """ | ||
| Pull an equal share of upstream output, ca at own capacity, | ||
| and compute the all-in price passed to the next chain node. | ||
|
|
||
| scenario_param: scenario param whose effective value scales this agent's capacity, via env.get_effective_value() | ||
| shock_key: PDL (entity, field) whoe effective value scales this agent's capacity | ||
| """ | ||
| margin = self.scenario.margin_transport | ||
|
|
||
|
|
@@ -135,7 +135,7 @@ def _move(self, upstream, scenario_param: str = ""): | |
| volume_in = total_volume / n_self | ||
|
|
||
| env = self.model.environment | ||
| effective_factor = env.get_effective_value(scenario_param) if scenario_param else 1.0 | ||
| effective_factor = env.get_effective_value(*shock_key) if shock_key else 1.0 | ||
|
|
||
| # effective capacity after applying port capacity shock | ||
| effective_capacity = self.capacity * effective_factor | ||
|
|
@@ -151,21 +151,21 @@ def _move(self, upstream, scenario_param: str = ""): | |
| # price = commodity price + freight fee per unit | ||
| # energy price factor raises transport operation costs | ||
| if self.quantity_available > 0: | ||
| energy_factor = env.get_effective_value("energy_price_factor") | ||
| energy_factor = env.get_effective_value("gas_supply", "price") | ||
| effective_costs = self.fixed_costs * energy_factor | ||
| freight_fee = (effective_costs / self.quantity_available) * (1.0 + margin) | ||
| self.unit_price = upstream_price + freight_fee | ||
| else: | ||
| self.unit_price = 0.0 | ||
|
|
||
|
|
||
| def _move_split(self, upstream_list, share: float, scenario_param: str = "", exclude_arg=False, exclude_usa=False): | ||
| def _move_split(self, upstream_list, share: float, shock_key: tuple[str, str] | None = None, exclude_arg=False, exclude_usa=False): | ||
| """ | ||
| Like _move, but routes only share fraction of total upstream volume through this port. | ||
| Used to split wholesaler output between Santos and Paranagua. | ||
|
|
||
| :param share: fraction of total wholesaler output for this port (e.g. 0.7 for Santos, 0.3 for Paranagua). | ||
| :param scenario_param: scenario param whose effective value scales this agent's capacity. | ||
| :param shock_key: PDL (entity, field) whoe effective value scales this agent's capacity | ||
| """ | ||
| margin = self.scenario.margin_transport | ||
| active_upstream = upstream_list.filter(lambda a: a.active) | ||
|
|
@@ -192,7 +192,7 @@ def _move_split(self, upstream_list, share: float, scenario_param: str = "", exc | |
| volume_in = (routable_volume * share) / n_self | ||
|
|
||
| env = self.model.environment | ||
| effective_factor = env.get_effective_value(scenario_param) if scenario_param else 1.0 | ||
| effective_factor = env.get_effective_value(*shock_key) if shock_key else 1.0 | ||
| effective_capacity = self.capacity * effective_factor | ||
|
|
||
| self.quantity_available = min(volume_in, effective_capacity) | ||
|
|
@@ -204,7 +204,7 @@ def _move_split(self, upstream_list, share: float, scenario_param: str = "", exc | |
| upstream_price = (total_value / total_volume) if total_volume > 0 else 0.0 | ||
|
|
||
| if self.quantity_available > 0: | ||
| energy_factor = env.get_effective_value("energy_price_factor") | ||
| energy_factor = env.get_effective_value("gas_supply", "price") | ||
| effective_costs = self.fixed_costs * energy_factor | ||
| freight_fee = (effective_costs / self.quantity_available) * (1.0 + margin) | ||
| self.unit_price = upstream_price + freight_fee | ||
|
|
@@ -244,7 +244,7 @@ def _step_sa_santos(self): | |
| self._move_split( | ||
| self.model.wholesalers, | ||
| share=self.scenario.santos_share, | ||
| scenario_param="port_capacity_santos", | ||
| shock_key=("santos_port", "supply"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| exclude_arg=True, | ||
| exclude_usa=True, | ||
| ) | ||
|
|
@@ -257,7 +257,7 @@ def _step_sa_paranagua(self): | |
| self._move_split( | ||
| self.model.wholesalers, | ||
| share=1.0 - self.scenario.santos_share, | ||
| scenario_param="port_capacity_paranagua", | ||
| shock_key=("paranagua_port", "supply"), | ||
| exclude_arg=True, | ||
| exclude_usa=True, | ||
| ) | ||
|
|
@@ -315,7 +315,7 @@ def _step_sea_arg(self): | |
| upstream_price = total_value / total_arg | ||
|
|
||
| if self.quantity_available > 0: | ||
| energy_factor = self.model.environment.get_effective_value("energy_price_factor") | ||
| energy_factor = self.model.environment.get_effective_value("gas_supply", "price") | ||
| effective_costs = self.fixed_costs * energy_factor | ||
| freight_fee = (effective_costs / self.quantity_available) * (1.0 + margin) | ||
| self.unit_price = upstream_price + freight_fee | ||
|
|
@@ -364,7 +364,7 @@ def _step_sea_usa(self): | |
| upstream_price = total_value / total_usa | ||
|
|
||
| if self.quantity_available > 0: | ||
| energy_factor = self.model.environment.get_effective_value("energy_price_factor") | ||
| energy_factor = self.model.environment.get_effective_value("gas_supply", "price") | ||
| effective_costs = self.fixed_costs * energy_factor | ||
| freight_fee = (effective_costs / self.quantity_available) * (1.0 + margin) | ||
| self.unit_price = upstream_price + freight_fee | ||
|
|
@@ -382,7 +382,7 @@ def _step_eu_rtm(self): | |
| + self.model.sea_lane_arg.filter(lambda a: a.active) | ||
| + self.model.sea_lane_usa.filter(lambda a: a.active) | ||
| ) | ||
| self._move(combined, scenario_param="port_capacity_rotterdam") | ||
| self._move(combined, shock_key=("rotterdam_port", "supply")) | ||
|
|
||
|
|
||
| def _step_eu_ham(self): | ||
|
|
@@ -393,6 +393,6 @@ def _step_eu_ham(self): | |
| """ | ||
| self._move( | ||
| self.model.sea_lane_paranagua, | ||
| scenario_param="port_capacity_hamburg", | ||
| shock_key=("hamburg_port", "supply"), | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| id,run_num,period_num,n_bra_farmers,n_arg_farmers,n_usa_farmers,n_wholesalers,n_transport_sa_santos,n_transport_sa_paranagua,n_sea_lane_santos,n_sea_lane_paranagua,n_sea_lane_arg,n_sea_lane_usa,n_transport_eu_rtm,n_transport_eu_ham,n_processors,n_feed_manufacturers,n_feed_traders,n_eu_farmers,farm_capacity_bra,farm_capacity_arg,port_capacity_santos,port_capacity_paranagua,port_capacity_rotterdam,port_capacity_hamburg,santos_share,fertilizer_price_factor,energy_price_factor,oil_mill_capacity,feed_mill_capacity,shock_ramp_steps,shock_onset_farm_bra,shock_end_farm_bra,shock_onset_farm_arg,shock_end_farm_arg,shock_onset_port_santos,shock_end_port_santos,shock_onset_port_paranagua,shock_end_port_paranagua,shock_onset_port_rotterdam,shock_end_port_rotterdam,shock_onset_port_hamburg,shock_end_port_hamburg,shock_onset_fertilizer,shock_end_fertilizer,shock_onset_energy,shock_end_energy,shock_onset_oil_mill,shock_end_oil_mill,shock_onset_feed_mill,shock_end_feed_mill,farm_size_sigma_bra,farm_size_sigma_eu,farm_size_seed,wholesaler_storage_capacity | ||
| 0,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,1.0,1.0,1.0,1.0,1.0,1.0,0.7,1.0,1.0,1.0,1.0,0,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0.0,0.0,42,2857.0 | ||
| 1,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.6,1.0,1.0,1.0,1.0,1.0,0.7,1.0,1.0,1.0,1.0,0,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0.4,0.4,42,2857.0 | ||
| 2,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.6,1.0,0.5,1.0,1.0,1.0,0.7,1.0,1.0,1.0,1.0,0,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0.4,0.4,42,2857.0 | ||
| id,run_num,period_num,n_bra_farmers,n_arg_farmers,n_usa_farmers,n_wholesalers,n_transport_sa_santos,n_transport_sa_paranagua,n_sea_lane_santos,n_sea_lane_paranagua,n_sea_lane_arg,n_sea_lane_usa,n_transport_eu_rtm,n_transport_eu_ham,n_processors,n_feed_manufacturers,n_feed_traders,n_eu_farmers,santos_share,shock_ramp_steps,farm_size_sigma_bra,farm_size_sigma_eu,farm_size_seed,wholesaler_storage_capacity | ||
| 0,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.7,0,0.0,0.0,42,2857.0 | ||
| 1,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.7,0,0.0,0.0,42,2857.0 |
8 changes: 4 additions & 4 deletions
8
src/provider_simenv/data/input/SimulatorScenarios_template.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| id,run_num,period_num,n_bra_farmers,n_arg_farmers,n_usa_farmers,n_wholesalers,n_transport_sa_santos,n_transport_sa_paranagua,n_sea_lane_santos,n_sea_lane_paranagua,n_sea_lane_arg,n_sea_lane_usa,n_transport_eu_rtm,n_transport_eu_ham,n_processors,n_feed_manufacturers,n_feed_traders,n_eu_farmers,farm_capacity_bra,farm_capacity_arg,port_capacity_santos,port_capacity_paranagua,port_capacity_rotterdam,port_capacity_hamburg,santos_share,fertilizer_price_factor,energy_price_factor,oil_mill_capacity,feed_mill_capacity,shock_ramp_steps,shock_onset_farm_bra,shock_end_farm_bra,shock_onset_farm_arg,shock_end_farm_arg,shock_onset_port_santos,shock_end_port_santos,shock_onset_port_paranagua,shock_end_port_paranagua,shock_onset_port_rotterdam,shock_end_port_rotterdam,shock_onset_port_hamburg,shock_end_port_hamburg,shock_onset_fertilizer,shock_end_fertilizer,shock_onset_energy,shock_end_energy,shock_onset_oil_mill,shock_end_oil_mill,shock_onset_feed_mill,shock_end_feed_mill,farm_size_sigma_bra,farm_size_sigma_eu,farm_size_seed,wholesaler_storage_capacity | ||
| 0,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,1.0,1.0,1.0,1.0,1.0,1.0,0.7,1.0,1.0,1.0,1.0,0,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0.0,0.0,42,2857.0 | ||
| 1,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.6,1.0,1.0,1.0,1.0,1.0,0.7,1.0,1.0,1.0,1.0,0,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0.4,0.4,42,2857.0 | ||
| 2,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.6,1.0,0.5,1.0,1.0,1.0,0.7,1.0,1.0,1.0,1.0,0,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0,365,0.4,0.4,42,2857.0 | ||
| id,run_num,period_num,n_bra_farmers,n_arg_farmers,n_usa_farmers,n_wholesalers,n_transport_sa_santos,n_transport_sa_paranagua,n_sea_lane_santos,n_sea_lane_paranagua,n_sea_lane_arg,n_sea_lane_usa,n_transport_eu_rtm,n_transport_eu_ham,n_processors,n_feed_manufacturers,n_feed_traders,n_eu_farmers,santos_share,shock_ramp_steps,farm_size_sigma_bra,farm_size_sigma_eu,farm_size_seed,wholesaler_storage_capacity | ||
| 0,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.7,0,0.0,0.0,42,2857.0 | ||
| 1,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.7,0,0.4,0.4,42,2857.0 | ||
| 2,1,365,10,5,8,3,1,1,1,1,1,1,1,1,3,3,3,10,0.7,0,0.4,0.4,42,2857.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still somewhat hard coded or not?
What happens if the PDL doesn't include bra or arg farmers at all?