Exemplo n.º 1
0
        static PopulationLayout ToLayout(PopulationSummary s)
        {
            var width_i = (int)Math.Round(PopulationBarWidth * ((double)s.Infectious / s.Total), MidpointRounding.AwayFromZero);
            var width_r = (int)Math.Round(PopulationBarWidth * ((double)s.Recovered / s.Total), MidpointRounding.AwayFromZero);

            return(new PopulationLayout
            {
                SusceptibleWidth = PopulationBarWidth - width_i - width_r,
                InfectiousWidth = width_i,
                RecoveredWidth = width_r,
            });
        }
Exemplo n.º 2
0
        public MainViewModel()
        {
            SusceptibleRatioVar = new ReactiveProperty <double>(AppModel.InitialSettings.PopulationRatio.Value.SusceptibleRatio);
            InfectiousRatioVar  = new ReactiveProperty <double>(AppModel.InitialSettings.PopulationRatio.Value.InfectiousRatio);

            SusceptibleRatioVar.Subscribe(s =>
            {
                var p0 = AppModel.InitialSettings.PopulationRatio.Value;
                var p  = new PopulationRatio
                {
                    SusceptibleRatio = s,
                    InfectiousRatio  = 1 - s - p0.RecoveredRatio,
                    RecoveredRatio   = p0.RecoveredRatio,
                };

                AppModel.InitialSettings.PopulationRatio.Value = p;
                InfectiousRatioVar.Value = p.InfectiousRatio;
            });
            InfectiousRatioVar.Subscribe(i =>
            {
                var p0 = AppModel.InitialSettings.PopulationRatio.Value;
                var p  = new PopulationRatio
                {
                    SusceptibleRatio = p0.SusceptibleRatio,
                    InfectiousRatio  = i,
                    RecoveredRatio   = 1 - p0.SusceptibleRatio - i,
                };

                AppModel.InitialSettings.PopulationRatio.Value = p;
            });

            SusceptibleRatioMaxValue = AppModel.InitialSettings.PopulationRatio
                                       .Select(p => 0.99 - p.RecoveredRatio)
                                       .ToReadOnlyReactiveProperty();
            InfectiousRatioMaxValue = AppModel.InitialSettings.PopulationRatio
                                      .Select(p => 1 - p.SusceptibleRatio)
                                      .ToReadOnlyReactiveProperty();

            PopulationImage   = AppModel.InfectionSnapshot.Select(DataModelHelper.GetBitmapBinary).ToReadOnlyReactiveProperty();
            PopulationSummary = AppModel.InfectionSnapshot.Select(DataModelHelper.ToSummary).ToReadOnlyReactiveProperty();
            PopulationLayout  = PopulationSummary.Select(ToLayout).ToReadOnlyReactiveProperty();
        }
Exemplo n.º 3
0
        public static PopulationSummary ToSummary(InfectionModel model)
        {
            var width  = model.InitialSettings.Size.Width;
            var height = model.InitialSettings.Size.Height;

            var summary = new PopulationSummary
            {
                Total = width * height,
            };

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    switch (model.Statuses[i, j])
                    {
                    case InfectionStatus.Susceptible:
                        summary.Susceptible++;
                        break;

                    case InfectionStatus.Infectious:
                        summary.Infectious++;
                        break;

                    case InfectionStatus.Recovered:
                        summary.Recovered++;
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                }
            }

            return(summary);
        }