예제 #1
0
        /// <summary>
        /// Compares two Constraints
        /// </summary>
        public static bool AreConstraintsEquals(Constraint first, Constraint second)
        {
            if (first.Sign != second.Sign || first.RightSide != second.RightSide)
                return false;

            for (var i = 0; i < 2; i++)
            {
                foreach (var var in first.LeftSide)
                {
                    var sCoeff = GetCoefficientByLabel(second, var.Label);
                    if (sCoeff == null)
                    {
                        if (var.Coefficient == 0)
                            continue;
                        return false;
                    }
                    if (var.Coefficient != sCoeff)
                        return false;
                }
                var tmp = first;
                first = second;
                second = tmp;
            }

            return true;
        }
예제 #2
0
 private static Fraction GetCoefficientByLabel(Constraint lim, string label)
 {
     foreach (var var in lim.LeftSide)
         if (var.Label == label)
             return var.Coefficient;
     return null;
 }
예제 #3
0
 /// <summary>
 /// Represents math Constraint(copy of input Constraint)
 /// </summary>
 public Constraint(Constraint constraint)
 {
     _leftSide = new List<Variable>(constraint._leftSide);
     Sign = constraint.Sign;
     _rightSide = new Fraction(constraint._rightSide);
 }
예제 #4
0
        /// <summary>
        /// Adds input constraint to current
        /// </summary>
        /// <param name="constraint">Constraint that must be equal</param>
        /// <exception cref="FormatException">If one of the constraints is not equal</exception>
        public void Add(Constraint constraint)
        {
            if (constraint.Sign != "=" || Sign != "=")
                throw new FormatException("Constraints must be equal constraints");

            var current = new EqualityConstraint(LeftSide, RightSide);
            var input = new EqualityConstraint(constraint.LeftSide, constraint.RightSide);

            current.Add(input);

            _leftSide = new List<Variable>(current.LeftSide);
            _rightSide = current.RightSide;
        }