Quasi-Simple computation in program - algorithm

I did not know whether I should post this in mathSE or stackoverflow, but since it involves code and some basic algorithms I went for SO.
My question comes from a program that I have to do based on this article:
Article
The problem is that I cannot seem to be able to allocate or understand some of the variables and how they fit, I personally think this is very sloppy mathematics and some rigorous stats would have probably benefited this article, but that's just me.
Anyway this is my pseudo-code/algorithm for the computation and it works:
/* Algorithm
*
* 1 Avg amount of sales - cupon face value
* 85 - 75 = 10 Additional $
*
* 2 Nbr cupons sold * redemption percentage (percentage Of Cupons Sold)
* 3000 * 85 = 2550 Number of tickets redemeed
*
* 3 Nbr cupons sold * sale price * percent taken by groupon
* 3000 * 35 * .50 = 52500 Groupon money limit goal
*
* 4 Nbr of tickets redeemed * Additional $
* 2550 * 10 = 25500 Additional money spent by customer
*
*
* 5 additional money spent by customer + grupon money limit
* 25500 + 52500 = 78000 Gross income
*
* Expenses
*
* 6 Nbr of tickets redeemed * avg amount sold * percent of incremental Cost Sales
* 2550 * 85 * 40 = 86700 Total expense
*
* 7 Nbr of tickets redeemed / Avg amount of cupons purchased by customers (number cupons purchased by custormers)
* 2550 / 2 = 1275 Nbr customers
*
* 8 Nbr customers * percent of existing customers (cuponsUsersAlreadyCustomers)
* 1275 * 0.60 = 765 amount of new customer (Standard deviation of average customer per population)
*
* 9 SD of avg customer per population * Percentage of new customer who returned (percent cupon user who become customers)
* 765 * 0.10 = 76.5 new repeat customer avg
*
* 10 Net cost / Avg new repeat customer
* 8700 / 76 = 114 Amount paid for each new regular
*
*/
The question is, where the heck that 60% comes from? and is it a fixed value? I mean technically 40% + 10% is 50% and 40% is the old customers. Second what about:
"7. What is the advertising value of having your business promoted to 900,000 people — that’s the number on Groupon’s Chicago list — even if they don’t buy a coupon? $1,000 advertising value."
Why do I need that? I mean I am already comparing how much each new customer will cost me with Groupon and traditional advertisement why is that there? do I need it in part of my computation?
It's a good project but this is really weird how the guy in the document is explaining the math!

The 60% comes from the assumption "4. 40 percent used by existing customers." Implicit seems to be the assumption that the "average number of coupons bought by each customer" does not differ significantly between new and existing customers. This is not mentioned explicitly, but since 2,550 is the number of redeemed coupons and the percentage is multiplied by 2,550 / 2 (assumed numbers of customers associated with these coupons) this seems to be a necessary assumption.
Edit: Sorry, I overlooked your second question. The $1,000 is mentioned only in the Revenue but not included in the calculation of the cost. In theory you could subtract it from the cost, but this is only sensible if you'd have spent that money on advertising anyways and it could thus be considered a cost external to the deal. It is however prudent to simply mention this additional benefit (which you get in addition to the new customers) but still consider it as part of the cost since it definitely has to be paid for.

Related

Calculate shipping costs on the basis of product weight

my math is not so good, but can you guys help me with this
problem statement
Suppose I have 4 books with weights and prices.
Book1, 0.5KG
Book2, 0.8KG
Book3, 1KG
Book4, 0.3KG
I have a base price (shipping cost) based on weight, which is 30 Rs Per 0.5KG.
Now when I select "book 1", the shipping cost will be 30 Rs, but how can I get the shipping cost for book 2,book 3 and book 4?
it's not related to any programming or algorithm , anyways
if
30Rs -> 0.5KG
x -> 0.8Kg
then simply for Book2
x = (30Rs*0.8KG)/0.5KG = 48Rs
similarly for book3 and book4:
book3 = (30Rs*1KG)/0.5KG = 60Rs
book4 = (30Rs*0.3KG)/0.5KG = 18Rs
another way to solve it is if every 30RS corresponds to 0.5KG then by dividing each side by 5 then 6RS corresponds to 0.1KG.
Book2 is 0.8KG which is 8 times the value 0.1KG then it must cost 8 times the value 6RS so 8 * 6 = 48RS similarly for **Book3 and Book4 where
Book3 = 10 * 6 = 60RS
Book4 = 3 * 6 = 18RS
If the pricing is in brackets, that is the cost for 0 - 0.5kg is 30RS, and 0.5 - 1kg is 60RS, then you have to do as follows:
First find how many brackets you have:
weight / bracketSize
For your books, this will be:
Book1: 0.5/0.5 // 1
Book2: 0.8/0.5 // 1.6
Book3: 1/0.5 // 2
Book4, 0.3/0.5 // 0.6
Then, you need to round that value up to the nearest whole number. How you do this will depend on what language you're using, but it's often called Ceiling or ceil:
Book1: Ceiling(1) // 1
Book2: Ceiling(1.6) // 2
Book3: Ceiling(2) // 2
Book4, Ceiling(0.6) // 1
Then multiply by price to get your answer.
Book1: 1 * 30 // 30
Book2: 2 * 30 // 60
Book3: 2 * 30 // 60
Book4, 1 * 30 // 30
In one line:
result = Ceiling(weight / bracketSize) * pricePerBracket

