private void AggregateMaxSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, float[] coverRatio, float[] FactorVector)
        {
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            //float[] factors = LevelAggInfo.GetFactor();
            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }
            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            int   MapPosition = 1;
            float MaxSubject  = 0;
            int   numOfMax    = 0;

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++) //for each parent
                {
                    //MaxSubject = TotalPayoutState[ChildrenMap[0]];
                    //MaxSubject = 0;
                    MaxSubject = TotalPayoutState[ChildrenMap[MapPosition - 1]] * factors[MapPosition - 1];
                    numOfMax   = 0;

                    for (int j = MapPosition + 1; j <= MapPartitions[i]; j++)
                    {
                        float temp = TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1];
                        MaxSubject = Math.Max(MaxSubject, temp);
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        if (MaxSubject == TotalPayoutState[ChildrenMap[j]] * factors[j])
                        {
                            coverRatio[j - 1] = 1;
                            numOfMax++;
                        }
                    }

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j - 1] /= numOfMax;
                    }

                    TotalSubjectState[ParentPosition] = MaxSubject * factors[MapPosition];
                    //MapPosition += MapPartitions[i];
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++) //for each parent
                {
                    MaxSubject = TotalPayoutState[ChildrenMap[MapPosition - 1]] * factors[MapPosition - 1];
                    numOfMax   = 0;

                    for (int j = MapPosition + 1; j <= MapPartitions[i]; j++)
                    {
                        float temp = TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1];
                        MaxSubject = Math.Max(MaxSubject, temp);
                    }

                    //ratio
                    for (int j = MapPosition; j <= MapPartitions[i]; j++)
                    {
                        if (MaxSubject == TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1])
                        {
                            coverRatio[j - 1] = 1;
                            numOfMax++;
                        }
                    }

                    for (int j = MapPosition; j <= MapPartitions[i]; j++)
                    {
                        coverRatio[j - 1] /= numOfMax;
                    }

                    TotalSubjectState[ParentPosition] = MaxSubject;
                    //MapPosition += MapPartitions[i];
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
        }
        private void AggregateMixSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, IDerivedCoverLevelNodeAggInfo DerivedInfo, float[] coverRatio, float[] FactorVector)
        {
            //TODO: for agg is fine, but for allocation we cannot use this method
            throw new NotSupportedException("Mix Derived cover subject is not supported");
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            int     MapPosition       = 1;
            float   TempSubject       = 0;
            float   ChildR            = 0;
            float   x = 0;

            float[] multiplier = DerivedInfo.GetMixFunctionMultiplier();
            //float[] factors = LevelAggInfo.GetFactor();
            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }
            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    TempSubject = TotalPayoutState[ChildrenMap[0]];
                    x           = multiplier[i];

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ChildR      = TotalPayoutState[ChildrenMap[j]];
                        TempSubject = (TempSubject + ChildR) - x * Math.Abs(TempSubject - ChildR) - Math.Abs(x) * (TempSubject + ChildR);
                    }
                    TotalSubjectState[ParentPosition] = TempSubject * factors[MapPosition];
                    MapPosition += MapPartitions[i];
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    TempSubject = TotalPayoutState[ChildrenMap[0]] * factors[0];
                    x           = multiplier[i];

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ChildR      = TotalPayoutState[ChildrenMap[j]] * factors[j];
                        TempSubject = (TempSubject + ChildR) - x * Math.Abs(TempSubject - ChildR) - Math.Abs(x) * (TempSubject + ChildR);
                    }
                    TotalSubjectState[ParentPosition] = TempSubject;
                    MapPosition += MapPartitions[i];
                    ParentPosition++;
                }
            }
        }
        private void AggregateSumSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, float[] coverRatio, float[] FactorVector)
        {
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            int     MapPosition       = 0;

            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }

            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    float ParentSubject = 0;
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ParentSubject += TotalPayoutState[ChildrenMap[j]] * factors[j];  //denominator
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j] = (ParentSubject == 0) ? 0 : TotalPayoutState[ChildrenMap[j]] * factors[j] / ParentSubject;
                    }

                    TotalSubjectState[ParentPosition] = ParentSubject;
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    float ParentSubject = 0;
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ParentSubject += TotalPayoutState[ChildrenMap[j]] * factors[j];  //denominator
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j] = (ParentSubject == 0) ? 0 : TotalPayoutState[ChildrenMap[j]] * factors[j] / ParentSubject;
                    }

                    TotalSubjectState[ParentPosition] = ParentSubject;
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
        }