Safe Haskell | None |
---|---|
Language | Haskell2010 |
ProductMixAuction.LP.Demand
Description
This module is responsible for calculating data for supply and demand curves of different types.
- data DemandCurveType
- data DemandCurve = DemandCurve {
- _dc_type :: DemandCurveType
- _dc_supply :: [(Units, Price)]
- _dc_demand :: [(Units, Price)]
- _dc_max_price :: Price
- defaultDemandCurves :: Supply u -> Maybe (TQSS fun) -> [DemandCurveType]
- calcDemand :: Goodly bid => Auction bid -> Maybe (TQSS TQSSTable) -> Map Good Units -> [DemandCurveType] -> IO (Map Good [DemandCurve])
- normalisedTotalDemandPoints :: forall bid. Ord bid => Supply Units -> [Bid bid] -> Map Good Price -> Map bid (Map Good Units) -> [(Units, Price)]
- stepsToPoints :: Price -> [Step Units] -> [(Units, Price)]
- bidSurplus :: Map Good Price -> Bid bid -> (Double, Set Good, Double, Set Good)
- dc_type :: Lens' DemandCurve DemandCurveType
- dc_supply :: Lens' DemandCurve [(Units, Price)]
- dc_demand :: Lens' DemandCurve [(Units, Price)]
- dc_max_price :: Lens' DemandCurve Price
Representation of demand curves
data DemandCurveType Source #
The demand curve type determines how to calculate supply and
demand. See calcDemand
for more details. Where applicable, the
Int
field gives the number of points to use when calculating
demand by repeated runs of the LP.
Constructors
VariableTotalAllocation Int | Base goods keep their original supply curve, and for other goods, we fix the supply based on the allocations resulting from the original run of the auction. |
FixedTotalAllocation Int | Supply curves of all goods are fixed based on the original allocations. |
AdjustedDemand Int | Only the supply curve for the current good is fixed, and it uses a large negative price to avoid quantities other than the target quantity. |
UnadjustedDemand | Aggregate demand of all the bids on this good, ignoring bidding on other goods (so paired bids are counted for multiple goods). Only really makes sense for horizontal auctions. |
UnadjustedDemandWithTQSS | Same demand curve values as |
NoDemand | Supply curve only, without any demand curve points. |
Instances
Eq DemandCurveType Source # | |
Read DemandCurveType Source # | |
Show DemandCurveType Source # | |
Generic DemandCurveType Source # | |
ToJSON DemandCurveType Source # | |
FromJSON DemandCurveType Source # | |
Arbitrary DemandCurveType Source # | |
type Rep DemandCurveType Source # | |
data DemandCurve Source #
Data for plotting a supply and demand curve graph.
Constructors
DemandCurve | |
Fields
|
Instances
Eq DemandCurve Source # | |
Show DemandCurve Source # | |
Generic DemandCurve Source # | |
ToJSON DemandCurve Source # | |
FromJSON DemandCurve Source # | |
Arbitrary DemandCurve Source # | |
type Rep DemandCurve Source # | |
defaultDemandCurves :: Supply u -> Maybe (TQSS fun) -> [DemandCurveType] Source #
Determine which graphs to generate for this supply by default.
For a horizontal supply we generate UnadjustedDemand
(and
UnadjustedDemandWithTQSS
if there is a constraint-based TQSS),
which do not require the number of points to be specified. For a
vertical supply we generate AdjustedDemand
with a small number of
points. Do not generate demand curves for more complex supply
orderings.
Calculating demand curves
calcDemand :: Goodly bid => Auction bid -> Maybe (TQSS TQSSTable) -> Map Good Units -> [DemandCurveType] -> IO (Map Good [DemandCurve]) Source #
Calculate a list of supply and demand curves for each good.
The number of units (horizontal axis) gives the amount allocated to the good and all successive goods. The price (vertical axis) gives the demand price of the good relative to the demand price of the previous good.
For UnadjustedDemand
and UnadjustedDemandWithTQSS
, the demand
of all the bids on this good is aggregated, ignoring bidding on
other goods (so paired bids are counted for multiple goods). This
only really makes sense for horizontal auctions. The latter adds
the TQSS vertically to the supply curve.
For other demand curve types, this uses calcDemandCurveLP
to run
the auction repeatedly over a range of quantities. The supply of
the current good is fixed to be the desired quantity. The supply
of other goods is adjusted depending upon the DemandCurveType
:
- For
VariableTotalAllocation
, the base goods keep their original supply curve, and for other goods, we fix the supply based on the allocations resulting from the original run of the auction. Fixed supply curves have a single step of height zero. - For
FixedTotalAllocation
, the supply curves of all goods are fixed based on the allocations. Fixed supply curves have a single step of height zero. - For
AdjustedDemand
, all goods other than the current good keep their original supply curves. The fixed supply curve for the current good has a single step with a large negative height.
normalisedTotalDemandPoints :: forall bid. Ord bid => Supply Units -> [Bid bid] -> Map Good Price -> Map bid (Map Good Units) -> [(Units, Price)] Source #
Calculate the normalised total demand as a decreasing step function from quantities to prices, represented as a list of points.
This works essentially as follows:
- Assign each bid's quantity demanded to one or more goods, giving an absolute demand curve for each good.
- Normalise each absolute demand curve by subtracting the supply curve for the corresponding good.
- Add the normalised demand curves horizontally.
For the first step, we must convert a bid into the demand on one or more goods. If the bid is definitely fully allocated (its surplus is strictly positive), its demand corresponds to what it is actually allocated. If the bid has a zero surplus, but is allocated something, its demand includes what it is actually allocated and uses an arbitrary allocated good for the remainder. Otherwise, if the bid is not allocated anything, use an arbitrary good that maximises its (possibly negative) surplus.
Note that for bids whose surplus is not strictly positive this is an approximation: making different arbitrary choices would change the demand graph (but only for quantities beyond the total allocated).
Utilities
stepsToPoints :: Price -> [Step Units] -> [(Units, Price)] Source #
Convert a list of steps into a list of points. This includes two points for each step (giving the left and right ends for each given price), plus an extra point indicating the line going off to infinity.
bidSurplus :: Map Good Price -> Bid bid -> (Double, Set Good, Double, Set Good) Source #
Given the auction prices and a bid, calculate:
- the maximal surplus
m
achieved by the bid (i.e. the value to the bid of its preferred goods at the given prices); - the set of goods
gs
that achieve surplusm
; - the maximal surplus
m'
achieved on goods that may be marginal for generalised bids (i.e. goods with a surplus of zero or a non-unique positive value); - the set of goods
gs'
that achieve surplusm'
.
Lenses
dc_type :: Lens' DemandCurve DemandCurveType Source #
dc_max_price :: Lens' DemandCurve Price Source #