#17048: Faster Posets.RandomPoset
---------------------------------+-----------------------------
       Reporter:  jmantysalo     |        Owner:
           Type:  enhancement    |       Status:  new
       Priority:  minor          |    Milestone:  sage-wishlist
      Component:  combinatorics  |   Resolution:
       Keywords:                 |    Merged in:
        Authors:                 |    Reviewers:
Report Upstream:  N/A            |  Work issues:
         Branch:                 |       Commit:
   Dependencies:                 |     Stopgaps:
---------------------------------+-----------------------------

Comment (by jmantysalo):

 Maybe we could also generate random posets with given restrictions? For
 example

 {{{
 # Graded poset

 # set_random_seed(0)
 from sage.misc.prandom import random
 from sage.misc.randstate import current_randstate
 dice=current_randstate()

 n=20
 prob=0.2
 # Too many 1-element levels... make better.
 levels=Partitions(n).random_element()
 p=Permutations(len(levels)).random_element()
 levels=[levels[x-1] for x in p]

 # Poset P will have 0..levels[0] as minimal element,
 # levels[0]..levels[1]-1 covering them and so on.
 G=DiGraph({x:[] for x in range(0,n)})
 prev_start=0
 prev_end=levels[0]

 for i in levels[1:]:
     # Connect every element of previous level to some element on this
 level
     for prev in range(prev_start, prev_end):
         r=randint(prev_end, prev_end+i-1)
         G.add_edge(prev, r)
     # Connect every element of this level to some element on previous
 level
     for e in range(prev_end, prev_end+i):
         if G.in_degree(e) == 0:
             r=randint(prev_start, prev_end-1)
             G.add_edge(r, e)
     # And now the random part
     for e1 in range(prev_start, prev_end):
         for e2 in range(prev_end, prev_end+i):
             if dice.c_rand_double() < prob:
                 G.add_edge(e1, e2)
     prev_start=prev_end
     prev_end=prev_end+i
 P=Poset(G);
 }}}

 Calling this kind of functions could be something like
 `Posets.RandomPoset(20, 0.2, properties=['graded', 'connected',
 'third_property'])`.

--
Ticket URL: <http://trac.sagemath.org/ticket/17048#comment:1>
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