How to minimize total distance for deliveries? - dynamic-programming

There are n houses on an infinitely long road where baskets are to be delivered. Imagine the road as an x-axis starting from negative infinity to positive infinity. We have to select a position of new warehouse in the road so that we can minimize the total distance for deliveries.
there is a single Truck that carry a maximum of m baskets.
task is to find the position for warehouse so that total distance needed to deliver all basket will be minimum possible.
Can anyone help me with question please?

Related

Handling Negative Values when Calculating Average & Value

I am working on a tool for Fantasy Football that calculates the average value a player offers per million pounds of cost. It essentially boils down to their average points per game divided by their cost.
So for example, a player who costs £10m and scores an average of 5 points per game offers 0.5 points per game per million. Whereas a player who costs £8m and scores an average of 5 points per game offers 0.625 points per game per million. Clearly the player who costs £8m is better value.
My problem is, players are capable of scoring negatively, and so how do I account for that in calculating the value of a player?
To give another example, a player who costs £10m and scores an average of -2 points per game offers -0.2 points per game per million. Whereas a player who costs £8m and scores an average of -2 points per game offers -0.25 points per game per million.
Now the player who costs £10m appears to be better value because their PPG/£m is higher. This shouldn't be true, they can't be better value if they cost more but score the same points. So if I have a list of players sorted by their value, calculated in this manner, some players will incorrectly show higher than players that are technically better value.
Is there a way to account for this problem? Or is just an unfortunate fact of the system I'm using?
One simple trick will be to slightly change your formula for PPG/£m as the ratio of the square of the average points he scored and the cost.
If you are particular about the scales, consider its positive square root.

Formula should be simple

