Exemple #1
0
def distro_branch_and_bound(root, incumbent=None):
    with Manager() as manager:
        info_dict = manager.dict()
        info_dict['incumbent'] = incumbent
        info_dict['incumbent_objective'] = float('inf')
        if not incumbent is None:
            info_dict['incumbent_objective'] = objective(incumbent)
            overcountings = []
            current = incumbent
            while not current is None:
                overcountings = [get_overcounting(current)] + overcountings
                current = get_parent(current)
            info_dict['incumbent_overcountings'] = overcountings

        num_processes = 40
        live_nodes = get_children(root)
        live_nodes = reduce(lambda X, Y : X + Y, map(lambda node : get_children(node), live_nodes))
        shuffle(live_nodes)
        num_live_nodes = len(live_nodes)
        
        ps = [make_and_start_process(branch_and_bound, (live_nodes[i*num_live_nodes/num_processes:(i+1)*num_live_nodes/num_processes], info_dict, i)) for i in range(num_processes)]
        
        for p in ps:
            p.join()
    
        return info_dict['incumbent']
Exemple #2
0
def distro_branch_and_bound(root, incumbent=None):
    with Manager() as manager:
        live_nodes = manager.dict()
        info_dict = manager.dict()
        info_dict['incumbent'] = incumbent
        info_dict['incumbent_objective'] = float('inf')
        if not incumbent is None:
            info_dict['incumbent_objective'] = objective(incumbent)
            overcountings = []
            current = incumbent
            while not current is None:
                overcountings = [get_overcounting(current)] + overcountings
                current = get_parent(current)
            info_dict['incumbent_overcountings'] = overcountings
        info_dict['num_processes'] = 15
        live_nodes = add_nodes(live_nodes, get_children(root))
        num_live_nodes = len(live_nodes)
        
        num_processes = info_dict['num_processes']
        ps = [make_and_start_process(branch_and_bound, (live_nodes, info_dict, i)) \
              for i in range(num_processes)]
        ps = [p for p in ps if not p is None]
        
        for p in ps:
            p.join()
    
        return info_dict['incumbent']
def distro_branch_and_bound(root, incumbent=None):
    with Manager() as manager:
        info_dict = manager.dict()
        info_dict['incumbent'] = incumbent
        info_dict['incumbent_objective'] = float('inf')
        if not incumbent is None:
            info_dict['incumbent_objective'] = objective(incumbent)
            overcountings = []
            current = incumbent
            while not current is None:
                overcountings = [get_overcounting(current)] + overcountings
                current = get_parent(current)
            info_dict['incumbent_overcountings'] = overcountings
        info_dict['num_processes'] = 15
        live_nodes = get_children(root)
        print len(live_nodes)
        live_nodes = breed_all_once(live_nodes)
        print len(live_nodes)
        shuffle(live_nodes)
        num_live_nodes = len(live_nodes)
        
        num_processes = info_dict['num_processes']
        ps = [make_and_start_process(branch_and_bound, (live_nodes[i*num_live_nodes/num_processes:(i+1)*num_live_nodes/num_processes], info_dict, i)) for i in range(num_processes)]
        
        for p in ps:
            p.join()
    
        return info_dict['incumbent']
def branch_and_bound(live_nodes, info_dict, my_id=0):
    print "started", my_id
    i = 2
    #live_nodes = remove_inferior(live_nodes, info_dict['incumbent'], info_dict['incumbent_overcountings'])
    waiting_on = []
    while len(live_nodes) > 0:
        if len(live_nodes) > q and info_dict['num_processes'] < 35 - (1 - 1):
            info_dict['num_processes'] = info_dict['num_processes'] + 1
            p1 = make_and_start_process(target=branch_and_bound, args=(live_nodes[:len(live_nodes)/2], info_dict, 10 * (1 + my_id)))
            live_nodes = live_nodes[len(live_nodes)/2:]
            waiting_on += [p1]
        if i == 0:
            pick, live_nodes = get_shallowest(live_nodes)
        elif i == 1:
            pick, live_nodes = get_best(live_nodes)
        elif i == 2:
            pick, live_nodes = get_deepest(live_nodes)
        print my_id, len(live_nodes), get_size(pick), "*****", get_size(info_dict['incumbent']), info_dict['num_processes']
        
        if is_feasible(pick):
            if objective(pick) < info_dict['incumbent_objective']:
                print "NEW INCUMBENT:", pick, get_size(pick), get_overcounting(pick)
                info_dict['incumbent'] = pick
                info_dict['incumbent_objective'] = objective(pick)
                overcountings = []
                while not pick is None:
                    overcountings = [get_overcounting(pick)] + overcountings
                    pick = get_parent(pick)
                info_dict['incumbent_overcountings'] = overcountings
                live_nodes = remove_inferior(live_nodes, info_dict['incumbent'], info_dict['incumbent_overcountings'])
        else:
            if has_children(pick) and get_size(pick) < get_size(info_dict['incumbent']) - 1:
                live_nodes = add_nodes(live_nodes, remove_inferior(get_children(pick), info_dict['incumbent'], info_dict['incumbent_overcountings']))
    
    for p in waiting_on:
        p.join()
    print "finished", my_id
    info_dict['num_processes'] = max(info_dict['num_processes'] - 1, 5)
def distro_branch_and_bound(root, incumbent=None):
    num_processes = 40
    live_nodes = root.get_children()
    num_live_nodes = len(live_nodes)
    
    with Manager() as manager:
        info_dict = manager.dict()
        info_dict['incumbent'] = incumbent
        info_dict['incumbent_objective'] = float('inf')
        if not incumbent is None:
            info_dict['incumbent_objective'] = incumbent.objective()
            overcountings = []
            current = incumbent
            while not current is None:
                overcountings = [current.get_overcounting()] + overcountings
                current = current.get_parent()
            info_dict['incumbent_overcountings'] = overcountings
        
        ps = [make_and_start_process(branch_and_bound, (SCPTree(live_nodes[i*num_live_nodes/num_processes:(i+1)*num_live_nodes/num_processes]), info_dict, i)) for i in range(num_processes)]
        
        for p in ps:
            p.join()
    
        return info_dict['incumbent']