public static int CountAdjcentPaths(PopulationData data, Cell cell)
    {
        int count = 0;
        int x     = cell.x;
        int y     = cell.y;

        if (x + 1 < data.maze.GetLength(0) && data.maze[x + 1, y].isPath)
        {
            count++;
        }

        if (x - 1 >= 0 && data.maze[x - 1, y].isPath)
        {
            count++;
        }

        if (y + 1 < data.maze.GetLength(1) && data.maze[x, y + 1].isPath)
        {
            count++;
        }

        if (y - 1 >= 0 && data.maze[x, y - 1].isPath)
        {
            count++;
        }

        return(count);
    }
        public IActionResult Index(PopulationData pd)
        {
            int x = pd.YearsToReachPopToSurpass();

            ViewBag.Years = x;
            return(View());
        }
Example #3
0
        private static Mesh BuildPopulationMesh(PopulationData data)
        {
            var count       = Math.Min(8192, data.Data.Count);
            var colors      = new Vector3Buffer(8 * count);
            var meshBuilder = new MeshBuilder();

            var matrix = Matrix.Identity;

            for (int i = 0; i < count; i++)
            {
                var location = data.Data[i];
                var height   = location.Size * 0.8f;
                var width    = 0.0025f;

                matrix.LoadIdentity();
                matrix.Rotate(Quaternion.CreateFromYawPitchRoll(MathF.Deg2Rad * (location.Lng), 0, MathF.Deg2Rad * (90 - location.Lat)));
                matrix.Translate(new Vector3(-0.5f * width, 0.5f + 0.5f * height, -0.5f * width));
                matrix.Scale(new Vector3(width, height, width));

                meshBuilder.AddBox(matrix);

                var color = Vector3.Lerp(new Vector3(0, 1, 0), new Vector3(1, 0.7f, 0), 3 * location.Size / data.Max);
                for (int k = 0; k < 8; k++)
                {
                    colors[k + i * 8] = color;
                }
            }

            var datamesh = meshBuilder.GetMesh();

            datamesh.Colors = colors;
            return(datamesh);
        }
Example #4
0
 /// <summary>
 /// aggiunge un'unità di popolazione alla lista di popolani liberi.
 /// </summary>
 /// <param name="unitToAdd"></param>
 public void AddPopulation(PopulationData unitToAdd)
 {
     AllFreePeople.Add(unitToAdd);
     if (OnFreePopulationChanged != null)
     {
         OnFreePopulationChanged();
     }
 }
Example #5
0
        public void GetPopulationDataTest()
        {
            var populationData = new PopulationData(Globals.testdataDirectory + "population.dat");

            populationData.Chance = 1;
            var data = populationData.getPopulationData();

            Assert.AreEqual(2, data.Count);
        }
Example #6
0
 void Start()
 {
     UpdateGraphic(" = " + AllFreePeople.Count);
     for (int i = 0; i < Startpop; i++)
     {
         PopulationData newUnit = CreatePopulation();
         AddPopulation(newUnit);
         AllPopulation.Add(newUnit);
     }
 }
Example #7
0
 /// <summary>
 /// morte di un popolano
 /// </summary>
 void UnitDeath(PopulationData unit)
 {
     AllFreePeople.Remove(unit);
     AllPopulation.Remove(unit);
     if (unit.building)
     {
         unit.building.Population.Remove(unit);
         unit.building = null;
     }
 }
Example #8
0
 /// <summary>
 /// restituisce l'edificio a cui appartiene l'unità passatagli.
 /// </summary>
 /// <param name="unit"></param>
 /// <returns></returns>
 public Vector3 GetBuildingContainingUnit(PopulationData unit)
 {
     foreach (BuildingView b in GetAllBuildingInScene())
     {
         if (b.Data.Population.Exists(u => u.UniqueID == unit.UniqueID))
         {
             return(b.transform.position);
         }
     }
     return(GameManager.I.gridController.GetCellPositionByStatus(CellDoomstock.CellStatus.Hole).WorldPosition);
 }
    public void saveDatFile()
    {
        BinaryFormatter bf = new BinaryFormatter ();
        FileStream file = File.Create (filePath + "/PopulationData.dat");

        Debug.Log (Application.persistentDataPath);

        PopulationData data = new PopulationData(this.pop);

        bf.Serialize (file, data);
        file.Close();
    }
