#17712: Adds memoization to the branch and bound for vertex separation
-------------------------+-------------------------------------------------
       Reporter:         |        Owner:
  dcoudert               |       Status:  needs_work
           Type:         |    Milestone:  sage-6.5
  enhancement            |   Resolution:
       Priority:  minor  |    Merged in:
      Component:  graph  |    Reviewers:
  theory                 |  Work issues:
       Keywords:         |       Commit:
        Authors:  David  |  4abd2bacff0b06ae13a4fb4d046c7ecee4716d28
  Coudert                |     Stopgaps:
Report Upstream:  N/A    |
         Branch:         |
  public/17712           |
   Dependencies:         |
  #17711                 |
-------------------------+-------------------------------------------------

Comment (by dcoudert):

 Hello Nathann,

 You are right, we could use a set instead of a dictionary and add the
 prefix `P` to the set only if `c(P)<\min_{L\in{\cal L}_P(V)} c(L)`.

 However, it is apparently faster to test if a frozenset is a key of a
 dictionary than if it is in a set.
 {{{
 sage: d = dict()
 sage: s = set()
 sage: for i in range(1, 11):
 ....:     for z in Combinations(range(2*i), i):
 ....:         d[frozenset(z)] = True
 ....:         s.add(frozenset(z))
 ....:
 sage: len(d)
 250952
 sage: %timeit len(d)
 10000000 loops, best of 3: 63 ns per loop
 sage: %timeit len(s)
 10000000 loops, best of 3: 59.9 ns per loop
 sage:
 sage: elt = d.keys()[randint(0, len(d)-1)]
 sage: %timeit elt in d
 10000000 loops, best of 3: 60.9 ns per loop
 sage: %timeit elt in s
 10000000 loops, best of 3: 163 ns per loop
 sage:
 sage: elt = d.keys()[randint(0, len(d)-1)]
 sage: %timeit elt in d
 10000000 loops, best of 3: 58.8 ns per loop
 sage: %timeit elt in s
 10000000 loops, best of 3: 160 ns per loop
 }}}


 What we can do is to change `is_known_prefix` as follows:
 {{{
         if size<1 or size>self.max_prefix_length:
             return False

         cdef int i
         cdef frozenset my_prefix = frozenset([prefix[i] for i in
 range(size)])

         return my_prefix in self.PT
 }}}
 and `update` as:
 {{{
         cdef int i
         if size>0 and size<=self.max_prefix_length \
            and not (is_improved and cost==upper_bound) \
            and len(self.PT)< self.max_prefix_number:

             my_prefix = frozenset(prefix[i] for i in range(size))
             self.PT[my_prefix] = True
 }}}
 Furthermore, if we do that inside `BAB_C`, we do only once `my_prefix =
 frozenset(prefix[i] for i in range(size))`.

 If you agree, I will implement the changes.

 David.

--
Ticket URL: <http://trac.sagemath.org/ticket/17712#comment:16>
Sage <http://www.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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to