How To Set Constraints As Integer In Solver
Mar 26, 2012I want to set constraints as an integer in solver. But I don't know how to do it.
View 5 RepliesI want to set constraints as an integer in solver. But I don't know how to do it.
View 5 RepliesI have a cell, D5, which is the sum of three other cells, A5 B5 and C5. (all currently empty). Cells A1 through C4 are filled with various numbers.
What I've been trying to do is use solver to say: Make D5 equal 200, do it by manipulating only A5 B5 and C5, and make it subject to the constraint that A5 must equal a value selected from A1:A4, and B5 must equal a value from B1:B4, and C5 ...etc. I have deliberately set it up so that there is only one solution.
I was doing fine until trying to create the constraints. How can I make a constraint that says "this cell" must equal "one of the following cells"? And if I can't do that, is there an alternate method of achieving the same result?
I was able to find a solution using the excel solver add in but unfortunately it cant take more then 200 constraints and hence gives an error. I am unable to find a different approach to this problem.......
View 9 Replies View RelatedI have a maximization problem. I have to maximize Kitchen Sets given available materials. I have 11 different Kitchen Sets and every set requires different material.I have attached an excel spreadsheet for making the problem more clear.
I have T1;T2;T3;T4;M1;M2;M3;M4;O1;O2;O3;O4;Z1;Z2;Z3;Z4 different materials. Every kitchen sets requires one material from T which is fixed (for example T2), one material from M which is fixed again (for example M3), one material from O which is fixed (for example O1) and one material from Z, which is fixed (for example Z4).To complete a set the sum of all materials used should equal to 4. I have some constrains T1+T2+T3+T4<=2 it is the same for M1+M2+M3+M4<=2, O1+O2+O3+O4<=2 and Z1+Z2+Z3+Z4<=2.
So basically my goal is to say which materials should I keep in stock in order to maximize the Kitchen Sets.
I want to take a shot at this spreadsheet exercise. Setup similar spreadsheet models.
Excel Exercise.xlsx
I'm trying to use solver to find the minimum value of a cell by changing 5 separate cells. These cells are subject to a set of constraints that are formulae. On top of that I have a large number of these solve's to run (The spreadsheet is creating randomly distributed data to form a Monte Carlo simulation). Therefore I am referencing the formulas using the ActiveCell, Offset() function. For some reason when running this code none of the values are changed. Also I changed the UserFinish to false so I could see what solver was doing at each solve, It stops at the correct cell (one after the final cell) but without me having to confirm it each time.
Here is the ....
I have a large Solver scenario (100 vars, 150 constraints), which is working really well, but slowly. It's pretty straightforward, using only integers for calculations, but takes a LONG time to find an answer.
What I was really wondering is why Solver doesn't just use strictly integers in variable cells that are constrained as integers? I'm sure it's inherent to the way Solver runs, but I know it would make integer calculation WAY easier and faster.
I have to use use the solver to calculate something (a mean-variance framework).
I am using the solver to minimize a cartain cell (variance) by making two cells equal through (expected return) by varying 10 cells( weights of assets), but I have to repeat this for 500+ times (for different expected returns).
Someone told me that I could best use some sort of loop through VBA. But I don't have a clue how that works.
I am trying to maximize fantasy football points based on projected points scored, salary and positional limits.
I have multiple sheets dedicated one per position (i.e. sheet named "QB", sheet named "RB", etc.). The relevant columns are: Name; FPT (projected points); Cost
NOTE: I have combined all the data into "sheet1" if necessary.
I need a VBA program or Solver to diagnose the largest possible combination of projected points based on the following constraints:
Constraint 1: Total value must be less-than or equal to $1,000,000
Constraint 2: Total players used must be equal to 10
Constraint 3-?: Of the 10, 2 must be QB, 2 must be RB, 2 must be WR, 1 must be TE, 1 must be DEF.....the other 2 can be RB, WR or TE
Obviously, each player can only be used once and I'm not sure if Solver can abide by that constraint, nor do I know how to apply the others. I'm thinking VBA could work, but I'm not familiar enough with the language to hammer out the code.
I have a small macro that downloads some data from a website and tweaks it Daily fantasy cheatsheet.zipa little, but I hope that won't affect any computations involving those values.
I need to calculate time period worked between 19h00 and 24h00 in following exemples,
start time 08h00 and End time 20h00, would be 1 hour
start time 20h00 and End time 08h00, would be 4 hours
I can't get IF fonction to work with times..
i've two time constraints with 22:00~6:00 and 6:00~22:00. i'll apply time span to two constraints,calculate time covering on two constraints. it will start at anywhere of 00:00~24:00, time span will be 00:00 ~24:00. i add some formula, a3=start time, b3=end time. time constraints with 22:00~06:00:
=IF(AND(A3<=22/24,B3>=6/24,A3>B3),8/24,IF(AND(A3<6/24,OR(B3>22/24,AND(B3>0,B3<6/24,A3>B3))),IF(B3>=22/24,(B3-22/24)+A3-6/24,(B3+1-22/24)+MOD(6/24-A3,1)),IF(AND(OR(A3>=22/24,A3<B3,A3=0),B3<=6/24),IF(OR(A3=0,A3=1),B3,IF(A3>B3,B3+1-A3,B3-A3)),IF(AND(A3<=22/24,B3<=6/24),MOD(B3-22/24,1),IF(AND(A3>=6/24,B3<=22/24,A3<B3),0,IF(AND(A3>=22/24,B3>=6/24),(1-A3)+6/24,IF(AND(A3<=22/24,B3>22/24),B3-22/24,6/24-A3)))))))
time constraints with 06:00~22:00. :C$3=start time,$B4=end time...............................
I am trying to write VBA code that will list all possible combinations of data contained in a worksheet based on a few conditions. I have a list that varies in length. In the first column is a list of numbers denoting a particular course number. In the second column is a list of numbers denoting the specific class number for the course. As an example, I have a 6 courses. The first course has 1 class, the second course has 3 classes, the third has 11, the fourth has 3, the fifth has 7, and the sixth has 6. Thus, my columns look like this:
A B
1 1
2 1
2 2
2 3
3 1
3 2
3 3
3 4
3 5
...
I need to list out all possible combinations of classes given that I must have all six courses. EXAMPLE (Course, Class):.......................
Whenever or not I should use VBA or ordinary formulas in Excel in order to do Vehicle Routing With Two-Dimensional Loading Constraints case. What I need is when I have coordinates of four bottom-right corners:
X Y
24 0
30 0
10 24
8 38
2L-CVRP, what I want to know is: In reality I have set of 200 coordinates (x,y) and I need to search for lowest y (its (24,0) and (30,0)) then I choose one with maximum x ((30,0) in this case). Then if for some reason item cannot be packed there, then I shall go to next lowest y, which is 24 giving coordinate (10,24), if I cannot use this corner, I search for next lowest y with as high x as possible, etc. BTW I use Evolver in order to find satisfying solution.
I need to optimize an Excel model with 5 variables each of which cam be any value from 1 to 20. The solution space, therefore, contains 3,200,000 combinations. I have a software(Palisade Risk) which can give out a random sampling of this solution space. I need to know how many combinations can be considered as a representative sample of this solution space - e.g. can it be 1%?.
View 5 Replies View RelatedThis is the code where you click on a cell that has been input from Data Validation, it gets a pop up textbox showing the text input. One drawback I see here is that when the sheet is protected, one needs to tick 'Edit Objects' in 'Allow all users of this worksheet to:' window to get the textbox to pop-up otherwise no textbox is shown.
So this leads to the accessed user to have the ability of deleting and moving the textbox in the protected spreadsheet. Do you have any idea to Protect the sheet, Get the textbox to pop up,
Disallow user to delete/move the textbox.
I have data for 500 companies over 10 years, in three criterions: “EPS”, “DPS” & “PX” (i.e. earnings, dividends and price).
For each company I have four lines recording the data, and given a letter code indicating how the change in dividends and earnings have been according to the following
(Examples)
DD-ED = Dividends Decreased & Earnings Decreased
ND-EI = No Dividends & Earnings Increased
As can be seen below this code is present for each company
What I need help with is some sort of lookup function which takes the average of the price changes (which is given in numerical values) only for the companies which code is equal to the code in the reference field.
So something like: =AVERAGE(IF((MOD(ROW(D2:D2353)-ROW(D2)+1,5))=0,IF(D2:D2353"",D2:D2353))) (currently counting every 5th line, since there is 4 lines between respectively PX/DPS/EPS for each company) –But with a constraint indicating only to include the value in the calculation if the codes are the same (e.g. "DI-EI" = "DI-EI").
So that the value, which is currently 20.96% (which now includes ALL price values), would only include those for the respective group (in this case, companies in the DE-EI group).
I want to use solver program. But when solver "changes cells" i want it to trigger my pivot tables in the workbook. So i added the code to my worksheet:
Private Sub Worksheet_Change(ByVal Target As Range)
ThisWorkbook.RefreshAll
End Sub
So when a change occurs, all my pivot tables will get refreshed and my data will change. Is solver able to trigger this event while solving an optimization problem?
I need to create a spreadsheet that will calculate the difference between two dates and show the result in days. The complicated part is that weekends (Sat and Sun) need to be ignored and any time after 4:30 pm needs to be treated as the next business day. I have been trying to look at similar questions in forum and use the WORKDAYS function with little success.
Example:
A1- 14/08/09 4:40 p.m.
B1- 17/08/09 9:10 a.m.
I need the answer (B1-A1) to show up as 0. But if the time in A1 was changed to 4:20 p.m. than the answer should be 1 day.
I received a reply somewhere
Dim i As Integer
is better used as
Dim i As Long.
Integers get cast to long in the OS, and then back to Integers when passed nback, so it is a unnecessary overhead.
but didn't want to hi-jack that thread
QUESTION:
why would we still use "integer" then?
I tested with
Sub testInteger()
Dim starttime As Double
starttime = Timer
Dim i As Integer
For i = 1 To 32766
Dim j As Integer
For j = 1 To 32766
Next j
Next i
I have been working on a basic input sheet for progress reporting at work to standardize the information and acheive a half decent automated report.
I am have trouble validating the textbox to only allow an integer to be entered in the box. On result of text being entered on add, a msgbox should prompt the user to enter only text.
How might I do this?
Private Sub CommandButton6_Click()
Dim iRow As Long
Dim ws As Worksheet
how can i sum integer like
1548=1+5+4+8=1+7=8
I have a problem with vlookup. Here is an example:
A1= 1.3
Then my data array would be something like this
C D
1 a
2 b
3 c
4 d
My problem is that the reference for the look up is a non-integer, but the data in the lookup is. How can I make this work?
Below is a snapshot of data in a column. I need a way to extract the number, may be a whole, may be decimal, and leave behind the text description. Result to be put into a new column:
Hernia Umbilical 553.1
Perirectal Abscess 566
Diverticulitis 577.0
553.21 Hernia Vental/Incisional
Abdominal Pain RUQ789.01
Abdominal Pain RLQ789.03
217: Benign Breast mass
541-appendicitis
Chronic 575.11 Cholecystitis
SBO560.81
786.05SOB
226/ Thyroid neoplasm
The idea here is that the integer could be integrated in anyway imaginable with the associated text. I don't need the text. The end result must display this in a new column:
553.1
566
577.0
553.21
789.01
789.03
217
541
575.11
560.81
786.05
226
i need is a script that will add two boxes together to get a sum in a third box, but where it is tricky for me is that i need the third box to retain the summed value even when either of the first two box values are deleted.
For example, say i have box A1=10, B1=40, and C1= SUM of A1 & B1 (so C1=50). Easy enough, but where im lost is that i want to be able to delete the value of either A1 or B1 and then have C1 still = 50, so then i can input another value into either A1 or B1 to continue to add to C1.
I'm creating a user form where the user can enter latitude and longitude in either Deg/Min/Sec format or Decimal Degrees. To go from decimal degrees into Deg/Min/Sec I need to do the following
A=Decimal Degrees (Single)
X=Degrees (Integer)
Y=Minutes (Integer)
Z=Seconds (Single)
X = Integer(A) <-- I need to cast A as an integer or truncate it. Not sure how to do this in VBA. Y = Integer[( A - X ) * 60] <-- Again, needs to be cast as an integer Z = {[( A - X ) * 60] - Y} * 60. I didn't see a native truncate function in Excel and in the past I've always used Left() or Right()
I am using the IsDate() and IsNumeric functions in my VBA code. Is there an equivalent function for testing if a value is an integer?
View 5 Replies View RelatedI'm trying to format a number inside of a chain of a string. So,
Worksheets("TASK").Cells(task_sht_current_row, task_sht_act_id_column) = Cells(current_act_row, work_package_column) & "-" & Cells(current_act_row, cti_wp_column) & "-" & current_act_step_num
So I'm trying to format the last variable so that it is always four digits, ie, 0001, 0034, 0204, 1234, etc...
Any clue how to do this, I've searched around and can't seem to find the code for it. I could do it with a long set of conditional statements, but I'm pretty sure there is a format function or something.
While reading the book "VBA and Macros for Excel", I can not understand the following
Dim concat As Variant
concat = 0#
What does the # indicates?
I am trying to drive Solver in Excel 2000 with a Visual Basic (version given as 9969) macro. SolverReset is observed, and SolverAdd puts the constraints in. But the SolverOK statement does nothing, so the SetCell and the ByChange windows stay empty.
SolverSolve is trying to do something, because the spreadsheet cell that should receive the return code from Solver gets an error value #VALUE! (The macro then stops, unable to process this entry.)
Solver is checked off ok in the References list in V.Basic.
The same macro, same spreadsheet, in the same Excel file, works fine on the other computer in my office with what I am told is a more recent version of Excel; i.e. this doesn't look like a coding error.
In the following code snippet I have worked out a way to verify that the user inputs an Integer and then prompts downstream if an improper value was entered. The user is prompted for a corrected reponse and loops until they get it right. The initial Cancel at the first prompt was causing issues until i saw poster: titarelli use StrPtr(). Except for subsequent cancels, the code works but it is clunky at best. How to tighten this up?
VB:
Dim Quantity As Variant
Dim CorrectedQuantity As Variant
Dim j As Integer
j = 194
Quantity = 0
CorrectedQuantity = 0
[Code] ......