Excel Solver LP with Count constraint - excel

I am doing a linear program with Excel Solver to minimize costs across different suppliers, and I was wondering if I could add a constraint that limits the total number of suppliers used? When I try the Count function, it counts everything unless the cell is blank, but solver puts in a zero if the supplier gets no volume. And Countif makes it nonlinear. Is there an alternative way to accomplish this?
objective - min P1V1 + P2V2 + P3V3 ...
s.t count (V1, V2, V3 etc) <= 3
where Pn= price of supplier n
Vn = volume of supplier n
In this case, multiple suppliers provide volume for a single item, and I am trying to limit the total suppliers to 3.
Edit: Also, the volume is going to several different plant locations. Is there also a way to limit the number of suppliers per plant?

Related

Generating data for a graph

Explanation: https://www.youtube.com/watch?v=j3Cau-qmSwk
Note: Yes I know it's possible with VBS. But I'm convinced it can be done using some more or less standard Excel features. I simply want to learn more of those features by solving this problem and this is what that bounty is about.
Example: https://drive.google.com/file/d/1s4IvVe-jiHmvlij8Zv0HWLYFzsCV_4nz/view?usp=sharing
Short explanation:
On the second Sheet ( Named Graph ) is what I want to achieve.
Prices for hosts A, B and C are generated by changing number of files on the first Sheet ( Named Prices )
Longer:
I have a graph that compares prices from a few different hosting providers.
Each one calculates it's price based on a few different factors.
For example one charges for views other charges for GB storage other for Transfer. I've brought them to a common denominator "a file number" so when I change a value in a "file" cell all of the prices change accordingly for each hosting provider.
I would like to present that on a graph.
That would give me a better understanding how each one of those hosting providers would scare overtime.
Do I have to input into the file cell 50,100,200,400 copying those prices each time onto the other sheet of is there a better, easier or maybe even more dynamic way to approach this?
Thanks
One solution is to use the following formula:
=(Prices!B$2*$A2*Prices!$B$8)+(Prices!B$3*Prices!$B$7*Prices!$B$8)+(Prices!B$4*Prices!$B$7*$A2)
In your "Graph" sheet, cell B2, where you have the table laying out the values, simply drag it down and across to fill out the other prices and hosts. Changing the file size in column A will update the formulae and thus the value and the graph.
From what I understand the price is calculated as follows
price =
(price per view) * (num of views) +
(price per transfer) * (num of views) * (file size) +
(price per storage) * (num of files) * (file size)
So, just add the appropriate relations in excel for the above price model based on the values you want to track.

Different aggregation functions for different dimensions in Excel pivot table

Can I define different aggregation methods for subtotals in different dimension in an Excel pivot table?
The following example shows a result I'm trying to obtain. The metric to aggregate is, let's say, lines of code of a software project. The 2 dimensions in question are Date and Organization. In source data, Organization is broken down into 2 columns, Department and Project, while Date is a single column and Excel makes up the Months/Years summaries automatically when making the ODBC data connection.
A metric such as this one should be aggregated differently along the different dimensions. For the Organization dimension, the subtotal for all projects of the department is the SUM, but in the date dimension, the subtotal for all months of the year is the MAX of any given month (or perhaps AVG, or last etc. but certainly not SUM).
I've tried to define the different aggregation methods in Excel in the field settings, but it always selects one or the other method for both dimensions. Is there a way to do it, preferably using standard Pivot Table mechanisms or at worst a UDF in Excel?
What I would do to tackle this problem is to add both aggregation functions: sum and max , then hide ( or shrink a lot ) those columns you do not want to display.
in the above example I shrink columns B,D,F and I because of they has values that are out of scope for your requirements.
The "Total Max of Loc" displays a value consistent with the function expressed throughout the entire column: that is "the maximum number of lines of code reached by each project in each department; this could lead to misunderstandings when we observe the values of the subtotals and grand total; i.e: The "Grand Total - Total Max of Loc" is not the "Total Max of Sum of Loc": in the example, it shows 18 which represents the absolute maximum value of Loc in a Project in each Department; In the same way the Total Max of Loc for Department 2 is 18 and form Department 1 is 12
When requested a different behavior as expressed in comment to this answer, I think we are entering into the strong customizations space and some solution could be found by writing custom macro and by leveraging the getpivotdata function or, if it can be acceptable for your case, simply by the addition of a new column with the max()formula and possibly hiding the column "Total Max of Loc"

How do I distribute a value over multiple cells evenly but under a maximum limit?

