I would like to solve the following problem, where I would want to know which numbers in the "Values" column adds up to the "Find" value (129.18).
I want to solve this using numpy's lingprog function, where I would assign 0 or 1 as the multiplier, such that the solution would give 1 for the values 4.28 & 124.90, and 0 for the rest of the values. The multiplier values can only be 0 or 1 (integers).
The issue is I have no Math background and I don't think I understand the examples in http://www.vision.ime.usp.br/~igor/articles/optimization-linprog.html and the documentation under https://docs.scipy.org
Values Multiplier Product Find: 129.18
4.28 ** 1 4.28
135.81 1 135.81
124.90 ** 1 124.90
293.51 1 293.51
7981.13 1 7981.13
The code I have so far is:
import numpy as np
from scipy.optimize import linprog
from numpy.linalg import solve
A = np.array([[1,1,1,1,1]])
B = np.array([129.18])
c = np.array([4.28, 135.81, 124.9, 293.51, 7981.13])
res = linprog(c,
A_eq=A,
b_eq=B,
bounds=(0, 1)
)
print('Optimal value:', res.fun, '\nX:', res.x)
print(res)
Obviously this is not working. How should I change the code so it meets my criteria?
1st time poster, but long time beneficiary of stackoverflow :) - thanks for any help that I can get on this question!
Cheers,