Professional Documents
Culture Documents
Submitted by:
Simone BANCORA
Swaminath VENKATESWARAN
January 2nd, 2017
Professor:
Fouad BENNIS
PROJECT DEFINITION THE DISCRETISATION APPROACH
Before going into the definition of our project, it is necessary to The method that we employed to optimize the trajectory AB is the
describe certain terms which are essential as a part of this project. method of discretisation. It is basically similar to the 1D meshing
We look into the world of Optimisation. Optimisation refers to of a line in Finite Element Analysis. The discretisation is done
finding the best possible solution which is defined according to according to the principle that if there exists a line segment AB and
the objective function (Criteria, Cost) from a given set of feasible there is a point M between AB, then the position of M can be found
solutions (admissible solutions defined according to the constraints). as:
The method of optimisation can be implemented manually or
through computer applications like Excel, Matlab etc. The main rule
of optimisation in programming is that it should intervene once the
program works and meets the functional specifications. Concerning
the project definition, we have a room of dimension 10x10 M = A + x(B-A) 0x1
containing some obstacles in the form of 4 circles distributed within
this space and two rectangular walls. Our objective is that when This is the logic of discretisation for the position of one point M on
there exists a trajectory AB (starting from A and ending at B), a segment AB. In our program, we have made the discretisation
it should travel within this 10x10 space by avoiding collisions ranging from 0 to 1 in steps of 0.05 and the logic explained in the
with the circles and the walls. To say precisely, we need to find an figure is implemented in our coding. A for loop is used for the
optimum trajectory AB such that it doesnt hit or go through the discretisation and it is shown in the code below:
circles and the walls. The optimisation is successfully implemented alpha=0:0.05:1;
in this project using the fmincon function provided by the Matlab for i=1:length(alpha)
software. The fmincon is a powerful optimisation function for M=A+(alpha(i)*(B-A));
finding the minimum of a constrained non-linear multivariable end
function. Its syntax is defined by:
Before we arrived at the final solution, we started off the work with
X=fmincon(fun,x0,A,b,Aeq,beq,Lb,Ub,nonlcon,options); a trajectory AB with one guess point and one circle, then we
implemented the logic to multiple guess points and two circles, then
where it starts at x0 and attempts to find a minimizer x of the we increased the number of circles to 4 and finally we implemented
function described in fun subject to the linear inequalities ! # %. the walls into the room along with the circles and optimised the
x0 can be a scalar, vector, or matrix. Aeq and beq refer to the equality trajectory AB. The reason why we went in steps was to basically
constraints and if they dont exist they can be set as [ ]. In our understand the method of optimisation and how the logic works for
program, the Lb and Ub is set according to our room space of 10x10 one obstacle before implementing it on a complete system. We will
and they can be set to [ ] if not needed in general. The options explain individually starting from our first step of the project.
feature defines the parameters for the algorithm. Instead of defining
all constraints here in fmincon, they can also be called as a function, (i) ONE CIRCLE AND ONE GUESS POINT
which we have actually done in our project. The program structure (Annex section 1.1 for codes)
is divided into three portions: The objective function, the In order to work with the optimisation in Matlab, it is essential to
constraint function and the main script. The field of interest i.e., provide a guess value which may be user input or pre-defined. The
the room which has the obstacles in the form of circles and walls is guess point in this case is basically a [1,2] array (PN_0). The
shown below: trajectory AB, will be split into segments as APN_0 and PN_0B.
(a) In the objective function, we will minimize the sum of the
norm of the segments APN_0 and PN_0B.
(b) In the constraint function, which is the critical part of our
program, we first do the method of discretisation in steps of
0.05 ranging from 0 to 1 for segments APN_0 and PN_0B.
Thanks to the for loop, we can successfully discretize the
segments. Now, the primary step in the method of
discretisation is to calculate the distance for every M point on
both the segments with respect to the centre of the circle
defined. These distances are calculated after the discretisation
of the segments, in the same loop. With the help of some arrays
we store these distance values. Once the looping ends, we now
extract the distances that are minimum with respect to the
centre of the circle on both the segments. The constraint will
be an inequality form which ensures that this minimum distance
is at least equal to or greater than the radius of the circle.
(c) In the main script, we define the guess point PN_0, co-
ordinates A, B and plot the circle using viscircles. Using
FIG 1: PROBLEM DEFINITION fmincon, we run the optimisation technique as it calls the
Now our objective would be to optimize a trajectory AB that travels objective function and the constraint function. The Lb and Ub
from left side to the right side without hitting the obstacles. We will in our case is [0 0] and [10 10] pertaining to the dimensions of
now explain our approaches in the following sections. the room. A hold on function after viscircles helps to
superimpose the plots of the segments APN_0 and PN_0B and
also the initial guess points at the end of the program. If we see
the results, the optimum point is found in such a way that it
1 | P a g e
passes tangentially or away from the circle thanks to the
constraints defined. The guess point is now shifted to an
optimum point as per our objective. The result of this approach
is shown below:
FIG 3: TWO CIRCLES, MULTIPLE POINTS
2 | P a g e
This technique is simpler and optimised and can be extracted will be 4. For ease of calculation, we assumed that two
extended to n number of points. of the guess points have to pass in between the walls. So
(b) In the constraint function, we now no longer run the code the middle value in the guess point array and its successive point
segment by segment or circle by circle. We have made a nesting will be made to pass between the walls without hitting them i.e.,
of two loops within one main for loop where the main for in our case it will be the fourth and fifth points in the guess
loop runs for all points including A and B, the first nested for points matrix. The constraint here is achieved by fixing two co-
loop runs for all circles and the next nested loop does the ordinates between walls. The trajectory will now be strictly
discretisation. Within the second nesting, we do the made to pass through the fixed co-ordinates between the
discretisation segment by segment and calculate the distances walls.
from each circle. At the end of this loop, we find the minimum (c) In the main script, there is no significant change when
distances with respect to all circles and the main for loop ends. compared to the previous section except that we introduce the
After this, with the help of another for loop, we calculate the command rectangle in order to plot the walls. The results for
constraints with respect to the radii and centre of circles one by this approach is shown below:
one. Also, the co-ordinates of A, B, C, R and the guess points
PN_0 are defined only in the main script and will be called as
parameters in the constraint and objective functions using
function handles.
(c) In the main script, the guess point array PN_0 is defined
followed by the co-ordinates A,B. With the help of four
viscircles commands, we plot the desired circles. The fmincon
is then made to run as it calls the objective and the constraint
functions. The results are now plotted with the co-ordinates of
AB and the guess points along with the circles using hold on.
The result obtained is shown below:
FIG 6: FIXED POINTS BETWEEN WALLS
3 | P a g e
1. Check the extreme points F and G of the segment: if they fall
inside the circle (FC or GC < R), move them outside.
2. Calculate the position of the point (N) which is the normal
projection of the centre of the circle on the segment.
3. Evaluate if this point N falls on the segment between F and G
4. If N falls between F and G, constrain the distance of the
segment from the centre (NC) to be R.
5. If N doesnt fall between F and G, no constraint is applied on
the distance.
We implement this logic in the constraint function where we
eliminate the for loop which is used for discretisation and use an
if-else condition to express this logic. To check if the new
constraint is working properly, a non optimized test environment
is created to simulate all the possible cases:
FIG 7: FINAL DISCRETE SOLUTION WITH PRE-DEFINED INITIAL POINTS
FIG 9: CONTINUOUS TEST GROUND (Annex section 2.1 for codes)
AN ALTERNATIVE METHOD:
THE CONTINUOUS APPROACH
Now that we have successfully implemented the method of
optimisation for a trajectory AB inside a 10x10 room by avoiding
collisions against circles and walls by the method of discretisation,
we now follow another approach where we no longer do the method
of discretisation. In other words, we employ a continuous
approach on trajectory AB, where the segments are no longer
discretised. AB will be as usual split into segments based on the
number of guess points. To calculate an optimal trajectory, we attain
the objective of making the segments of AB to pass tangentially or
away from the circles, but only in the case that a segment would
have crossed the circle. This change will affect the logic of the
constraint function.
To explain the solution we found, we will start with a simple
example: lets take one segment FG and one circle of centre C and
radius R. We want to make sure FG does not cross the circle, but
FIG 10: FINAL CONTINUOUS SOLUTION WITH PRE-DEFINED INITIAL POINTS
avoid to move FG away if there is no need to. We will achieve this
by using the following logic:
4 | P a g e
INSTRUCTIONS TO RUN THE CODES:
The programs relative to the various steps described have been
collected in the folder Codes. It is possible to see that the code
experienced a progressive improvement from the first exercise to
the last. The final programs for the two approaches are in the 5.Final
Discrete and in the 7.Final Continuous folders named respectively
final_discrete.m and final_cont.m, both working with the
option to use a pre-defined matrix of points and a randomly
generated one. If Pre-defined is selected, a matrix of points PN_0
will be used with the following values:
PN_0=[8 8; 3 7; 3.5 3; 5 5; 5.5 4.5; 7 3.5; 6 1];
If Random is selected instead, a (7,2) matrix of values will be
randomly generated with a fixed rng value. In the folder Master
Program (Discrete and Continuous) it is possible to find one last
program, which is called Optim_project_both_methods.m
(Annex 3 for the codes). This code includes both the discrete and
the continuous approaches in the same program, and the method
to be used can be decided at startup.
FIG 11: FINAL CONTINUOUS SOLUTION WITH RANDOM INITIAL POINTS
(Annex section 2.2 for codes)
5 | P a g e