+ Reply to Thread
Results 1 to 6 of 6

Excel OpenSolver: non linearity issue

  1. #1
    Registered User
    Join Date
    02-16-2022
    Location
    Moscow, Russia
    MS-Off Ver
    Office 365
    Posts
    3

    Excel OpenSolver: non linearity issue

    Hi all,

    Kindly ask to help with non linearity issue (in a linear model btw..)

    On Model 1 tab there is a model with demand/supply constraints - Solver works just fine, no issues here.
    On Model 2 tab I add new constraint - 1 supplier per region, while using basically same formula as for supply/demand constraint.

    And this somehow breaks linearity rule for the model, can't understand why.
    NonLinear error.png

    I assume that using "MAX" function in array formulas makes the model non-smooth, but can't think of a workaround right now...

    I am using OpenSolver, standard linear solver. Excel 365.
    Would really appreciate your help!
    Attached Files Attached Files

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

    Re: Excel OpenSolver: non linearity issue

    Expressing the constraint of 1 supplier per region is not as easy as it seems in Excel, if we must avoid non-linear functions, or at least I can't see an easy implementation.

    One way to deal with it is using a set of indicator (binary) variables that will switch to one as soon as the sum in a given region and for a given supplier is greater than zero. Once we have them, we can easily constrain their sum to be 1 for each region.

    In the attached file you find a setup with one more matrix of aux_vars, and below that the constraint to force them to 1. The value of the constant (5) is as little as possible (there are at most 4 clients per region, and only 1 supplier for each).

    Let me know if this works for you.

    HTH,

    Francesco
    Attached Files Attached Files
    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
    02-16-2022
    Location
    Moscow, Russia
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Excel OpenSolver: non linearity issue

    Hydraulics, many thanks for your response! Your solution seems to be the right one.

    I do have a few questions though, if you don't mind. I need to extrapolate this solution to a bigger dataset, and not everything is clear to me, unfortunately:

    Quote Originally Posted by Hydraulics View Post
    One way to deal with it is using a set of indicator (binary) variables
    Can't quite wrap my head around this concept.

    How one can generally separate situations when creation of a constraint is enough, from a situation when I have to create auxiliary variables to overcome this non-linearity issue?

    Like in this example - I don't get the overall difference between supply and demand constraint (linear) and number of suppliers constraint (somehow non-linear).

    And why the last one should be an aux.variable, instead of being a constraint, like it is supposed to be in my perfect world..

    Quote Originally Posted by Hydraulics View Post
    The value of the constant (5) is as little as possible (there are at most 4 clients per region, and only 1 supplier for each).
    Am I correct to assume that this constant is a max number of clients (rows) that could be allocated to 1 supplier in a region?

    ---

    On a separate topic - would really appreciate if you could suggest reading materials that explain this topic in a simple manner.

    Thank you once again!

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

    Re: Excel OpenSolver: non linearity issue

    Let's name the main binary variables as X_i,j, where i is the client and j the supplier, and consider the set linked to the first region and supplier (from X_1,1 to X_3,3).
    Saying that we want at most 1 supplier in each region is like saying that, for each of the 9 bin vars in this set, the sum with any var of another supplier must be <= 1. For instance:

    X_1,1 + X_1,4 <= 1
    X_1,1 + X_1,5 <= 1
    ...
    X_1,1 + X_1,15 <= 1
    X_1,1 + X_2,4 <= 1
    ...
    X_1,1 + X_3,15 <= 1

    and so on for the remaining vars, suppliers and regions. It could also be written as

    X_1,1 + sum(X_i,j) <= 1, with i = 1 to 3, j = 4 to 15

    As you can see, these constraints are linear, and they can be expressed in a compact form if you use some high-level mathematical/algebraic programming language as GAMS, or Pyomo. With Excel, we should add them to the model through VBA (I can't imagine doing it by hand).
    Instead, we can calculate the sum for each set, and reason on a 8x5 matrix. The only problem is, now we deal with integers, not binary vars. So, to answer your second question, we need some aux vars to map the values (0 - max_sum) to (0 - 1).

    Unfortunately, there is no general rule to follow. We usually add aux vars when we have discontinuous functions, and among them, if statements are by far the most common, but this rule is not written in stone.

    The constant is the smallest integer greater than the max number of clients that can be allocated in a region, you are right. We can use 5 because there are also the constraints in column AK. Without them, 21 would be enough (supplier 3 - Chuvash republic).

    I'm not aware of a single source dealing exactly with this topic: building a good model, and using bin vars to linearize constraints, is a skill you acquire through experience.

    You may find interesting:

    Integer programming tricks (from the AIMMS guide), pdf;

    chapter 9 of Applied Mathematical Programming, which is freely available;

    chapter 9 and 10 of Model Building in Mathematical Programming, H. Paul Williams, that has a set of classic problems whose solutions with Excel I'm publishing on my blog, sooner or later.

    HTH,

    Francesco

  5. #5
    Registered User
    Join Date
    02-16-2022
    Location
    Moscow, Russia
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Excel OpenSolver: non linearity issue

    Quote Originally Posted by Hydraulics View Post
    Let's name the main binary variables as X_i,j, where i is the client and j the supplier, and consider the set linked to the first region and supplier (from X_1,1 to X_3,3).
    Saying that we want at most 1 supplier in each region is like saying that, for each of the 9 bin vars in this set, the sum with any var of another supplier must be <= 1. For instance:

    ...
    Francesco,

    Thanks a lot for such a clear explanation, it makes a lot more sense now.

    And indeed, need to work on further experience in building models. Your reading materials will definitely help.

    With your will mark the thread as solved.

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

    Re: Excel OpenSolver: non linearity issue

    If you think your question has been answered, yes, please do mark the thread as solved.

    I'll add only one thing: your model is of the integer (binary) linear kind, therefore much harder to solve compared to a continuous one.
    OpenSolver has a very nice engine (there is a model in this forum with 210k bin vars!), but if your dataset is much bigger than your sample worksheet, you may need to set the Branch and Bound tolerance to higher values.

    HTH,

    Francesco

+ 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. Excel Solver - linearity requirements not met in binary variable
    By tiredandconfused in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2020, 09:34 PM
  2. Looping Excel OpenSolver for X Number of Times
    By RollingDice in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-21-2020, 08:17 AM
  3. Understanding OpenSolver
    By mike_302 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-07-2020, 07:02 AM
  4. Trying to set objective cell of opensolver on VBA
    By lucasar in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-23-2016, 03:40 PM
  5. Replies: 5
    Last Post: 08-18-2016, 09:13 AM
  6. Extent of linearity of a curve. Vehicle Dynamics
    By Suraj Ballakuraya in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 03-25-2013, 07:58 AM
  7. Excel Solver: linearity and MOLP
    By fboehlandt in forum Excel General
    Replies: 1
    Last Post: 12-16-2010, 03:07 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