Ticket #9579: trac_9579.patch

File trac_9579.patch, 1.7 KB (added by ncohen, 10 years ago)
  • sage/numerical/mip.pyx

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1279852661 -28800
    # Node ID 9d7e813ea56845517441af2ffb90f7d64054e567
    # Parent  af5f40a73eda5a6a0a811ef973ce57180b48953e
    trac 9579 -- Raise an exception when a bad argument is given to add_constraint
    
    diff -r af5f40a73eda -r 9d7e813ea568 sage/numerical/mip.pyx
    a b  
    666666        - ``max`` -- An upper bound on the constraint (set to ``None``
    667667          by default). This must be a numerical value.
    668668        - ``min`` -- A lower bound on the constraint.  This must be a
    669           numerical value
     669          numerical value.
    670670        - ``name`` -- A name for the constraint.
    671671
    672672        EXAMPLE:
     
    727727
    728728            sage: p=MixedIntegerLinearProgram()
    729729            sage: p.add_constraint(sum([]),min=2)
     730
     731        Min/Max are numerical ::
     732
     733            sage: v = p.new_variable()
     734            sage: p.add_constraint(v[3] + v[5], min = v[6])
     735            Traceback (most recent call last):
     736            ...
     737            ValueError: min and max arguments are required to be numerical
     738
    730739        """
    731740        if linear_function is None or linear_function is 0:
    732741            return None
    733742
     743        # Raising an exception when min/max are not as expected
     744        from sage.rings.all import RR
     745        if ((min is not None and min not in RR)
     746            or (max is not None and max not in RR)):
     747
     748            raise ValueError("min and max arguments are required to be numerical")
     749
    734750        if isinstance(linear_function, LinearFunction):
    735751
    736752            f = linear_function.dict()