I am creating a game, and have run into quite a tricky problem which I have been wrestling for days. I have been able to turn into somewhat mathematical terms (bare with me, I'm a programmer not mathematician) -- but I am no closer to a solution.
var constants = [1000, 100, 10]; // arbitrary length, arbitrary positive numbers
var contributions = [?, ?, ?]; // an array of each constants respective contribution
Given an array of constants, I am trying to generate an array of contributions which represents each constants contribution to a pool.
SUM(constants[i] * contributions[i]) === pool
That is to say, each constant multiplied by their contribution ... summed up is known as the pool.
Here are the constraints I have to obey:
FOREACH i in constants.length:
constants.length * (constants[i] * contribution[i]) isLessThanOrEqualTo pool
That is to say, if I get the amount of constants I have .. multiply it by constants contribution ... it will always be less than or equal to the size of the pool.
And the last constraint:
All contributions must be less than or equal to 0.01
In other words, no constant can contribute more than 1% of its value to the pool.
Given these constraints, what I want to do is construct my array of contributions in such a way to maximize pool.
What I am looking for, is a function which turns an array of constants into an array of contributions. If anyone could give me any pointers, place to start, library suggestions .. or even work through how this problem would be solved for the example: constants = [1000, 100, 10] -- i would be highly appreciative.
Maximize p = 1000x + 100y + 10z subject to x <= 0.01 y <= 0.01 z <= 0.01 3(1000x) - 1000x - 100y - 10z <= 0 3(100y) - 1000x - 100y - 10z <= 0 3*(10z) - 1000x - 100y - 10z <= 0
into: http://www.zweigmedia.com/RealWorld/simplex.html
It solves as p=0 (which as you demonstrated, is not the case)
– Heptic Jul 28 '14 at 17:29and everything's good.
– Quang Hoang Jul 28 '14 at 17:44I then want to create a "last cashout bonus" scheme, where peoples bonus is proportional to how much they bet ... in such a way that is fair for the casino and the player. However, the maths is totally doing my head in..
– Heptic Jul 28 '14 at 18:14