/// <summary>
        /// Simulates the occupancy process.
        /// </summary>
        /// <param name="dataFieldName">Name of the data field to store the simulation results.</param>
        /// <param name="notify">if set to <c>true</c> sends a message when the background thread finishes the simulation.</param>
        /// <exception cref="System.ArgumentException">Agent location cannot be found</exception>
        public void Simulate(string dataFieldName, bool notify)
        {
            var timer     = System.Diagnostics.Stopwatch.StartNew();
            var trailData = new Dictionary <Cell, double>();

            foreach (Cell item in this._host.cellularFloor.Cells)
            {
                trailData.Add(item, 0.0d);
            }
            while (this.TotalWalkTime < this.Duration)
            {
                this.TimeStep       = this.FixedTimeStep;
                this.TotalWalkTime += this.FixedTimeStep;
                this.WalkTime      += this.FixedTimeStep;
                while (this.TimeStep != 0.0d)
                {
                    this.TimeStepUpdate();
                    if (this._onError)
                    {
                        return;
                    }
                }
                Cell vantageCell = this._host.cellularFloor.FindCell(this.CurrentState.Location);
                if (trailData.ContainsKey(vantageCell))
                {
                    trailData[vantageCell] += 1;
                }
                else
                {
                    throw new ArgumentException("Agent location cannot be found");
                }
            }
            foreach (Cell item in this._host.cellularFloor.Cells)
            {
                if (item.FieldOverlapState == OverlapState.Outside)
                {
                    trailData.Remove(item);
                }
                //if (this._trailData[item] == 0.0d)
                //{
                //    this._trailData.Remove(item);
                //}
            }
            var results = new SpatialAnalysis.Data.SimulationResult(dataFieldName, trailData, this.FixedTimeStep * 1000, this.Duration / (60 * 60));

            this._host.AddSimulationResult(results);

            timer.Stop();
            double time = timer.Elapsed.TotalSeconds;

            timer = null;
            if (notify)
            {
                MessageBox.Show(dataFieldName + " was added!\n" + "Run time: " + time.ToString() + " (Seconds)\n" + "'Seconds' per 'Occupancy Hour': " + (time / (this.Duration / (60 * 60))).ToString(), "Simulation Completed");
            }
        }
コード例 #2
0
        /// <summary>
        /// Applies filter on the specified spatial data.
        /// </summary>
        /// <param name="spatialData">The spatial data.</param>
        /// <param name="name">The name of the filtered data.</param>
        /// <param name="filter">The weighting factors of the filter.</param>
        /// <param name="rayIndices">The ray indices.</param>
        /// <param name="cellularFloor">The cellular floor.</param>
        /// <returns>ISpatialData.</returns>
        public static ISpatialData Apply(ISpatialData spatialData, string name, double[,] filter,
                                         Dictionary <Index, Index[]> rayIndices, CellularFloor cellularFloor)
        {
            int neighborhood_range             = filter.GetLength(0);
            Dictionary <Cell, double> filtered = new Dictionary <Cell, double>();

            foreach (Cell cell in spatialData.Data.Keys)
            {
                double value = IsovistClippedGaussian.Apply(spatialData, cell, filter, neighborhood_range, rayIndices, cellularFloor);
                filtered.Add(cell, value);
            }
            ISpatialData newData = null;

            switch (spatialData.Type)
            {
            case DataType.SpatialData:
                if (spatialData.GetType() == typeof(SpatialDataField))
                {
                    newData = new SpatialDataField(name, filtered);
                }
                else if (spatialData.GetType() == typeof(SimulationResult))
                {
                    SimulationResult simulationResult = (SimulationResult)spatialData;
                    newData = new SimulationResult(name, filtered, simulationResult.TimeStep, simulationResult.SimulationDuration);
                }
                else if (spatialData.GetType() == typeof(MandatorySimulationResult))
                {
                    MandatorySimulationResult mandatorySimulationResult = (MandatorySimulationResult)spatialData;
                    newData = new MandatorySimulationResult(name, filtered, mandatorySimulationResult.TimeStep, mandatorySimulationResult.SimulationDuration, mandatorySimulationResult.WalkedDistancePerHour,
                                                            mandatorySimulationResult.TimeInMainStations, mandatorySimulationResult.WalkingTime, mandatorySimulationResult.ActivityEngagementTime,
                                                            mandatorySimulationResult.SequencesWhichNeededVisualDetection, mandatorySimulationResult.AverageDelayChanceForVisualDetection,
                                                            mandatorySimulationResult.MinimumDelayChanceForVisualDetection,
                                                            mandatorySimulationResult.MaximumDelayChanceForVisualDetection);
                }
                break;

            case DataType.ActivityPotentialField:
                newData = new FieldUtility.Activity(filtered, ((Activity)spatialData).Origins, ((Activity)spatialData).DestinationArea, ((Activity)spatialData).DefaultState, name, cellularFloor);
                ((Activity)newData).TrySetEngagementTime(((Activity)spatialData).MinimumEngagementTime, ((Activity)spatialData).MaximumEngagementTime);
                break;

            case DataType.OccupancyEvent:
                if (spatialData.GetType() == typeof(MandatoryEvaluationEvent))
                {
                    MandatoryEvaluationEvent event_ = (MandatoryEvaluationEvent)spatialData;
                    newData = new SpatialAnalysis.Events.MandatoryEvaluationEvent(name, filtered, event_.Likelihood, event_.TimeSamplingRate, event_.TimeStep, event_.Duration,
                                                                                  event_.MaximumVelocityMagnitude, event_.VisibilityAngle, event_.HasCapturedVisualEvents, event_.HasCapturedDataEvents, event_.EventType, event_.CapturedEventTrails)
                    {
                        HasActivityEngagementEvent = event_.HasActivityEngagementEvent
                    };
                }
                else
                {
                    EvaluationEvent event_ = (EvaluationEvent)spatialData;
                    newData = new SpatialAnalysis.Events.EvaluationEvent(name, filtered, event_.Likelihood, event_.TimeSamplingRate, event_.TimeStep, event_.Duration,
                                                                         event_.MaximumVelocityMagnitude, event_.VisibilityAngle, event_.HasCapturedVisualEvents, event_.HasCapturedDataEvents, event_.EventType, event_.CapturedEventTrails);
                }
                break;
            }
            return(newData);
        }