Excel Solver with non-adjacent cell constraint? -


I am a novice with Excel Solver and only after learning about a data science book has learned about it. I want to be more familiar with this device, so I am trying my hand to solve different problems. Although I'm stuck on one, and I'm not sure if it is possible to use solver for it? Actually, the obligation to check me is that two cells can be imminent.

My problem: I have a different number of stones I want to maximize the number of leaves obtained by lifting bags, but they can not be close to each other.

This is in the spreadsheet with me:

  • Value = Number of stones in the bag
  • Choose whether to select the bag or not (binary) < / Li>
  • violation = (select bag number of bag) 1 - (* bag select number) bag 2

    In this case where I raise two adjacent bags, violation = -1.

      + ------ ------ + ---- + ---- + ---- + --- + --- --- ---------- + | Bag number 1 | 2 | 3 | 4 | 5 | Total value. + ------------ + ---- + ---- + ---- + --- + --- + ------------- + | Price | 10 | 20 | 30 | 40 | 50 | 150 | | Select | 0 | 0 | 0 | 0 | 0 | 0 | | Violation | 0 | 0 | 0 | 0 | | | + ------------ + ---- + ---- + ---- + --- + --- + ------------- +   

    Optimal solution:

      + ------------ + ---- + ---- + - --- --- --- + ------------- + | Bag number 1 | 2 | 3 | 4 | 5 | Total value. + ------------ + ---- + ---- + ---- + --- + --- + ------------- + | Price | 10 | 20 | 30 | 40 | 50 | 150 | | Select | 1 | 0 | 1 | 0 | 1 | 90 | | Violation | 1 | -3. 3 | -5 | | | + ------------ + ---- + ---- + ---- + --- + --- + ------------- I have tried to combine a few narrow constraints:  
    • Putting a binary constraint on the selected row
    • Violation & Gt; = 0 more violation & lt; = - 2
    • Total Goal Value & lt; = Total Possible Value (150)

      I have made this problem for myself, is it also viable?

      Yes, the problem is well.

      I suggest a different way of preparing the impending obstacles. Specifically, I use the following:

        select_1 + select_2 & lt; = 1 select_2 + select_3 & lt; = 1 select_3 + select_4 & lt; = 1 select_4 + select_5 & lt; = 1   

      This indicates that (1,2), (2,3), (3,4) and (4,5) ) Most of the pair can be selected . The advantage of this is that it does not use the bag number, which can normally be the name of a bag (i.e., a string instead of a number). There is also another advantage: we do not need to define variables in the form of binary, but only continuous and between 0 and 1: 0 & lt; = Select_i & lt; = 1 , i = 1, ..., 5 for everyone. The reason for this is that the resulting obstacle is the matrix, which means that there is an optimal solution to solve the binary problem in which select_i is either 0 or 1 .

      My spreadsheet layout is:

       Enter the image details

      Note that using different colors to differentiate between variables (green), hindrance (red) and data (blue) is a good practice. I also mark the objective cell with a green font.

      Here are the formulas :

      here Enter the image details

      and here is the Solver model :

      Note that the matrix is ​​completely unique that the optimal solution will be binary value Generally this is not true and we need to define variables in the form of binary and Sahara.

      I hope that The helps Happy modeling!

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -