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
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
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
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
def __init__(self, library, options, flabels, F0s, f0s, rlabels, R0s, r0s, initial): f0s = list(f0s) F0s = list(F0s) r0s = list(r0s) R0s = list(R0s) for i, (fname, F0, f0) in enumerate(zip(flabels, F0s, f0s)): F0.belongs(f0) F = initial.get_ftype(fname) f0s[i] = express_value_in_isomorphic_space(F0, f0, F) F0s[i] = F for i, (rname, R0, r0) in enumerate(zip(rlabels, R0s, r0s)): R0.belongs(r0) R = initial.get_rtype(rname) r0s[i] = express_value_in_isomorphic_space(R0, r0, R) R0s[i] = R self.library = library self.options = options self.flabels = flabels self.rlabels = rlabels self.F0s = F0s self.R0s = R0s self.r0s = r0s self.f0s = f0s context = create_context0(flabels, F0s, f0s, rlabels, R0s, r0s, initial=initial) from mcdp_opt.optimization_state import OptimizationState unconnected = [] for o in options: ndp = library.load_ndp(o) try: ndp.check_fully_connected() except NotConnected as e: if o.lower() == "raspberrypi2": # pass unconnected.append(o) for u in unconnected: options.remove(u) print('Removing the unusable options %s' % sorted(unconnected)) print('Remaining with %s' % sorted(options)) lower_bounds = {} for fname, F0, f0 in zip(flabels, F0s, f0s): r = CResource(get_name_for_fun_node(fname), fname) lower_bounds[r] = F0.U(f0) from mcdp_opt.partial_result import get_lower_bound_ndp ndp, table = get_lower_bound_ndp(context) (_R, ur), _tableres = self.get_lower_bounds(ndp, table) self.num_created = 0 s0 = OptimizationState(self, options, context, executed=[], forbidden=set(), lower_bounds=lower_bounds, ur=ur, creation_order=self.get_next_creation()) self.root = s0 # open nodes self.states = [s0] self.actions = [(s0, ActionExpand())] # tuples of state, action # connected self.done = [] # impossible self.abandoned = [] # expanded self.expanded = [] # extra ndps not present in library self.additional = {} # str -> NamedDP self.iteration = 0 # for visualization self.G = nx.DiGraph() self.G_dom = nx.DiGraph() # domination graph