Exemple #1
0
def read_file(filename):
    with open(filename) as f:
        content = f.readlines()

    filename_k_dict = {"graphs/graph0.txt": 3, "graphs/graph1.txt": 3, "graphs/graph-color-1.txt": 4, "graphs/graph-color-2.txt": 4,
                       "graphs/rand-50-4-color1.txt": 4, "graphs/rand-100-4-color1.txt": 4,
                       "graphs/rand-100-6-color1.txt": 6, "graphs/spiral-500-4-color1.txt": 4, "gcolor1.txt": 4, "gcolor2.txt": 4, "gcolor3.txt": 4}
    #k = int(raw_input("k: "))

    #k = filename_k_dict[filename]
    k =4
    variable_dict = {}

    nr_of_variables, nr_of_constraints = map(int, content[0].rstrip().split(" "))
    # Reads all the variables into a variable dictionary.
    # key = variable index and value = Variable object
    for i in range(1, nr_of_variables + 1):
        vertex_info = map(float, content[i].rstrip().split(" "))
        v = Variable(index=int(vertex_info[0]), x=vertex_info[1], y=vertex_info[2], k=k)
        variable_dict[v.index] = v

    constraints = []
    # Reads all constraints into a list containing Constraint objects
    for j in range(i + 1, nr_of_variables + nr_of_constraints + 1):
        constraint_info =  map(int, content[j].rstrip().split(" "))
        constr = Constraint(variable_dict, involved_variables=constraint_info)
        constr.constraining_func = makefunc(var_names=["x", "y"], expression="x != y")
        constraints.append(constr)

    return variable_dict, constraints
Exemple #2
0
def read_file(filename):
    with open(filename) as f:
        content = f.readlines()

    filename_k_dict = {
        "graphs/graph0.txt": 3,
        "graphs/graph1.txt": 3,
        "graphs/graph-color-1.txt": 4,
        "graphs/graph-color-2.txt": 4,
        "graphs/rand-50-4-color1.txt": 4,
        "graphs/rand-100-4-color1.txt": 4,
        "graphs/rand-100-6-color1.txt": 6,
        "graphs/spiral-500-4-color1.txt": 4,
        "gcolor1.txt": 4,
        "gcolor2.txt": 4,
        "gcolor3.txt": 4
    }
    #k = int(raw_input("k: "))

    #k = filename_k_dict[filename]
    k = 4
    variable_dict = {}

    nr_of_variables, nr_of_constraints = map(int,
                                             content[0].rstrip().split(" "))
    # Reads all the variables into a variable dictionary.
    # key = variable index and value = Variable object
    for i in range(1, nr_of_variables + 1):
        vertex_info = map(float, content[i].rstrip().split(" "))
        v = Variable(index=int(vertex_info[0]),
                     x=vertex_info[1],
                     y=vertex_info[2],
                     k=k)
        variable_dict[v.index] = v

    constraints = []
    # Reads all constraints into a list containing Constraint objects
    for j in range(i + 1, nr_of_variables + nr_of_constraints + 1):
        constraint_info = map(int, content[j].rstrip().split(" "))
        constr = Constraint(variable_dict, involved_variables=constraint_info)
        constr.constraining_func = makefunc(var_names=["x", "y"],
                                            expression="x != y")
        constraints.append(constr)

    return variable_dict, constraints
Exemple #3
0
def read_file(filename):
    with open(filename) as f:
        content = f.readlines()

    nr_of_columns, nr_of_rows = map(int, content[0].rstrip().split(" "))
    # (x, y)
    dimensions = (nr_of_columns, nr_of_rows)

    variable_dict = {}
    rows = []
    columns = []
    constraints = []

    variable_index = 0
    # Add all rows as variables
    for i in range(1, nr_of_rows+1):
        segments = map(int, content[i].rstrip().split(" "))
        variable = Variable(index=variable_index, direction="row", direction_nr=variable_index, length=nr_of_columns, segments=segments)
        variable_dict[variable_index] = variable
        variable_index += 1
        rows.append(variable)

    # Add all columns as variables
    for i in range(nr_of_rows+1, nr_of_rows+nr_of_columns+1):
        # Reversing the segments order to make it on the right format
        segments = map(int, content[i].rstrip().split(" "))[::-1]
        variable = Variable(index=variable_index, direction="column", direction_nr=i-(nr_of_rows+1),length=nr_of_rows, segments=segments)
        variable_dict[variable_index] = variable
        variable_index += 1
        columns.append(variable)

    # Creating one constraint for each cell shared by a column and a row
    for column in columns:
        for row in rows:
            constraint = Constraint(variable_dict, involved_variables=[column.index, row.index])
            constraint.constraining_func = makefunc(["x", "y"], "x == y")
            constraints.append(constraint)

    return dimensions, variable_dict, constraints