コード例 #1
0
        private void _InitGrid(Mars.Interfaces.Layer.Initialization.TInitData initData)
        {
            if (initData.LayerInitConfig != null && !string.IsNullOrEmpty(initData.LayerInitConfig.File))
            {
                var table = Mars.Common.IO.Csv.CsvReader.MapData(initData.LayerInitConfig.File, null, false);

                var xMaxIndex = table.Columns.Count;
                int yMaxIndex = table.Rows.Count - 1;

                _dimensionX = table.Columns.Count;
                _dimensionY = table.Rows.Count;
                foreach (System.Data.DataRow tableRow in table.Rows)
                {
                    for (int x = 0; x < xMaxIndex; x++)
                    {
                        var value = tableRow[x].ToString();
                        if (double.TryParse(value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture,
                                            out var result))
                        {
                            SetRealValue(x, yMaxIndex, result);
                        }
                        else
                        {
                            SetStringValue(x, yMaxIndex, value);
                        }
                    }
                    yMaxIndex--;
                }
            }
        }
コード例 #2
0
        public override bool InitLayer(
            Mars.Interfaces.Layer.Initialization.TInitData initData,
            Mars.Interfaces.Layer.RegisterAgent regHandle,
            Mars.Interfaces.Layer.UnregisterAgent unregHandle)
        {
            base.InitLayer(initData, regHandle, unregHandle);
            this._Register   = regHandle;
            this._Unregister = unregHandle;

            _InitGrid(initData);
            this._AllBlackEnvironment = new Mars.Components.Environments.SpatialHashEnvironment <AllBlack>(_dimensionX, _dimensionY, true);
            this._WallabyEnvironment  = new Mars.Components.Environments.SpatialHashEnvironment <Wallaby>(_dimensionX, _dimensionY, true);

            _AllBlackAgents = Mars.Components.Services.AgentManager.SpawnAgents <AllBlack>(
                initData.AgentInitConfigs.First(config => config.Type == typeof(AllBlack)),
                regHandle, unregHandle,
                new System.Collections.Generic.List <Mars.Interfaces.Layer.ILayer> {
                this
            });
            _WallabyAgents = Mars.Components.Services.AgentManager.SpawnAgents <Wallaby>(
                initData.AgentInitConfigs.First(config => config.Type == typeof(Wallaby)),
                regHandle, unregHandle,
                new System.Collections.Generic.List <Mars.Interfaces.Layer.ILayer> {
                this
            });

            return(true);
        }
コード例 #3
0
        public override bool InitLayer(
            Mars.Interfaces.Layer.Initialization.TInitData initData,
            RegisterAgent regHandle,
            UnregisterAgent unregHandle)
        {
            base.InitLayer(initData, regHandle, unregHandle);
            _Register   = regHandle;
            _Unregister = unregHandle;

            _InitGrid(initData);
            _AnimalEnvironment = new SpatialHashEnvironment <Animal>(_dimensionX, _dimensionY, true);

            _AnimalAgents = Mars.Components.Services.AgentManager.SpawnAgents <Animal>(
                initData.AgentInitConfigs.First(config => config.Type == typeof(Animal)),
                regHandle, unregHandle,
                new List <ILayer> {
                this
            });

            return(true);
        }
