0

I have a set of inequalities that I have to solve. These inequalities are related to circle packing, where I have N circles and all of them are interrelated between the rest of the circles. Which functions could I use to solve this? I have tried using solve in MATLAB but this doesn't work with inequalities. E.g. given 3 circles, the number of inequalities is (N*(N-1))/2, so with 3 cirlces I have 3 equations. Let's call them A, B and C, with radius 200, 300 and 400 respectively. With A,B and C I have 3 different inequalities:

dist(a,b) >= 200+300
dist(b,c) >= 300+400
dist(c,a) >= 200+400

Where

dist(p1,p2) = sqrt((p1.x - p2.x)^2 + (p1.y - p2.y)^2)

I would like to get p1.x, p1.y, p2.x, p2.y, p3.x, p3.y such as their distances are the closest to the right part of the inequalities.

With 3 circles there's no problem because it'll be always a solution that satisfies and minimizes the inequalities, but the problem comes when I have a lot of circles, p.e. 10 circles.

The objectives in this case are:

dist(a,b) = 200+300
dist(b,c) = 300+400
dist(a,c) = 200+400

Now I will show you what is my idea to solve this:

syms x1 x2 x3 x4 x5 y1 y2 y3 y4 y5

//What I want to get
unknowns = [ x1 x2 x3 x4 x5 y1 y2 y3 y4 y5]

//Equations that must be satisfied
eqns(1) = sqrt((x1-x2)^2 + (y1-y2)^2) >= 300;   // dist(1,2)>=300
eqns(2) = sqrt((x1-x3)^2 + (y1-y3)^2) >= 400;   // dist(1,3)>=400
eqns(3) = sqrt((x1-x4)^2 + (y1-y4)^2) >= 350;   // dist(1,4)>=350
eqns(4) = sqrt((x1-x5)^2 + (y1-y5)^2) >= 200;   // dist(1,5)>=200
eqns(5) = sqrt((x3-x2)^2 + (y3-y2)^2) >= 320;   // dist(2,3)>=320
eqns(6) = sqrt((x4-x2)^2 + (y4-y2)^2) >= 300;   // dist(2,4)>=300
eqns(7) = sqrt((x5-x2)^2 + (y5-y2)^2) >= 330;   // dist(2,5)>=330
eqns(8) = sqrt((x3-x4)^2 + (y3-y4)^2) >= 130;   // dist(3,4)>=230
eqns(9) = sqrt((x3-x5)^2 + (y3-y5)^2) >= 120;   // dist(3,5)>=400
eqns(10) = sqrt((x5-x4)^2 + (y5-y4)^2) >= 100;   // dist(4,5)>=130

// My objective functions I want to optimize
objs(1) = sqrt((x1-x2)^2 + (y1-y2)^2) == 300;   // dist(1,2)=300
objs(2) = sqrt((x1-x3)^2 + (y1-y3)^2) == 400;   // dist(1,3)=400
objs(3) = sqrt((x1-x4)^2 + (y1-y4)^2) == 350;   // dist(1,4)=350
objs(4) = sqrt((x1-x5)^2 + (y1-y5)^2) == 200;   // dist(1,5)=200
objs(5) = sqrt((x3-x2)^2 + (y3-y2)^2) == 320;   // dist(2,3)=320
objs(6) = sqrt((x4-x2)^2 + (y4-y2)^2) == 300;   // dist(2,4)=300
objs(7) = sqrt((x5-x2)^2 + (y5-y2)^2) == 330;   // dist(2,5)=330
objs(8) = sqrt((x3-x4)^2 + (y3-y4)^2) == 130;   // dist(3,4)=230
objs(9) = sqrt((x3-x5)^2 + (y3-y5)^2) == 120;   // dist(3,5)=400
objs(10) = sqrt((x5-x4)^2 + (y5-y4)^2) == 100;   // dist(4,5)=130

// And now.. what can I use??

//Solve doesn't work...
solve(eqns, unknowns, IgnoreAnalyticConstraints)

I would expect that the result satisfies all the equations at the same time, and the distance between every pair of circles is the closest to the desired, but NEVER smaller than it.

Here it's a graphic example: If I have this input, Input with 6 terminal nodes

The output should be something like this, where the distances between every pair of terminal nodes are respected: Output of 6 circles fixed

It's a circle packing problem with constraints, because all the circles must be as close between them as they are drawn in the input

The heuristic should be like:

1.- Add first circle

2.- Add second circle that is connected with the first and satisfying the required distance

3.- Add third circle that is connected with the first and second and satisfies the required distances

4.- ....

Maybe could I try also with bruteforce? I'm not sure

Thank you so much

  • solve will give you an exact solution not the most optimized solution. So if your equalities lead to an overdetermined system with no exact solution, `solve` will of course failed. For optimization with constraint there is the `fmincon` function. Take also into account that if you have multiple objectif functions that need to be optimized at the same time matlab cannot guess which function should be the more optimized ! I guess that there is certainly a better approach – obchardon Mar 27 '19 at 16:35
  • Are these objective functions equally weighted? Are these being solved in a sequential order? Are you wanting to minimize the sum of all 10 objective functions? (or the weighted sum) Perhaps you could [edit] the question and add some clarification. – SecretAgentMan Mar 27 '19 at 19:00
  • Thank you both of you! @obchardon I tried yesterday with genetic algorithm `ga` but nothing worked so I will try with `fmincon` function. @SecretAgentMan I edited it adding more information, thanks for your advices – Daniel Bermejo Sánchez Mar 28 '19 at 10:16

0 Answers0