Changeset b14b495


Ignore:
Timestamp:
May 17, 2010 2:01:26 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
ec9962b
Parents:
da5b93c
Message:

Permute the constraint order for different compositions. Also add argument to
seed the generator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/compose.py

    rda5b93c rb14b495  
    44import re
    55import os
     6import random
    67
    78from optparse import OptionParser
     
    148149                got_all = False
    149150    return got_all
     151
     152def randomize_constraint_order(indexes):
     153    """
     154    Randomly reorder the lists of constraints that provides and accepts hold.
     155    """
     156    if not isinstance(indexes, tuple):
     157        indexes = (indexes,)
     158
     159    for idx in indexes:
     160        for k in idx.keys():
     161            random.shuffle(idx[k])
    150162
    151163def remote_ns2topdl(uri, desc, cert):
     
    229241parser.add_option('--certfile', dest='cert', default=None,
    230242        help='Certificate to use as identity')
     243parser.add_option('--seed', dest='seed', type='int', default=None,
     244        help='Random number seed')
    231245
    232246opts, args = parser.parse_args()
     
    239253else:
    240254    cert = None
     255
     256random.seed(opts.seed)
    241257
    242258comps = [ ]
     
    276292    constraints = [ c for c in constraints if isinstance(c.name, tuple )]
    277293
     294# Mix up the constraint indexes
     295randomize_constraint_order((provides, accepts))
     296
    278297# Now the various components live in the same namespace and are marked with
    279298# their composition requirements.
Note: See TracChangeset for help on using the changeset viewer.