Changeset 966c620


Ignore:
Timestamp:
May 19, 2010 6:56:37 AM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
df3179c
Parents:
7ee16b3
Message:

Allow more control over how constraints are matched

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/compose.py

    r7ee16b3 r966c620  
    167167                action='store_true',
    168168                help='allow solutions where unrequired constraints fail')
     169        self.add_option('--same_node', dest='same_node', action='store_true',
     170                default=False,
     171                help='Allow loops to the same node to be created.')
     172        self.add_option('--same_topology', dest='same_topo',
     173                action='store_true', default=False,
     174                help='Allow links within the same topology to be created.')
     175        self.add_option('--same_pair', dest='multi_pair',
     176                action='store_true', default=False,
     177                help='Allow multiple links between the same nodes " + \
     178                        "to be created.')
    169179
    170180    @staticmethod
     
    243253            i.substrate = [ sub_map.get(ii, ii) for ii in i.substrate ]
    244254
    245 def meet_constraints(candidates, provides, accepts):
     255def meet_constraints(candidates, provides, accepts,
     256        same_node=False, same_topo=False, multi_pair=False):
    246257    """
    247258    Try to meet all the constraints in candidates using the information in the
     
    261272            for a in c.accepts:
    262273                for can in provides.get(a,[]):
    263                     # A constraint cannot satisfy itself, nor do we allow loops
    264                     # within the same topology.  This also excludes matched
    265                     # constraints.
    266                     if can.name != c.name and can.topology != c.topology and \
    267                             not can.match:
     274                    # A constraint cannot satisfy itself nor can it match
     275                    # multiple times.
     276                    if can != c and not can.match:
     277                        # Unless same_node is true disallow nodes satisfying
     278                        # their own constraints.
     279                        if not same_node and can.name == c.name:
     280                            continue
     281                        # Unless same_topo is true, exclude nodes in the same
     282                        # topology.
     283                        if not same_topo and can.topology == c.topology:
     284                            continue
    268285                        # Don't allow multiple matches between the same nodes
    269                         # (the "if" above is already pretty crowded).
    270                         if c.name in node_match and \
     286                        if not multi_pair and c.name in node_match and \
    271287                                can.name in node_match[c.name]:
    272288                            continue
     
    615631
    616632    if not meet_constraints([c for c in constraints if c.required],
    617             provides, accepts):
     633            provides, accepts, opts.same_node, opts.same_topo, opts.multi_pair):
    618634        if opts.lax:
    619635            warn("warning: could not meet all required constraints")
     
    622638
    623639    meet_constraints([ c for c in constraints if not c.match ],
    624             provides, accepts)
     640            provides, accepts, opts.same_node, opts.same_topo, opts.multi_pair)
    625641
    626642    # Add testbed attributes if requested
Note: See TracChangeset for help on using the changeset viewer.