+ Reply to Thread
Results 1 to 11 of 11

SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

  1. #1
    Registered User
    Join Date
    06-18-2019
    Location
    Brasil
    MS-Off Ver
    2016
    Posts
    5

    Question SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    Hi, I need some help to solve a problem with a lot of restrictions.

    In this problem, I have 207 projects and each one release one part of my year objective.

    All projects that are Status = 1, are already done. And Status 0, need to be done.

    Each project has a different percentage when it is done. It's important to know that some projects are only punctuating when other 2 projects are also finished. For example, the project "j" only punctuating if project "h" and "i" are already finished.

    I need to find the project that I can do in a week to see whose give me the best Result "I1"
    but I have a limitation, that is described in cell "I2". For this example, I need to search what the best 5 projects that I need to focus to give me the best possible result.

    Projects that are already done (1) can't change for undone (0).

    Firstly I thought to solve this problem with the solver from excel, but there are so many variables that need to be restricted. Beyond that e need to set the variables that can't be changed and the maximum variables that can be changed.

    So, could someone help me with this interesting problem?

    I can't attach the file in the website, then I sent the link in google drive:
    drive.google.com/file/d/1Sz3yL-wPUWC9z7O2I3GKeHPrtGejk_1f/view?usp=sharing

  2. #2
    Valued Forum Contributor Hydraulics's Avatar
    Join Date
    07-15-2018
    Location
    Udine - Italy
    MS-Off Ver
    Office 365
    Posts
    370

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    Quote Originally Posted by dontafy View Post
    All projects that are Status = 1, are already done. And Status 0, need to be done.
    [...]
    Projects that are already done (1) can't change for undone (0).
    Do you mean that only projects with a 0 are variables for your problem? This is important because it will reduce them to 122.

    Quote Originally Posted by dontafy View Post
    Each project has a different percentage when it is done. It's important to know that some projects are only punctuating when other 2 projects are also finished. For example, the project "j" only punctuating if project "h" and "i" are already finished.

    I need to find the project that I can do in a week to see whose give me the best Result "I1"
    but I have a limitation, that is described in cell "I2". For this example, I need to search what the best 5 projects that I need to focus to give me the best possible result.
    First, if projects with 1 are already finished and can't be set to 0, we can look for the best result among the remaining ones. Is this correct?

    Second, I don't understand how to deal with multiple projects.
    Two sets of them will give you 3*2=6 single projects, but you are looking for the best 5, so your solution should at most have 2 singles and a set. Can you clarify this point?
    Aim high or don't even try.
    ---------------------------------
    If your question has been answered, don't forget to mark the thread as SOLVED.
    If you find an answer helpful, click on the star icon at the bottom of the post.

  3. #3
    Registered User
    Join Date
    06-18-2019
    Location
    Brasil
    MS-Off Ver
    2016
    Posts
    5

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    Quote Originally Posted by Hydraulics View Post
    Do you mean that only projects with a 0 are variables for your problem? This is important because it will reduce them to 122.
    Yes, only projects with a zero.



    Quote Originally Posted by Hydraulics View Post
    First, if projects with 1 are already finished and can't be set to 0, we can look for the best result among the remaining ones. Is this correct?
    That's correct, we need to change only the projects with 0. The project with 1 can't be changed.

    Quote Originally Posted by Hydraulics View Post
    Second, I don't understand how to deal with multiple projects.
    Two sets of them will give you 3*2=6 single projects, but you are looking for the best 5, so your solution should at most have 2 singles and a set. Can you clarify this point?
    That is simple. What I sad is one of the possibilities, and you are correct. Probably a set and 2 singles are de best possibilities. But is also possible that 5 singles give-me a higher percentage than a set and two single. Or perhaps, one project form a set is already done. For this case, we need to test all the possibilities.

    That I thought was to use "solver evolutionary", where the restriction is to the projects being binary and the differences between the initial and final set is equal to 5.
    My problem is how to select only the zero variables automatically.

    perhaps I need to do a VBA code that gives me all cells that have zero, where I can concatenate this and put into the solver.

    Solver.jpg

  4. #4
    Valued Forum Contributor Hydraulics's Avatar
    Join Date
    07-15-2018
    Location
    Udine - Italy
    MS-Off Ver
    Office 365
    Posts
    370

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    I hope someone else can help you with the automation through VBA (maybe Alf if he sees this thread), I think it is an interesting but time consuming project.

    However, I have found a solution for your problem.

    - For each single project there will be a binary variable.
    - In a set of projects, if only one is still unfinished than we add a simple binary variable.
    - If only one is finished, we have two variables and a constraint imposing A1=A2 (A1 being the status of project 1).
    - With 3 unfinished projects there are two constraints, A1=A2 and A1=A3.
    - The sum of variables is set equal to a given number (5), the sum of percentages is the objective function to maximize.

    In the objective function we must take care of projects within a set that are already finished. I have translated the logic condition in a set of two constraints and a binary variable.
    If A1, A2 A3 are the projects, and A1 is finished, we want to set a variable B that will be 1 if and only if both A2 and A3 are equal to 1 (this binary variable will then multiply the percentage to be added to the total).

    A2+A3-2*B<=0
    2*B-A2-A3<=0

    These equations are changed when only 1 project is still unfinished: A3-B<=0 and B-A3<=0.

    With this setup the solution (using Simplex LP and 0% as integer optimality in the options) with 5 projects will include a set and 4 singles for a total of 16.896%.
    The selected projects are highlighted with a conditional formatting.

    I have tested the model changing some percentage and number of projects and it seems to be able to choose the best ones.

    Since there is a limit in the number of characters that Solver can accept in the variable cell reference, I have reordered your data to keep variables as close to each other as possible. You may wish to find an alternate way for ordering your worksheet.

    HTH
    Attached Files Attached Files

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    Well I had a go at it and the result was some good and some bad.

    First of all I used "OpenSolver" to optimize the result as the excel solver did not manage to handle the number of cells.

    There are two macros in in the uploaded file I would suggest you start by running the macro "ColorMarkere"

    This macro traces all the dependencies of a cell in the D column if if that cell needs a 1 in the 3 cells in the B column. These dependent cells colored yellow.
    If B cell value is 1 the in the last dependent cell B value and the corresponding D cell value start with the formula "=(If(SUM ..." than that D cell is colored red. See cell D30.

    The OpenSolver will add a binary value in range E2:E208 but there is a constraint stating that the value in the F column should be equal to or less than 1 and since
    the F value is equal to the value of the B cell and the corresponding E cell value this stops OpenSolver from setting a binary value in the matching E cell if the value of the B cell is already set to 1.

    Scrolling down the values in the E columns checking the results the first problem is the OpenSolver has put a 1 in E11 but as D11 is dependent on h and i this is
    not a good idea. Lets remember that.

    Cell D30 is marked red but the values in the two dependent cells are small and OpenSolver has rightly ignored them.

    Cell E32 is marked as a cell to select and that looks ok.

    Cell D47 is marked red but the values in the two dependent cells are small and OpenSolver has rightly ignored them.

    Cell E76 is marked as a cell to select and that looks ok.

    Cell D98 is marked red but not selected by OpenSolver because B98 = 1, but if cell B97 is set to 1 then the dependency is fulfilled and full points for D98 is achieved.

    Cell D124 is marked red but the values in the two dependent cells are small even if one is missing on value in B123 to get the result.

    Cell E178 is marked as a cell to select and that looks ok.

    So this is the bad part you have to scroll down the results and make a manual adjustment.

    There is also a macro named "RunOpenSolver" this macro will run OpenSolver after you have

    1) downloaded this freebie from the University of Auckland NZ and installed it on you PC.

    https://opensolver.org/

    2) You also need to set a reference to both the excel solver and OpenSolver "Visual Basic" icon -> Tools -> References and tick box "solver" and "OpenSolver"

    Alf
    Attached Files Attached Files
    Last edited by Alf; 08-17-2019 at 11:35 AM.

  6. #6
    Registered User
    Join Date
    06-18-2019
    Location
    Brasil
    MS-Off Ver
    2016
    Posts
    5

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    Quote Originally Posted by Alf View Post
    Well I had a go at it and the result was some good and some bad.

    First of all I used "OpenSolver" to optimize the result as the excel solver did not manage to handle the number of cells.

    There are two macros in in the uploaded file I would suggest you start by running the macro "ColorMarkere"

    This macro traces all the dependencies of a cell in the D column if if that cell needs a 1 in the 3 cells in the B column. These dependent cells colored yellow.
    If B cell value is 1 the in the last dependent cell B value and the corresponding D cell value start with the formula "=(If(SUM ..." than that D cell is colored red. See cell D30.

    The OpenSolver will add a binary value in range E2:E208 but there is a constraint stating that the value in the F column should be equal to or less than 1 and since
    the F value is equal to the value of the B cell and the corresponding E cell value this stops OpenSolver from setting a binary value in the matching E cell if the value of the B cell is already set to 1.

    Scrolling down the values in the E columns checking the results the first problem is the OpenSolver has put a 1 in E11 but as D11 is dependent on h and i this is
    not a good idea. Lets remember that.

    Cell D30 is marked red but the values in the two dependent cells are small and OpenSolver has rightly ignored them.

    Cell E32 is marked as a cell to select and that looks ok.

    Cell D47 is marked red but the values in the two dependent cells are small and OpenSolver has rightly ignored them.

    Cell E76 is marked as a cell to select and that looks ok.

    Cell D98 is marked red but not selected by OpenSolver because B98 = 1, but if cell B97 is set to 1 then the dependency is fulfilled and full points for D98 is achieved.

    Cell D124 is marked red but the values in the two dependent cells are small even if one is missing on value in B123 to get the result.

    Cell E178 is marked as a cell to select and that looks ok.

    So this is the bad part you have to scroll down the results and make a manual adjustment.

    There is also a macro named "RunOpenSolver" this macro will run OpenSolver after you have

    1) downloaded this freebie from the University of Auckland NZ and installed it on you PC.



    2) You also need to set a reference to both the excel solver and OpenSolver "Visual Basic" icon -> Tools -> References and tick box "solver" and "OpenSolver"

    Alf
    It works perfectly, thanks for your help

  7. #7
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    You are welcome and thanks for feedback

    Still I'm not too happy with this setup as I find it takes to much manual input and also using solver is an overkill as there are no difficult calculations involved.

    At the moment I'm therefore working with another setup.

    1) Read in all the values in range C2:C208 if the corresponding B values are 0 into an array + if the B value is 1 but the corresponding D value is 0 (see row 97) this C value should also be read into the array.

    2) Having made the array the macro now reads the values from the array using the "Large" function as this will present the values from the biggest to the smallest.

    3) As soon as macro gets a value from the array it will go to the cell that contains this value and wait for and input and after input / "OK" macro will take the next value from the array running in a loop set for 5 loops or a higher number.

    4) With the input of number in the cell macro could also write the top 5 names in the L column.

    If you think this is a worthwhile idea I would suggest you start a new thread uploading you file with the "ColorMarker" and ask for help using array and "Large" technique or a better way to solve this problem.

    Myself I'll keep on working along those lines I've described above but as my macro skill is not in the top 10 level your best chance to get help is to start a new thread as this gets more attention than an "old" thread.

    So for my oven amusement I'll keep on working with this problem and see if I can solve this but for a quick and fast answer (hopefully) I recommend start a new thread.

    Alf

  8. #8
    Valued Forum Contributor Hydraulics's Avatar
    Join Date
    07-15-2018
    Location
    Udine - Italy
    MS-Off Ver
    Office 365
    Posts
    370

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    Alf is absolutely right, the problem can be solved entirely with formulas.

    I have changed as little as possible the original layout:

    - there is a manual color formatting for the sets of projects; of these rows we use only the last one with three formulas in column D, E, F

    =SUM(C9:C11)
    =COUNTIF(B9:B11,0)
    =SE(E11<>0;D11/E11;0)


    that give us the total percentage, the number of unfinished projects in the set and the average percentage.

    - for regular projects there are again three formulas

    =IF(B2=0,C2,0)
    =IF(B2=0,1,0)
    =IF(E2<>0,D2/E2,0)


    giving us the % (taking into account the status), the weight (always zero or 1) and again the percentage.

    Using this setup, the best projects are ordered with

    =LARGE(($F$2:$F$208*($E$2:$E$208<=$J$2-H6+1)),H6)

    When we consider a set with more than 1 unfinished projects, a conditional formatting will check for the current total of projects already found and gray out rows that are outside the given number in J2.

    The name of the project in the table is correct for single projects, but for sets it will refer to the last element (for instance, cs with the original data).

    HTH
    Attached Files Attached Files

  9. #9
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    Well done Francesco !!

    And just only using formulas you got everything in place. Most impressed.

    Good then I can do the things my wife told me to and not be sneaking off working with forum problems on the sly trying to sort out arrays.

    Alf

  10. #10
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    With time on my hands I made a macro driven setup that don't uses solver still a manual evaluation is needed to determine what values to choose.

    To test run macro "FindMaxVal" this macro will ask how many high values it should find so enter 5 for instance and click OK.

    There are now 3 new columns the first one is labeled "Missing" and the value shown in E11 tells that are 3 jobs that must be done (H9, I10 and J11) before one gets the full
    the full points that are shown in cell F11. The green color in G11 shows that this is one of the 5 highest values found in range C2:C208.

    So the macro reacts on the C11 value of 2,580% and not on the F11 value of 3,696%. But again to get this one has to do 3 jobs better wait a bit.

    The next suggestion is C32 with a value of 2,662%, seems ok as well as C76 with 4,845%. CF92 with 2,309% is ok and C98 only need a 1 in B97 to get the full score for all the three cells 5,223%.

    That was 4 values taken care of, what about the fifth value? Starting filling the B9:B11 range with a 1?

    Another option is to run the "ClearForNew" macro and do a rerun but this time enter a 6 when macro asks for how many high numbers it should find. Five of these found values are of cource the same as before but ther is a 6th value now cell C168 that is 1,856%.

    So ether one chooses C32, C76, C92, C97 and C9 or does C32, C76, C92, C97 and finally C168 and wait a bit after more jobs are done and the other remaining values are lower?

    Alf
    Attached Files Attached Files
    Last edited by Alf; 08-21-2019 at 04:17 PM.

  11. #11
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: SOLVER problem with a lot of restrictions (BEST POSSIBLES VALUES)

    I'm still not satisfied with the last solution I posted. The array solution is a better one than the OpenSolver but I was not satisfied with the setup for the array solution.

    It could have been made more user friendly, so for my own satisfaction as I have a problem with unfinished and sloppy work I've made a last model that I'm reasonable pleased with.

    Alf
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Solver Problem: Only 100 Values To Check
    By danc1982 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-17-2017, 04:39 PM
  2. Replies: 7
    Last Post: 12-31-2016, 12:29 PM
  3. [SOLVED] IF : if a figure falls between two others in a long range of possibles
    By Wilgoss in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 12-21-2014, 08:53 PM
  4. [SOLVED] Excel SOLVER problem, claims it is solved but retains original values. Example given.
    By ad9051 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-25-2012, 04:18 PM
  5. return a different look up using 2 possibles
    By excellentexcel in forum Excel General
    Replies: 4
    Last Post: 03-10-2009, 04:40 AM
  6. Advanced restrictions in solver
    By 77anders in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-06-2009, 11:38 AM
  7. Interesting Solver problem (Solver encounters an error)
    By MrShorty in forum Excel General
    Replies: 3
    Last Post: 12-22-2005, 06:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1