I have an array P = [1, 5, 3, 6, 4, ...]
of size N
and average A
.
I want to find the most efficient way to maximize the following 3D function:
f(x, y) = 1 / ( (1+e^(-6(x-2))) * (1+e^(-6(y-2))) * (1+e^(-0.1x-0.3y+1.5)) )
where x = c(S) = Count(S)
and y = m(S) = Min(S[0]/A, S[1]/A, ..., S[n]/A)
, and S
is a subset of P
. The subset does not have to be continuous in P
.
I have a feeling that this can maybe be reduced to some variant of the subset sum problem but I really have no idea where to start other than sorting P
. The goal is to implement the algorithm in PHP, but really any pseudocode would help a lot.
If you are looking for a clever math reduction, agree with others, the place is the math exchange. Otherwise, start with the Math_Combinatorics library. Then you should be able to grind through all unique combinations of S with:
require_once 'Math/Combinatorics.php';
$combos = new Math_Combinatorics;
$P = [1, 5, 3, 6, 4, ...];
for ($n = 1; $n <= count($P); $n++) {
foreach ($combos->combinations($P, $n) as $S) {
... your calculations on S go here ...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With