Commit 2ebc436d authored by Jason Rhinelander's avatar Jason Rhinelander

Make market.firms() return a set of firms, not ids

The C++ eris interface returns the ids for performance reasons; the
python interface isn't so concerned with that, so just do agent lookups
and return a python set of all the actual firms.
parent 41168881
...@@ -58,7 +58,15 @@ void bind_market(py::module &m) { ...@@ -58,7 +58,15 @@ void bind_market(py::module &m) {
"Creates a Reservation object for the given agent, quantity, and maximum expenditure. This method is for internal use by Market subclasses to actually create the object; external callers should call reserve() instead. This method removes the payment from the agent ") "Creates a Reservation object for the given agent, quantity, and maximum expenditure. This method is for internal use by Market subclasses to actually create the object; external callers should call reserve() instead. This method removes the payment from the agent ")
.def("add_firm", &Market::addFirm, "Adds the given firm to the firms supplying output units in this market.") .def("add_firm", &Market::addFirm, "Adds the given firm to the firms supplying output units in this market.")
.def("remove_firm", &Market::removeFirm, "Removes the given firm from the firms supplying output units in this market. This only needs to be called explicitly when the firm remains in the simulation; firms removed from the simulation will have this called automatically.") .def("remove_firm", &Market::removeFirm, "Removes the given firm from the firms supplying output units in this market. This only needs to be called explicitly when the firm remains in the simulation; firms removed from the simulation will have this called automatically.")
.def("firms", &Market::firms, "Returns the set of firms that supply this market") // NB: firms in the Python interface is a python set of firms, unlike the C++ interface
// where firms() is a (C++) unordered_set of firm *ids*
.def("firms", [](Market &m) {
py::set firms;
auto sim = m.simulation();
for (auto fid : m.firms())
firms.add(py::cast(sim->agent<Firm>(fid)));
return firms; }, "Returns a set of firms that supply this market.")
.def_readonly("output_unit", &Market::output_unit, "The bundle in terms of which output quantities are measured.") .def_readonly("output_unit", &Market::output_unit, "The bundle in terms of which output quantities are measured.")
.def_readonly("price_unit", &Market::price_unit, "The bundle in terms of which output prices are measured.") .def_readonly("price_unit", &Market::price_unit, "The bundle in terms of which output prices are measured.")
; ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment