Exemplo n.º 1
0
def create_model(cuts_quantity, maxl):
    patterns = get_patterns(cuts_quantity, maxl)
    model = LpProblem("Cubicator3000", LpMinimize)

    '''
    patterns is a array of vectors. i=1...n, j=1..m
    cuts is a array of floats j=1..m
    X_i is int variable for times the pattern is used.
    '''

    dict_X = {}
    n = len(patterns)
    m = len(cuts_quantity)

    for i in range(n):
        dict_X[i] = LpVariable("Pattern {} gets used".format(i), cat=LpInteger,
                               lowBound=0)
        dict_X[i].index = i

    # F.O sum over X variables
    model += lpSum([dict_X[i] for i in range(n)]), "Minimize tables used"
    # restrictions: the amount of every cut should be the amount demanded
    for j in range(m):
        temp_var = lpSum([dict_X[i] * patterns[i][j] for i in range(n)])
        temp_string = "the amount of cut {} produced equals the demanded"
        model += temp_var == cuts_quantity[j][1], temp_string.format(j)
    return model, patterns