Example data with desired outcome that I need to calculate
I have 12 items of a certain current value. I have a 'soft' cap of $1,000,000 for these values. Some of the items fall above, and some below this cap level.
I have an amount of money (for this example $900,000) that I want to distribute amongst only the items that fall below the cap (in this example 6 items), with the aim of bringing the value of these items up to but not over the cap value.
If I distribute the $900,000 evenly over these 6 items (each receiving $150,000), you can see that items 2 and 9 would then be over the $1,000,000 cap. So items 2 and 9 should only receive $100,000 to raise their value to the cap, then the remaining 4 items would receive and equal share on the remaining pool of money ($700,000 / 4 = $175,000).
So I need a formula to check every item to see if it needs a distribution (i.e below the cap) and then portion/divide out the money pool as illustrated above in the desired distribution column.
Note: The pool of money to be distributed can change. Also the number of items below the cap can change. The cap value itself can change.
I am hoping to avoid VBA or Solver because the spreadsheet could be used on other people's computers.
Hopefully this makes sense. Thanks.
EDIT:
So far I have been able to get close by adding a helper column and using the following formula:
=IF(SUM($F$6:F14)=$D$23,0,E15*MIN(D15,($D$23-SUM($F$6:F14))/SUM(E15:$E$18)))
Working example when values are sorted.
This seems to work when the values are sorted in descending order, as shown in the example image above. But seems to break when the values are a bit more randomly assorted which is likely to happen (as in the original post).
Just to give you an idea of how the solver can be set up to do a capital budget model here is one, also shows the solver and its settings:

Excel group cells in a table based on their combined total value

i would like a list of client names where together they have a combined amount of 1000. so, say if jim and tod's combined amount of money <= 1000 and jim, tod, jill >= 1000 then list jim and tod in a cell, then in the next cell if jill, joy, and pat <=1000 and jill, joy, pat, and tam >= 1000 then list jill, joy, and pat and so fourth until all of the clients are in a list.
Is this possible? I am learning and am not sure where to start so i would greatly appreciate if someone can help point me in the right direction to solve this problem?
Assuming your criterion for a group is that the money sums to less than or equal to 1000, then this is straightforward. Simply accumulate the Money amount down the list of names and start a new group and (reset the accumulator) whenever the cumulative amount exceeds 1000.
This gives you the group number for each name (see column D in picture below). A separate problem is then to list the names for each group number. In the picture, I have allowed for a maximum of 5 names per group but if real data indicates this is insufficient then allowing more is straightforward.
The set of groups obtained using this approach is dependent on the ordering of the rows of input data - change this ordering and the result is a different set of groups.
Perhaps a more interesting and challenging problem is to define a set of groups which meet not only the <=1000 criterion but also other criteria such as: minimise number of groups overall and equalise, as far as possible, the total money allocated to each group. But that is a very different problem!

Creating randomized lab partner matrix in Excel

I'd like to use Excel to generate a randomized lab partner list, without using VB (due to security settings on the PCs).
Parameters are as follows:
Number of students: 10-30, one worksheet per total number desired
Number of partners: Three for first two labs, and two for the other four-five.
Number of lab stations: 10
Repeats: Ideally none, but it is permissible for a student to have a repeat partner from one of the first two labs.
Excel version: 2007
To clarify, each student will have two labs where they share a lab station with up to two other students, giving a maximum lab size of 30 students. After that, they will be strictly limited to two students per station, giving a maximum of 20 students. Each student will have four of these limited labs, with there being a total of five such labs presented, to allow for either odd-numbered classes, or a class size between 21-30.
Each student is simply numbered from 1-30, so a cell could, for instance, state "5, 24" as the two students for that lab station.
True RNG is not important, and in fact, only needs to be performed once to make these matrices.
I think this is a bit tricky without using VBA, but here is one approach that is OK for small groups. I have tried it using a group of just nine so that the screen shot should be readable.
The method is basic Fisher-Yates
A Start with a group of students size n represented by a list of numbers 1 to n.
B Generate a random number r in range 1 to n
C Pick the rth element from the list
D Remove the rth element from the list
E Reduce n by 1
F Repeat from B until n=1.
In Excel:-
Fill A2:A10 and D2:L2 with numbers 1-9
Put the following in B2 and pull down:-
=RANDBETWEEN(1,10-A2)
Put this in C2 and pull down:-
=OFFSET(D2,0,B2-1)
Put this in D3 and pull down and across:-
=IF(D2>=$C2,E2,D2)
The ID's will be in column C so the first three would be in group 1, the next three in group 2 etc.
By the way, your question is a special case of generating non-repeating random numbers - see
Generating unique random numbers without VBA
The array formula described here does it in one step - modified slightly for this problem it would look like
=SMALL(IF(COUNTIF(C$1:C1,ROW(INDIRECT("1:9")))=0,ROW(INDIRECT("1:9"))),RANDBETWEEN(1,(9-ROWS(C$2:C2)+1)))

Resources