#6869: [with patch, needs review] LP and MIP Solvers in Sage ( with symbolics )
-------------------------+--------------------------------------------------
 Reporter:  ncohen       |       Owner:  jkantor   
     Type:  enhancement  |      Status:  new       
 Priority:  major        |   Milestone:  sage-4.1.2
Component:  numerical    |    Keywords:            
 Reviewer:               |      Author:            
   Merged:               |  
-------------------------+--------------------------------------------------

Comment(by mvngu):

 ncohen asked this question in IRC:
 {{{
 10:45 < ncohen> mvngu: do you know what this is ?
 10:45 < ncohen> ERROR: Please define a s == loads(dumps(s)) doctest.
 }}}
 This is encouraging you to define an equality method `__eq__()` for each
 of the three classes `MIP`, `MIPSolverException`, and `MIPVariable`. Say
 you have instantiated two objects of the class `MIPVariable`. How can you
 test to see whether or not they are the same object? In Python, this is
 usually implemented in the method `__equ__()` of a class. If a class
 defines this method, you can compare two objects of that class using the
 double-equal operator `==`. For example:
 {{{
 sage: a1 = AlphabeticStrings()
 sage: a2 = AlphabeticStrings()
 sage: a1 == a2
 True
 }}}
 Take the case of writing the method `__eq__()` for the class
 `MIPVariable`. Are there criteria to tell us that two objects of the class
 `MIPVariable` are the same? If `m1` and `m2` are two such objects, you can
 define them to be the same object if their corresponding attributes have
 the same values. Each object of `MIPVariable` has these attributes: `dim`,
 `dict`, `x`, `f`. One way to write the `__eq__()` method for `MIPVariable`
 is this:
 {{{
 def __eq__(self, other):
     r"""
     <insert lengthy documentation here, with examples>
     """
     return self.dim == other.dim and self.dict == other.dict and self.x ==
 other.x and self.f == other.f
 }}}
 In the "EXAMPLES" section of that method, you should have an example as
 follows with appropriate values for `x`, `f`, and `dim`:
 {{{
 sage: m = MIPVariable(someX, someF, someDim)
 sage: m == loads(dumps(m))
 True
 }}}
 which should return True when you actually doctest the MIP module. Define
 a similar equality method for the other two classes.
 [[BR]]

 One thing I dislike in code is to see it squashed together. This makes it
 more difficult to read, taking into account also that other people need to
 understand what that code does, its logical flow, and they might have been
 spending all day reading code. Good coding style is a plus here if you
 want your code to be as easily understandable as possible. Instead of
 doing this:
 {{{
 self.dim=dim
 self.dict={}
 self.x=x
 self.f=f
 }}}
 do this:
 {{{
 self.dim = dim
 self.dict = {}
 self.x = x
 self.f = f
 }}}
 [[BR]]

 Another issue is global namespace pollution. What I mean is that you
 should try to avoid as much as possible injecting your module, class, or
 function names into the global namespace when Sage loads itself. This is
 what you're currently doing with this code:
 {{{
 from sage.numerical.mip import *
 }}}
 What this means is that when you load Sage, all the class and function
 names defined in the module mip.pyx are loaded into the global namespace.
 An advantage to this is that a user doesn't have to first import the
 relevant class or function prior to using it. With the above import
 statement, I can do this
 {{{
 sage: m = MIPVariable(x,f)
 }}}
 Without the import statement, I would need to do this:
 {{{
 sage: from sage.numerical.mip import MIPVariable
 sage: m = MIPVariable(x,f)
 }}}
 I can see that importing stuff when Sage is being loaded saves a lot of
 time explicitly importing that stuff. But a downside is that the global
 namespace is being polluted with module, class or function names that are
 not really necessary to load at the start. As more names are put into the
 global namespace, it takes longer and longer to load Sage.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6869#comment:6>
Sage <http://sagemath.org/>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to