Suppose I have K arrays of different sizes:
A1 = [X1, X2, X3 .... Xn]
A2 = [Y1, Y2, Y3 .... Ym] .. and K-2 more such arrays.
All arrays contain elements of same data type.
And then I have a function, F = f(Xn, Ym,...K-2 more such elements)
. The function basically requires exactly one element from each array, and my objective is to find a maximum value for this function. And also, which all elements make it
maximum.
Important Info
Nature of function: All arrays are sorted (descending order). And first element in each array provides the best solution to the function (maximizes the function within its peer set). So, the ideal case would be picking up the first element from each array. But there is a constraint, which I can best describe as:
Suppose these elements are numbers, then I have to keep their total sum less than some constant value. So the constraint is:
Xn + Ym + ... and others <= Constant
EDIT: As @Spektre asked, the function is exponential in nature.
How can I solve this without brute force? Any pointers on solutions to similar existing problems would also help!
I understand divide & conquer, dynamic programming and linear programming upto the extent taught in Introduction to Algorithms-CLRS. So, if I can apply any of those, I am not able to figure that out with respect to this problem.
EDIT: An example function and dataset for the above problem:
Maximize: F = ax + by + cz
The above function was not very accurate representation of original problem.
UPDATE: Example function updated
F = xh(x)g(x) + yh(y)g(y) + zh(z)g(z)
h and g are non decreasing linear function of x/y/z. Range of h varies from 1 to 2. Range of g varies from 1 to 50. Domain of x,y,z is positive real numbers with average value in millions (consider 10 million as maximum for the example case ahead).
Example dataset (x,y,z are in millions):
x is in [20,18,17,15,12,9,8,5]
y is in [26,21,16,13,6,3,2,1]
z is in [45,42,41,40,12,3,2,1,0]
So the arrays contain random but sorted values.
And a,b,c > 1
So take a = 2, b=3 and c=4 for instance making the function as:
F = 2x + 3y + 4z
The constraint: x + y + z <= 50
I've updated the example function after Spektre's solution, but that algorithm should still be valid as function is still an increasing function of x,y,z.
Example code of h(), g() and arrays (in JavaScript)
function h(a) {
var h = 1 + 0.0000001 * a;
return h;
}
function g(a) {
var g = (50 / 10000000) * a;
return g;
}
function f(x, y, z) {
var f = x * Math.pow(h(x), g(x)) + y * Math.pow(h(y), g(y)) + z * Math.pow(h(z), g(z));
return f;
}
var maxSum = 5000000;
function isSumLessThanMax(x, y, z) {
if (x + y + z <= maxSum) {
return true;
}
else {
return false;
}
}
var x = [2000000, 1800000, 1700000, 1500000, 1200000, 900000, 800000, 500000];
var y = [2600000, 2100000, 1600000, 1300000, 600000, 300000, 200000, 100000];
var z = [4500000, 4200000, 4100000, 4000000, 1200000, 300000, 200000, 100000, 0];