I am a Java developer building a web app that I will be deploying "in the cloud" (I hate that expression) in a few months. I'm trying to develop a function that will let me spawn and kill the right amount of "computing horsepower" (virtual machines) depending on the current load of the system (by "load" I mean traffic, # of users, etc.).
I have developed such a function, but because it's been so long since I cracked open any of my college mmathbooks, there's one component of it that I'm struggling with that could/should be re-written as it is a piecewise function.
Basically, I have an "outer"/main function c
that maps a real (the load) to an integer (# of virtual machines I should have running to support the load):
c : L in the domain of reals --> z in the domain of integers c(L) = A * t(L)
Where c(L)
is the function that my Java code will call, L
is a measure of the current load on the system (of type double
since load could be 5.0 or 34.2094, etc.), A
is a fairly-complicated function that doesn't concern this question (so I omitted it), and t(L)
is the piecewise function I need help re-writing:
t(L) = { 0 : if L < 1 { L+1 : if L is an integer // 5.0 == 5 { ceil(L) : if L is not an integer // 5.5
I understand that the first and third piecewise rules sort of contradict each other, but the first one (0 : if L <1
) trumps/overrides the last one (ceil(L) : if L not integer
).
So, if L
is less than 1, I need t(L)
to always return 0. Otherwise, if its an integer, I need it to return L+1
, or ceil(L)
for any other reals.
So, some examples:
t(0.5) = 0 t(1) = 2 // 1 + 1 -> 2 t(1.5) = 2 // ceil(1.5) -> 2 t(2) = 3 t(57.39854) = 58
Note: L
will always be non-negative (0+).
For the life of me I can't figure out how to re-write t(L)
in such a way as to be "in-line" or normal (not containing if-else
piecewise rules). Thanks for any and all help here!