@@ -528,28 +528,62 @@ cdef class MixedIntegerLinearProgram(SageObject):
528528 linear_function = __call__
529529
530530 def _repr_ (self ):
531- r """
532- Returns a short description of the ``MixedIntegerLinearProgram``.
531+ r """
532+ Return a short description of the ``MixedIntegerLinearProgram``.
533533
534- EXAMPLES::
534+ EXAMPLES::
535535
536- sage: p = MixedIntegerLinearProgram( solver='GLPK')
537- sage: v = p. new_variable( nonnegative =True)
538- sage: p. add_constraint( v[1 ] + v[2 ], max=2 )
539- sage: print ( p )
540- Mixed Integer Program ( maximization , 2 variables, 1 constraints )
541- """
542- cdef GenericBackend b = self ._backend
536+ sage: p = MixedIntegerLinearProgram( solver='GLPK')
537+ sage: v = p. new_variable( binary =True)
538+ sage: p. add_constraint( v[1 ] + v[2 ], max=1 )
539+ sage: p
540+ Boolean Program ( no objective , 2 variables, 1 constraint )
541+ """
542+ cdef GenericBackend b = self ._backend
543543
544- return (" Mixed Integer Program " +
544+ cdef int nvars = b.ncols()
545+ cdef int i
546+
547+ cdef int have_int = 0 , have_bool = 0 , have_cont = 0
548+ for i in range (nvars):
549+ if b.is_variable_binary(i):
550+ have_bool = 1
551+ elif b.is_variable_integer(i):
552+ have_int = 1
553+ else :
554+ have_cont = 1
555+
556+ if have_cont:
557+ if have_int or have_bool:
558+ kind = " Mixed Integer Program"
559+ else :
560+ kind = " Linear Program"
561+ elif have_int:
562+ kind = " Integer Program"
563+ elif have_bool:
564+ kind = " Boolean Program"
565+ else :
566+ # We have no variables...
567+ kind = " Mixed Integer Program"
568+
569+ if (all (b.objective_coefficient(i) == 0 for i in range (nvars))
570+ and b.objective_constant_term() == 0 ):
571+ minmax = " no objective"
572+ elif b.is_maximization():
573+ minmax = " maximization"
574+ else :
575+ minmax = " minimization"
545576
546- ( " \" " + self ._backend.problem_name()+ " \" "
547- if (str (self ._backend.problem_name()) != " " ) else " " )+
577+ def plural (num , noun ):
578+ if num != 1 :
579+ noun = noun + " s"
580+ return f" {num} {noun}"
548581
549- " ( " + (" maximization" if b.is_maximization() else " minimization" ) +
582+ name = b.problem_name()
583+ if name:
584+ kind += f' "{name}"'
550585
551- " , " + str (b.ncols()) + " variables, " +
552- str (b.nrows()) + " constraints )" )
586+ return f" {kind} ({minmax}, {plural(b.ncols(), 'variable')}, {plural(b.nrows(), 'constraint')})"
553587
554588 def __copy__ (self ):
555589 r """
@@ -687,7 +721,7 @@ cdef class MixedIntegerLinearProgram(SageObject):
687721 sage: p = MixedIntegerLinearProgram( solver='GLPK')
688722 sage: p. set_problem_name( "Test program")
689723 sage: p
690- Mixed Integer Program "Test program" ( maximization , 0 variables, 0 constraints )
724+ Mixed Integer Program "Test program" ( no objective , 0 variables, 0 constraints)
691725 """
692726 self ._backend.problem_name(name)
693727
0 commit comments