Accord.Math.Optimization.QuadraticObjectiveFunction.initialize C# (CSharp) Method

initialize() private method

private initialize ( string>.Dictionary terms ) : void
terms string>.Dictionary
return void
        private void initialize(Dictionary<Tuple<string, string>, double> terms)
        {
            linear = new Dictionary<string, double>();
            quadratic = new Dictionary<Tuple<string, string>, double>();

            var list = new SortedSet<string>();

            foreach (var term in terms)
            {
                if (term.Key.Item2 != null)
                {
                    list.Add(term.Key.Item1);
                    list.Add(term.Key.Item2);

                    quadratic.Add(term.Key, term.Value);
                }
                else if (term.Key.Item1 != null)
                {
                    list.Add(term.Key.Item1);

                    linear.Add(term.Key.Item1, term.Value);
                }
                else
                {
                    c = term.Value;
                }
            }

            int i = 0;
            foreach (var variable in list)
            {
                InnerVariables.Add(variable, i);
                InnerIndices.Add(i, variable);
                i++;
            }

            NumberOfVariables = Variables.Count;
            this.Q = createQuadraticTermsMatrix();
            this.d = createLinearTermsVector();

            this.Function = function;
            this.Gradient = gradient;
        }