Matlab code for burglar optimization problem
A burglar with a bag break into a house and find some items that have different weights and values but there is a maximum wight that he can curry. what items the burglar should take to maximize the value.
the program should have three inputs and at least two outputs.
inputs:
w: the weight vector of the item
v: the value of the item {ie v(n) is the value of item that its wight w(n)}
Wmax: the maximum total weight the burglar can carry.
output:
Vmax: The total optimize value of the items
x: a vector with the same length of w that has zero to represent the item that is not taken and 1 to represent taken items.
Note: I have related python code but I don't understand python but this could help:
def maxVal0(w, v, i, aW):
m = {}
return fastMaxVal(w, v, i, aW, m)
def fastMaxVal(w, v, i, aW, m)
global numCalls
numCalls += 1
try: return m[(i, aW)]
except KeyError:
if i == 0:
if w[i] <= aW:
m[(i, aW)] = v[i]
return v[i]
else:
m[(i, aW)] = 0
return 0
without_i = fastMaxVal(w, v, i1, aW, m)
if w[i] > aW:
m[(i, aW)] = without_i
return without_i
else: with_i = v[i] + fastMaxVal(w, v, i1, aW  w[i], m)
res = max(with_i, without_i)
m[(i, aW)] = res
return res
