/// <summary> /// Try to reduce the magnitude of the coefficients used. /// Has a side effect on the coefficients, but leaves the meaning of the linear constraint /// unchanged. /// </summary> public void Normalize() { // compute the gcd of the numerators and the gcd of the denominators Rational gcd = rhs; foreach (Rational r in coefficients.Values) { gcd = Rational.Gcd(gcd, r); } // Change all coefficients, to divide their numerators with gcdNum and to // divide their denominators with gcdDen. Hashtable /*IVariable->Rational*/ newCoefficients = new Hashtable/*IVariable->Rational*/ (coefficients.Count); foreach (DictionaryEntry /*IVarianble->Rational*/ e in coefficients) { Rational r = (Rational)(cce.NonNull(e.Value)); if (r.IsNonZero) { newCoefficients.Add(e.Key, Rational.FromBignums(r.Numerator / gcd.Numerator, r.Denominator / gcd.Denominator)); } else { newCoefficients.Add(e.Key, r); } } coefficients = newCoefficients; rhs = rhs.IsNonZero ? Rational.FromBignums(rhs.Numerator / gcd.Numerator, rhs.Denominator / gcd.Denominator) : rhs; }