#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
#-*- coding: cp1251 -*- # PuLP from pulp import * # (LP) prob = LpProblem( "Knapsack problem" , LpMaximize) # , x1 = LpVariable( "x1" , 0, 10, 'Integer' ) x2 = LpVariable( "x2" , 0, 10, 'Integer' ) x3 = LpVariable( "x3" , 0, 10, 'Integer' ) # ( " " ) prob += 17*x1 + 30*x2 + 75*x3, "obj" # ( " " ) prob += 1.5*x1 + 2.5*x2 + 6*x3 <= 20, "c1" # prob.solve() # print "Status:" , LpStatus[prob.status] # for v in prob.variables(): print v.name, "=" , v.varValue # print ( "objective = %s$" % value (prob.objective)) * This source code was highlighted with Source Code Highlighter .
~$ python knapsack.py
Status: Optimal
x1 = 2.0
x2 = 2.0
x3 = 2.0
objective = 244.0$
Source: https://habr.com/ru/post/83918/
All Articles