I485: Biologically Inspired Computing

Lab 0: Python Review


Training Exercises

  1. For beginners: Drunken ant. A flat ant lives on a flat world. It is intoxicated and meanders on its world. Simulate this random walk for a few steps, and calculate its net displacement.
    • First, make a few assumptions. Assume that the 2D coordinates of the world are only integers: (x, y) where x and y can be a positive or negative integer. Assume that the flat is of infinite size, that is x and y can be very large numbers. Assume that the center of the world is at (0, 0), and the ant always starts from there and takes exactly 10 steps from there.
    • Second, implement the world coordinates. One way is to use tuples.
    • Third, implement the ant's drunken walk. Starting from the center of the world, the ant must take a small step in a random direction. You can use the modules available in the package 'random' for this. Remember to make random additions to both x and y directions.
    • Finally, calculate the net displacement. This is the Euclidean distance between its position of the ant on the 10th step and the center of the world from where the ant first takes off. You may also wish to keep track of the full trail and calculate the total distance walked.
  2. More Advanced: Graph traversal. Take a piece of paper, and make up a small graph (or network) with 5 vertices (or nodes) in it. Randomly assign a few links or edges between them. Your graph drawing should look something like this. Label the nodes with numbers or strings.
    • Your first task is to represent this graph in Python. You may use any data-structure of your choice: it may be a dictionary with keys standing for node labels and values standing for the neighboring nodes’ labels, or two separate lists, one containing all the “from” nodes, and the other lists of lists containing lists of all the “to” nodes that each “from” node is connected to, or define an adjacency matrix, or you can get creative.
    • Your second task is to pick up all possible paths between two chosen nodes where no path visits a node more than once. Note that since there are only 5 nodes, the maximum number of edges in such paths between any two nodes is only 4. You may also wish to play with directed edges where you assign a direction to each edge in your graph, so your program will be constrained to traverse edges only along the directions specified.




All Class Labs

I485 Biologically-inspired Computing

Life Inspired