I have a table in Microsoft Excel that I'd like to use to calculate the best combination of coaches to house the supplied number of passengers. Here is a simplified version of the table:
I need to enter three formulas in the coach count column that calculates the best value-for-money combination of coaches that can carry all the passengers. For example, if there was 40 passengers, the result should be one 49-seat coach as opposed two 20-seat coaches as it's the cheapest combination.
I have no idea how I would work on implementing these formulas and would appreciate some pointers.
So far, all I have in C4 is
=IF(MOD(B1, A4) = 0, B1 / A4, 0) which only works with multiples of 20 and does not account for combinations of coaches or cost efficiency.
Perhaps this is too complex of a task to implement in formulae? Would I be better off using a VB macro, or simply leaving it to the user to calculate the best combination?
There are two ways to address this problem. I will outline both solutions:
Option 1: In Worksheet Formulas
I'd have to spend more time on this in order to find a really elegant solution for this route, but here's a functional approach that should work well enough. Here are some quick highlights:
Firstly, you need to add a column to your table that outlines the minimum number of seats a coach carries. This helps to facilitate the vlookup.
Secondly, make sure that your lookup table is sorted in ascending order according to the minimum # of seats.
I have made the assumption that the most effective pricing model is to get the majority of people onto the largest coach (or many of the largest coach), and then to use the smallest coach that would accommodate the remaining people. If this is not a fair assumption, then this solution may not be appropriate.
Here are screenshots of the final outcome:
And the formulas required to make it: (and a link in case you need to blow it up: http://i.stack.imgur.com/hKjQK.jpg)
Note: You'll notice that the previous answer is incorrect, as it suggested that 74 people would need to spend $180 instead of $140.
Option 2: Using Excel's Solver Add-In
Enable the solver add-in (File --> Options --> Add-ins --> Excel Add-ins (Manage) --> Solver Add-In)
Configure worksheet as shown:
UI:
The formulas:
On the Ribbon, go to the Data Tab, Analysis Group, & Click Solver.
Configure Solver as follows:
Click "Solve" and then click "Ok"
Final Outcome:
This seems to be a classic linear programming problem. You need to minimize total cost = (number of coach 1 times 50) + (number of coach 2 times 60) + (number of coach 3 times 80), subject to the constraint that (number of coach 1 times 20) + (number of coach 2 times 29) + (number of coach 3 times 49) is greater than or equal to (number of attendees), and all numbers of coaches are greater than or equal to zero. I think Excel's Solver is the tool for such a problem. You don't need to implement any of the solution yourself, you just set it up and Solver handles the algorithmic stuff.
Try this:
Sample calculation
With Formulas showing
The idea is to check for the largest coach first, using the integer value of division Count/Seats. The do the same for the 2nd largest coach with the remaining people. Etc etc.
Related
(I use the term "teams" generically here because the entirety of this question rests on ranking, and it seemed to be the most intuitive language to describe my problem.)
In a league of 30 teams, each day only 8 teams play. The results for those teams are ranked ordinally from 1 to 8 for the day. This continues "forever", so that additional results must be recorded every day.
Example after 4 days:
I want to calculate a single number to describe the relationship between two teams. For instance, given the example, the value (in a 2d table) that describes the relationship of Ace to Get is 1. Ace beat Get twice and Get beat Ace once (2-1).
I have been messing with Sumproduct, Match, and Index to get get values, which I could calculate using many extra tables, but I may need to add "teams" on the fly, and I do not know how large the pool of teams will become. Because of this, I was hoping to be able to use a single formula in the 2d relationship table. The results of that table, looking at just day 1 and day 2 given the previous example, are:
Is there a direct formula I can use to calculate the results to populate that table?
You can try following formula:
=IF($A11<>B$10;
SUMPRODUCT(
IF(MMULT(($B$1:$I$1)*($B$2:$I$3=$A11);ROW($1:$8)^0)
<MMULT(($B$1:$I$1)*($B$2:$I$3=B$10);ROW($1:$8)^0);
1;
-1)
*(((MMULT(--($B$2:$I$3<>$A11);ROW($1:$8)^0)=8)
+(MMULT(--($B$2:$I$3<>B$10);ROW($1:$8)^0)=8))
=0));
"")
Copy right and down.
I've been trying to create this spreadsheet for days, but I'm just not sure on how to approach the final part of it, so I'm hoping someone on here will be able to help me.
To give you some context I'm trying optimize how many pallets of certain products we can fit onto a truck. Some pallets weigh more than others and some are much more common than others. We always put 24 pallets on, but if we were to combine with other less common products that weight less we could fit on 25 (or possibly even 26).
I need to create a spreadsheet where the user enters an amount of a certain item (product A which is the most common) and it gives all the possible combinations of the other products that could go with it that keeps it under a certain weight.
So for example. The user says they need to send out 17 of product A. It would then give you all the combinations that could fit with those 17 that keeps it below weight and at 25 (or 26) in total.
If it helps here at the actual weights below:
Product A = 1.138
Product B = 1.009776
Product C = 1.089
Product D = 1.092
Product E = 0.86556
Maximum weight is 28.
Is anyone help to help me achieve this?
I've found this document but this excel sheet doesn't aim to add up to 25 (or 26) which I want. I also don't need it to add up to 28, just be less than 28.
I've faced the same problem in a similar situation, I needed to optimize the way the logistics load the trucks. I haven't applied any of this yet, but I found this Spreadsheet for the knapsak problem. Between all values you pass to the sheet, the VBA get as many as possible values that fits the limit you also pass.
This spreadsheet is limited to 5 weights, but you might be capable to make it receive N weights.
Edited:
after using Solver which Saulo Suggested I have managed to get excel sorting them in to groups up to 8 groups of 3. though am approaching troubles when going further ideally at this time I need to be able to do 18 groups of 3. but even with the same settings obviously adjusting for the increase in groups excel seems to belly up on the process and fails, any suggestions to adapt to this?
I am trying to figure out an easy and as accurate as possible without going too crazy with the math and formulas as I am basic with my excel coding (coding in general) to calculate the ideal groups of 3 based on rank and strength for a video game.
I want to pair the strongest with the weakest and then fill the gaps evenly for the 3rd person. so, that each team’s overall strength is the same roughly.
factors I have is a designated leader(rank) and an overall power level(strength).
doing this manually isn't too hard but trying to automate it is. any thoughts or suggestions would be amazing!?
something like this but automated which is where I am getting stuck, as I want to be able to add more players and adjust strengths as they come along.
Hope this makes sense.
Jordan, you have a classic situation to use "Solver". First of all, you have to make "Solver available in your Excel. Select Home -> Option -> Supplements -> Solver. Then, the solver button´s will be at the "Data" menu.
Solver is about solving a problem with especific conditions, changing specific cell, with specifc purpose. In your case, your purpose is creat teams with the minimal strength diference. A condition of your problem is that teams should have the same number of players. See how I organized the sheet.
Sheet
When do you open solver, the first field is "Seat Goal". Our goal (or purpose) is reduce the diference between teams as minimal as possible. So we selected the cell with the diference between teams. Then we have to tell to excel that our purpose is that cell have the minimal value (chossing "min").
Then we have to tell excel wich cells they can change values to achieve our goal. In this case, Excel can change the teams of player, so we select the cells with the teams.
Last we have to tell excel whats condition (or restrictions) of this problem. The first restction is that the total of player of team 1 is tree. The total of players of team 2 is, both, 3. Then we have to tell to excel what are the limits (superior and inferior) of values of variable cells. In this case, we chose superior or equal to 1, AND (other restrction) inferior or equal to 2.
Ok. Now we have a problem with specif goal, changing the value of specifc cells, with specif restriction. Now solver can work. Then choose the method of soluction "Evolutionary", Honestly, I do know the diference between the methods, but my experience is that evolutionary method works better than the others.
I recomend reading the excel tutorial on solver. At first, all of us think that is too dificult, but believe that is simpler than it seems.
I have a list of 153 golfers with associated salaries and average scores.
I want to find the combination of 6 golfers that optimizes avg score and keeps salary under $50,000.
I've tried using Solver, but I am stuck! Can anyone help please? :)
Illustrating a solution that is pretty close to what #ErwinKalvelagen suggested.
Column A is the names of the 153 golfers
Column B is the golfers salaries (generated by =RANDBETWEEN(50, 125)*100, filled down, then Copy/Paste Values)
Column C is the golfers average scores (generated by =RANDBETWEEN(70, 85), filled down, then Copy/Paste Values)
Column D is a 0 or 1 to indicate if the golfer is included.
Cell F2 is the total salary, given by =SUMPRODUCT(B2:B154,D2:D154)
Cell G2 is the number of golfers, given by =SUM(D2:D154)
Cell H2 is the average score of the team, given by =SUMPRODUCT(C2:C154,D2:D154)/G2
The page looks like this, before setting up Solver ...
The Solver setup looks like this ...
According to the help, it says to use Evolutionary engine for non-smooth problems. In Options, I needed to increase the Maximum Time without improvement from 30 to 300 (60 may have been good enough).
It took a couple of minutes for it to complete. It reached the solution of 70 fairly quickly, but spent more time looking for a better answer.
And here are the six golfers it came up with.
Of the golfers with an average of 70, it could have found a lower salary.
In Cell I2 added the formula =F2+F2*(H2-70) which is essentially salary penalized by increases in average score above 70 ...
... and use the same Solver setup, except to minimize Cell I2 instead of H2 ...
and these are the golfers it chose ...
Again - it looks like there is still a better solution. It could have picked Name97 instead of Name96.
This is a simple optimization problem that can be solved using Excel solver (just use "Simplex Lp solver" -- somewhat of a misnomer as we will use it here to solve an integer programming or MIP problem).
You need one column with 153 binary (BIN) variables (Excels limit is I believe 200). Make sure you add a constraint to set the values to Binary. Lets call this column INCLUDE; Solver will fill it with 0 or 1 values. Sum these values, and add a constraint with SUMINCLUDE=6. Then add a column with INCLUDE * SCORE. Sum this column and this is your objective (optimizing the average is the same as optimizing the sum). Then add a column with INCLUDE*SALARY and sum these. Add a constraint with SUMSALARY <= 50k. Press solve and done.
I don't agree with claims that Excel will crash on this or that this does not fit within the limits of Excels solver. (I really tried this out).
I prefer the simplex method above the evolutionary solver as the simplex solver is more suitable for this problem: it is faster (simplex takes < 1 seconds) and provides optimal solutions (evolutionary solver gives often suboptimal solutions).
If you want to solve this problem with Matlab a function to look at is intlinprog (Optimization Toolbox).
To be complete: this is the mathematical model we are solving here:
Results with random data:
....
I have a requirement in Excel to spread small; i.e. pennies, monetry rounding errors fairly across the members of my club.
The error arises when I deduct money from members; e.g. £30 divided between 21 members is £1.428571... requiring £1.43 to be deducted from each member, totalling £30.03, in order to hit the £30 target.
The approach that I want to take, continuing the above example, is to deduct £1.42 from each member, totalling £29.82, and then deduct the remaining £0.18 using an error spreading technique to randomly take an extra penny from 18 of the 21 members.
This immediately made me think of Reservoir Sampling, and I used the information here: Random selection,
to construct the test Excel spreadsheet here: https://www.dropbox.com/s/snbkldt6e8qkcco/ErrorSpreading.xls, on Dropbox, for you guys to play with...
The problem I have is that each row of this spreadsheet calculates the error distribution indepentently of every other row, and this causes some members to contribute more than their fair share of extra pennies.
What I am looking for is a modification to the Resevoir Sampling technique, or another balanced / 2 dimensional error spreading methodology that I'm not aware of, that will minimise the overall error between members across many 'error spreading' rows.
I think this is one of those challenging problems that has a huge number of other uses, so I'm hoping you geniuses have some good ideas!
Thanks for any insight you can share :)
Will
I found a solution. Not very elegant, through.
You have to use two matrix. In the first you get completely random number, chosen with =RANDOM() and in the second you choose the n greater value
Say that in F30 you have the first
=RANDOM()
cell.
(I have experimented with your sheet.)
Just copy a column of n (in your sheet 8) in column A)
In cell F52 you put:
=IF(RANK(F30,$F30:$Z30)<=$A52, 1, 0)
Until now, if you drag left and down the formulas, you have the same situation that is in your sheet (only less elegant und efficient).
But starting from the second row of random number you could compensate for the penny esbursed.
In cell F31 you put:
=RANDOM()-SUM(F$52:F52)*0.5
(pay attention to the $, each random number should have a correction basated on penny already spent.)
If the $ are ok you should be OK dragging formulas left and down. You could also parametrize the 0.5 and experiment with other values. With 0,5 I have a error factor (the equivalent of your cell AB24) between 1 and 2