Beispiel #1
0
        /// <summary>
        ///   Attempts to create a <see cref="LinearConstraint"/>
        ///   from a <see cref="string"/> representation.
        /// </summary>
        ///
        /// <param name="str">The string containing the constraint in textual form.</param>
        /// <param name="function">The objective function to which this constraint refers to.</param>
        /// <param name="constraint">The resulting constraint, if it could be parsed.</param>
        /// <param name="culture">The culture information specifying how
        ///   numbers written in the <paramref name="constraint"/> should
        ///   be parsed. Default is CultureInfo.InvariantCulture.</param>
        ///
        /// <returns><c>true</c> if the function could be parsed
        ///   from the string, <c>false</c> otherwise.</returns>
        ///
        public static bool TryParse(string str, CultureInfo culture,
                                    IObjectiveFunction function, out LinearConstraint constraint)
        {
            // TODO: implement this method without the try-catch block.

            try
            {
                constraint = new LinearConstraint(function, str, culture);
            }
            catch (FormatException)
            {
                constraint = null;
                return(false);
            }

            return(true);
        }
Beispiel #2
0
 /// <summary>
 ///   Attempts to create a <see cref="LinearConstraint"/>
 ///   from a <see cref="string"/> representation.
 /// </summary>
 ///
 /// <param name="str">The string containing the constraint in textual form.</param>
 /// <param name="function">The objective function to which this constraint refers to.</param>
 /// <param name="constraint">The resulting constraint, if it could be parsed.</param>
 ///
 /// <returns><c>true</c> if the function could be parsed
 ///   from the string, <c>false</c> otherwise.</returns>
 ///
 public static bool TryParse(string str,
                             IObjectiveFunction function, out LinearConstraint constraint)
 {
     return(TryParse(str, CultureInfo.InvariantCulture, function, out constraint));
 }