Example #10
0
    /// <summary>
    /// genera un'unità di populationData
    /// </summary>
    /// <returns></returns>
    PopulationData CreatePopulation()
    {
        PopulationData unitToInstantiate = new PopulationData
        {
            // MaxAge = UnityEngine.Random.Range(MinLife, MaxLife),

            FoodRequirements = UnityEngine.Random.Range(MinFoodRequirement, MaxFoodRequirement),
            EatingTime       = 1
        };

        unitToInstantiate.Awake();
        return(unitToInstantiate);
    }
Example #11
0
    /// <summary>
    /// toglie un'unità di popolazione dalla lista di popolani liberi.
    /// </summary>
    /// <param name="unitIDToRemove"></param>
    public PopulationData GetUnit(string unitIDToRemove)
    {
        PopulationData pdata = AllFreePeople.Find(p => p.UniqueID == unitIDToRemove);

        if (!AllFreePeople.Remove(pdata))
        {
            return(null);
        }
        if (OnFreePopulationChanged != null)
        {
            OnFreePopulationChanged();
        }
        return(pdata);
    }
    public static Cell GetRandomFreeItemCell(PopulationData data)
    {
        Cell       cell;
        Vector2Int pos = new Vector2Int();

        do
        {
            cell  = data.mazePath[Random.Range(0, data.mazePath.Count)];
            pos.x = cell.x;
            pos.y = cell.y;
        }while (pos.Equals(data.startPos) || pos.Equals(data.exitPos) || data.mazeData[pos.x, pos.y].item != null);

        return(cell);
    }
    public static Cell GetRandomFreeUnitCell(PopulationData data)
    {
        Cell       cell;
        Vector2Int pos = new Vector2Int();

        do
        {
            cell  = data.mazePath[Random.Range(0, data.mazePath.Count)];
            pos.x = cell.x;
            pos.y = cell.y;
        }while (pos.Equals(data.startPos) || pos.Equals(data.exitPos) || !Maze.Instance.CanMoveTo(pos));

        return(cell);
    }
Example #14
0
    protected void cbx_changwat_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList   lSender   = sender as DropDownList;
        Int32          lGeocode  = Convert.ToInt32(lSender.SelectedValue);
        PopulationData lGeocodes = null;

        cbx_amphoe.Items.Clear();
        lGeocodes = TambonHelper.GetGeocodeList(lGeocode);
        foreach (PopulationDataEntry lEntry in lGeocodes.Data.SubEntities)
        {
            if (!lEntry.Obsolete)
            {
                cbx_amphoe.Items.Add(new ListItem(lEntry.English, lEntry.Geocode.ToString()));
            }
        }
    }
        protected void OneTrajectoryVisualisation()
        {
            // Create legend
            var legend = new LegendCreator();

            legend.OutputLegendImage();
            legend.OutputLegendTitle();

            var sections = new List <KMLAnimatorSectionInterface>();

            // Contour animator
            List <int> contoursOfInterest = (_view.VisualiseContoursOfInterest) ? _view.ContoursOfInterest : null;
            var        contourAnimator    = new ContourKMLAnimator(temporalGrid, trajectory, contoursOfInterest);

            if (_view.VisualiseGradient)
            {
                contourAnimator.SetGradientSettings((int)_view.LowestContourValue, (int)_view.HighestContourValue, (int)_view.ContourValueStep);
            }

            // Create sections
            sections.Add(new LegendKMLAnimator());
            sections.Add(new AircraftKMLAnimator(trajectory.Aircraft, trajectory));
            sections.Add(new AirplotKMLAnimator(trajectory));
            sections.Add(new GroundplotKMLAnimator(trajectory));
            sections.Add(contourAnimator);
            //new AnnoyanceKMLAnimator(temporalGrid, population.getPopulationData())
            if (_view.Heatmap)
            {
                var population = new PopulationData(Globals.currentDirectory + "population.dat");
                population.Chance = _view.PopulationFactor;
                var section = new HeatmapKMLAnimator(population);
                section.DotSize = _view.PopulationDotSize;
                section.DotFile = _view.PopulationDotFile;
                sections.Add(section);
            }

            // Create animator
            var camera   = new FollowKMLAnimatorCamera(trajectory.Aircraft, trajectory);
            var animator = new KMLAnimator(sections, camera);

            animator.AnimationToFile(trajectory.Duration, Globals.webrootDirectory + "visualisation.kml");

            _view.Invoke(delegate { _view.PreparationCalculationCompleted(); });
        }
