Vous êtes sur la page 1sur 3

Algorithms and Computability

Laboratory Project Initial Methodology


Omar Alshaker, Fares Alahmar, Symon Salloum, and Jakob Karabula

1
1.1

Introduction
The Problem

This document contains a methodology description for the Algorithms and Computability project prepared by students
from Faculty of Mathematics and Information Science of Warsaw University of Technology. The main assumption of the
problem is that we have L regular language with an alphabet L which is a set of *. And assuming that a tool is given,
such that ( x, y *) answers the question x RL y.
1.2

The Task

The task is to address the following key requirements:


1. To construct a Deterministic Finite Automata DFA that accepts L, or any automata close to it.
2. To apply Particle Swarm Optimization PSO as a mechanism to find transition tables that minimize the number of
errors.

Input

The computation process will take the Deterministic Finite Automata as a text file input from the user, the DFA itself
will be represented in the following manner:
1. DFA states represented with numbers 1, 2, 3, ..., n, where n is the number of the states.
2. R is the number of symbols in the alphabet (if needed, consecutive symbols in the alphabet are denoted as 1, 2, ..., r ).
3. The transition function table will be represented in seperate matrices; a matrix for each symbol.

Word generation

We will use this Java default function to convert a cononical index into a string using a given radix, and in our case the
radix is the input alphabet length ||.
I n t e g e r . t o S t r i n g ( i n t CANONICAL, i n t RADIX)
Using the function above, the bigger share will be to the short words, however, a significant number of long words will
be generated, too. All the generated words will be saved in a list called Dictionary.

Transition Table

For ease of implementation, each symbol in will have its own transition table. The transition table will basically be a
boolean 2D array looking like this:
q0 q1 q2
q0 0 1 0
q1 1 0 0
q2 1 0 0
Such that q1 , q2 . . . q3 are states.

5
5.1

Algorithm
Introduction to PSO

Particle Swarm Optimization is a computational technique inspired by nature and developed in 1995 by J. Kennedy
and R. Eberhart after observing the social behavior of bird flocking or fish schooling. The methodology uses a number
of agents we call particles that constitute a swarm moving around in the search space over time, looking for the best
solution. Each one of these particles adjusts its flying according to its own flying experience and the flying experience
of other particles, so the collection of particles is our changing solutions, the search area is all possible optimal global
solutions while moving to final area or state, each particle will keep track of its best personal solution and its best
value for global best solution, comparing those collected values to each others at the very end will give us the optimal
position to each particle. During the simulation each particle will adjust its traveling speed and its position dynamically
corresponding to the flying experiences of itself and its neighbors.

Laboratory Project Initial Methodology

5.2

Functions

1. FindClosestParticle(P osition): its basically a function that searches the solution space for the closest particle to
the given position.
2. GenerateDFA(P osition): This function creates an FDA with all its transition tables for each symbol in the alphabet.
The created DFA is mathmatically correlated with the P osition parameter.
3. GenerateDFA(States, Alphabet): This function creates an FDA from a given set of states and an alphabet.
4. GetPointInSpiralCurve(r, , Center): This function return a point in a Fermats Spiral curve using the equation:
r2 = a2 .
5.3

Algorithm

5.4

Variables

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.

S: The solution space.


k: The number if particles in space S.
Pi : The ith particle in the solution space S.
G: The best global solution position.
CurrentP article: The Current particle-under-testing.
CurrentErrorRate: Temportary double decimal number to keep particle-under-testing ErrorRate.
M inimumErrorRate: The minimum error rate.
AvgP osition: The average position.
CurrentV elocity = 1;
W rongCount: The number of words unaccepted by the generated DFA
CorrectCount: The number of words accepted by the generated DFA
LocalBestP article: The best solution particle.
The flow of solving the problem is concluded in steps:

1. Phase I
(a) Parse the text file and realize the given R, , and states.
(b) Build the FDA using GenerateDFA(States, ) function 5.2.3.
(c) Generate a number of arbitrary words as described in secion 3.
(d) Loop through Dictionary words and simulate the user-given DFA to determine whether an arbitary word is accepted. If not, remove it from Dictionary.
(e) Now Dictionary consists of only words that are accepted by the given FDA.
2. Phase II
(a) Using a loop; from 0 to k, generate k random DF As from the given alphabet uniformly distributed in Space S,
using, GenerateDFA(position); such that position is the a random value generated with every loop.
(b) Now we have the solution space S populated.
3. Phase III
(a) Loop through each Particle Pi to calculate AvgP osition.
(b) Initialize M inimumErrorRate to 1.
(c) By calculating average positon. we are in the middle of the solution space.
4. Phase IV
FOR i = 0 to arbitary m do:
FOR angle = 0 to 360 do:
tempLocation = GetPointInSpiralCurve(i, angle, AvgP osition);
CurrentP article = FindClosestParticle(tempLocation);
Simulate CurrentP articles DFA with a subset of words from Dictionary to Calculate:
CurrentErrorRate =

W rongCount
CorrectCount

then set CurrentP article.ErrorRate = CurrentErrorRate, to keep track of each particle error rate.
IF CurrentErrorRate < M inimumErrorRate; then:
M inimumErrorRate := CurrentErrorRate
G := CurrentP article;
ENDIF
4

CurrentV elocity = b (
angle+ = CurrentV elocity
END FOR
END FOR.
Now G is the Global Solution.

Pi1 .ErrorRate)
+ 1) c
Pi .ErrorRate

Laboratory Project Initial Methodology

5. Phase V, finding the local best


CurrentV elocity = 1;
LocalBestP article = G;
M inimumErrorRate = 1;
FOR i = 0 to arbitary m do:
FOR angle = 0 to 360 do:
tempLocation = GetPointInSpiralCurve(i/CurrentV elocity, angle, LocalBestP article.position);
# Here, unlike Phase IV, we generate the FDA. not just find it
CurrentP article = GenerateDFA(tempLocation);
Simulate CurrentP articles DFA with a subset of words from Dictionary to Calculate:
CurrentErrorRate =

W rongCount
CorrectCount

then set CurrentP article.ErrorRate = CurrentErrorRate, to keep track of each particle error rate.
IF CurrentErrorRate < M inimumErrorRate; then:
M inimumErrorRate := CurrentErrorRate
LocalBestP article := CurrentP article;
ENDIF
4
Pi1 .ErrorRate)
CurrentV elocity = b (
+ 1) c
Pi .ErrorRate
END FOR
END FOR.
Return LocalBestP article;
5.5
1.
2.
3.
4.

Classes



DFA { function boolean Simulate(word), State StartState, State AllStates, TT
T ansitiaionT ables }
Position: an abstract class depicting particle position.
Particle { Integer ID,
 DFA df a, Position position, Integer distance, double ErrorRate }
Dictionary { String
words }

5.6

Complexity Analysis

This section will be documented through implementation with graphs and concrete calculations.
5.7

Resources

www.swarmintelligence.org
www.mathworks.com
www.wikipedia.org

Vous aimerez peut-être aussi