+ Reply to Thread
Results 1 to 4 of 4

Optimization by reordering

  1. #1
    Registered User
    Join Date
    07-19-2019
    Location
    St. Paul, MN
    MS-Off Ver
    2018 Excel
    Posts
    2

    Optimization by reordering

    I am trying to set up a code to reorder rows of data to put them in the optimal order, based on minimizing a value. The example I have below, I have 10 items. I want to reorder the rows to minimize the differences between values in the value1 and value2 column, value1 having a larger bias for being grouped together. Can someone help me with a code that can be used for this? Another way of putting it, I want to group like values in value1 first, and then group as much as possible in value2. I would need to be able to reuse this function over and over again for different data sets.
    Any help much appreciated.

    How data is given:
    example1.JPG


    Optimized data: (did this by hand, need to have it done automatically)
    example2.JPG
    Attached Images Attached Images

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Optimization by reordering

    We probably need to understand exactly how you know that this is the "optimum" arrangement. My first effort was to use the Data->Sort command to sort in ascending order by the first column and in ascending order by the 2nd column. The result was a sum of differences of 4212 which is quite a bit smaller than the 6408 you show in your optimized screenshot. My result:
    1000 -- 4
    1000 -- 5 -- 0 -- 1
    1050 -- 3 -- 50 -- 2
    1050 -- 4 -- 0 -- 1
    1050 -- 6 -- 0 -- 2
    3000 -- 3 -- 1950 -- 3
    3000 -- 5 -- 0 -- 2
    4500 -- 5 -- 1500 -- 0
    4500 -- 6 -- 0 -- 1
    5200 -- 6 -- 700 -- 0
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    07-19-2019
    Location
    St. Paul, MN
    MS-Off Ver
    2018 Excel
    Posts
    2

    Re: Optimization by reordering

    My mistake, I see how my method is flawed. Let's try this...

    I am trying to reorder the rows of data so the following is true:
    1. Cells of the same value are grouped together in the value1 column
    2. When possible, cells of the same value are grouped together in the value2 column, still obeying the first rule

    This is how I rearranged the data in my example, you are correct it was not actually optimized. I am wondering if there is a code that will force the cells in value1 to group together, and then optimize value2 column to minimize the differences between cells, while keeping the first rule true.

    I hope this makes sense.

    Attachment 633280

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Optimization by reordering

    I am not aware of any existing code for this exact problem, but I'm sure something could be developed. Task 1 is a simple sort, and then task 2 should be a matter of finding the optimum order.

    As I have thought a little about this, I wonder if it would be appropriate to treat it like a "shortest path" problem. If the value 1 column is the x coordinate and the value 2 column is the y coordinate for each node, then the minimum difference seems like it should be represented by the shortest path through the nodes. Here's a tutorial for putting together a shortest path problem in Excel -- see if it helps: https://www.excel-easy.com/examples/...h-problem.html

+ 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. Question about automatic reordering
    By Cillendor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2015, 01:50 PM
  2. [SOLVED] Reordering Data
    By akboche in forum Excel General
    Replies: 5
    Last Post: 01-09-2015, 03:23 PM
  3. Reordering Rows
    By VelvetRevolver84 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-01-2013, 12:15 AM
  4. [SOLVED] Reordering Charts
    By PlamenGo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-02-2012, 11:54 AM
  5. Excel reordering columns
    By ray.reck in forum Excel General
    Replies: 1
    Last Post: 02-26-2012, 09:34 PM
  6. reordering issue
    By fa5fou5 in forum Excel General
    Replies: 4
    Last Post: 02-09-2012, 12:06 PM
  7. Reordering a list
    By Buffy500 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2009, 05:38 AM

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