# 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 welldefined 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


1304  1304  
1305  1305  OUTPUT: 
1306  1306  
1307   A dictionary with the following keyword:value pairs: 
 1307  A dictionary with the following keyword:value pair: 
1308  1308  
1309  1309  * ``'bounded'``: Boolean. Whether the linear expression 
1310  1310  ``expr`` is bounded from above on ``self``. 
1311  1311  
 1312  If ``expr`` is bounded from above, the following additional 
 1313  keyword:value pairs are set to provide information about the 
 1314  supremum: 
 1315  
1312  1316  * ``'sup_n'``: Integer. The numerator of the supremum value. 
1313  1317  
1314   * ``'sup_d'``: Integer. The denominator of the supremum 
1315   value. Can be zero if the linear expression is not bounded. 
 1318  * ``'sup_d'``: Nonzero integer. The denominator of the supremum 
 1319  value. 
1316  1320  
1317  1321  * ``'maximum'``: Boolean. ``True`` if and only if the supremum 
1318  1322  is also the maximum value. 
1319  1323  
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. 
1324  1326  
1325  1327  EXAMPLES:: 
1326  1328  
… 
… 

1340  1342  sage: cs.insert( x>0 ) 
1341  1343  sage: p = NNC_Polyhedron(cs) 
1342  1344  sage: p.maximize( +x ) 
1343   {'sup_d': 0, 'sup_n': 0, 'bounded': False, 'maximum': False, 'generator': None} 
 1345  {'bounded': False} 
1344  1346  sage: p.maximize( x ) 
1345  1347  {'sup_d': 1, 'sup_n': 0, 'bounded': True, 'maximum': False, 'generator': closure_point(0/1)} 
1346  1348  """ 
… 
… 

1358  1360  mpz_set(Int_sup_d.value, sup_d.get_mpz_t()) 
1359  1361  
1360  1362  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 } 
1362  1364  else: 
1363   return { 'bounded':rc, 'sup_n':Int_sup_n, 'sup_d':Int_sup_d, 'maximum':maximum, 'generator':None } 
 1365  return { 'bounded':False } 
1364  1366  
1365  1367  
1366  1368  def minimize(self, Linear_Expression expr): 
… 
… 

1373  1375  
1374  1376  OUTPUT: 
1375  1377  
1376   A dictionary with the following keyword:value pairs: 
 1378  A dictionary with the following keyword:value pair: 
1377  1379  
1378  1380  * ``'bounded'``: Boolean. Whether the linear expression 
1379  1381  ``expr`` is bounded from below on ``self``. 
1380  1382  
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'``: Nonzero integer. The denominator of the infimum 
 1390  value. 
1385  1391  
1386  1392  * ``'minimum'``: Boolean. ``True`` if and only if the infimum 
1387  1393  is also the minimum value. 
1388  1394  
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. 
1393  1397  
1394  1398  EXAMPLES:: 
1395  1399  
… 
… 

1411  1415  sage: p.minimize( +x ) 
1412  1416  {'minimum': False, 'bounded': True, 'inf_d': 1, 'generator': closure_point(0/1), 'inf_n': 0} 
1413  1417  sage: p.minimize( x ) 
1414   {'minimum': False, 'bounded': False, 'inf_d': 0, 'generator': None, 'inf_n': 0} 
 1418  {'bounded': False} 
1415  1419  """ 
1416  1420  cdef PPL_Coefficient inf_n 
1417  1421  cdef PPL_Coefficient inf_d 
… 
… 

1427  1431  mpz_set(Int_inf_d.value, inf_d.get_mpz_t()) 
1428  1432  
1429  1433  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 } 
1431  1435  else: 
1432   return { 'bounded':rc, 'inf_n':Int_inf_n, 'inf_d':Int_inf_d, 'minimum':minimum, 'generator':None } 
 1436  return { 'bounded':False } 
1433  1437  
1434  1438  
1435  1439  def contains(self, Polyhedron y): 