Class Curve_Disco_PwAffine

  • All Implemented Interfaces:
    Curve, Curve_Affine, Curve_PwAffine
    Direct Known Subclasses:
    ArrivalCurve_Disco_PwAffine, MaxServiceCurve_Disco_PwAffine, ServiceCurve_Disco_PwAffine

    public class Curve_Disco_PwAffine
    extends java.lang.Object
    implements Curve_PwAffine
    Class representing a piecewise linear curve, defined on [0,inf).
    The curve is stored as an array of LinearSegment objects. Each of these objects defines a linear piece of the curve from one inflection point up to, but not including, the next. It is possible to define discontinuities by defining two subsequent LinearSegment instances which start at the same inflection point. In this case, the second segment needs to have leftopen set to true to indicate that the inflection point is excluded from the second segment.
    All arithmetic operations on a curve return a new instance of class Curve.
    • Field Detail

      • is_delayed_infinite_burst

        protected boolean is_delayed_infinite_burst
      • is_rate_latency

        protected boolean is_rate_latency
      • has_rate_latency_meta_info

        protected boolean has_rate_latency_meta_info
      • is_token_bucket

        protected boolean is_token_bucket
      • has_token_bucket_meta_info

        protected boolean has_token_bucket_meta_info
    • Constructor Detail

      • Curve_Disco_PwAffine

        protected Curve_Disco_PwAffine()
        Creates a CurveDNC instance with a single segment on the x-axis.
      • Curve_Disco_PwAffine

        protected Curve_Disco_PwAffine​(Curve curve)
      • Curve_Disco_PwAffine

        protected Curve_Disco_PwAffine​(int segment_count)
        Creates a Curve instance with segment_count empty LinearSegment instances.
        Parameters:
        segment_count - the number of segments
    • Method Detail

      • hasRateLatencyMetaInfo

        public boolean hasRateLatencyMetaInfo()
      • setRL_MetaInfo

        public void setRL_MetaInfo​(boolean has_rate_latency_meta_info)
        Specified by:
        setRL_MetaInfo in interface Curve
      • setRL_Components

        public void setRL_Components​(java.util.List<Curve> rate_latencies)
        Specified by:
        setRL_Components in interface Curve
      • hasTokenBucketMetaInfo

        public boolean hasTokenBucketMetaInfo()
      • setTB_MetaInfo

        public void setTB_MetaInfo​(boolean has_token_bucket_meta_info)
        Specified by:
        setTB_MetaInfo in interface Curve
      • setTB_Components

        public void setTB_Components​(java.util.List<Curve> token_buckets)
        Specified by:
        setTB_Components in interface Curve
      • createNewCurve

        private void createNewCurve​(int segment_count,
                                    boolean empty)
      • createZeroSegmentsCurve

        private void createZeroSegmentsCurve​(int segment_count)
      • initializeCurve

        protected void initializeCurve​(java.lang.String curve_str)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • forceThroughOrigin

        protected void forceThroughOrigin()
      • clearMetaInfo

        private void clearMetaInfo()
      • getSegment

        public LinearSegment_Disco getSegment​(int pos)
        Starting at 0.
        Specified by:
        getSegment in interface Curve
        Parameters:
        pos - Position of the segment to return.
        Returns:
        The linear segment at position pos.
      • getSegmentCount

        public int getSegmentCount()
        Returns the number of segments in this curve.
        Specified by:
        getSegmentCount in interface Curve
        Returns:
        the number of segments
      • getSegmentDefining

        public int getSegmentDefining​(Num x)
        Returns the number of the segment that defines the function value at x-coordinate x. The number of the segment is usually the same as the one returned by getSegmentLimitRight(x), except for if a segment starts at x and is left-open. In this case the function returns the previous segment, rather than the current segment, as the previous segment defines x.
        Specified by:
        getSegmentDefining in interface Curve
        Parameters:
        x - the x-coordinate
        Returns:
        the index of the segment into the array.
      • getSegmentLimitRight

        public int getSegmentLimitRight​(Num x)
        Returns the number of the segment that defines the value of the function when computing the limit to the right of the function at x-coordinate x. The number of the segment is usually the same as the one returned by getSegmentDefining(x), except for if a segment starts at x and is left-open. In this case the function returns the current segment, rather than the previous segment.
        Parameters:
        x - the x-coordinate
        Returns:
        the index of the segment into the array.
      • setSegment

        public void setSegment​(int pos,
                               LinearSegment s)
      • setSegments

        protected void setSegments​(LinearSegment[] segments)
      • addSegment

        public void addSegment​(LinearSegment s)
        Adds a LinearSegment to the end of the curve.
        Note: It is the user's responsibility to add segments in the order of increasing x-coordinates.
        Specified by:
        addSegment in interface Curve
        Parameters:
        s - the segment to be added.
      • addSegment

        public void addSegment​(int pos,
                               LinearSegment s)
        Adds a LinearSegment at the location pos of the curve.
        Note1; Segments after pos will be pushed back by one position.
        Note2: It is the user's responsibility to add segments in the order of increasing x-coordinates.
        Specified by:
        addSegment in interface Curve
        Parameters:
        pos - the index into the segment array to add the new segment.
        s - the segment to be added.
      • removeSegment

        public void removeSegment​(int pos)
        Removes the segment at position pos.
        Specified by:
        removeSegment in interface Curve
        Parameters:
        pos - the index of the segment to be removed.
      • isDiscontinuity

        public boolean isDiscontinuity​(int pos)
        Returns whether the inflection point is a (real or unreal) discontinuity.
        Specified by:
        isDiscontinuity in interface Curve
        Parameters:
        pos - the index of the IP
        Returns:
        true if the IP is a discontinuity, false if not.
      • isRealDiscontinuity

        public boolean isRealDiscontinuity​(int pos)
        Returns whether the inflection point is a real discontinuity, i.e. the y0 of the leftopen segment differs from the previous one.
        Specified by:
        isRealDiscontinuity in interface Curve
        Parameters:
        pos - the index of the IP
        Returns:
        true if the IP is a real discontinuity, false if not.
      • isUnrealDiscontinuity

        public boolean isUnrealDiscontinuity​(int pos)
        Returns whether the inflection point is an unreal discontinuity, i.e. the y0 of the leftopen segment is coincident with the y0 of the previous segment and therefore the unreal discontinuity may safely be removed.
        Specified by:
        isUnrealDiscontinuity in interface Curve
        Parameters:
        pos - the index of the IP
        Returns:
        true if the IP is an unreal discontinuity, false if not.
      • isWideSenseIncreasing

        public boolean isWideSenseIncreasing()
        Tests whether the curve is wide-sense increasing.
        Specified by:
        isWideSenseIncreasing in interface Curve
        Returns:
        whether the curve is wide-sense increasing.
      • isConvex

        public boolean isConvex()
        Tests whether the curve is convex.
        Specified by:
        isConvex in interface Curve
        Returns:
        whether the curve is convex.
      • isConvexIn

        public boolean isConvexIn​(Num a,
                                  Num b)
        Tests whether the curve is convex in [a,b].
        Specified by:
        isConvexIn in interface Curve
        Parameters:
        a - the lower bound of the test interval.
        b - the upper bound of the test interval.
        Returns:
        whether the curve is convex
      • isConcave

        public boolean isConcave()
        Tests whether the curve is concave.
        Specified by:
        isConcave in interface Curve
        Returns:
        whether the curve is concave.
      • isConcaveIn

        public boolean isConcaveIn​(Num a,
                                   Num b)
        Tests whether the curve is concave in [a,b].
        Specified by:
        isConcaveIn in interface Curve
        Parameters:
        a - the lower bound of the test interval.
        b - the upper bound of the test interval.
        Returns:
        whether the curve is concave.
      • isAlmostConcave

        public boolean isAlmostConcave()
        Tests whether the curve is almost concave, i.e. it is concave once its function value is larger than 0.
        Specified by:
        isAlmostConcave in interface Curve
        Returns:
        whether the curve is almost concave.
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface Curve
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface Curve
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns a string representation of this curve.
        Specified by:
        toString in interface Curve
        Overrides:
        toString in class java.lang.Object
        Returns:
        the curve represented as a string.
      • f

        public Num f​(Num x)
        Returns the function value at x-coordinate x, if x>=0, and NaN if not.
        Specified by:
        f in interface Curve
        Parameters:
        x - the x-coordinate
        Returns:
        the function value
      • fLimitRight

        public Num fLimitRight​(Num x)
        Returns the limit to the right of the function value at x-coordinate x, if x>=0, and NaN if not.
        Specified by:
        fLimitRight in interface Curve
        Parameters:
        x - the x-coordinate
        Returns:
        the function value
      • f_inv

        public Num f_inv​(Num y)
        Returns the smallest x value at which the function value is equal to y.
        Specified by:
        f_inv in interface Curve
        Parameters:
        y - the y-coordinate
        Returns:
        the smallest x value
      • f_inv

        public Num f_inv​(Num y,
                         boolean rightmost)
        Returns the x value at which the function value is equal to y. If rightmost is true, returns the rightmost x-coordinate, otherwise the leftmost coordinate.
        Specified by:
        f_inv in interface Curve
        Parameters:
        y - The y-coordinate.
        rightmost - Return the rightmost x coordinate instaed of the leftmost one (default).
        Returns:
        The smallest x value.
      • getSegmentFirstAtValue

        private int getSegmentFirstAtValue​(Num y)
        Returns the first segment at which the function reaches the value y. It returns -1 if the curve never reaches this value.
        Parameters:
        y - the y-coordinate
        Returns:
        the segment number
      • getLatency

        public Num getLatency()
        Returns the x-coordinate of the inflection point after which the function values are greater than zero.
        Specified by:
        getLatency in interface Curve
        Returns:
        the latency of this curve.
      • getBurst

        public Num getBurst()
        Specified by:
        getBurst in interface Curve
        Returns:
        the burstiness
      • getGradientLimitRight

        public Num getGradientLimitRight​(Num x)
        Returns the gradient to the right of the function value at x-coordinate x, if x>=0, and NaN if not.
        Specified by:
        getGradientLimitRight in interface Curve
        Parameters:
        x - the x-coordinate
        Returns:
        the function value
      • getUltAffineRate

        public Num getUltAffineRate()
        Returns the gradient of the last segment.
        Specified by:
        getUltAffineRate in interface Curve
        Returns:
        the rate of the ultimately affine part.
      • getRL_Property

        public boolean getRL_Property()
      • setRateLateny

        public void setRateLateny​(boolean is_rate_latency)
        Specified by:
        setRateLateny in interface Curve
      • getRL_ComponentCount

        public int getRL_ComponentCount()
        Returns the number of rate latency curves the curve can be decomposed into.
        Specified by:
        getRL_ComponentCount in interface Curve
        Returns:
        the number of rate latency curves
      • getRL_Component

        public Curve_Disco_PwAffine getRL_Component​(int i)
        Returns the ithe rate latency curve that this curve can be decomposed into.
        Specified by:
        getRL_Component in interface Curve
        Parameters:
        i - the number of the rate latency curve
        Returns:
        the rate latency curve
      • decomposeIntoRateLatencies

        private void decomposeIntoRateLatencies()
        Decomposes this curve into a list of rate latency curves and stores this list in the curve's rate_latencies field.
        Note: Curve must be convex.
      • setTokenBucket

        public void setTokenBucket​(boolean is_token_bucket)
        Specified by:
        setTokenBucket in interface Curve
      • getTB_ComponentCount

        public int getTB_ComponentCount()
        Returns the number of token buckets the curve can be decomposed into.
        Specified by:
        getTB_ComponentCount in interface Curve
        Returns:
        the number of token buckets
      • getTB_Component

        public Curve_Disco_PwAffine getTB_Component​(int i)
        Returns the ithe token bucket curve that this curve can be decomposed into.
        Specified by:
        getTB_Component in interface Curve
        Parameters:
        i - the number of the token bucket
        Returns:
        the token bucket
      • decomposeIntoTokenBuckets

        private void decomposeIntoTokenBuckets()
        Decomposes this curve into a list of token bucket curves and stores this list in the curve's token_buckets field.
        Note: Curve must be concave.
      • createHorizontal

        public Curve_Disco_PwAffine createHorizontal​(Num y)
        Creates a horizontal curve.
        Specified by:
        createHorizontal in interface Curve
        Parameters:
        y - the y-intercept of the curve
        Returns:
        a Curve instance