Example #16
0
    /// <summary>
    /// Aggiunge all'edificio _building l'unità di popolazione con l'ID _unitIDToAdd
    /// </summary>
    /// <param name="_building"></param>
    public void AddPopulation(BuildingData _building, string _unitIDToAdd)
    {
        if (GameManager.I.populationManager.GetAllFreePeople().Count > 0)
        {
            //aggiunge il popolano all'edificio
            PopulationData pdata = GameManager.I.populationManager.GetUnit(_unitIDToAdd);
            _building.Population.Add(pdata);
            pdata.building = _building;

            //cambia lo stato del building a Producing.
            if (_building.Population.Count == 1 && _building.ID != "Casa" && _building.ID != "Foresta")
            {
                GameManager.I.buildingManager.GetBuildingView(_building.UniqueID).SetBuildingStatus(BuildingState.Producing);
            }

            //GameManager.I.messagesManager.ShowMessage(pdata, PopulationMessageType.AddToBuilding, GameManager.I.buildingManager.GetBuildingView(_building.UniqueID));
            //GameManager.I.messagesManager.ShowBuildingMessage(GameManager.I.buildingManager.GetBuildingView(_building.UniqueID), BuildingMessageType.PeopleAdded);
            GameManager.I.messagesManager.ShowiInformation(MessageLableType.AddPopulation, GameManager.I.gridController.Cells[XpositionOnGrid, YpositionOnGrid], true);
        }
    }
Example #17
0
        public async Task <JsonResult> ShowPopulation(int?id = null)
        {
            if (id == null)
            {
                memCache.TryGetValue("selectedYear", out id);
            }
            if (id != null)
            {
                memCache.Set("selectedYear", id, new MemoryCacheEntryOptions()
                             .SetSlidingExpiration(TimeSpan.FromMinutes(45))
                             .SetAbsoluteExpiration(TimeSpan.FromHours(1)));
                var data = await GetData((int)id);

                var returnVal = new PopulationData()
                {
                    Data = data, Year = (int)id
                };
                return(Json(returnVal));
            }
            return(null);
        }
Example #18
0
        private static List <PopulationData> ReadPopulationData()
        {
            var populationData = new List <PopulationData>();

            var json = File.ReadAllText("Resources\\Data\\population909500.json");
            var arr  = JArray.Parse(json);

            foreach (JArray item in arr)
            {
                var year      = Int32.Parse((string)((JValue)item[0]).Value);
                var locations = (JArray)item[1];

                var entry = new PopulationData()
                {
                    Year = year
                };
                populationData.Add(entry);

                for (int i = 0; i < locations.Count; i += 3)
                {
                    var lat  = Convert.ToInt32(((JValue)locations[i]).Value);
                    var lng  = Convert.ToInt32(((JValue)locations[i + 1]).Value);
                    var size = Convert.ToSingle(((JValue)locations[i + 2]).Value);

                    var location = new LocationPopulation()
                    {
                        Lat  = lat,
                        Lng  = lng,
                        Size = size
                    };
                    entry.Max = Math.Max(size, entry.Max);
                    entry.Data.Add(location);
                }
            }

            return(populationData);
        }
Example #19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.treemap.DataSource = PopulationData.GetData();
 }
