public override string ToString() { var equationAsString = new StringBuilder(); if (!LeftSide.Any()) { equationAsString.Append(" 0"); } else { // constant first, then by index asc var queuedTermsOnLeft = LeftSide.OrderBy(term => term.Variable.HasValue ? (int)term.Variable.Value.Index : -1); foreach (var term in queuedTermsOnLeft) { if (!(term.SignedCoefficient == 0 && term.Variable.HasValue)) { equationAsString.Append(string.Format(string.Format(" {0}", term))); } } } switch (SideConnection) { case SideConnection.LessThan: equationAsString.Append(" <"); break; case SideConnection.LessThanOrEqual: equationAsString.Append(" <="); break; case SideConnection.Equal: equationAsString.Append(" ="); break; case SideConnection.GreaterThanOrEqual: equationAsString.Append(" >="); break; case SideConnection.GreaterThan: equationAsString.Append(" >"); break; default: break; } if (!RightSide.Any()) { equationAsString.Append(" 0"); } else { var queuedTermsOnRight = RightSide.OrderBy(term => term.Variable.HasValue ? (int)term.Variable.Value.Index : -1); foreach (var term in queuedTermsOnRight) { if (!(term.SignedCoefficient == 0 && term.Variable.HasValue)) { equationAsString.Append(string.Format(string.Format(" {0}", term))); } } } return(equationAsString.ToString().Trim()); }