The EffectState keeps track of all positive and negative contributions of a certain effect. The positive effects increase its total score, the negative effects reduce it. Note that a positive effect can still be undesirable, e.g. the total threat score.
Exemple #1
0
 public void AddEffectState(EffectState state)
 {
     if (state.Name != Name) return;
     Count += state.Count;
     positiveScore += state.PositiveScore;
     //negativeScore += state.NegativeScore;
 }
Exemple #2
0
 public void SubtractEffectState(EffectState state)
 {
     if (state.Name != Name) return;
     negativeScore += state.PositiveScore;
 }
Exemple #3
0
        private void UpdateState(PhaseState phase)
        {
            // Clear computations
            foreach (var threat in phase.Threats)
            {
                threat.InfluencedBy.Clear();
                threat.CombinedEffects.Clear();
            }
            foreach (var measure in phase.Measures)
            {
                measure.Influences.Clear();
                measure.CombinedEffects.Clear();
            }

            // Determine which measure influences which threat (and vice versa)
            foreach (var measure in phase.Measures)
            {
                if (measure.InfluenceRadiusInMeter <= 0) continue;
                foreach (var threat in phase.Threats)
                {
                    var overlap = threat.Effects.Select(effect => effect.Name).Intersect(measure.Effects.Select(effect => effect.Name)).Any();
                    if (!overlap) continue;
                    //var distanceInMeter = CoordinateUtils.Distance(measure.Position.Latitude, measure.Position.Longitude, threat.Position.Latitude, threat.Position.Longitude) * 1000;
                    //if (distanceInMeter > measure.InfluenceRadiusInMeter) continue;
                    //var relPoint = new Point(threat.Position.Longitude - measure.Position.Longitude, threat.Position.Latitude - measure.Position.Latitude);
                    if (!isInArcSegment(measure.Position, threat.Position, measure.StartAngleInDegree, measure.EndAngleInDegree, measure.InfluenceRadiusInMeter)) continue;
                    threat.InfluencedBy.Add(measure);
                    measure.Influences.Add(threat);
                }
            }
            // Compute the effects of this influence: threat is reduced, measure effectiveness is increased, labels are updated
            foreach (var threat in phase.Threats)
            {
                foreach (var threatEffect in threat.Effects)
                {
                    var combinedEffect = new EffectState(threatEffect.Name);
                    combinedEffect.AddEffectState(threatEffect);
                    foreach (var measure in threat.InfluencedBy)
                    {
                        foreach (var measureEffect in measure.Effects)
                        {
                            combinedEffect.SubtractEffectState(measureEffect);
                        }
                    }
                    threat.CombinedEffects.Add(combinedEffect);
                    updateThreatVisualisation(threat);
                }

                // For this phase, compute the combined threat
                foreach (var ce in threat.CombinedEffects)
                {
                    if (!phase.threatStates.ContainsKey(ce.Name)) phase.threatStates[ce.Name] = ce;
                    else phase.threatStates[ce.Name].AddEffectState(ce);
                }
            }
            foreach (var measure in phase.Measures)
            {
                // For this phase, compute the combined effect
                foreach (var ce in measure.Effects)
                {
                    if (!phase.measureStates.ContainsKey(ce.Name)) phase.measureStates[ce.Name] = ce;
                    else phase.measureStates[ce.Name].AddEffectState(ce);
                }
            }
        }
Exemple #4
0
        private void add(PoI poi, bool isThreat)
        {
            var effectStates   = new List<EffectState>();
            var resourceStates = new List<ResourceState>();
            var activePhases   = new List<string>();

            // Clear all influences
            poi.Labels[InfluenceLabel] = string.Empty; 

            // Process the labels
            foreach (var label in poi.Labels)
            {
                // Test to see if there is a match in the InputText
                var match = regex.Match(label.Key);
                if (!match.Success) continue;

                var eamType = match.Groups[1].Value.ToLower(); // Index 0 represents the capture
                var title   = match.Groups[2].Value.ToLower();
                switch (eamType)
                {
                    case "effect":
                        if (string.IsNullOrEmpty(label.Value)) continue;
                        EffectLevel level;
                        if (!Enum.TryParse<EffectLevel>(label.Value, out level) || level == EffectLevel.None) continue;
                        var isDisturbance = label.Key.EndsWith(DisturbanceLevelLabel);
                        var effect = new EffectState(title, level, isDisturbance);
                        effectStates.Add(effect);
                        break;
                    case "capacity":
                        if (string.IsNullOrEmpty(label.Value) || string.Equals(label.Value, "0", StringComparison.InvariantCultureIgnoreCase)) continue;
                        var resourceState = new ResourceState(title);
                        resourceState.AddCapacity(label.Value);
                        resourceStates.Add(resourceState);
                        break;
                    case "phase":
                        if (TryGetPhaseState(title) == null) phaseStates.Add(new PhaseState(title));
                        if (!string.Equals(label.Value, "true", StringComparison.InvariantCultureIgnoreCase)) continue;
                        activePhases.Add(title);
                        break;
                }
            }

            // Update each phase that is affected
            foreach (var title in activePhases)
            {
                var phase = TryGetPhaseState(title);
                if (phase == null) return;
                if (isThreat)
                    phase.Threats .Add(new PoIState(poi, effectStates));
                else
                    phase.Measures.Add(new PoIState(poi, effectStates, resourceStates));
                foreach (var rs in resourceStates)
                {
                    ResourceState resourceState;
                    if (phase.resourceStates.TryGetValue(rs.Name, out resourceState)) resourceState.AddCapacityAsNumber(rs.Capacity);
                    else phase.resourceStates.TryAdd(rs.Name, rs);
                }
            }
        }