public void Add_WithPrimaryKey_ContainsRecordWithDefaultSecondaryKey()
        {
            _dictionary.Add(1, "stamat");

            Assert.That(_dictionary.Contains(new KeyValuePair <(int, string), string>
                                                 ((1, default(string)), "stamat")));
        }
Beispiel #2
0
 /// <summary>
 /// Generate sensitivities from the results of <see cref="PerturbAndObserveRunner{T}.RunPerturbAndObserve"/>,
 /// and using the selection functions <see cref="ResultSelector"/> and <see cref="RecordedPerturbationSelector"/>.
 /// </summary>
 /// <param name="perturbAndObserveRunner">The <see cref="PerturbAndObserveRunner{T}"/> to determine sensitivities
 /// from.</param>
 /// <returns>A twin-key dictionary with each value representing the sensitivity of the specified value at the Y-element
 /// to changes in the perturbed value at the X-element.</returns>
 public TwinKeyDictionary<String, String, double> GenerateSensitivities(PerturbAndObserveRunner<T> perturbAndObserveRunner)
 {
     var results = new TwinKeyDictionary<String, String, double>();
     foreach (var perturbation in perturbAndObserveRunner.AfterValues)
     {
         foreach (var observation in perturbation.Value)
         {
             T oldResult;
             if (!perturbAndObserveRunner.BeforeValues.TryGetValue(observation.Key, out oldResult))
                 continue;
             var sensitivity = (Convert.ToDouble(ResultSelector(observation.Value)) - Convert.ToDouble(ResultSelector(oldResult)))/Convert.ToDouble(RecordedPerturbationSelector(perturbation.Key.Item2));
             results.Add(perturbation.Key.Item1.Item1, observation.Key.Item1, sensitivity);
         }
     }
     return results;
 }
Beispiel #3
0
        // Merges the dictionaries obtained by GetVoltageSensitivityToComplexPower.
        private static TwinKeyDictionary <String, String, VoltageSensitivityToPQDataSet> TwinKeyDictionaryMerge(TwinKeyDictionary <String, String, double> MagReal, TwinKeyDictionary <String, String, double> MagImag,
                                                                                                                TwinKeyDictionary <String, String, double> PhaseReal,
                                                                                                                TwinKeyDictionary <String, String, double> PhaseImag
                                                                                                                )
        {
            var newDictionary = new TwinKeyDictionary <String, String, VoltageSensitivityToPQDataSet>();

            foreach (var X in MagReal.MapX)
            {
                foreach (var Y in X.Value)
                {
                    var val = new VoltageSensitivityToPQDataSet();
                    val.dV_dP = Y.Value;
                    val.dV_dQ = MagImag.MapX[X.Key][Y.Key];
                    val.dd_dP = PhaseReal.MapX[X.Key][Y.Key];
                    val.dd_dQ = PhaseImag.MapX[X.Key][Y.Key];
                    newDictionary.Add(X.Key, Y.Key, val);
                }
            }
            return(newDictionary);
        }
        // Merges the dictionaries obtained by GetVoltageSensitivityToComplexPower.
        private static TwinKeyDictionary<String, String, VoltageSensitivityToPQDataSet> TwinKeyDictionaryMerge(TwinKeyDictionary<String,String,double> MagReal, TwinKeyDictionary<String,String,double> MagImag, 
TwinKeyDictionary<String,String,double> PhaseReal, 
TwinKeyDictionary<String,String,double> PhaseImag
)
        {
            var newDictionary = new TwinKeyDictionary<String, String, VoltageSensitivityToPQDataSet>();
            foreach(var X in MagReal.MapX)
                foreach (var Y in X.Value)
                {
                    var val = new VoltageSensitivityToPQDataSet();
                    val.dV_dP = Y.Value;
                    val.dV_dQ = MagImag.MapX[X.Key][Y.Key];
                    val.dd_dP = PhaseReal.MapX[X.Key][Y.Key];
                    val.dd_dQ = PhaseImag.MapX[X.Key][Y.Key];
                    newDictionary.Add(X.Key, Y.Key, val);
                }
            return newDictionary;
        }