コード例 #4
0
        public override bool InitLayer(
            Mars.Interfaces.Layer.Initialization.TInitData initData,
            Mars.Interfaces.Layer.RegisterAgent regHandle,
            Mars.Interfaces.Layer.UnregisterAgent unregHandle)
        {
            base.InitLayer(initData, regHandle, unregHandle);
            this._Register   = regHandle;
            this._Unregister = unregHandle;

            _DistanceMetric = Mars.Mathematics.SpaceDistanceMetric.Chebyshev;
            var _gisLayerExist = false;

            if (!_isDefault && _lowerLeft != null && _upperRight != null)
            {
                this._AirTrafficControllerEnvironment = Mars.Components.Environments.GeoHashEnvironment <AirTrafficController> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);

                this._AircraftEnvironment = Mars.Components.Environments.GeoHashEnvironment <Aircraft> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);

                this._ObserverEnvironment = Mars.Components.Environments.GeoHashEnvironment <Observer> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);

                this._PilotEnvironment = Mars.Components.Environments.GeoHashEnvironment <Pilot> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);

                this._WeatherEnvironment = Mars.Components.Environments.GeoHashEnvironment <Weather> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);
            }
            else if (_gisLayerExist)
            {
                var geometries = new List <GeoAPI.Geometries.IGeometry>();
                var _factory   = new NetTopologySuite.Utilities.GeometricShapeFactory();
                var _feature   = new NetTopologySuite.Geometries.GeometryCollection(geometries.ToArray()).EnvelopeInternal;
                _minLon = _feature.MinX;
                _minLat = _feature.MinY;
                _maxLon = _feature.MaxX;
                _maxLat = _feature.MaxY;

                this._AirTrafficControllerEnvironment = Mars.Components.Environments.GeoHashEnvironment <AirTrafficController>
                                                        .BuildByBBox(_feature.MinX, _feature.MinY, _feature.MaxX, _feature.MaxY);

                this._AircraftEnvironment = Mars.Components.Environments.GeoHashEnvironment <Aircraft>
                                            .BuildByBBox(_feature.MinX, _feature.MinY, _feature.MaxX, _feature.MaxY);

                this._ObserverEnvironment = Mars.Components.Environments.GeoHashEnvironment <Observer>
                                            .BuildByBBox(_feature.MinX, _feature.MinY, _feature.MaxX, _feature.MaxY);

                this._PilotEnvironment = Mars.Components.Environments.GeoHashEnvironment <Pilot>
                                         .BuildByBBox(_feature.MinX, _feature.MinY, _feature.MaxX, _feature.MaxY);

                this._WeatherEnvironment = Mars.Components.Environments.GeoHashEnvironment <Weather>
                                           .BuildByBBox(_feature.MinX, _feature.MinY, _feature.MaxX, _feature.MaxY);
            }
            else if (_lowerLeft != null && _upperRight != null)
            {
                this._AirTrafficControllerEnvironment = Mars.Components.Environments.GeoHashEnvironment <AirTrafficController> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);

                this._AircraftEnvironment = Mars.Components.Environments.GeoHashEnvironment <Aircraft> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);

                this._ObserverEnvironment = Mars.Components.Environments.GeoHashEnvironment <Observer> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);

                this._PilotEnvironment = Mars.Components.Environments.GeoHashEnvironment <Pilot> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);

                this._WeatherEnvironment = Mars.Components.Environments.GeoHashEnvironment <Weather> .BuildByBBox(_lowerLeft.Longitude, _lowerLeft.Latitude, _upperRight.Longitude, _upperRight.Latitude);
            }
            else
            {
                throw new ArgumentException("No environment boundary was used for agent layer 'TestLayer'");
            }

            _AirTrafficControllerAgents = Mars.Components.Services.AgentManager.SpawnAgents <AirTrafficController>(
                initData.AgentInitConfigs.First(config => config.Type == typeof(AirTrafficController)),
                regHandle, unregHandle,
                new System.Collections.Generic.List <Mars.Interfaces.Layer.ILayer> {
                this
            });
            _AircraftAgents = Mars.Components.Services.AgentManager.SpawnAgents <Aircraft>(
                initData.AgentInitConfigs.First(config => config.Type == typeof(Aircraft)),
                regHandle, unregHandle,
                new System.Collections.Generic.List <Mars.Interfaces.Layer.ILayer> {
                this
            });
            _ObserverAgents = Mars.Components.Services.AgentManager.SpawnAgents <Observer>(
                initData.AgentInitConfigs.First(config => config.Type == typeof(Observer)),
                regHandle, unregHandle,
                new System.Collections.Generic.List <Mars.Interfaces.Layer.ILayer> {
                this
            });
            _PilotAgents = Mars.Components.Services.AgentManager.SpawnAgents <Pilot>(
                initData.AgentInitConfigs.First(config => config.Type == typeof(Pilot)),
                regHandle, unregHandle,
                new System.Collections.Generic.List <Mars.Interfaces.Layer.ILayer> {
                this
            });
            _WeatherAgents = Mars.Components.Services.AgentManager.SpawnAgents <Weather>(
                initData.AgentInitConfigs.First(config => config.Type == typeof(Weather)),
                regHandle, unregHandle,
                new System.Collections.Generic.List <Mars.Interfaces.Layer.ILayer> {
                this
            });

            return(true);
        }