Esempio n. 1
0
 public IVarianceIResultElement Calculate(
     IVarianceIResultElementFactory varianceIResultElementFactory,
     ItIndexElement tIndexElement,
     IΛIndexElement ΛIndexElement,
     Il l,
     It t,
     Ist st,
     IVarianceΦ varianceΦ,
     Iz z)
 {
     return(varianceIResultElementFactory.Create(
                tIndexElement,
                ΛIndexElement,
                st.Value
                .Select(w =>
                        varianceΦ.GetElementAtAsdecimal(
                            w.sIndexElement,
                            l.GetElementAt(
                                tIndexElement.Key
                                -
                                w.tIndexElement.Key
                                +
                                (int)Math.Floor(
                                    (decimal)w.tIndexElement.Key
                                    /
                                    (tIndexElement.Key + 1))
                                *
                                t.GetT()),
                            ΛIndexElement)
                        *
                        z.GetElementAtAsint(
                            w.sIndexElement,
                            w.tIndexElement))
                .Sum()));
 }
Esempio n. 2
0
        public Constraints6ConstraintElement(
            ItIndexElement tIndexElement,
            IΛIndexElement ΛIndexElement,
            Il l,
            It t,
            Ist st,
            IΦHat ΦVHat,
            IIHat IHat,
            Iz z)
        {
            Expression LHS = IHat.Value[tIndexElement, ΛIndexElement];

            Expression RHS = Expression.Sum(
                st.Value
                .Select(
                    y =>
                    (double)ΦVHat.GetElementAtAsdecimal(
                        y.sIndexElement,
                        l.GetElementAt(
                            tIndexElement.Key
                            -
                            y.tIndexElement.Key
                            +
                            (int)Math.Floor(
                                (decimal)(y.tIndexElement.Key)
                                /
                                (tIndexElement.Key + 1))
                            *
                            t.GetT()),
                        ΛIndexElement)
                    *
                    z.Value[y.sIndexElement, y.tIndexElement]));

            this.Value = LHS == RHS;
        }
        public Constraints11ConstraintElement(
            IdIndexElement dIndexElement,
            IwIndexElement wIndexElement,
            Id d,
            Il l,
            Ipa pa,
            IP P,
            Iprob prob,
            ITPx x,
            Iμ μ)
        {
            Expression LHS = μ.Value[wIndexElement, dIndexElement];

            ImmutableList <Tuple <IpIndexElement, IaIndexElement, double> > .Builder builder = ImmutableList.CreateBuilder <Tuple <IpIndexElement, IaIndexElement, double> >();

            foreach (IpIndexElement pIndexElement in pa.Value.Where(i => P.IsThereElementAt(wIndexElement, i.pIndexElement)).Select(w => w.pIndexElement).Distinct())
            {
                foreach (IaIndexElement aIndexElement in pa.Value.Select(w => w.aIndexElement).Distinct())
                {
                    int dLowerBound = aIndexElement.Key <= dIndexElement.Key ? dIndexElement.Key - aIndexElement.Key : d.GetMaximumKey() + dIndexElement.Key - aIndexElement.Key;

                    double RHSSum = 0;

                    for (int w = dLowerBound;
                         w <= l.GetMaximumLengthOfStay();
                         w = w + 1)
                    {
                        RHSSum +=
                            (double)prob.GetElementAtAsdecimal(
                                pIndexElement,
                                l.GetElementAt(
                                    w));
                    }

                    builder.Add(
                        Tuple.Create(
                            pIndexElement,
                            aIndexElement,
                            RHSSum));
                }
            }

            ImmutableList <Tuple <IpIndexElement, IaIndexElement, double> > RHSSums = builder.ToImmutableList();

            Expression RHS = Expression.Sum(
                pa.Value
                .Where(i => P.IsThereElementAt(wIndexElement, i.pIndexElement))
                .Select(
                    y =>
                    RHSSums.Where(w => w.Item1 == y.pIndexElement && w.Item2 == y.aIndexElement).Select(w => w.Item3).SingleOrDefault()
                    *
                    x.Value[
                        y.pIndexElement,
                        y.aIndexElement]));

            this.Value = LHS == RHS;
        }
        public IExpectedValueΦResultElement Calculate(
            IExpectedValueΦResultElementFactory expectedValueΦResultElementFactory,
            IlIndexElement lIndexElement,
            IsIndexElement sIndexElement,
            IΛIndexElement ΛIndexElement,
            Il l,
            It t,
            IL L,
            Ip p,
            Iμ μ)
        {
            int Ls = L.GetElementAtAsint(
                sIndexElement);

            int τLowerBound = 0;

            int τUpperBound = (int)Math.Floor(
                (decimal)
                (Ls - lIndexElement.Value.Value.Value)
                /
                t.GetT());

            decimal sum = 0;

            for (int τ = τLowerBound; τ <= τUpperBound; τ = τ + 1)
            {
                int lPrimeLowerBound = lIndexElement.Value.Value.Value + τ * t.GetT() + 1;

                int lPrimeUpperBound = Ls;

                for (int lPrime = lPrimeLowerBound; lPrime <= lPrimeUpperBound; lPrime = lPrime + 1)
                {
                    sum +=
                        p.GetElementAtAsdecimal(
                            sIndexElement,
                            l.GetElementAt(
                                lPrime),
                            ΛIndexElement);
                }
            }

            return(expectedValueΦResultElementFactory.Create(
                       sIndexElement,
                       lIndexElement,
                       ΛIndexElement,
                       μ.GetElementAtAsdecimal(
                           sIndexElement,
                           ΛIndexElement)
                       *
                       sum));
        }
        public IVarianceΦResultElement Calculate(
            IVarianceΦResultElementFactory varianceΦResultElementFactory,
            IlIndexElement lIndexElement,
            IsIndexElement sIndexElement,
            IΛIndexElement ΛIndexElement,
            Il l,
            It t,
            IL L,
            Ip p,
            Iμ μ,
            Iσ σ)
        {
            int Ls = L.GetElementAtAsint(
                sIndexElement);

            int τLowerBound = 0;

            int τUpperBound = (int)Math.Floor(
                (decimal)
                (Ls - lIndexElement.Value.Value.Value)
                /
                t.GetT());

            // Mean
            decimal meanSum = 0;

            for (int τ = τLowerBound; τ <= τUpperBound; τ = τ + 1)
            {
                int lPrimeLowerBound = lIndexElement.Value.Value.Value + τ * t.GetT() + 1;

                int lPrimeVarianceUpperBound = Math.Min(
                    lIndexElement.Value.Value.Value + τ * t.GetT() + t.GetT(),
                    Ls);

                int lPrimeCovarianceUpperBound = Math.Min(
                    lIndexElement.Value.Value.Value + τ * t.GetT() + t.GetT(),
                    Ls - 1);

                // Mean: Variance
                for (int lPrime = lPrimeLowerBound; lPrime <= lPrimeVarianceUpperBound; lPrime = lPrime + 1)
                {
                    meanSum +=
                        (τ + 1)
                        *
                        p.GetElementAtAsdecimal(
                            sIndexElement,
                            l.GetElementAt(
                                lPrime),
                            ΛIndexElement)
                        *
                        (1 - p.GetElementAtAsdecimal(
                             sIndexElement,
                             l.GetElementAt(
                                 lPrime),
                             ΛIndexElement));
                }

                // Mean: Covariance
                for (int lPrime = lPrimeLowerBound; lPrime <= lPrimeCovarianceUpperBound; lPrime = lPrime + 1)
                {
                    int lHatLowerBound = lPrime + 1;

                    int lHatUpperBound = Ls;

                    for (int lHat = lHatLowerBound; lHat <= lHatUpperBound; lHat = lHat + 1)
                    {
                        meanSum -=
                            (τ + 1)
                            *
                            2
                            *
                            p.GetElementAtAsdecimal(
                                sIndexElement,
                                l.GetElementAt(
                                    lPrime),
                                ΛIndexElement)
                            *
                            p.GetElementAtAsdecimal(
                                sIndexElement,
                                l.GetElementAt(
                                    lHat),
                                ΛIndexElement);
                    }
                }
            }

            // Variance
            decimal varianceSum = 0;

            for (int τ = τLowerBound; τ <= τUpperBound; τ = τ + 1)
            {
                int lPrimeLowerBound = lIndexElement.Value.Value.Value + τ * t.GetT() + 1;

                int lPrimeUpperBound = Ls;

                for (int lPrime = lPrimeLowerBound; lPrime <= lPrimeUpperBound; lPrime = lPrime + 1)
                {
                    varianceSum +=
                        p.GetElementAtAsdecimal(
                            sIndexElement,
                            l.GetElementAt(
                                lPrime),
                            ΛIndexElement);
                }
            }

            return(varianceΦResultElementFactory.Create(
                       sIndexElement,
                       lIndexElement,
                       ΛIndexElement,
                       μ.GetElementAtAsdecimal(
                           sIndexElement,
                           ΛIndexElement)
                       *
                       meanSum
                       +
                       σ.GetElementAtAsdecimal(
                           sIndexElement,
                           ΛIndexElement)
                       *
                       σ.GetElementAtAsdecimal(
                           sIndexElement,
                           ΛIndexElement)
                       *
                       varianceSum
                       *
                       varianceSum));
        }