python
Dashboard
My Repos
Compilers
Python Online
Node JS Online
Golang Online
codepy
Login
My Repos
Sign Out
Online Python Interpreter
Stop
Run
# Modelo from pulp import * import numpy #Ler o arquivo #teste = np.loadtxt("Hard28_BPP13.txt") #V = int(teste[1]) # Capacidade dos recipientes #v = teste[2:teste.size].astype(int) # Peso de cada item #n = v.size # Quantidade de itens C = 1000 # Capacidade dos Bins v = [3,2,1,2,3,1,2,6,1,7,3] # Itens n = len(v) #Quantidade de Itens # Variaveis #Na matriz x, o elemeto xij = 1 se o item i esta no bin j e 0 caso contrario x = [LpVariable("x{0}{1}".format(i, j), cat = "Binary") for i in range(n) for j in range(n)] #No vetor y, yi = 1 se tem algum item no bin i e 0 caso contrario y = [LpVariable("y{0}".format(i), cat = "Binary") for i in range(n)] # Modelo modelo = LpProblem("BPP", LpMinimize) #criando o modelo # Funcao Objetivo modelo += sum(y) #A funcao objetivo eh a quantidade de bins # Restricoes for k in range(n): modelo += sum(x[j] for j in range(n*k, (n*k)+n)) == 1 # Cada item pode estar em apenas um recipiente modelo += sum(x[j]*v[l] for j,l in zip(range(k, n**2, n), range(n))) <= C*y[k] # Nenhum bin pode estar sobrecarregado modelo += sum(y) >=1 # Solucao LpSolverDefault.msg = 1 modelo.solve() # Aqui da erro print(LpStatus[modelo.status]) print(value(modelo.objective))
Share this code with others
Public
Clear
My Repos
Repo
Lang
Login
Register
Login
Create a free account. No Credit card info required.
I agree with the Codepy
Term of Service
Sign Up