def genrate_and_write(name, func):
    random_instance = random.Random()
    random_instance.seed(42)

    with open(outplut_dir + '/' + name + '.txt', 'w') as file:
        for step in stepper(130):
            print(name, ' ', step)
            file.write(str(step))
            file.write('\n')
            for i in range(300):
                numRoles = numLeafs = step
                tree = Node.generate_tree(numRoles, numLeafs, random_instance)
                cost = func(tree, numRoles + 1)
                cost_at_forign_role = cost.pop()
                cost = [c for i, c in enumerate(cost) if i in tree.union]
                cost.append(cost_at_forign_role)
                file.write(str(cost))
                file.write('\n')
Beispiel #2
0
        node.preferred = left_set.union(right_set)
        node.intersect = False
        return node.preferred
    if len(intersect) == 1:
        node.setColor(next(iter(intersect)))
    node.preferred = intersect
    node.intersect = True
    return intersect

def copy_parent_color(node, color):
    if node.left is None:
        assert node.right is None
        return # skip leafs
    if node.getColor() == None:
        if color in node.preferred or not node.intersect:
            node.setColor(color)
        else:
            node.setColor(next(iter(node.preferred)))
        #node.setColor(color)
    copy_parent_color(node.left, node.getColor())
    copy_parent_color(node.right, node.getColor())

if __name__ == '__main__':
    numRoles = 4
    numLeafs = 10
    tree = Node.generate_tree(numRoles, numLeafs)
    sols = optimal(tree, numRoles)
    print(tree)
    print(tree.sol_str())
    print(sols)