Code Documentation MFA (Movable Finite Automata) Eric Klemchak CS391/CS392
1 Contents 1.Overview... 2 1.1Introduction... 2 1.2MajorFunctions... 2 2.Dataflow... 2 3Controlflow... 3 4.Logical/PhysicalDataDesignDescription... 3 4.1TurtleVariables... 3 4.2GlobalVariables... 4 5.InterfacetotheOutsideWorld... 4 6.SystemCreation... 5
2 1. Overview 1.1 Introduction The purpose of this project is to rebuild a modeling program created by a graduate student of Narendra Goel. The original program was written in Turbo C++ and ran in a DOS environment. Dr. Goel used the program in his research to simulate the self-assembly of bacteriophages. Dr. Pryor wants a version of the program that will run in Net Logo so he could use it for classroom demonstrations. 1.2 Major Functions The program has four major functions. Move Groups This function moves each group one unit in a random direction (up, down, left, or right). If a translation will cause two groups to overlap, the translation is skipped and the next group will attempt to move. Rotate Groups This function attempts to rotate each group 90 degrees clockwise or counterclockwise. If a rotation will cause two groups to overlap, the rotation is skipped and the next group will attempt to rotate. Check for Bonds Each turtle will check if there is another turtle in an adjacent square (top, bottom, left, or right). If there is a neighboring turtle, the two turtles will check their corresponding rules to see if they will bond with each other. If the rules are satisfied, the adjacent turtle s group number will be set equal to the original turtle s group number. Get Input This function parses the MFA file that the user made. It checks to make sure that all five sections are present: Type, Color, Border, Qty, and Bond function and that they are correctly formatted. If there is a syntax error, the function will display an error message to the user. 2. Data flow The data flow diagram will be added to the final draft.
3 3 Control flow 4. Logical/Physical Data Design Description Net Logo has four types of agents: turtles, patches, links, and the observer. Each type of agent can own variables. For example, all turtles can have a hunger variable. When the simulation runs, each turtle updates its own copy of the hunger variable. The programmer can also make global variables which only have one copy. 4.1 Turtle Variables Heading Orientation of the turtle. North = 0 degrees, East = 90 degrees, South = 180 degrees, and West = 270 degrees. Color Color of the turtle. The turtles are colored according to the Net Logo color scheme. Size Size of the turtle relative to the patches. By default, the turtles are set to size 1 which is the same size as a single patch.
4 GroupNum Which group the turtles belong to. If two turtles have the same groupnum, they will rotate and move as one unit. When a bond is formed, the groupnum of the second turtle is set to the groupnum of the first turtle. bufferx, buffery, bufferheading Before a turtle rotates or moves, it uses the buffer to check if will overlap with another turtle. For example, suppose a turtle is at patch (3,4). If the turtle wants to move up, it will set its buffer to (3,5). If patch (3,5) is empty, the turtle s coordinates (and heading) as set to the buffer s coordinates. If patch (3,5) is not empty, the buffer is discarded and the turtle will remain at its original position. 4.2 Global Variables GroupList A list of groups in the current simulation. The list is actively updated as groups bonds with each other. For example, if the simulation starts with 5 turtles, grouplist is initialized with [1, 2, 3, 4, 5]. If group 2 bonds with group 4, group 2 is removed from the list: [1, 3, 4, 5]. 5. Interface to the Outside World
5 The program has three main buttons: Setup, Run Simulation, and Clear. The user can also adjust the speed at which the simulation runs by using the speed slider on the top. The program will accept a plain text file (extension.txt) as input. The text file is divided into five sections: Type, Color, Border, Qty, and Bond function. Please see user documentation for examples and a more detailed description of each field. 6. System Creation The program will be distributed as a zip file containing several items: MFA.nlogo This is the main program file. User Documentation.txt This file discusses how to use MFA.nlogo. It discusses how the program works, how to create an MFA file, and possible applications in chemistry and biology. Premade MFA Files Five.txt, T.txt, and Cross.txt. The program will come with several premade files to be used as templates and to demonstrate how the simulation works.