Example #20
0
 public abstract bool AttemptSpawn(PopulationData data);
    public void Save()
    {
        Debug.Log("Save");

        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Create(Application.persistentDataPath + "/PopulationData.dat" );

        PopulationData data = new PopulationData(testPop.testedPools, testPop.untestedPools);

        bf.Serialize(file, data);
        file.Close();
    }
Example #22
0
    private void OnEvent(TimedEventData _eventData)
    {
        #region Birth
        if (_eventData.ID == "Birth")
        {
            if (GameManager.I.GetResourceDataByID("Food").Value > 0 && GameManager.I.buildingManager.IsThereAnySpace())
            {
                PopulationData newUnit = CreatePopulation();
                AddPopulation(newUnit);
                AllPopulation.Add(newUnit);
                BuildingView firstOpening = GameManager.I.buildingManager.GetFirstOpening();
                firstOpening.Data.Population.Add(newUnit);
                GameManager.I.messagesManager.ShowiInformation(MessageLableType.Birth, firstOpening.Data.Cell);
            }
        }
        #endregion

        #region FineMese
        if (_eventData.ID == "FineMese")
        {
            for (int i = 0; i < AllPopulation.Count; i++)
            {
                AllPopulation[i].Month++;

                if (AllPopulation[i].Month >= 12)
                {
                    AllPopulation[i].MaxAge--;
                    if (AllPopulation[i].MaxAge <= 0)
                    {
                        AllPopulation[i].Month = 0;
                    }
                }
            }
        }
        #endregion

        #region Food
        if (_eventData.ID == "Eat")
        {
            for (int i = 0; i < AllPopulation.Count; i++)
            {
                int eatingTime = AllPopulation[i].EatingTime;
                AllPopulation[i].EatingTime--;
                if (AllPopulation[i].EatingTime <= 0)
                {
                    AllPopulation[i].EatingTime = 0;
                    GameManager.I.GetResourceDataByID("Food").Value -= AllPopulation[i].FoodRequirements;
                    if (AllPopulation[i].EatingTime <= 0)
                    {
                        AllPopulation[i].EatingTime = eatingTime;
                    }
                    #region morte di fame
                    if (GameManager.I.GetResourceDataByID("Food").Value <= 0)
                    {
                        GameManager.I.GetResourceDataByID("Food").Value = 0;
                        GameManager.I.uiManager.FoodText.color          = Color.red;
                        UnitDeath(AllPopulation[i]);
                    }
                    #endregion
                }
            }
        }
    }
Example #23
0
        private void CalculateLocalGovernmentPopulation()
        {
            var allTambon = _allEntities.Where(x => x.type == EntityType.Tambon).ToList();
            foreach ( var localEntityWithoutPopulation in _localGovernments.Where(x =>
                x.LocalGovernmentAreaCoverage.Any() && !x.population.Any(
                y => y.Year == PopulationReferenceYear && y.source == PopulationDataSource)) )
            {
                var populationData = new PopulationData();
                localEntityWithoutPopulation.population.Add(populationData);
                foreach ( var coverage in localEntityWithoutPopulation.LocalGovernmentAreaCoverage )
                {
                    var tambon = allTambon.Single(x => x.geocode == coverage.geocode);
                    var sourcePopulationData = tambon.population.FirstOrDefault(y => y.Year == PopulationReferenceYear && y.source == PopulationDataSource);
                    if ( sourcePopulationData != null )
                    {
                        populationData.year = sourcePopulationData.year;
                        populationData.referencedate = sourcePopulationData.referencedate;
                        populationData.referencedateSpecified = sourcePopulationData.referencedateSpecified;
                        populationData.source = sourcePopulationData.source;

                        List<HouseholdDataPoint> dataPointToClone = new List<HouseholdDataPoint>();
                        dataPointToClone.AddRange(sourcePopulationData.data.Where(x => x.geocode == localEntityWithoutPopulation.geocode));
                        if ( !dataPointToClone.Any() )
                        {
                            if ( coverage.coverage == CoverageType.completely )
                            {
                                dataPointToClone.AddRange(sourcePopulationData.data);
                            }
                            else
                            {
                                dataPointToClone.AddRange(sourcePopulationData.data.Where(x => x.type == PopulationDataType.nonmunicipal));
                            }
                        }
                        foreach ( var dataPoint in dataPointToClone )
                        {
                            var newDataPoint = new HouseholdDataPoint();
                            newDataPoint.male = dataPoint.male;
                            newDataPoint.female = dataPoint.female;
                            newDataPoint.households = dataPoint.households;
                            newDataPoint.total = dataPoint.total;
                            newDataPoint.geocode = coverage.geocode;
                            newDataPoint.type = dataPoint.type;
                            populationData.data.Add(newDataPoint);
                        }
                    }
                }
                if ( populationData.data.Count == 1 )
                {
                    populationData.data.First().type = PopulationDataType.total;
                }
                populationData.CalculateTotal();
            }
        }
 public HeatmapKMLAnimator(PopulationData population)
 {
     DotSize     = 3000;
     DotFile     = "dot2_30.png";
     _population = population.getPopulationData();
 }
