Happy Neighbors Guaranteed with Pyomo!
Alireza Soroudi, PhD
Lead Data Scientist @ bluecrux || SMIEEE || Optimization expert || Healthcare management || Lab Digitalization || Power and Energy systems || Developer || Author / Speaker || (views are mine)
Why did the mathematician live in a 6x6 lattice? Because s(he) wanted to be surrounded by her/his square neighbors!
Not funny ? I know...
Let's look at nother story :
A total of 9 individuals occupy a 3x3 lattice, with each person residing in a distinct square. An individual's neighbors consist of those who occupy squares that share a common edge with their own square.
Each person in the lattice is given a unique natural number N, with the condition that if a person is assigned a value of N>1, their adjacent neighbors must be assigned all natural numbers from 1 to N-1. (the problem is borrowed form [1])
Look at the following figure to further explain the problem:
But what is the optimal solution ?
How to fill these cells to maximize the total score ?
Looks easy ? No.
Problem formulation
Let's formulate the problem. This the first and the most important part of any optimization problem (right after data gathering and preparation).
The formulation can be further enhanced. How ?
By limiting the upper bound for xi . Why ? based on the location of xi it may not be allowed to take all numbers from 1 to N (see case D). so the upper bound of each cell is found (N_{i,max}) .
By adding this filter to the formulation, the number of binary variables will reduce.
领英推荐
Pyomo Code
Results
3*3 lattice
4*4 lattice
5*5 lattice
6*6 lattice
Applications:
Reference:
https:// research.ibm. com/haifa/ ponderthis/challenges/December2012.html
Business Analyst, Data-Driven Problem-Solver, Aspiring Consultant
1 年First of all, thanks for sharing! I might have misunderstood the problem. In the provided result for the 3*3 lattice isn't there something wrong? The central cell of the lattice (number 3) has 4 neighbors and the value of 2 of them is "4" which is greater than "3". Doesn't it violate one of our assumptions (if a person is assigned a value of N>1, their adjacent neighbors must be assigned all natural numbers from 1 to N-1.)?
Lead Data Scientist @ bluecrux || SMIEEE || Optimization expert || Healthcare management || Lab Digitalization || Power and Energy systems || Developer || Author / Speaker || (views are mine)
1 年Github code : https://github.com/OptimizationExpert/Pyomo/blob/0e4be3bd9f577474fb321fe483b472779f12265f/fill_chess-Github.ipynb