# Problem switching from Binary to PositiveInteger domain

Just started with Pyomo and was taking some samples from this knapsack problem tutorial: https://pyomocontrib-simplemodel.readthedocs.io/en/latest/knapsack.html

However for my optimization problem I'd like to be able to utilize the PositiveInteger domain. I tried editing the code above as follows:

``````v = {'hammer':8, 'wrench':3, 'screwdriver':6, 'towel':11}
w = {'hammer':5, 'wrench':7, 'screwdriver':4, 'towel':3}
limit = 14
items = list(sorted(v.keys()))

# Create model
m = ConcreteModel()

# Initialization **ADDED BY ME**
m.x_init = Set(initialize=['hammer','wrench','screwdriver','towel'])
lb = {'hammer':0,'wrench':0,'screwdriver':0,'towel':0}
ub = {'hammer':2,'wrench':2,'screwdriver':2,'towel':2}

# **ADDED BY ME**
def fb(model,i):
return (lb[i],ub[i])

# Variables
m.x = Var(m.x_init,domain=PositiveIntegers,bounds=fb)
## Changed from
# m.x = Var(items, domain=Binary)

# Objective
m.value = Objective(expr=sum(v[i]*m.x[i] for i in items))

# Constraint
m.weight = Constraint(expr=sum(w[i]*m.x[i] for i in items) <= limit)

# Optimize
solver = SolverFactory('glpk')
status = solver.solve(m)

# Print the status of the solved LP
print("Status = %s" % status.solver.termination_condition)

# Print the value of the variables at the optimum
for i in items:
print("%s = %f" % (m.x[i], value(m.x[i])))

# Print the value of the objective
print("Objective = %f" % value(m.value))
``````

And I am getting the error "No value for uninitialized NumericValue object x[hammer]". I'm really stumped. If the line m.x_init = Set(initialize()) isn't creating a set/unordered list of initialized variables what is it doing? Or is it just not in the form of x['index']?