コード例 #1
0
def sched(s, to_load, graph, n):
    if to_load == []:
        param = find_params(graph, n, s)
        obj = param[0].primal
        if best == []:
            best.append(obj)
            sbest.append(s)
        elif obj < best[-1]:
            best.append(obj)
            sbest.append(s)
    else:
        for v in to_load:
            if (type(v) == tuple and v[0] in s and v[1] in s) or type(v) == int:
                t = deepcopy(s)
                t.append(v)
                branch = [x for x in to_load if x != v]
                sched(t, branch, graph, n)
コード例 #2
0
def sched(graph, n):
    m = len(graph)
    inv_graph = invert_dict(graph)
    for v in permutations(range(1, n+1)):
        for e in permutations(range(1, m+1)):
            s = [v[i] for i in range(n)]
            edg = [inv_graph[e[i]] for i in range(m)] 
            s = s + edg
            param = find_params(graph, n, s)
            obj = param[0].primal
            if best == []: 
                best.append(obj)
                sbest.append(s)
                print best
                print sbest
            elif obj < best[-1]:
                best.append(obj)
                sbest.append(s)
                print best
                print sbest
コード例 #3
0
four_clique = {(1,2):1, (1,3):2, (1,4):3, (2,3):4, (2,4):5, (3,4):6}
####################

if __name__ == '__main__':
    # set the input graph here
    graph = four_clique

    # the next few lines compute the number of vertices
    vertices = []
    for e in graph:
        if e[0] not in vertices:
            vertices.append(e[0])
        if e[1] not in vertices:
            vertices.append(e[1])
    n = len(vertices)

    to_load = vertices + graph.keys()
    # best is a list to hold the progression of best costs found
    best = []
    # sbest is a list to hold the progression of corresponding best schedules 
    sbest = []
    sched(graph, n)
    print 'progression of best objective values and accompanying schedule'
    print best
    print sbest
    print
    print 'Best schedule found is ', sbest[-1]
    print 'Parameters for this schedule are'
    param = find_params(graph, n, sbest[-1])
    print_params(graph, n, param)