Ejemplo n.º 1
0
    def call(self, opt, c):
        context = clone_context(c.context)

        con = Connection(self.cresource.dp, self.cresource.s, self.cfunction.dp, self.cfunction.s)

        context.add_connection(con)
        executed = c.executed + [self]
        # XXX
        forbidden = c.forbidden | set([self])

        from mcdp_opt.partial_result import get_lower_bound_ndp

        ndp, table = get_lower_bound_ndp(context)
        (R, ur), tableres = opt.get_lower_bounds(ndp, table)
        lower_bounds = tableres

        from mcdp_opt.optimization_state import OptimizationState

        s2 = OptimizationState(
            opt=opt,
            options=c.options,
            context=context,
            executed=executed,
            forbidden=forbidden,
            lower_bounds=lower_bounds,
            ur=ur,
            creation_order=opt.get_next_creation(),
        )
        return s2
Ejemplo n.º 2
0
    def call(self, opt, c):
        context = clone_context(c.context)

        ndp = opt.load_ndp(self.id_ndp)

        if not self.id_ndp in context.names:
            name = self.id_ndp
        else:
            name = context.new_name(prefix=self.id_ndp)
        context.add_ndp(name, ndp)

        con = Connection(self.cresource.dp, self.cresource.s, name, self.fname)
        context.add_connection(con)

        executed = c.executed + [self]
        # XXX
        forbidden = c.forbidden | set([self])

        lower_bounds = dict(**c.lower_bounds)

        # get lower bounds for the new one
        lower_bounds_a = get_new_lowerbounds(context=context, name=name, lower_bounds=lower_bounds)
        for k, u in lower_bounds_a.items():
            if len(u.minimals) == 0:
                msg = "Unfeasible: %s" % (lower_bounds_a)
                raise Exception(msg)

        print("new lowerbounds: %s" % lower_bounds_a)
        for rname in ndp.get_rnames():
            r = CResource(name, rname)
            if not r in lower_bounds_a:
                msg = "Cannot find resource."
                raise_desc(ValueError, msg, r=r, lower_bounds_a=lower_bounds_a)
            lower_bounds[r] = lower_bounds_a[r]

        del lower_bounds[self.cresource]

        from mcdp_opt.partial_result import get_lower_bound_ndp

        ndp, table = get_lower_bound_ndp(context)
        (_R, ur), _tableres = opt.get_lower_bounds(ndp, table)

        from mcdp_opt.optimization_state import OptimizationState

        s2 = OptimizationState(
            opt=opt,
            options=c.options,
            context=context,
            executed=executed,
            forbidden=forbidden,
            lower_bounds=lower_bounds,
            ur=ur,
            creation_order=opt.get_next_creation(),
        )

        s2.info("Parent: #%s" % c.creation_order)
        s2.info("Action: #%s" % self)
        return s2
Ejemplo n.º 3
0
    def call(self, opt, c):
        context = clone_context(c.context)

        ndp = opt.load_ndp(self.id_ndp)

        if not self.id_ndp in context.names:
            name = self.id_ndp
        else:
            name = context.new_name(prefix=self.id_ndp)
        context.add_ndp(name, ndp)

        con = Connection(self.cresource.dp, self.cresource.s, name, self.fname)
        context.add_connection(con)

        executed = c.executed + [self]
        # XXX
        forbidden = c.forbidden | set([self])

        lower_bounds = dict(**c.lower_bounds)

        # get lower bounds for the new one
        lower_bounds_a = get_new_lowerbounds(context=context, name=name,
                                             lower_bounds=lower_bounds)
        for k, u in lower_bounds_a.items():
            if len(u.minimals) == 0:
                msg = 'Unfeasible: %s' % (lower_bounds_a)
                raise Exception(msg)

        print('new lowerbounds: %s' % lower_bounds_a)
        for rname in ndp.get_rnames():
            r = CResource(name, rname)
            if not r in lower_bounds_a:
                msg = 'Cannot find resource.'
                raise_desc(ValueError, msg, r=r, lower_bounds_a=lower_bounds_a)
            lower_bounds[r] = lower_bounds_a[r]

        del lower_bounds[self.cresource]

        from mcdp_opt.partial_result import get_lower_bound_ndp
        ndp, table = get_lower_bound_ndp(context)
        (_R, ur), _tableres = opt.get_lower_bounds(ndp, table)

        from mcdp_opt.optimization_state import OptimizationState
        s2 = OptimizationState(opt=opt, options=c.options,
                                 context=context, executed=executed,
                                 forbidden=forbidden, lower_bounds=lower_bounds, ur=ur,
                                 creation_order=opt.get_next_creation())

        s2.info('Parent: #%s' % c.creation_order)
        s2.info('Action: #%s' % self)
        return s2
Ejemplo n.º 4
0
def get_lower_bound_ndp(context):
    """
        We create an NDP where each open resource becomes a new resource.
        and all the functions are given a lower bound of 0.
        
        The new resources are given a name like: dummy<i>
    """
    context = clone_context(context)
    
    unconnected_fun, unconnected_res = get_missing_connections(context)
    
    # let's remove the new resources that are unconnected
    for rname, name, _ndp in context.iterate_new_resources():
        if (name, rname) in unconnected_fun:
            unconnected_fun.remove((name, rname))
            del context.names[name]
            context.rnames.remove(rname)

    # create a new resource for each unconnected resource
    resource2var = {} # CResource -> str
    for dp, s in unconnected_res:
        r = CResource(dp, s)
        R = context.get_rtype(r)
        rname = 'dummy%d' % len(resource2var)
        context.add_ndp_res_node(rname, R)
        c = Connection(dp1=dp, s1=s, dp2=get_name_for_res_node(rname), s2=rname)
        context.add_connection(c)
        resource2var[r] = rname
        
    # add a minimal bound for all unconnected functions
    for dp, s in unconnected_fun:
        f = CFunction(dp, s)
        F = context.get_ftype(f)
        minimals = F.get_minimal_elements()
        res = get_constant_minimals_as_resources(F, minimals, context)
        c = Connection(dp1=res.dp, s1=res.s, dp2=dp, s2=s)
        context.add_connection(c)
    
    ndp = CompositeNamedDP.from_context(context)
    
    ndp.check_fully_connected()
    return ndp, resource2var
Ejemplo n.º 5
0
    def call(self, opt, c):
        context = clone_context(c.context)

        con = Connection(self.cresource.dp, self.cresource.s,
                         self.cfunction.dp, self.cfunction.s)

        context.add_connection(con)
        executed = c.executed + [self]
        # XXX
        forbidden = c.forbidden | set([self])

        from mcdp_opt.partial_result import get_lower_bound_ndp
        ndp, table = get_lower_bound_ndp(context)
        (R, ur), tableres = opt.get_lower_bounds(ndp, table)
        lower_bounds = tableres

        from mcdp_opt.optimization_state import OptimizationState
        s2 = OptimizationState(opt=opt, options=c.options,
                                 context=context, executed=executed,
                                 forbidden=forbidden, lower_bounds=lower_bounds,
                                 ur=ur, creation_order=opt.get_next_creation())
        return s2