Ticket #10039: trac_10039_ppl_fix_extremize.2.patch

File trac_10039_ppl_fix_extremize.2.patch, 5.1 KB (added by vbraun, 8 years ago)

Updated patch

  • sage/libs/ppl.pyx

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1301922214 14400
    # Node ID ce00088aa6a06694488f5db633aa5b33e9e7252d
    # Parent  0ca66b4e49c9b5d5964eb8f4d7178eb51f30678a
    Trac #10039: Change minimize/maximize to only return relevant information
    
    I changed return value of the maximize/minimize methods to only return
    {'bounded':False} if the linear program is unbounded, since all other
    dictionary entries are not well-defined in that case. If the linear program
    is bounded then the returned dictionary is the same as before and
    contains information about the sup/inf value, whether it is a maximum,
    and where it is attained.
    
    diff --git a/sage/libs/ppl.pyx b/sage/libs/ppl.pyx
    a b  
    13041304
    13051305        OUTPUT:
    13061306
    1307         A dictionary with the following keyword:value pairs:
     1307        A dictionary with the following keyword:value pair:
    13081308
    13091309        * ``'bounded'``: Boolean. Whether the linear expression
    13101310          ``expr`` is bounded from above on ``self``.
    13111311
     1312        If ``expr`` is bounded from above, the following additional
     1313        keyword:value pairs are set to provide information about the
     1314        supremum:
     1315
    13121316        * ``'sup_n'``: Integer. The numerator of the supremum value.
    13131317
    1314         * ``'sup_d'``: Integer. The denominator of the supremum
    1315           value. Can be zero if the linear expression is not bounded.
     1318        * ``'sup_d'``: Non-zero integer. The denominator of the supremum
     1319          value.
    13161320
    13171321        * ``'maximum'``: Boolean. ``True`` if and only if the supremum
    13181322          is also the maximum value.
    13191323
    1320         * ``'generator'``: a :class:`Generator`. When maximization
    1321           succeeds, will be assigned a point or closure point where
    1322           expr reaches its supremum value.  If ``expr`` is unbounded,
    1323           ``None``.
     1324        * ``'generator'``: a :class:`Generator`. A point or closure
     1325          point where expr reaches its supremum value.
    13241326
    13251327        EXAMPLES::
    13261328
     
    13401342            sage: cs.insert( x>0 )
    13411343            sage: p = NNC_Polyhedron(cs)
    13421344            sage: p.maximize( +x )
    1343             {'sup_d': 0, 'sup_n': 0, 'bounded': False, 'maximum': False, 'generator': None}
     1345            {'bounded': False}
    13441346            sage: p.maximize( -x )
    13451347            {'sup_d': 1, 'sup_n': 0, 'bounded': True, 'maximum': False, 'generator': closure_point(0/1)}
    13461348        """
     
    13581360        mpz_set(Int_sup_d.value, sup_d.get_mpz_t())
    13591361
    13601362        if rc:
    1361             return { 'bounded':rc, 'sup_n':Int_sup_n, 'sup_d':Int_sup_d, 'maximum':maximum, 'generator':g }
     1363            return { 'bounded':True, 'sup_n':Int_sup_n, 'sup_d':Int_sup_d, 'maximum':maximum, 'generator':g }
    13621364        else:
    1363             return { 'bounded':rc, 'sup_n':Int_sup_n, 'sup_d':Int_sup_d, 'maximum':maximum, 'generator':None }
     1365            return { 'bounded':False }
    13641366
    13651367
    13661368    def minimize(self, Linear_Expression expr):
     
    13731375
    13741376        OUTPUT:
    13751377
    1376         A dictionary with the following keyword:value pairs:
     1378        A dictionary with the following keyword:value pair:
    13771379
    13781380        * ``'bounded'``: Boolean. Whether the linear expression
    13791381          ``expr`` is bounded from below on ``self``.
    13801382
    1381         * ``'inf_n'``: Integer. The numerator of the supremum value.
    1382 
    1383         * ``'inf_d'``: Integer. The denominator of the supremum
    1384           value. Can be zero if the linear expression is not bounded.
     1383        If ``expr`` is bounded from below, the following additional
     1384        keyword:value pairs are set to provide information about the
     1385        infimum:
     1386
     1387        * ``'inf_n'``: Integer. The numerator of the infimum value.
     1388
     1389        * ``'inf_d'``: Non-zero integer. The denominator of the infimum
     1390          value.
    13851391
    13861392        * ``'minimum'``: Boolean. ``True`` if and only if the infimum
    13871393          is also the minimum value.
    13881394
    1389         * ``'generator'``: a :class:`Generator` or ``None``. When
    1390           maximization succeeds, will be assigned a point or closure
    1391           point where expr reaches its supremum value. If ``expr`` is
    1392           unbounded, ``None``.
     1395        * ``'generator'``: a :class:`Generator`. A point or closure
     1396          point where expr reaches its infimum value.
    13931397       
    13941398        EXAMPLES::
    13951399
     
    14111415            sage: p.minimize( +x )
    14121416            {'minimum': False, 'bounded': True, 'inf_d': 1, 'generator': closure_point(0/1), 'inf_n': 0}
    14131417            sage: p.minimize( -x )
    1414             {'minimum': False, 'bounded': False, 'inf_d': 0, 'generator': None, 'inf_n': 0}
     1418            {'bounded': False}
    14151419        """
    14161420        cdef PPL_Coefficient inf_n
    14171421        cdef PPL_Coefficient inf_d
     
    14271431        mpz_set(Int_inf_d.value, inf_d.get_mpz_t())
    14281432
    14291433        if rc:
    1430             return { 'bounded':rc, 'inf_n':Int_inf_n, 'inf_d':Int_inf_d, 'minimum':minimum, 'generator':g }
     1434            return { 'bounded':True, 'inf_n':Int_inf_n, 'inf_d':Int_inf_d, 'minimum':minimum, 'generator':g }
    14311435        else:
    1432             return { 'bounded':rc, 'inf_n':Int_inf_n, 'inf_d':Int_inf_d, 'minimum':minimum, 'generator':None }
     1436            return { 'bounded':False }
    14331437
    14341438
    14351439    def contains(self, Polyhedron y):