public void Add(Linear.Constraint constraint)
        {
            if (constraint.Coefficients.Count != d_parameters.Count)
            {
                throw new Linear.BadDimension("Number of coefficients ({0}) does not match number of parameters ({1})", constraint.Coefficients.Count, d_parameters.Count);
            }

            d_constraints.Add(constraint);
        }
 public bool ValidateNull(Dictionary <string, double> values, out Linear.Constraint constraint)
 {
     return(Validate(values, d_nullspaceConstraints, out constraint));
 }
        private bool Validate(Dictionary <string, double> values, List <Linear.Constraint> constraints, out Linear.Constraint constraint)
        {
            Linear.Vector vals = new Linear.Vector(d_parameters.Count);
            constraint = null;

            foreach (string idx in d_parameters)
            {
                vals.Add(values[idx]);
            }

            foreach (Linear.Constraint c in constraints)
            {
                if (!c.Validate(vals))
                {
                    constraint = c;
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        private void ConstraintViolationError(string msg, ConstraintMatrix cons, Solution solution, Dictionary <string, double> values, Linear.Constraint constraint)
        {
            List <string> s   = new List <string>();
            double        tot = 0;

            for (int i = 0; i < cons.Parameters.Count; ++i)
            {
                string name = cons.Parameters[i];
                s.Add(String.Format("{0:0.000} * {1} ({2:0.000})", constraint.Coefficients[i], name, values[name]));

                tot += constraint.Coefficients[i] * values[name];
            }

            string ss = String.Join(" + ", s.ToArray());

            Console.WriteLine("Constraint violated ({4}): {0} {1} {2:0.000} (expected {3:0.000})", ss, constraint.Equality ? "=" : "<=", tot, constraint.Value, msg);
        }