Example #25
0
 public void SetupSavedPopulationData(PopulationData populationData)
 {
     //Debug.Log("SetupSavedPopulationData");
     SetPopulationParameters(populationData.totalPopulationAmount, populationData.attackPercentage, populationData.defensePercentage, populationData.productionPercentage);
     PlanetCanvasManager.instance.SetPopulationPercentages(populationAttackPercentage, populationDefensePercentage, populationProductionPercentage);
 }
        protected void MultipleTrajectoryVisualisation()
        {
            // Legend
            var legend = new LegendCreator();

            // plot legend
            legend.OutputLegendImage();
            legend.OutputLegendTitle();

            // Create sections
            var sections = new List <KMLAnimatorSectionInterface>();

            //sections.Add(new MaintainMultipleGroundPlotKMLAnimator(trajectories));
            if (!VisualiseOptimisation)
            {
                // Contour animator
                List <int> contoursOfInterest = (_view.VisualiseContoursOfInterest) ? _view.ContoursOfInterest : null;
                var        contourAnimator    = new ContourKMLAnimator(temporalGrid, null, contoursOfInterest);
                if (_view.VisualiseGradient)
                {
                    legend.SetSettings(_view.LowestContourValue, _view.HighestContourValue);
                    contourAnimator.SetGradientSettings((int)_view.LowestContourValue, (int)_view.HighestContourValue, (int)_view.ContourValueStep);
                }
                contourAnimator.AltitudeOffset = (_view.MapFile != "");
                sections.Add(new MultipleGroundplotKMLAnimator(trajectories));
                sections.Add(new LegendKMLAnimator());
                sections.Add(contourAnimator);
            }
            else
            {
                trajectories = TrajectoryFitness.trajectories;
                sections.Add(new FitnessGroundPlotKMLAnimator(trajectories));
            }
            if (_view.MapFile != "")
            {
                sections.Add(new CustomMapKMLAnimator(_view.MapFile, _view.MapBottomLeft, _view.MapUpperRight));
            }
            if (_view.Heatmap)
            {
                var population = new PopulationData(Globals.currentDirectory + "population.dat");
                population.Chance = _view.PopulationFactor;
                var section = new HeatmapKMLAnimator(population);
                section.DotSize = _view.PopulationDotSize;
                section.DotFile = _view.PopulationDotFile;
                sections.Add(section);
            }

            var camera = new TopViewKMLAnimatorCamera(
                new GeoPoint3D(4.9773743, 52.2384423,
                               _view.CameraAltitude)
                );
            // Create animator

            /*
             * var camera = new TopViewKMLAnimatorCamera(
             *  new GeoPoint3D(referencePoint.GeoPoint.Longitude, referencePoint.GeoPoint.Latitude,
             *  _view.CameraAltitude)
             * );
             */
            var animator = new KMLAnimator(sections, camera);

            animator.Duration = 0;
            animator.AnimationToFile(trajectories.Count, Globals.webrootDirectory + "visualisation.kml");

            _view.Invoke(delegate { _view.PreparationCalculationCompleted(); });
        }