//public double GetSumOfAllXCellFuzzyOutputs()
        //{
        //    var sum = 0.0;
        //    foreach(var xCellFuzzy in ListOfXCellFuzzy)
        //    {
        //        sum += xCellFuzzy.OutputFuzzyValue;
        //    }
        //    return sum;
        //}

        //public override void GetInputData() //Diastole
        //{
        //    if(this.ListOfInputChannels.Count>0)
        //    {
        //        IN = ListOfInputChannels[0].Aij;

        //        var lowerLimit = IN - RegionsManager.r;
        //        var upperLimit = IN + RegionsManager.r;
        //        if (RegionsManager.TryToAddANewRegion(lowerLimit, upperLimit))//RegionsManager.CheckIfRegionIsAvailable(lowerLimit, upperLimit))
        //        {
        //            var xCellFuzzyNew = new XCellFuzzy($"{lowerLimit}<{Id}<{upperLimit}", Layer, RegionsManager.R);
        //            xCellFuzzyNew.ListOfInputChannels.Add(ListOfInputChannels[0]);
        //            //RegionsManager.TryToAddANewRegion(lowerLimit, upperLimit);
        //            ListOfXCellFuzzy.Add(xCellFuzzyNew);
        //            //xCellFuzzyNew.GetInputData();
        //            //Recalculate_r();
        //        }

        //        foreach (var xCellFuzzy in ListOfXCellFuzzy)
        //        {
        //            xCellFuzzy.GetInputData();
        //            xCellFuzzy.SendOutputData();
        //        }
        //    }
        //}

        //public override void SendOutputData() //Systole
        //{
        //    //var lowerLimit = IN - RegionsManager.r;
        //    //var upperLimit = IN + RegionsManager.r;
        //    //if (RegionsManager.TryToAddANewRegion(lowerLimit, upperLimit))//RegionsManager.CheckIfRegionIsAvailable(lowerLimit, upperLimit))
        //    //{
        //    //    var xCellFuzzyNew = new XCellFuzzy($"{lowerLimit}<{Id}<{upperLimit}", Layer, RegionsManager.R);
        //    //    xCellFuzzyNew.ListOfInputChannels.Add(ListOfInputChannels[0]);
        //    //    //RegionsManager.TryToAddANewRegion(lowerLimit, upperLimit);
        //    //    ListOfXCellFuzzy.Add(xCellFuzzyNew);
        //    //    //xCellFuzzyNew.GetInputData();
        //    //    //Recalculate_r();
        //    //}

        //    //foreach (var xCellFuzzy in ListOfXCellFuzzy)
        //    //{
        //    //    xCellFuzzy.GetInputData();
        //    //    xCellFuzzy.SendOutputData();
        //    //}

        //    XCellFuzzy xCellFuzzyWithGreaterOutput = null;
        //    double greaterOutput = 0;
        //    foreach (var xCellFuzzy in ListOfXCellFuzzy.Where(xCellFuzz => xCellFuzz.ListOfOutputChannels[0].IsActive && xCellFuzz.ListOfOutputChannels[0].Aij > 0))
        //    {
        //        if (!ORExplodeLayer.ListOfXCellsOrExplode.Any(xCellORExplode => xCellORExplode.Id == xCellFuzzy.Id))
        //        {
        //            var xCellOrExplode = new XCellORExplode(xCellFuzzy.Id, this.Layer);
        //            ORExplodeLayer.ListOfXCellsOrExplode.Add(xCellOrExplode);
        //            ORExplodeLayer.ListOfInputChannels.Add(xCellFuzzy.ListOfOutputChannels[0]);
        //        }
        //        if (xCellFuzzy.ListOfOutputChannels[0].Aij > greaterOutput)
        //        {
        //            greaterOutput = xCellFuzzy.ListOfOutputChannels[0].Aij;
        //            xCellFuzzyWithGreaterOutput = xCellFuzzy;
        //        }
        //    }

        //    if (xCellFuzzyWithGreaterOutput != null)
        //    {
        //        var outputChannelFound = ListOfOutputChannels.FirstOrDefault(outputChannel => outputChannel.XCellOrigin.Id == xCellFuzzyWithGreaterOutput.Id);
        //        if (outputChannelFound == null)
        //        {
        //            ListOfOutputChannels.Add(xCellFuzzyWithGreaterOutput.ListOfOutputChannels[0]);
        //        }
        //    }
        //}

        public override void GetInputData() //Diastole
        {
            if (this.ListOfInputChannels.Count > 0)
            {
                IN = ListOfInputChannels[0].Aij;

                var lowerLimit = IN - RegionsManager.r;
                var upperLimit = IN + RegionsManager.r;
                if (RegionsManager.TryToAddANewRegion(lowerLimit, upperLimit))//RegionsManager.CheckIfRegionIsAvailable(lowerLimit, upperLimit))
                {
                    var xCellFuzzyNew = new XCellFuzzy($"{lowerLimit}<{Id}<{upperLimit}", Layer, RegionsManager.R);
                    xCellFuzzyNew.ListOfInputChannels.Add(ListOfInputChannels[0]);
                    //RegionsManager.TryToAddANewRegion(lowerLimit, upperLimit);
                    ListOfXCellFuzzy.Add(xCellFuzzyNew);
                    //xCellFuzzyNew.GetInputData();
                    //Recalculate_r();
                }

                foreach (var xCellFuzzy in ListOfXCellFuzzy)
                {
                    xCellFuzzy.GetInputData();
                    xCellFuzzy.SendOutputData();
                }
            }
        }
        public override void SendOutputData() //Systole
        {
            //var lowerLimit = IN - RegionsManager.r;
            //var upperLimit = IN + RegionsManager.r;
            //if (RegionsManager.TryToAddANewRegion(lowerLimit, upperLimit))//RegionsManager.CheckIfRegionIsAvailable(lowerLimit, upperLimit))
            //{
            //    var xCellFuzzyNew = new XCellFuzzy($"{lowerLimit}<{Id}<{upperLimit}", Layer, RegionsManager.R);
            //    xCellFuzzyNew.ListOfInputChannels.Add(ListOfInputChannels[0]);
            //    //RegionsManager.TryToAddANewRegion(lowerLimit, upperLimit);
            //    ListOfXCellFuzzy.Add(xCellFuzzyNew);
            //    //xCellFuzzyNew.GetInputData();
            //    //Recalculate_r();
            //}

            //foreach (var xCellFuzzy in ListOfXCellFuzzy)
            //{
            //    xCellFuzzy.GetInputData();
            //    xCellFuzzy.SendOutputData();
            //}

            XCellFuzzy xCellFuzzyWithGreaterOutput = null;
            double     greaterOutput = 0;

            foreach (var xCellFuzzy in ListOfXCellFuzzy.Where(xCellFuzz => xCellFuzz.ListOfOutputChannels[0].IsActive && xCellFuzz.ListOfOutputChannels[0].Aij > 0))
            {
                if (!ORExplodeLayer.ListOfXCellsOrExplode.Any(xCellORExplode => xCellORExplode.Id == xCellFuzzy.Id))
                {
                    var xCellOrExplode = new XCellORExplode(xCellFuzzy.Id, this.Layer);
                    ORExplodeLayer.ListOfXCellsOrExplode.Add(xCellOrExplode);
                    ORExplodeLayer.ListOfInputChannels.Add(xCellFuzzy.ListOfOutputChannels[0]);
                }
                if (xCellFuzzy.ListOfOutputChannels[0].Aij > greaterOutput)
                {
                    greaterOutput = xCellFuzzy.ListOfOutputChannels[0].Aij;
                    xCellFuzzyWithGreaterOutput = xCellFuzzy;
                }
            }

            if (xCellFuzzyWithGreaterOutput != null)
            {
                var outputChannelFound = ListOfOutputChannels.FirstOrDefault(outputChannel => outputChannel.XCellOrigin.Id == xCellFuzzyWithGreaterOutput.Id);
                if (outputChannelFound == null)
                {
                    ListOfOutputChannels.Add(xCellFuzzyWithGreaterOutput.ListOfOutputChannels[0]);
                }
            }
        }