pub struct PwlCurve(/* private fields */);
Expand description
A representation of a piecewise-linear, weakly monotone decreasing demand curve
Demand curves define a bidder’s willingness to pay for different quantities of a good. In flow trading, these curves must be:
- Piecewise-linear (defined by a sequence of points)
- Weakly monotone decreasing (price non-increasing as rate increases)
- Include the point rate=0 in their domain (must allow zero trade)
Unlike a ConstantCurve
, all values (rates and prices) must be finite.
Implementations§
Source§impl PwlCurve
impl PwlCurve
Sourcepub fn new(points: Vec<Point>) -> Result<Self, PwlCurveError>
pub fn new(points: Vec<Point>) -> Result<Self, PwlCurveError>
Creates a new PwlCurve from a vector of points, validating all constraints
Sourcepub unsafe fn new_unchecked(points: Vec<Point>) -> Self
pub unsafe fn new_unchecked(points: Vec<Point>) -> Self
Creates a new PwlCurve without validating the points
§Safety
This function bypasses all validation checks. The caller must guarantee that
the points satisfy all requirements validated by PwlCurve::try_from
.
Using invalid points can lead to incorrect behavior in downstream systems,
particularly in the solver which assumes valid monotone curves.
Trait Implementations§
Source§impl From<PwlCurve> for DemandCurve
impl From<PwlCurve> for DemandCurve
Source§impl Into<PwlCurveDto> for PwlCurve
impl Into<PwlCurveDto> for PwlCurve
Source§fn into(self) -> PwlCurveDto
fn into(self) -> PwlCurveDto
Source§impl TryFrom<PwlCurveDto> for PwlCurve
impl TryFrom<PwlCurveDto> for PwlCurve
Source§fn try_from(value: PwlCurveDto) -> Result<Self, Self::Error>
fn try_from(value: PwlCurveDto) -> Result<Self, Self::Error>
Attempts to create a PwlCurve from a DTO, validating all constraints
§Validation
This function validates that:
- The vector is not empty
- No coordinate values are NaN
- Points are ordered by ascending rate and descending price (monotonicity)
- The curve domain includes rate=0 (allows zero trade)
§Errors
Returns PwlCurveError
if any validation fails.