Commit 4d881c7e authored by Jason Rhinelander's avatar Jason Rhinelander

De-prefix eris_id_t and eris_time_t

This lets external code use `eris::id_t` and `eris::time_t` which is
far nicer than `eris::eris_id_t`.

The existing `eris_id_t` and `eris_time_t` are kept as deprecated
aliases for the new ones.
parent e197b4ff
......@@ -55,7 +55,7 @@ Guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml)
classes.
- Header files beginning with a lower-case letter are used for collections of
small classes or definitions. For example, the `eris_id_t` typedef is
small classes or definitions. For example, the `eris::id_t` typedef is
defined in eris/types.hpp, and a few small algorithm functions and classes
are in `eris/algorithms.hpp`.
......
[
{ symbol: ["eris::eris_id_t", "private", "<eris/types.hpp>", "public"] },
{ symbol: ["eris::id_t", "private", "<eris/types.hpp>", "public"] },
{ include: ["<eris/types.hpp>", "public", "<eris/Simulation.hpp>", "public"] },
{ include: ["\"eris/types.hpp\"", "public", "<eris/Simulation.hpp>", "public"] },
{ include: ["<eris/types.hpp>", "public", "<eris/Bundle.hpp>", "public"] },
......
......@@ -16,7 +16,7 @@ BundleSigned::BundleSigned(MemberID g, double q) { set(g, q); }
BundleSigned::BundleSigned(const BundleSigned &b) {
for (auto &g : b) set(g.first, g.second);
}
BundleSigned::BundleSigned(const std::initializer_list<std::pair<eris_id_t, double>> &init) {
BundleSigned::BundleSigned(const std::initializer_list<std::pair<id_t, double>> &init) {
for (auto &g : init) set(g.first, g.second);
}
......@@ -26,7 +26,7 @@ Bundle::Bundle(const BundleSigned &b) : BundleSigned() {
for (auto &g : b) set(g.first, g.second);
}
Bundle::Bundle(const Bundle &b) : Bundle((BundleSigned&) b) {}
Bundle::Bundle(const std::initializer_list<std::pair<eris_id_t, double>> &init) {
Bundle::Bundle(const std::initializer_list<std::pair<id_t, double>> &init) {
for (auto &g : init) set(g.first, g.second);
}
......@@ -55,16 +55,16 @@ void Bundle::set(MemberID gid, double quantity) {
bool BundleSigned::empty() const {
return q_stack_.front().empty();
}
std::unordered_map<eris_id_t, double>::size_type BundleSigned::size() const {
std::unordered_map<id_t, double>::size_type BundleSigned::size() const {
return q_stack_.front().size();
}
int BundleSigned::count(MemberID gid) const {
return q_stack_.front().count(gid);
}
std::unordered_map<eris_id_t, double>::const_iterator BundleSigned::begin() const {
std::unordered_map<id_t, double>::const_iterator BundleSigned::begin() const {
return q_stack_.front().cbegin();
}
std::unordered_map<eris_id_t, double>::const_iterator BundleSigned::end() const {
std::unordered_map<id_t, double>::const_iterator BundleSigned::end() const {
return q_stack_.front().cend();
}
......@@ -224,7 +224,7 @@ Bundle Bundle::operator / (double d) const {
// for the static (e.g. 3 >= b) operator, as it just translate this into (b <= 3)
#define _ERIS_BUNDLE_CPP_COMPARE(OP, REVOP) \
bool BundleSigned::operator OP (const BundleSigned &b) const noexcept {\
std::unordered_set<eris_id_t> goods;\
std::unordered_set<id_t> goods;\
for (auto &g : *this) goods.insert(g.first);\
for (auto &g : b) goods.insert(g.first);\
\
......@@ -527,7 +527,7 @@ void BundleSigned::_print(std::ostream &os) const {
os << "(";
// Sort the keys:
std::set<eris_id_t> keys;
std::set<id_t> keys;
for (auto &g : *this)
keys.insert(g.first);
......
......@@ -24,7 +24,7 @@ namespace eris {
* object calling set() internally, to verify values, i.e. positive quantities when needed).
*
* You can iterate through goods via the usual begin() / end() pattern; note that these get mapped
* to through to the underlying std::unordered_map<eris_id_t,double>'s cbegin() and cend() methods,
* to through to the underlying std::unordered_map<eris::id_t,double>'s cbegin() and cend() methods,
* and so are immutable.
*
* The usual `+`, `-`, `*`, `/` operators are overloaded as expected for adding/scaling bundles,
......@@ -89,7 +89,7 @@ class BundleSigned {
* Since an initializer_list requires constant values, this is primary useful for debugging
* purposes.
*/
BundleSigned(const std::initializer_list<std::pair<eris_id_t, double>> &init);
BundleSigned(const std::initializer_list<std::pair<id_t, double>> &init);
/** Creates a new Bundle by copying quantities from another Bundle.
*
......@@ -127,18 +127,18 @@ class BundleSigned {
/** This method is is provided to be able to use a Bundle in a range for loop; it is, however, a
* const_iterator, mapped internally to the underlying std::unordered_map's cbegin() method.
*/
std::unordered_map<eris_id_t, double>::const_iterator begin() const;
std::unordered_map<id_t, double>::const_iterator begin() const;
/** This method is is provided to be able to use a Bundle in a range for loop; it is, however, a
* const_iterator, mapped internally to the underlying std::unordered_map's cend() method.
*/
std::unordered_map<eris_id_t, double>::const_iterator end() const;
std::unordered_map<id_t, double>::const_iterator end() const;
/** Returns the number of goods in the bundle. Note that values that have not been
* explicitly set (and thus return a value of 0) are *not* included in the size(), but
* values that have been explitly set (even to 0) *are* included.
*/
std::unordered_map<eris_id_t, double>::size_type size() const;
std::unordered_map<id_t, double>::size_type size() const;
/** Returns true iff size() == 0. Note that empty() is not true for a bundle with explicit
* quantities of 0; for testing whether a bundle is empty in the sense of all quantities
......@@ -474,7 +474,7 @@ class BundleSigned {
* Bundle()
* BundleSigned([3]=-3.75, [2]=0, [1]=4.2e-24)
*
* The value in brackets is the eris_id_t of the good.
* The value in brackets is the eris::id_t of the good.
*/
friend std::ostream& operator << (std::ostream &os, const BundleSigned &b);
......@@ -486,11 +486,11 @@ class BundleSigned {
class valueproxy {
private:
BundleSigned &bundle_;
const eris_id_t gid_;
const id_t gid_;
public:
valueproxy() = delete;
/// Constructs a valueproxy from a BundleSigned and good id of the proxied value
valueproxy(BundleSigned &bn, eris_id_t gid) : bundle_(bn), gid_(gid) {}
valueproxy(BundleSigned &bn, id_t gid) : bundle_(bn), gid_(gid) {}
/// Assigns a new value to the proxied bundle quantity
void operator=(double q) { bundle_.set(gid_, q); }
/// Adds a value to the current proxied bundle quantity
......@@ -508,7 +508,7 @@ class BundleSigned {
private:
// The stack of quantity maps; the front of q_stack_ is the currently visible quantities;
// remainder items are the pre-transaction values.
std::forward_list<std::unordered_map<eris_id_t, double>> q_stack_ = {std::unordered_map<eris_id_t, double>()};
std::forward_list<std::unordered_map<id_t, double>> q_stack_ = {std::unordered_map<id_t, double>()};
// If non-empty, we're inside an encompassing transaction or fake transaction. The value at
// the beginning of the list tells us whether it's a encompassing transaction (started by
......@@ -530,7 +530,7 @@ class Bundle final : public BundleSigned {
/// Creates a new Bundle containing a single good of the given quantity.
Bundle(MemberID g, double q);
/// Creates a new Bundle from an initializer list of goods and quantities.
Bundle(const std::initializer_list<std::pair<eris_id_t, double>> &init);
Bundle(const std::initializer_list<std::pair<id_t, double>> &init);
/** Creates a new Bundle by copying quantities from a BundleSigned. If the other Bundle is
* currently in a transaction, only the current values are copied; the transactions and
* pre-transactions values are not.
......@@ -783,7 +783,7 @@ class Bundle final : public BundleSigned {
* Bundle()
* BundleSigned([3]=-3.75, [2]=0, [1]=4.2e-24)
*
* The value in brackets is the eris_id_t of the good.
* The value in brackets is the eris::id_t of the good.
*/
friend std::ostream& operator << (std::ostream &os, const Bundle& b);
......@@ -797,8 +797,8 @@ class Bundle final : public BundleSigned {
* \param good the id of the good that was assigned a negative value
* \param value the negative value that was assigned
*/
negativity_error(eris_id_t good, double value) :
std::range_error("eris_id_t=" + std::to_string(good) + " assigned illegal negative value "
negativity_error(id_t good, double value) :
std::range_error("good[" + std::to_string(good) + "] assigned illegal negative value "
+ std::to_string(value) + " in Bundle."), good(good), value(value) {}
/** Constructor for a negativity exception for a negative quantity with a given
* error message.
......@@ -807,10 +807,10 @@ class Bundle final : public BundleSigned {
* \param good the id of the good that was assigned a negative value
* \param value the negative value that was assigned
*/
negativity_error(const std::string& what_arg, eris_id_t good, double value) :
negativity_error(const std::string& what_arg, id_t good, double value) :
std::range_error(what_arg), good(good), value(value) {}
/// The id of the good that caused the error
const eris_id_t good;
const id_t good;
/// The illegal value that caused the error
const double value;
};
......
......@@ -6,17 +6,17 @@ double Consumer::currUtility() const {
return utility(assets);
}
std::map<eris_id_t, double> Consumer::Differentiable::gradient(const std::vector<eris_id_t> &goods, const BundleNegative &b) const {
std::map<eris_id_t, double> grad;
std::map<id_t, double> Consumer::Differentiable::gradient(const std::vector<id_t> &goods, const BundleNegative &b) const {
std::map<id_t, double> grad;
for (auto good : goods)
grad[good] = d(b, good);
return grad;
}
std::map<eris_id_t, std::map<eris_id_t, double>> Consumer::Differentiable::hessian(const std::vector<eris_id_t> &goods, const BundleNegative &b) const {
std::map<eris_id_t, std::map<eris_id_t, double>> hess;
std::vector<eris_id_t> priorG;
std::map<id_t, std::map<id_t, double>> Consumer::Differentiable::hessian(const std::vector<id_t> &goods, const BundleNegative &b) const {
std::map<id_t, std::map<id_t, double>> hess;
std::vector<id_t> priorG;
for (auto g1 : goods) {
for (auto g2 : priorG) {
......
......@@ -42,10 +42,10 @@ class Consumer::Differentiable : public Consumer {
* default implementation simply calls d() for each good, but subclasses may override that
* behaviour (i.e. if a more efficient alternative is available).
*
* \param g a std::vector<eris_id_t> of the goods for which the gradient is sought
* \param g a std::vector<id_t> of the goods for which the gradient is sought
* \param b the BundleNegative (typically a Bundle instance) at which the gradient is to be evaluated
*/
virtual std::map<eris_id_t, double> gradient(const std::vector<eris_id_t> &g, const BundleNegative &b) const;
virtual std::map<id_t, double> gradient(const std::vector<id_t> &g, const BundleNegative &b) const;
/** Returns the Hessian (as a two-dimensional nested std::map) for the given set of goods g
* given a Bundle b. The Bundle and std::vector of Good ids is specified separately because
* the Bundle is not required to contain all of the goods at which the Hessian is to be
......@@ -57,10 +57,10 @@ class Consumer::Differentiable : public Consumer {
* overridden. As with gradient(), this may also be overridden if a more efficient
* calculation is available.
*
* \param g a std::vector<eris_id_t> of the goods for which the hessian is sought
* \param g a std::vector<id_t> of the goods for which the hessian is sought
* \param b the Bundle at which the hessian is to be evaluated
*/
virtual std::map<eris_id_t, std::map<eris_id_t, double>> hessian(const std::vector<eris_id_t> &g, const BundleNegative &b) const;
virtual std::map<id_t, std::map<id_t, double>> hessian(const std::vector<id_t> &g, const BundleNegative &b) const;
};
/** Very simple consumer class that takes a function (or lambda) that takes a const BundleNegative &
......
......@@ -11,12 +11,12 @@ void Market::addFirm(SharedMember<Firm> f) {
dependsWeaklyOn(f);
}
void Market::removeFirm(eris_id_t fid) {
void Market::removeFirm(id_t fid) {
auto lock = writeLock();
suppliers_.erase(fid);
}
const std::unordered_set<eris_id_t>& Market::firms() {
const std::unordered_set<id_t>& Market::firms() {
return suppliers_;
}
......@@ -79,7 +79,7 @@ Market::Reservation::~Reservation() {
release();
}
void Market::Reservation::firmReserve(eris_id_t firm_id, BundleNegative transfer) {
void Market::Reservation::firmReserve(id_t firm_id, BundleNegative transfer) {
auto firm = market->simAgent<Firm>(firm_id);
firm_reservations_.push_front(firm->reserve(transfer));
}
......
......@@ -156,7 +156,7 @@ class Market : public Member {
* Positive amounts are to be transferred from the firm, negative amounts are to be
* transferred to the firm. This is intended to be called only by Market subclasses.
*/
void firmReserve(eris_id_t firm_id, BundleNegative transfer);
void firmReserve(id_t firm_id, BundleNegative transfer);
/** Calls buy() on the market. Calling obj->buy() is a shortcut for calling
* `obj->market->buy(obj)`.
*/
......@@ -289,11 +289,11 @@ class Market : public Member {
/** Removes f from the firms supplying in this market. This is called automatically if a
* firm passed to addFirm is removed from the simulation; manual calling is only needed if a
* firm exits the market but stays in the simulation. */
virtual void removeFirm(eris_id_t fid);
virtual void removeFirm(id_t fid);
/** Returns the std::unordered_set of the eris_id_t's of firms supplying this market.
/** Returns the std::unordered_set of the eris::id_t's of firms supplying this market.
*/
const std::unordered_set<eris_id_t>& firms();
const std::unordered_set<id_t>& firms();
/** Exception class thrown when a quantity that exceeds the market capacity has been
* requested.
......@@ -329,7 +329,7 @@ class Market : public Member {
protected:
/// Firms participating in this market
std::unordered_set<eris_id_t> suppliers_;
std::unordered_set<id_t> suppliers_;
/** Creates a Reservation and returns it. For use by subclasses only. The reserved payment
* (i.e. p*price_unit) will be transferred out of the Agent's assets Bundle and held
......
......@@ -4,7 +4,7 @@
namespace eris {
std::atomic<eris_id_t> Member::next_id_{1};
std::atomic<id_t> Member::next_id_{1};
void Member::dependsOn(MemberID dep_id) {
simulation()->registerDependency(id(), dep_id);
......
......@@ -28,10 +28,10 @@ class Member : private noncopyable {
virtual ~Member() = default;
/** Returns the eris_id_t ID of this member. An ID is assigned when the Member is created,
/** Returns the eris::id_t ID of this member. An ID is assigned when the Member is created,
* and is unique across all Member instances.
*/
eris_id_t id() const { return id_; }
id_t id() const { return id_; }
/** Returns true if this member belongs to a simulation, false otherwise.
*/
......@@ -67,7 +67,7 @@ class Member : private noncopyable {
}
/// Shortcut for `member.simulation()->t()`, i.e. returns the current simulation time period.
eris_time_t simT() const { return simulation()->t(); }
time_t simT() const { return simulation()->t(); }
/** Records a dependency with the Simulation object. This should not be called until after
* the member has been added to a simulation, and is typically invoked in an overridden
......@@ -630,10 +630,10 @@ class Member : private noncopyable {
private:
// The global id counter
static std::atomic<eris_id_t> next_id_;
static std::atomic<id_t> next_id_;
// The unique id
eris_id_t id_{next_id_++};
id_t id_{next_id_++};
/** Stores a weak pointer to the simulation this Member belongs to. */
std::weak_ptr<eris::Simulation> simulation_;
......
......@@ -41,7 +41,7 @@ void Simulation::insert(const SharedMember<Member> &member) {
}
// Macro for the 4 nearly-identical versions of these two functions. When adding to the simulation,
// we need to assign an eris_id_t, give a reference to the simulation to the object, insert into
// we need to assign an eris::id_t, give a reference to the simulation to the object, insert into
// agents_/goods_/markets_/others_, register any optimization implementations, and invalidate the
// associated filter cache. When removing, we need to undo all of the above.
// This should be the *ONLY* place anything is ever added or removed from agents_, goods_, markets_,
......@@ -58,7 +58,7 @@ void Simulation::insert##TYPE(const SharedMember<CLASS> &member) {\
member->simulation(shared_from_this());\
insertOptimizers(member);\
}\
void Simulation::remove##TYPE(eris_id_t id) {\
void Simulation::remove##TYPE(id_t id) {\
std::lock_guard<std::recursive_mutex> mbr_lock(member_mutex_);\
auto member = MAP.at(id);\
auto lock = member->writeLock();\
......@@ -88,12 +88,12 @@ void Simulation::remove(MemberID id) {
}
}
void Simulation::removeNoDefer(eris_id_t id) {
void Simulation::removeNoDefer(id_t id) {
if (agents_.count(id)) removeAgent(id);
else if (goods_.count(id)) removeGood(id);
else if (markets_.count(id)) removeMarket(id);
else if (others_.count(id)) removeOther(id);
else throw std::out_of_range("eris_id_t to be removed does not exist");
else throw std::out_of_range("eris::id_t to be removed does not exist");
}
void Simulation::processDeferredQueue() {
......@@ -111,7 +111,7 @@ void Simulation::processDeferredQueue() {
insert(to_insert);
}
else if (not deferred_remove_.empty()) {
eris_id_t to_remove = deferred_remove_.front();
id_t to_remove = deferred_remove_.front();
deferred_remove_.pop_front();
deferred_mutex_.unlock();
removeNoDefer(to_remove);
......@@ -163,7 +163,7 @@ void Simulation::removeOptimizers(const SharedMember<Member> &member) {
}
}
void Simulation::removeDeps(eris_id_t member) {
void Simulation::removeDeps(id_t member) {
std::lock_guard<std::recursive_mutex> lock(member_mutex_);
if (!depends_on_.count(member)) return;
......
......@@ -68,10 +68,10 @@ class Simulation : public std::enable_shared_from_this<Simulation>, private nonc
/// Destructor. When destruction occurs, any outstanding threads are killed and rejoined.
virtual ~Simulation();
/// Alias for a map of eris_id_t to SharedMember<T> of arbitrary type T
template <class T> using MemberMap = std::unordered_map<eris_id_t, SharedMember<T>>;
/// Alias for a map of eris::id_t to SharedMember<T> of arbitrary type T
template <class T> using MemberMap = std::unordered_map<id_t, SharedMember<T>>;
/// typedef for the map of id's to the set of dependent members
using DepMap = std::unordered_map<eris_id_t, std::unordered_set<eris_id_t>>;
using DepMap = std::unordered_map<id_t, std::unordered_set<id_t>>;
/** Wrapper around std::enable_if that defines a typedef `type` (defaulting to
* SharedMember<Derived>) only if `Derived` is a `Base` member type. `Base` must itself be
......@@ -100,25 +100,25 @@ class Simulation : public std::enable_shared_from_this<Simulation>, private nonc
return SharedMember<T>(NAME##s_.at(id)); \
}
/** Accesses an agent given the agent's eris_id_t. Templated to allow conversion to
/** Accesses an agent given the agent's eris::id_t. Templated to allow conversion to
* a SharedMember of the given Agent subclass; defaults to Agent.
*/
ERIS_SIM_MEMBER_ACCESS(A, Agent, agent) // agent(eris_id_t)
ERIS_SIM_MEMBER_ACCESS(A, Agent, agent) // agent(id_t)
/** Accesses a good given the good's eris_id_t. Templated to allow conversion to a
/** Accesses a good given the good's eris::id_t. Templated to allow conversion to a
* SharedMember of the given Good subclass; defaults to Good.
*/
ERIS_SIM_MEMBER_ACCESS(G, Good, good) // good(eris_id_t)
ERIS_SIM_MEMBER_ACCESS(G, Good, good) // good(id_t)
/** Accesses a market given the market's eris_id_t. Templated to allow conversion to a
/** Accesses a market given the market's eris::id_t. Templated to allow conversion to a
* SharedMember of the given Market subclass; defaults to Market.
*/
ERIS_SIM_MEMBER_ACCESS(M, Market, market) // market(eris_id_t)
ERIS_SIM_MEMBER_ACCESS(M, Market, market) // market(id_t)
/** Accesses a non-agent/good/market member that has been added to this simulation. This is
* typically an optimization object.
*/
ERIS_SIM_MEMBER_ACCESS(O, Member, other) // other(eris_id_t)
ERIS_SIM_MEMBER_ACCESS(O, Member, other) // other(id_t)
#undef ERIS_SIM_MEMBER_ACCESS
......@@ -353,7 +353,7 @@ class Simulation : public std::enable_shared_from_this<Simulation>, private nonc
*
* This is initially 0 (until the first run() call).
*/
eris_time_t t() const { return t_; }
time_t t() const { return t_; }
/** enum of the different stages of the simulation, primarily used for synchronizing threads.
*
......@@ -460,7 +460,7 @@ class Simulation : public std::enable_shared_from_this<Simulation>, private nonc
void insertOther(const SharedMember<Member> &other);
// Internal remove() method that doesn't defer if currently running
void removeNoDefer(eris_id_t id);
void removeNoDefer(id_t id);
// Processes any deferred member insertions/removals. This is called at the end of each
// stage (while the exclusive run lock is held).
......@@ -468,10 +468,10 @@ class Simulation : public std::enable_shared_from_this<Simulation>, private nonc
// Internal method to remove one of the various types. Called by the public remove()
// method, which figures out which type the removal request is for.
void removeAgent(eris_id_t aid);
void removeGood(eris_id_t gid);
void removeMarket(eris_id_t mid);
void removeOther(eris_id_t oid);
void removeAgent(id_t aid);
void removeGood(id_t gid);
void removeMarket(id_t mid);
void removeOther(id_t oid);
// Determines which (if any) optimization interfaces the member implements, and records it
// for the next optimization stage.
......@@ -511,13 +511,13 @@ class Simulation : public std::enable_shared_from_this<Simulation>, private nonc
DepMap depends_on_, weak_dep_;
// Removes hard dependents
void removeDeps(eris_id_t member);
void removeDeps(id_t member);
// Notifies weak dependents
void notifyWeakDeps(SharedMember<Member> member);
// Tracks the iteration number, can be accessed via t().
eris_time_t t_ = 0;
time_t t_ = 0;
/* Threading variables */
......@@ -577,7 +577,7 @@ class Simulation : public std::enable_shared_from_this<Simulation>, private nonc
// stage/priority.
std::list<SharedMember<Member>> deferred_insert_;
// List of ids with deferred removal to be removed at the end of the current stage/priority
std::list<eris_id_t> deferred_remove_;
std::list<id_t> deferred_remove_;
// Mutex governing the two above variables
std::mutex deferred_mutex_;
......
......@@ -250,18 +250,18 @@ class Stepper final {
/// Struct holding the results of a call to an optimization function such as single_peak_search() or
/// `constrained_maximum_search()`
template <typename ArgType = double, typename ValueType = double> struct search_result {
ArgType arg; ///< The argument that maximizes the searched function
ValueType value; ///< The value of the function at `.arg`
template <typename domain_t = double, typename value_t = double> struct search_result {
domain_t arg; ///< The argument that maximizes the searched function
value_t value; ///< The value of the function at `.arg`
/** Whether `.arg` is strictly inside the given left/right limits. If false, the found value
* was at one of the end-points, and may not actually be a peak at all.
*/
bool inside;
/// Number of iterations, if applicable (-1 otherwise).
int iterations;
operator ArgType() const { return arg; } ///< Implicit conversion to double returns `.arg`
operator domain_t() const { return arg; } ///< Implicit conversion to double returns `.arg`
search_result(ArgType a, ValueType v, bool in, int it = -1) :
search_result(domain_t a, value_t v, bool in, int it = -1) :
arg(std::move(a)), value(std::move(v)), inside(in), iterations(it) {}
};
......
......@@ -7,11 +7,11 @@ namespace eris { namespace consumer {
CobbDouglas::CobbDouglas(double c) : constant(c) {}
CobbDouglas::CobbDouglas(
eris_id_t g1,
id_t g1,
double exp1,
eris_id_t g2,
id_t g2,
double exp2,
eris_id_t g3,
id_t g3,
double exp3,
double c
) : constant(c) {
......@@ -19,7 +19,7 @@ CobbDouglas::CobbDouglas(
if (g2 != 0) exponents[g2] = exp2;
if (g3 != 0) exponents[g3] = exp3;
}
CobbDouglas::CobbDouglas(const std::unordered_map<eris_id_t, double> &exps, double c) : constant(c), exponents(exps) {}
CobbDouglas::CobbDouglas(const std::unordered_map<id_t, double> &exps, double c) : constant(c), exponents(exps) {}
// Constant
double& CobbDouglas::coef() {
......
......@@ -25,11 +25,11 @@ class CobbDouglas : public Consumer::Differentiable {
* coefficients can be accessed via the coef() and exp() methods.
*/
CobbDouglas(
eris_id_t g1,
id_t g1,
double exp1,
eris_id_t g2 = 0,
id_t g2 = 0,
double exp2 = 1.0,
eris_id_t g3 = 0,
id_t g3 = 0,
double exp3 = 1.0,
double c = 1.0
);
......@@ -39,7 +39,7 @@ class CobbDouglas : public Consumer::Differentiable {
* \param exps a map of goods to exponents
* \param c the optional leading coefficient, defaulting to 1.0
*/
CobbDouglas(const std::unordered_map<eris_id_t, double> &exps, double c = 1.0);
CobbDouglas(const std::unordered_map<id_t, double> &exps, double c = 1.0);
/// Accesses the constant term.
double& coef();
......@@ -67,8 +67,8 @@ class CobbDouglas : public Consumer::Differentiable {
protected:
/// The constant offset. \sa coef()
double constant = 0.0;
/// The map of exponents. \sa exp(eris_id_t)
std::unordered_map<eris_id_t, double> exponents;
/// The map of exponents. \sa exp(id_t)
std::unordered_map<id_t, double> exponents;
private:
// Wrapper around pow() that redefines some special 0/infinity cases.
double power(double val, double exponent) const;
......
......@@ -12,7 +12,7 @@ namespace eris { namespace consumer {
Polynomial::Polynomial(double offset) : offset(offset) {}
Polynomial::Polynomial(std::map<eris_id_t, std::vector<double>> coef, double offset) : offset(offset), coefficients(coef) {}
Polynomial::Polynomial(std::map<id_t, std::vector<double>> coef, double offset) : offset(offset), coefficients(coef) {}
double& Polynomial::coef(MemberID g, unsigned int n) {
if (n == 0) return coef();
......@@ -97,9 +97,9 @@ double Polynomial::d2(const BundleNegative &b, MemberID g1, MemberID g2) const {
// Override Consumer's hessian function: since off-diagonals of the Hessian are
// 0 for this class, we can skip those calculations.
std::map<eris_id_t, std::map<eris_id_t, double>>
Polynomial::hessian(const std::vector<eris_id_t> &goods, const BundleNegative &b) const {
std::map<eris_id_t, std::map<eris_id_t, double>> H;
std::map<id_t, std::map<id_t, double>>
Polynomial::hessian(const std::vector<id_t> &goods, const BundleNegative &b) const {
std::map<id_t, std::map<id_t, double>> H;
for (auto g1 : goods) {
for (auto g2 : goods) {
......
......@@ -25,7 +25,7 @@ class Polynomial : public Consumer::Differentiable {
* u(\mathbf{X}) = 3 + 5 x_1 - x_1^2 + 5 x_3^2 - x_3^3
* \f]
*/
Polynomial(std::map<eris_id_t, std::vector<double>> coef, double offset = 0.0);
Polynomial(std::map<id_t, std::vector<double>> coef, double offset = 0.0);
/** Returns a (mutable) reference to the coefficient on the \f$g^n\f$ term. If the
* coefficient or lesser coefficients for the given good do not yet exist, they will be
......@@ -76,15 +76,15 @@ class Polynomial : public Consumer::Differentiable {
* Consumer::Differentiable with a more efficient version, since only diagonal elements need
* to be calculated (off-diagonal elements are always 0).
*/
virtual std::map<eris_id_t, std::map<eris_id_t, double>>
hessian(const std::vector<eris_id_t> &g, const BundleNegative &b) const override;
virtual std::map<id_t, std::map<id_t, double>>
hessian(const std::vector<id_t> &g, const BundleNegative &b) const override;
protected:
/// The constant offset term in the consumer's utility.
double offset = 0.0;
/// The map of coefficients for the consumer's utility.
std::map<eris_id_t, std::vector<double>> coefficients;
std::map<id_t, std::vector<double>> coefficients;
};
......
......@@ -5,7 +5,7 @@
namespace eris { namespace consumer {
Quadratic::Quadratic(double offset) : offset(offset) {}
Quadratic::Quadratic(std::map<eris_id_t, double> linear, double offset) : offset(offset), linear(linear) {}
Quadratic::Quadratic(std::map<id_t, double> linear, double offset) : offset(offset), linear(linear) {}
// Constant
double& Quadratic::coef() {
......
......@@ -24,7 +24,7 @@ class Quadratic : public Consumer::Differentiable {
* coefficients have to be set individually after construction using &coef(MemberID,
* MemberID).
*/
Quadratic(std::map<eris_id_t, double> linear, double offset = 0.0);
Quadratic(std::map<id_t, double> linear, double offset = 0.0);
/// Accesses the constant term.
double& coef();
......@@ -62,13 +62,13 @@ class Quadratic : public Consumer::Differentiable {
/// The constant offset. \sa coef()
double offset = 0.0;
/// The map of coefficients on linear terms. \sa coef(MemberID)
std::map<eris_id_t, double> linear;
std::map<id_t, double> linear;
/** The nested map of coefficients on quadratic terms. \sa coef(MemberID, MemberID) Note
* that we only store values for which the outer key is less than or equal to the inner key.
* That is, we store `quad[3][4]` but not `quad[4][3]`. `coef(MemberID, MemberID)` handles this
* argument reordering so that both `coef(3, 4)` and `coef(4, 3)` access `quad[3][4]`.
*/
std::map<eris_id_t, std::map<eris_id_t, double>> quad;
std::map<id_t, std::map<id_t, double>> quad;
};
} }
......@@ -127,9 +127,9 @@ class InterStepper : public Member, public virtual OptApply {
/// Whether we are going to step up. Calculated in optimize(), given to stepper_ in apply()
bool curr_up_ = false;
/// The period; we only try to take a step every `period_` times. 1 means always.
const eris_time_t period_;
const time_t period_;
/// The offset; we take a step in periods in which `sim->t() % period_ == period_offset_`
const eris_time_t period_offset_;
const time_t period_offset_;
/// True if we're going to step this round. Will be always true if `period_ == 1`.
bool stepping_ = false;
/// True if we're going to jump this round instead of stepping.
......
......@@ -73,8 +73,8 @@ class ProfitStepper : public InterStepper {
/// Declares a dependency on the handled firm when added to the simulation
virtual void added() override;
/// The eris_id_t of the firm this stepper applies to.
const eris_id_t firm_;
/// The eris::id_t of the firm this stepper applies to.
const id_t firm_;
/** Stores a fixed Bundle telling us what money is so that we can compare profits. Thus
* this stores the *initial* firm price, since that will be denominated in money. We can't/
......
......@@ -56,7 +56,7 @@ class QFStepper : public ProfitStepper {
virtual void take_jump() override;
private:
eris_id_t firm_;
id_t firm_;
double jump_cap_;
};
......
......@@ -24,7 +24,7 @@ class FixedIncome : public Member, public virtual Initialize {
Bundle income;
private:
const eris_id_t agent_id_;
const id_t agent_id_;
};
} }
......@@ -12,7 +12,7 @@
namespace eris { namespace intraopt {
IncrementalBuyer::IncrementalBuyer(const Consumer &consumer, eris_id_t money, int rounds) :