im a bit of a rookie to Excel and I cant find an exact answer to my question.
Basically I want to get picture 1(https://i.stack.imgur.com/8E5zv.png) to do what picture 2 (https://i.stack.imgur.com/LXJhq.png
) is showing. Its probably a really easy question.
So any value total over 10,000 will be charged at the 25p rate and any value below 10,000 will be charged a the 40p rate.
so cumulatively, one person may have claimed 9999 miles since starting and they put in a new expense claim for 10 miles, I would like the 1 mile to go to the 40p rate and the other 9 to the 25p rate.
What sort of formula would I need?
Thanks for any help in advance!
If the previous cumulative mileage is denoted by Old, the additional mileages by Miles and the threshold at which the lower rate is payable by Thold then consider the following. There are 3 cases:
Old+Miles<=Thold: All Miles paid at the higher rate
Old<Thold<=Old+Miles: Miles split so that Thold-Old paid at higher rate and Miles-(Thold-Old) at lower rate
Thold<=Old: All Miles paid at lower rate.
Miles are paid at the higher rate whenever Old is less than Thold and the number of miles paid at the higher rate is the lesser of Miles (Case 1.) and Thold-Old (Case 2.). This could be expressed in Excel-like way as
`=IF(Thold-Old>0,IF(Miles<Thold-Old,Miles, Thold-Old),0)`
but a much more succinct expression is
`=MIN(Miles,MAX(Thold-Old,0))`
Both formulae, deliver a correct result in all 3 cases (including a value of zero for case 3.) and so each represents a generally applicable formula for the number of miles to be paid at the higher rate.
Similarly, miles are paid at the lower rate whenever Old+Miles exceeds Thold and the number paid at this rate is the lesser of Miles (Case 3.) and Miles-(Thold-Old) (Case 2.). In this case the IF expression is:
`=IF(Old+Miles>Thold,IF(Miles<Miles-(Thold-Old),Miles,Miles-(Thold-Old)),0)
but this can be equivalently written as
`=IF(Old+Miles-Thold>0,IF(Miles<Miles+Old-Thold,Miles, Miles+Old-Thold),0)`
and I will leave it for you as an exercise to work out the succinct version. The formula(e) deliver a result of 0 for case 1. and so are generally applicable for calculating the miles to be paid at the lower rate.

Draw coins (without replacement) at random

I am running into a problem that asks me to calculate the probability and standard deviation. The problem is follows:
Coins with values 1 through N (inclusive) are placed into a bag. All the coins from the bag are iteratively drawn (without replacement) at random. For the first coin, you are paid the value of the coin. For subsequent coins, you are paid the absolute difference between the drawn coin and the previously drawn coin. For example, if you drew 5,3,2,4,1
, your payments would be 5,2,1,2,3
for a total payment of 13
.
What is the standard deviation of your total payment for N=20?
What is the probability that your total payment is greater than or equal to 160 for N=20?
Can I get your help with these two questions?
Thanks!!

Monte Carlo Simulation using Excel Solver

I am trying to figure out what the optimal number of products I should make per day are, displaying the values in a chart and then using the chart to find the optimal number of products to make per day.
Cost of production: $4
Sold for: $12
Leftovers sold for $1
So the ideal profit for a product is $8, but it could be -$3 if it's left over at the end of the day.
The daily demand of sales has a mean of 150 and a standard deviation of 30.
I have been able to generate a list of random numbers using to generate a list of how many products: NORMINV(RAND(),mean,std_dev)
but I don't know where to go from here to figure out the amount sold from the amount of products made that day.
The number sold on a given day is min(# produced, daily demand).
ADDENDUM
The decision variable is a choice you make: "I will produce 150 each day", or "I will produce 145 each day". You told us in the problem statement that daily demand is a random outcome with a mean of 150 and a SD of 30. Let's say you go with producing 150, the mean of demand. Since it's the mean of a symmetric distribution, half the time you will sell everything you made and have no losses, but in most of those cases you actually could have sold more and made more money. You can't sell products you didn't make, so your profit is capped at selling 150 on those days. The other half of the time, you won't sell all 150 and will take a loss on the unsold items, reducing your profit a bit. The actual profit on any given day is a random variable, because it is determined by random demand.
Since profit is random, you can calculate your average earnings across many days based on the assumption that you produce 150. You can also average earnings based on the assumption that you produce 140 per day, or 160 per day, or any other number. It sounds like you've been asked to plot those average earnings versus how many you decided to produce, and choose a production level that results in the highest long-term average earnings.

Manager game: How to calculate market values?

Usually players in a soccer manager game have market values. The managers sell their players in accordance with these market values. They think: "Oh, the player is worth 3,000,00 so I'll try to sell him for 3,500,000".
All players have three basic qualities:
strength value (1-99)
maximal strength they can ever attain (1-99)
motivation (1-5)
current age (16-40)
Based on these values, I calculate the market values at the moment. But I would like to calculate the market values dynamically according to the player transfers in the last period of time. How could I do this?
I have the above named qualities and the player transfers of the last period of time available for calculation.
How could I calculate it? Do I have to group the last transferred players by the qualities and simply take the average transfer price?
I hope you can help me.
Note: players=items/goods, managers=users
My suggestion: define a distance function that takes two players stats and return a distance value. Now that you have a distance between the two (that corresponds to the similarity between them) you can use the K-means algorithm to find clusters of similar players.
For each cluster you can take a number of values that can help you calculate the so called 'market price' (like the average or median value).
Here's a very simple example of how you could compute the distance function between two players:
float distance(Player player1, Player player2){
float distance = 0.0;
distance += abs(player1.strength - player2.strength) / strengthRange;
distance += abs(player1.maxStrength - player2.maxStrength) / maxStrength;
distance += abs(player1.motivation - player2.motivation) / motivationRange;
distance += abs(player1.age - player2.age) / ageRange;
return distance;
}
Now that you have the distance function you can apply the k-means algorithm:
Assign each player randomly to a cluster.
Now compute the centroid of each cluster. In your case the centroid coordinates will be (strength, maxStrength, motivation, age). To compute the centroid strength coordinate, for example, just average the strengths for the all players in the cluster.
Now assign each player to the nearest centroid. Note that in this step some players may have its cluster changed.
Repeat steps 2 and 3 until you have convergence or, in other words, until no player have its cluster changed in step 3.
Now that you have the clusters, you can calculate the average price fore similar players.
One thing that you could do is look at recent transfers of similar(1) players. Say all transfers within 2-5 game weeks of similar players and then take the average (or median or some other calculated value) of their sale price.
(1) You will have to define similiar in some way, i.e a defender with +-10 in defence, +-3 in passing and +-2 years of age. More factors give more precise results.
Or you could use a little Economics 101 and try to define the supply and demand for that specific player based on:
Number of players in the league with similar capabilities (you could use the clustering method mentioned before) and number of those players "available" for transfer
Number of teams that own the players with similar capabilities and number of teams that are in need for such players
Now with these number you could calculate the supply (available players for transfer) and demand (teams in need for those players) and use that to modify your base price (which can be your last transfer price or a base price for a player) up or down (ie more demand than supply will tend to push the prices up and vice versa)
After that it becomes negotiation game where you can take a look at some of the Game Theory literature to solve the actual exchange price.
Hope this at least give you a different look into it.

Resources