Commit 46cff556 authored by Jason Rhinelander's avatar Jason Rhinelander

Rename Bundle's transferApprox() to transfer()

Add a deprecated transferApprox() that forwards its arguments to
transfer().
parent a16e073f
......@@ -403,7 +403,7 @@ void BundleSigned::endEncompassing() {
}
BundleSigned BundleSigned::transferApprox(const BundleSigned &amount, BundleSigned &to, double epsilon) {
BundleSigned BundleSigned::transfer(const BundleSigned &amount, BundleSigned &to, double epsilon) {
beginTransaction(true);
to.beginTransaction(true);
BundleSigned actual;
......@@ -448,7 +448,7 @@ BundleSigned BundleSigned::transferApprox(const BundleSigned &amount, BundleSign
return actual;
}
BundleSigned BundleSigned::transferApprox(const BundleSigned &amount, double epsilon) {
BundleSigned BundleSigned::transfer(const BundleSigned &amount, double epsilon) {
beginTransaction(true);
BundleSigned actual;
actual.beginEncompassing();
......@@ -491,7 +491,7 @@ bool Bundle::hasApprox(const BundleSigned &amount, const Bundle &to, double epsi
const double &q = g.second > 0 ? (*this)[g.first] : to[g.first];
// If the final amount is lower than -ε*(original q), the transferApprox will fail
// If the final amount is lower than -ε*(original q), the transfer will fail
if (q - abs_transfer <= -epsilon * q)
return false;
}
......@@ -504,7 +504,7 @@ bool Bundle::hasApprox(const BundleSigned &amount, double epsilon) const {
const double &q = (*this)[g.first];
// If the final amount is lower than -ε*(original q), the transferApprox will fail
// If the final amount is lower than -ε*(original q), the transfer will fail
if (q - g.second <= -epsilon * q)
return false;
}
......
......@@ -199,7 +199,7 @@ class BundleSigned {
/// Scales a BundleSigned's quantities by `1/d`
BundleSigned& operator /= (double d);
/// The default epsilon for transferApprox() and hasApprox(), if not specified.
/// The default epsilon for transfer() and hasApprox(), if not specified.
static constexpr double default_transfer_epsilon = 1.0e-12;
/** Transfers (approximately) the given amount between two Bundles. Positive quantities in
......@@ -210,7 +210,7 @@ class BundleSigned {
*
* Calling
*
* from.transferApprox(amount, to);
* from.transfer(amount, to);
*
* is roughly equivalent to
*
......@@ -254,10 +254,10 @@ class BundleSigned {
*
* \sa Bundle::hasApprox(const BundleSigned&, BundleSigned&, double)
*/
BundleSigned transferApprox(const BundleSigned &amount, BundleSigned &to, double epsilon = default_transfer_epsilon);
BundleSigned transfer(const BundleSigned &amount, BundleSigned &to, double epsilon = default_transfer_epsilon);
/** Transfers approximately the given amount from the caller object and returns it. This is
* like the above 3-argument transferApprox(const BundleSigned&, BundleSigned&, double)
* like the above 3-argument transfer(const BundleSigned&, BundleSigned&, double)
* except that the amount is not transferred into a target Bundle but simply returned. Like
* the 3-argument version, negative transfer amounts are added to the calling object and
* will be negative in the returned object.
......@@ -267,8 +267,8 @@ class BundleSigned {
* This method is also useful for adding or removing approximate amounts from a bundle by
* simple ignoring the return value. Thus the following:
*
* bundle.transferApprox({ goodid, 3.0 });
* bundle.transferApprox({ goodid, -4.0 });
* bundle.transfer({ goodid, 3.0 });
* bundle.transfer({ goodid, -4.0 });
*
* is roughly the same as:
*
......@@ -276,8 +276,8 @@ class BundleSigned {
* bundle[goodid] += 4.0;
*
* except when the bundle initially contains values very close to (but not exactly equal to)
* 3 or -1: in the former case, the first transferApprox will remove slightly more or less
* than 3 (and remove the good from the bundle entirely); the second transferApprox adds
* 3 or -1: in the former case, the first transfer() will remove slightly more or less
* than 3 (and remove the good from the bundle entirely); the second transfer() adds
* exactly 4 units of `goodid` to the bundle. If the initial value is -1, the first call
* subtracts exactly 3, and the second call ends up adding slightly more or less than 4 to
* bring the quantity to exactly 0 (and then removes it).
......@@ -294,7 +294,18 @@ class BundleSigned {
*
* \sa Bundle::hasApprox(const BundleSigned&, double)
*/
BundleSigned transferApprox(const BundleSigned &amount, double epsilon = default_transfer_epsilon);
BundleSigned transfer(const BundleSigned &amount, double epsilon = default_transfer_epsilon);
/// transferApprox() is a deprecated name for transfer()
template <typename... Args>
#if __cplusplus >= 201402L
[[deprecated("transferApprox() is deprecated; use transfer() instead")]]
#else
[[deprecated]]
#endif
BundleSigned transferApprox(Args &&...args) {
return transfer(std::forward<Args>(args)...);
}
/// Adds two BundleSigned objects together and returns the result.
BundleSigned operator + (const BundleSigned &b) const;
......@@ -734,18 +745,18 @@ class Bundle final : public BundleSigned {
*
* is notionally equivalent to:
*
* (a >= transfer.positive() and b >= transfer.negative())
* (a >= transfer.positive() && b >= transfer.negative())
*
* except that it allows slight numerical imprecision when the compared amounts are very
* similar.
*
* If this method returns true, it is a guarantee that transferApprox() called with the same
* If this method returns true, it is a guarantee that transfer() called with the same
* arguments will succeed (i.e. without resulting in a Bundle::negativity_error exception).
*/
bool hasApprox(const BundleSigned &amount, const Bundle &to, double epsilon = default_transfer_epsilon) const;
/** Returns true if the called-upon bundle has approximately enough of each
* positive-quantity good in `amount` to complete a transfer via transferApprox(). Negative
* positive-quantity good in `amount` to complete a transfer via transfer(). Negative
* quantites in `amount` are ignored.
*
* a.hasApprox(bundle)
......@@ -756,7 +767,7 @@ class Bundle final : public BundleSigned {
*
* except that it allows for numerical error for goods with very similar quantities.
*
* If this method returns true, it is a guarantee that transferApprox() called with the same
* If this method returns true, it is a guarantee that transfer() called with the same
* arguments will succeed (i.e. without resulting in a Bundle::negativity_error exception).
*/
bool hasApprox(const BundleSigned &amount, double epsilon = default_transfer_epsilon) const;
......
......@@ -97,7 +97,7 @@ Firm::Reservation Firm::reserve(const BundleNegative &reserve) {
// Transfer any assets we matched above into reserves
if (common != 0) {
assets.transferApprox(common, reserves_, epsilon);
assets.transfer(common, reserves_, epsilon);
}
return createReservation(reserve);
......@@ -108,7 +108,7 @@ void Firm::produceReserved(const Bundle &b) {
Bundle to_produce;
try {
to_produce = reserved_production_.transferApprox(b, epsilon);
to_produce = reserved_production_.transfer(b, epsilon);
}
catch (Bundle::negativity_error& e) {
// If the transfer throws a negativity error, we attempted to transfer more than
......@@ -128,7 +128,7 @@ void Firm::produceReserved(const Bundle &b) {
Bundle produced = produce(to_produce);
if (produced != to_produce) // Reduce planned excess production appropriately
excess_production_.transferApprox(produced - to_produce, epsilon);
excess_production_.transfer(produced - to_produce, epsilon);
assets += produced;
}
......@@ -155,20 +155,20 @@ void Firm::Reservation::transfer(Bundle &to) {
try {
// Take payment:
Bundle in = bundle.negative();
to.transferApprox(bundle.negative(), assets, epsilon);
to.transfer(bundle.negative(), assets, epsilon);
// Now transfer and/or produce output
Bundle out = bundle.positive();
out.beginEncompassing();
Bundle from_reserves = Bundle::common(firm->reserves_, out);
Bundle done = firm->reserves_.transferApprox(from_reserves, to, epsilon);
out.transferApprox(done, epsilon);
Bundle done = firm->reserves_.transfer(from_reserves, to, epsilon);
out.transfer(done, epsilon);
if (out > 0) {
// Need to produce the rest
firm->produceReserved(out);
assets.transferApprox(out, to, epsilon);
assets.transfer(out, to, epsilon);
}
// Call this in case any of the excess production and/or payment assets allow us to reduce
......@@ -213,7 +213,7 @@ void Firm::Reservation::release() {
// Anything left should be transferrable from reserves to assets. This could throw a negativity
// exception if something got screwed up.
firm->reserves_.transferApprox(res_pos, firm->assets, firm->epsilon);
firm->reserves_.transfer(res_pos, firm->assets, firm->epsilon);
firm->reduceProduction();
}
......
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