Odoo14 - Questions about limit_memory soft and hard

I'm trying to figure out how memory limits work and how to choose the right values.
My test server (VM) has 16GB of RAM and 4 vCPUs but it is a shared server, so I choose to use only 2 vCPUs and 2GB of RAM.
I look in the official documentation, and I calculate how many workers and RAM I need (https://www.odoo.com/documentation/14.0/administration/install/deploy.html#worker-number-calculation) .
W = Workers (workers)
2 workers for 1 CPU
CW = Cron Workers (max_cron_threads)
TW = W + CW
Worker number calculation
(#CPU * 2) + CW
(2 * 2) + 1 = 5 theorical maximal workers
Memory size calculation
Needed RAM = W * ( (light_worker_ratio * light_worker_ram_estimation) + (heavy_worker_ratio * heavy_worker_ram_estimation) )
5 * ((0.8 * 150) + (0.2 * 1024)) = 1624 (~2GB of RAM).
Ok, now, I go to the "configuration sample" (https://www.odoo.com/documentation/14.0/administration/install/deploy.html#id5) and I see I need to estimate how many concurrent users I'll have.
Can you confirm that the number of concurrent users includes all website visitors and not only the connected users?
In the configuration sample, how do you calculate/estimate the value of the limit? (limit_memory_hard, limit_memory_soft, limit_request, limit_time_cpu, limit_time_real)
I've read a lot of documentations (official or not), but they never say how to calculate these values.
Examples:
https://github.com/DocCyblade/tkl-odoo/issues/49 (I really don't understand how DocCyblade finds its values with its formula)
https://github.com/DocCyblade/tkl-odoo/blob/master/overlay/etc/odoo/openerp-server.conf
https://linuxize.com/post/how-to-install-odoo-14-on-ubuntu-20-04/
https://www.rosehosting.com/blog/how-to-speed-up-odoo/. 2048 is the default value since Odoo 10, not 640. If I try its formula, I will find that :
limit memory soft : 5 * 2147483648 = 10737418240
limit memory hard : 5 * 2684354560 = 13421772800
Can you help me, please?
Thanks

how to find maximum profit while selling some garbage item

I have one problem statement for which i need write an algo. can somebody help me?
Problem is :
i have different length of iron rod let say {26, 103, 59}, i want to sell the same length of iron rod so that i can earn maximum profit. Also i have to cutting charge lets say 10 Rs/unit.
Case 1, if cutting charge is Rs 100 and sell length of 51 feet with cost 100 per unit.
then 103/ 51 = 2 length ((51 * 100 * 2) - ((1 * 100) + 200 ) = 9900
59 / 51 = 1 length ((51 * 100 * 1) - ((8 * 100) + 1* 100) = 4200
26/52 = 0 length((0 * 100)) - (26 * 100 ) = -2600
now total profit is = 11500
But if cutting charge is vary then this calculation like failed, can some one tell how can develop algo to find the maximum profit.

How to optimize Cartesian product

Is there a better way to compute Cartesian product. Since Cartesian product is a special case that differs on each case. I think, I need to explain what I need to achieve and why I end up doing Cartesian product. Please help me if Cartesian product is the only solution for my problem. If so, how to improve the performance?
Background:
We are trying to help customers to buy products cheaper.
Let say customer ordered 5 products (prod1, prod2, prod3, prod4, prod5).
Each ordered product has been offered by different vendors.
Representation Format 1:
Vendor 1 - offers prod1, prod2, prod4
vendor 2 - offers prod1, prod5
vendor 3 - offers prod1, prod2, prod5
vendor 4 - offers prod1
vendor 5 - offers prod2
vendor 6 - offers prod3, prod4
In other words
Representation Format 2:
Prod 1 - offered by vendor1, vendor2, vendor3, vendor4
Prod 2 - offered by vendor5, vendor3, vendor1
prod 3 - offered by vendor6
prod 4 - offered by vendor1, vendor6
prod 5 - offered by vendor3, vendor2
Now to choose the best vendor based on the price. We can sort the products by price and take the first one.
In that case we choose
prod 1 from vendor 1
prod 2 from vendor 5
prod 3 from vendor 6
prod 4 from vendor 1
prod 5 from vendor 3
Complexity:
Since we chose 4 unique vendors, we need to pay 4 shipping prices.
Also each vendor has a minimum purchase order. If we don't meet it, then we end up paying that charge as well.
In order to choose the best combination of products, we have to do Cartesian product of offered products to compute the total price.
total price computation algorithm:
foreach unique vendor
if (sum (product price offered by specific vendor * quantity) < minimum purchase order limit specified by specific vendor)
totalprice += sum (product price * quantity) + minimum purchase charge + shipping price
else
totalprice += sum (product price * quantity) + shipping price
end foreach
In our case
{vendor1, vendor2, vendor3, vendor4}
{vendor1, vendor3, vendor5}
{vendor6}
{vendor1, vendor6}
{vendor2, vendor3}
4 * 3 * 1 * 2 * 2 = 48 combination needs to be computed to find the best combination.
{vendor1,vendor1, vendor6, vendor1, vendor2} = totalprice1,
{vendor1, vendor3, vendor6, vendor1, vendor2} = totalprice2,
*
{vendor4, vendor5, vendor6, vendor6, vendor3} = totalprice48
Now sort the computed total price to find the best combination.
Actual problem:
If the customer orders more than 15 products, and assume, each product has been offered by 8 unique vendors, then we end up computing 8^15=35184372088832 combinations, which takes more than couple of hours. If the customer orders more than 20 products then it takes more than couple of days.
Is there a solution to approach this problem in a different angle?
Your problem can get even more complex. A simple example:
Product 1 2 3
Vendor 1 10 20 40
Vendor 2 20 10 40
--------------------------
needed cnt 100 100 25
You need 100 El. of P1, 100 of P2, and 25 of P3.
P1 can be purchased for 1000 at V1, P2 for 1000 at V2, and P3 for 1000 at V1 or V3.
Now shipping would be free, if you purchase for 1500, but cost you 200 at each vendor else.
So if you order everything at V1, you would pay 4000:
1000+2000+1000+0 (shipping) = or for the same sum
2000+1000+1000+0 at V2, or splitted
1000+0+0+200 = 1200 at V1 plus
0+1000+1000+0 = 2000 at V2,
which sums up to 3200 and could be found by your method.
But you could split the purchase of product 3 this way:
1000+0+500+0 = 1500 at V1 plus
0+1000+500+0 = 1500 at V2
which only sums up to 3000 and would not be found by your method.
Afaik, there is established research in such topics, and the keywords are matrices and system of equations.
You can describe your problem as
f(c11, p11) + f(c22, p12) + f(c13, p13) = c1 => dc1
f(c21, p21) + f(c22, p22) + f(c23, p23) = c2 => dc2
...
f(c31, p31) + f(c32, p32) + f(c13, p33) = c3 => dc3
where cij is the count of product j at vendor i and pij is the price of product j at vendor i, but f(c11,p11) is not just count*price, but a function of count and price, since there might be a quantity discount. The right side is the purchase total for vendor i.
This is without purchase discount, which has to be modeled on top. If the discount on shipping is only depending on the total costs, it can be modeled just from ci => dci.
You would try to minimize sum (dc1+dc2+...+dcm).

Progressive non-linear algorithm for increasing discount

A system has to support 100 users and the price for support is 3
A system has to support 10 000 users and the price for support is 1
I have to devise an algorithm to give me the price in between so it will gradually rise with the number of users.
I tried to multiply the number of users by 0.0002 to get the discount value and I got
300 users * 0.0002 = 0.06 discount, so price for support = 2.94
total income = 300 * 2.94 = 882
5000 users * 0.0002 = 1 discount, so price for support = 2
total income = 5000 * 2 = 10 000
8000 users * 0.0002 = 1.6 discount, so price for support = 1.4
total income = 8000 * 1.4 = 11 200
10 000 users * 0.0002 = 2 discount, so price for support = 1
total income = 8000 * 1.4 = 10 000
So you see after a given point I am actually having more users but receiving less payment.
I am not a mathematician and I now this is not really a programming question, but I don't know where else to ask this. I will appreciate if someone can help me with any information. Thanks!
price = n * (5 - log10(n)) will work for 100 < n < 10000.
Just make sure you're using base-10 log and not natural (base-e) log. If your language doesn't have base-10 log normally, you can calculate it like this:
function log10(x) { return log(x)/log(10); }.
For 100 users, that's 100 * (5 - log10(100)), which gives 100 * (5 - 2), which is 300.
For 1000 users, that's 1000 * (5 - log10(1000)), which gives 1000 * (5 - 3), which is 2000.
For 10000 users, that's 10000 * (5 - log10(10000)), which gives 10000 * (5 - 4), which is 10000.
Let's pick some more random figures.
2500 users: 2500 * (5 - log10(2500)) gives us 2500 * (5 - 3.39794), which is 4005.
6500 users: 6500 * (5 - log10(6500)) gives us 6500 * (5 - 3.81291), which is 7716.
8000 users: 8000 * (5 - log10(8000)) gives us 8000 * (5 - 3.90309), which is 8775.
Should work out about right for what you're modelling.
Scaling the price per user linearly didn't work as you showed, but you can try scaling the total income linearly instead.
total income for 100 users = 300
total income for 10000 users = 10000
total income for n users = (n-100) / (10000-100) * (10000-300) + 300
You know that the total income for n users is the price for support per user times the number of users, that means, now you have to find the function f(n) such that f(n) * n = (n-100) / (10000-100) * (10000-300) + 300.
And if you have to show that as the total income always increase, the price for support always decrease, just show that f'(n) ≤ 0 when 100 ≤ n ≤ 10000.

Resources