1 of 26

Python and Research

Aniq Ur Rahman

2 of 26

Hello!

I am Aniq Ur Rahman

@Aniq55

2

3 of 26

Abstract

  • Journey
  • Simulations
  • Verification

  • Problem
  • Solution
  • Python

3

4 of 26

Introduction

The link between Python and Research

5 of 26

Research?

  • Problem statement
  • Solution concept
  • Experimentation
  • Validation
  • Results
  • Pass/Fail

5

6 of 26

Why code your solution?

  • Provides freedom
  • Prepackaged software drives�the research goal
  • Research questions are complex, prepackaged softwares aren’t
  • With programming based approach, you can do anything
  • Replicability of results
  • Order food vs. Cook food

6

7 of 26

Why code in Python?

  • Clear
  • Algorithmic
  • Large standard library
  • Powerful libraries
  • Highly portable
  • Free
  • Large User community

7

8 of 26

Real-time simulation in Python

A step-by-step guide

9 of 26

Important Libraries

  • numpy
  • matplotlib
  • time
  • threading

9

10 of 26

Scenario

Description of Problem statement

11 of 26

Scenario

  • Swarm of Drones (UAV) nD
  • Detect ground survivors nS
  • Rescue them
  • Fixed range R
  • Fixed test area L x L
  • Random distribution
  • Random walk by drones

11

12 of 26

Solution

Our approach to the solving the problem

13 of 26

Solution

  • Class for UAV UAV.py
  • Class for Survivors survivor.py
  • Functions for chaos chaos.py
  • Define constants constants.py
  • Global variables constants.py
  • Real-time simulation main.py
  • Plotting the results plotter.py

13

14 of 26

UAV class

Data members:

  • ID unique identity
  • position x, y
  • velocity velx, vely
  • rescued list of survivors rescued
  • _time_ to measure time
  • Init_time time of initialization

14

uav.py

15 of 26

UAV class

Functions:

  • __init__ Initialize
  • update_position Move the UAV
  • search_survivors Search for survivors

15

uav.py

16 of 26

Survivor class

Data members:

  • ID unique identity
  • position x, y
  • marked_safe whether rescued

16

survivor.py

17 of 26

Randomness

random_pos():

  • random.uniform(0, L)

random_val():

  • random.uniform(-10.0, 10.0)

17

chaos.py

18 of 26

Random walk mobility of UAVs

update_position(time_elapsed):

  • x = (x + velx* time_elapsed* random_val() )%L
  • y = (y + vely* time_elapsed* random_val() )%L

18

uav.py

19 of 26

Searching for Survivors

search_survivors():

  • init_time = time()
  • While search is not complete:
    • Mark safe the survivors in range
    • Time delay (for rescue)
    • update_position( time() - _time_ )
    • _time_ = time()
    • Write data to file

19

uav.py

20 of 26

Defining Global variables

  • DRONES List of drone objects
  • SURVIVORS List of survivor objects
  • missions List of parallel threads
  • output_file File for logging output

20

constants.py

21 of 26

Creating objects

  • for i in range(nD):
    • DRONES.append( UAV(i, random_pos(), random_pos(), Vmax, Vmax )

  • for i in range(nS):
    • SURVIVORS.append( survivor(i, random_pos(), random_pos() )

21

main.py

22 of 26

Running parallel threads

  • for i in range(nD):
    • process = threading.Thread( target=DRONES[i].search_survivors(), args=None )
    • process.start()
    • missions.append(process)

22

main.py

23 of 26

Extracting results

search_survivors():

  • ...
  • While search is not complete:
    • ...
    • ...
    • output_file.write("%d, %f\n"�%( len(SURVIVORS),�time.time()- self.init_time) )

23

uav.py

24 of 26

Visual Representation

  • import matplotlib.pyplot as plt
  • f = open(‘out.txt’, ‘r’)
  • N, T = [], []
  • for line in f:
    • l = line.split(‘,’)
    • N.append(int(l[0]))
    • T.append(float(l[1]))
  • plt.plot(T,N)
  • plt.show()

24

plotter.py

25 of 26

Quotations are commonly printed as a means of inspiration and to invoke philosophical thoughts from the reader.

25

26 of 26

Thanks!

Any questions?

You can find me at:

@Aniq55

aniqrah@protonmail.com

26