+ Reply to Thread
Results 1 to 9 of 9

Need help with another optimization problem using VBA

  1. #1
    Registered User
    Join Date
    04-08-2022
    Location
    Montreal Canada
    MS-Off Ver
    Microsoft 365
    Posts
    15

    Post Need help with another optimization problem using VBA

    Hey guys, I have another optimization problem that I really need help with.

    To simplify things, I'm only going to give 10 dummy data points (instead of my 500+ that I have)

    Each data point has 2 values associated with it: The frequency (in days) and duration to complete the task (in minutes).

    There is going to be 2 user inputs: Number of slots and available time per slots

    You can imagine these 2 user inputs as a graph where the number of slots is the x-axis and available time is the y-axis.

    The number of slots corresponds to a year divided into slots.

    What I would like to do is to put all my data points into all the available slots and create a job plan, but make sure that the tasks in each slot don't go over the available time.

    Here's my approach: For this example, Number of slots = 12, Available time = 120 min [Attached file]
    1) Sort the frequency from lowest to largest.
    2) Divide 365days by the lowest frequency and round down. (i.e. 365 divided by 90 = 4 [rounded down])
    3) Divide the number of slots by the value found in 2) (i.e. 12 slots /4 = 3)
    With the number found in 3), I will only focus on that number of slots for a frequency of 90 days
    4) Populate each slot by putting only one task per slot and looping it until all tasks are in (i.e. There are 4 tasks with a frequency of 90 days [We'll call it A,B,C,D]. Task A will go in slot 1, Task B will go in slot 2, Task C will go in slot 3, Task D will loop and go back into slot 1. If there isn't enough available time, Task D will check in slot 2)
    5)Once all the tasks are in, slots 1,2, and 3 are copied to the other slots. Meaning that slots 1,2,3 = slots 4,5,6 = slots 7,8,9 = slots 10,11,12

    Repeat from step 1 with the next frequency (i.e. 180 days)
    1) 180 days
    2) 365 days / 180 = 2 rounded down
    3) 12 slots /2 = 6
    I will only focus on the first 6 slots
    4) Populate the slots with tasks having 180 days. But this time, there are already other tasks in it. It needs to check from slot 1 to 6 where is the next available slot to fit given the remaining time. (i.e. there are 3 tasks with frequency of 180 days, [we'll call if E,F,G]. Task E will check if there is available time in slot 1. If yes, put it in there, else check the next slot. Loop slots 1 to 6 until all tasks of 180 days frequency are in)
    5) Copy slots 1,2,3,4,5,6 to the other slots ==> slots 1,2,3,4,5,6 = slots 7,8,9,10,11,12.

    Repeat again with the next frequency.

    Sorry if it's difficult to understand by text. The attached file has the final solution included, so if you follow the steps, you should get the same thing.

    If you know an easier solution, feel free to share it.

    Thank you for your help.

    NOTE: I don't need to have the graph drawn. I just want to know in which slot does each task goes into (It can be another column next the the dataset)
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Need help with another optimization problem using VBA

    This sounds like a task for SOLVER, but I confess I don't really understand the process and constraints at the moment.

    For instance are you trying to arrange the tasks so that the slots are as evenly occupied as possible, i.e. minimising the difference between the 'spare' spaces on the y axis?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    04-08-2022
    Location
    Montreal Canada
    MS-Off Ver
    Microsoft 365
    Posts
    15

    Re: Need help with another optimization problem using VBA

    Hey Richard,

    Thanks for the quick reply.

    I only need to put all the tasks in the slots. It does not need to be 100% optimized. I want a tool that would automate the process of assigning tasks to each slot without doing it manually

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Need help with another optimization problem using VBA

    I thought solver might help but I believe there's a limitation of 200 constraints which will probably get caught by the large number of points you have.

    I'll take a look at a VBA approach.

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

    Re: Need help with another optimization problem using VBA

    Quote Originally Posted by TheVuongster View Post
    Hey guys, I have another optimization problem that I really need help with. [...]
    This seems to be a variant of the job scheduling problem.

    As Richard wrote, Solver cannot help us if you have more then 500 jobs. We could try with OpenSolver, but these problems are known for being very hard to solve even for small instances and with dedicated engines.

    If you attach a representative sample of the problem, I may try and setup a model, but I can't promise anything.

    HTH,

    Francesco
    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.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Need help with another optimization problem using VBA

    Here's a first draft of what I think you are asking for.

    It creates the matrix of results which if they are correct could then be used to create the coloured boxes representation, but the first thing to do is agree the basic numbers are correct.

    The approach here is to ripple down starting with the first task, create the numbers for the first slot then move to the second & subsequent slots.

    As it stands I notice that if the available time is set to less than 120 then an error occurs. I think it's because it's not possible to distribute all the times given the current order of tasks. This needs more examination, maybe a different order of tasks would give a different result. I note that an error also occurs if the tasks are sorted in descending order.

    However if you'd check the basic results we can then move on to address anomalies
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    04-08-2022
    Location
    Montreal Canada
    MS-Off Ver
    Microsoft 365
    Posts
    15

    Re: Need help with another optimization problem using VBA

    Wow this is amazing! I just had to change the formula a bit for the period frequency offset, but this might be what I needed!! Thank you very much for your help!

  8. #8
    Registered User
    Join Date
    04-08-2022
    Location
    Montreal Canada
    MS-Off Ver
    Microsoft 365
    Posts
    15

    Re: Need help with another optimization problem using VBA

    Hey Richard, I need your help again. When I try to put my data into your program, I noticed that it doesn't check for other available slots before giving me the "error = there may not be enough time" message, but there are still unused slots. Also, in some situations, the code just stops and doesn't go through the entire list of tasks.

    I am attaching the workbook with my data as an example of what I mean.
    Using Available time as 120 and number of slots as 24, the code stops on the task at line 23 and doesn't continue when there are slots 8-12 and 20-24 still unused.
    Attached Files Attached Files

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Need help with another optimization problem using VBA

    Hi,

    Just returned from a long weekend away. I'll take a look later.

+ 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. optimization problem
    By kema in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-19-2020, 01:13 PM
  2. Need Help with an Optimization Packing Problem
    By Kaenon in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-11-2015, 06:18 PM
  3. Solver Optimization Problem
    By greywolf00 in forum Excel General
    Replies: 6
    Last Post: 10-13-2014, 12:43 PM
  4. Problem Using Solver with an optimization stock problem
    By Jagrubski in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-24-2013, 03:41 AM
  5. Complex Optimization problem through VBA
    By usmanzkhan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-21-2012, 06:09 PM
  6. product mix optimization problem
    By lucabi in forum Excel General
    Replies: 2
    Last Post: 08-19-2012, 02:15 PM
  7. Optimization Problem
    By learningtoride in forum Excel General
    Replies: 0
    Last Post: 06-28-2011, 03:52 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