-
Notifications
You must be signed in to change notification settings - Fork 43
Tariff Region #661
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
base: main
Are you sure you want to change the base?
Tariff Region #661
Changes from 7 commits
9a090ce
1afed45
f223a9e
dcfba68
f5d7b56
7e84754
5c6bf1e
9fc9c9d
7583c75
0b7a179
e69e482
ce88ca1
3545250
486f288
0776f75
d6b2f7a
7d1c71f
ce232f5
da1addc
e34d274
eeb2873
bdaee88
e6d6fe3
9cf210d
db1d099
72db1b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #include "tariff_region.h" | ||
|
|
||
| namespace cycamore { | ||
|
|
||
| TariffRegion::TariffRegion(cyclus::Context* ctx) | ||
| : cyclus::Region(ctx) {} | ||
|
|
||
| TariffRegion::~TariffRegion() {} | ||
gonuke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| void TariffRegion::EnterNotify() { | ||
| Region::EnterNotify(); | ||
|
|
||
| } | ||
|
|
||
| void TariffRegion::AdjustMatlPrefs(cyclus::PrefMap<cyclus::Material>::type& prefs) { | ||
gonuke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (auto& req_pair : prefs) { | ||
|
|
||
| // Iterate over the bids in the request portfolio | ||
| for (auto& bid_pair : req_pair.second) { | ||
|
|
||
| // Get the bid | ||
| cyclus::Bid<cyclus::Material>* bid = bid_pair.first; | ||
|
|
||
| // Get the supplier - use manager() to get the Agent* from the Trader* | ||
| cyclus::Agent* supplier = bid->bidder()->manager(); | ||
|
|
||
| // Traverse up the hierarchy to get the supplier's region | ||
| cyclus::Region* supplier_region = nullptr; | ||
| cyclus::Agent* current = supplier; | ||
| while (current != nullptr) { | ||
| supplier_region = dynamic_cast<cyclus::Region*>(current); | ||
|
||
| if (supplier_region != nullptr) { | ||
| break; // Found a region | ||
| } | ||
| current = current->parent(); | ||
| } | ||
|
||
|
|
||
| // If the supplier is in the region list, apply the appropriate adjustment | ||
| auto it = std::find(region_names.begin(), region_names.end(), | ||
| supplier_region->prototype()); | ||
| if (it != region_names.end()) { | ||
| double cost_multiplier = 1.0 + adjustments[it - region_names.begin()]; | ||
| bid_pair.second *= cost_multiplier > 0.0 ? 1.0 / cost_multiplier : std::numeric_limits<double>::infinity(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void TariffRegion::AdjustProductPrefs(cyclus::PrefMap<cyclus::Product>::type& prefs) { | ||
|
|
||
| // Iterate over the preferences | ||
| for (auto& req_pair : prefs) { | ||
| // Iterate over the bids in the request portfolio | ||
| for (auto& bid_pair : req_pair.second) { | ||
|
|
||
| // Get the bid | ||
| cyclus::Bid<cyclus::Product>* bid = bid_pair.first; | ||
|
|
||
| // Get the supplier - use manager() to get the Agent* from the Trader* | ||
| cyclus::Agent* supplier = bid->bidder()->manager(); | ||
|
|
||
| // Traverse up the hierarchy to get the supplier's region | ||
| cyclus::Region* supplier_region = nullptr; | ||
| cyclus::Agent* current = supplier; | ||
| while (current != nullptr) { | ||
| supplier_region = dynamic_cast<cyclus::Region*>(current); | ||
| if (supplier_region != nullptr) { | ||
| break; // Found a region | ||
| } | ||
| current = current->parent(); | ||
| } | ||
|
|
||
| // If the supplier is in the region list, apply the appropriate adjustment | ||
| auto it = std::find(region_names.begin(), region_names.end(), | ||
| supplier_region->prototype()); | ||
| if (it != region_names.end()) { | ||
| double cost_multiplier = 1.0 + adjustments[it - region_names.begin()]; | ||
| bid_pair.second *= cost_multiplier > 0.0 ? 1.0 / cost_multiplier : std::numeric_limits<double>::infinity(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extern "C" cyclus::Agent* ConstructTariffRegion(cyclus::Context* ctx) { | ||
| return new TariffRegion(ctx); | ||
| } | ||
|
|
||
| } // namespace cycamore | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||
| #ifndef CYCAMORE_SRC_TARIFF_REGION_H_ | ||||||
| #define CYCAMORE_SRC_TARIFF_REGION_H_ | ||||||
|
|
||||||
| #include "cyclus.h" | ||||||
| #include <string> | ||||||
|
|
||||||
| namespace cycamore { | ||||||
|
|
||||||
| class TariffRegion : public cyclus::Region { | ||||||
| public: | ||||||
| TariffRegion(cyclus::Context* ctx); | ||||||
| virtual ~TariffRegion(); | ||||||
gonuke marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| virtual void EnterNotify(); | ||||||
| virtual void AdjustMatlPrefs(cyclus::PrefMap<cyclus::Material>::type& prefs); | ||||||
| virtual void AdjustProductPrefs(cyclus::PrefMap<cyclus::Product>::type& prefs); | ||||||
|
|
||||||
| #pragma cyclus | ||||||
|
|
||||||
| private: | ||||||
| cyclus::Region* FindRegionByName(const std::string& name); | ||||||
| cyclus::Region* FindRegionInHierarchy(cyclus::Agent* agent, const std::string& name); | ||||||
|
||||||
|
|
||||||
| #pragma cyclus var { \ | ||||||
| "default": [], \ | ||||||
| "doc": "List of regions that will have a trade adjustment " \ | ||||||
| "(subsidy)" \ | ||||||
| } | ||||||
| std::vector<std::string> region_names; | ||||||
|
|
||||||
| #pragma cyclus var { \ | ||||||
| "default": [], \ | ||||||
| "doc": "Adjustments (1+val) to apply to trades from affected " \ | ||||||
|
||||||
| "doc": "Adjustments (1+val) to apply to trades from affected " \ | |
| "doc": "Adjustments (multiply by (1+val)) to apply to cost of trades from affected " \ |
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.
Should we check that we have the same number of entries in the two vectors of input? Is that typical of other inputs that we expect to be coordinated like this?
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.
That seems wise.