I have a problem in which I have a finite set of values, say:
[1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10]
I would like to write an algorithm in which I provide a target value, and in which a list of two (quantity, value) pairs is returned such that the following rules are followed. The rules are listed in decreasing order of importance, with un-numbered rules being 'nice-to-have' but note 'have-to-have'.
- The sum of all the products of the quantity-value pairs equals the target value
- Either one or two quantity-value pairs are used
- Each pair in an integer quantity and one of the values from the list
- The sum of quantities are be minimized
- The two values are within 2 of each other, such that (value2 - value1) <= 2
- The number of 1/2 values are minimized
- The lowest values possible in the list are used
My question is as follows: do the parameters of this problem fall within any of the 'classic', or well-known/researched computer algorithms? If some of the conditions were tweaked, could this problem be made to look more like a 'classic' optimization problem?
I am interested in approaching this problem in any other way than 'brute force', however my knowledge of different optimization problems is sparse.
Edit
Here are some examples:
#------Example 1------------
print(find_combination(16.5))
# output = ({'qty':1, value:4.5},
# {'qty':2, value:6})
# The following is invalid because the sum of qty is
# equivalent but more half values are used
# output = ({'qty':3, value:5.5})
#------Example 2------------
print(find_combination(15))
# output = ({'qty':3, value:5})
# The following is invalid because it uses more half
# values, and the sum of the quantity is not at least
# two less than the above answer
# output = ({'qty':2, value:7.5})
#------Example 3------------
print(find_combination(12))
# output = ({'qty':2, 'value':6})
# The following is invalid because the two values are
# not within two of each other. Also, the number of
# different values was not minimized
# output = ({'qty':1, 'value':2},
{'qty':1, 'value':10})