Friday, May 13, 2011

Non-deterministic Finite State Automaton

FSA files


Today I am going to talk about my finite state automaton project that I did for my data structures class. I am pretty proud of this one since I started this class with no C++ experience and ended it by being the first person in my study group to get it finished. In case this is a recruiter reading this who doesn't know what an FSA does, http://en.wikipedia.org/wiki/Finite-state_machine

I started off by experimenting with how I wanted to handle the edges and nodes as constructs. Then I set about planning how I wanted the FSA to get constructed by writing up simple ones on a whiteboard and experimenting with connecting them. From that I decided I was going to work my way from a single accept node back to a single start node by creating simple FSAs and pointing the end nodes to the previously constructed FSA and the start node of the last FSA becomes the start node of the entire thing.



In order to actually run the FSA, I went with an input loop that first has a loop to fully explore all epsilon connections from a list of starting nodes, adding nodes with non-epsilon connections to a second list and then having a second loop to test each node in the second list for edges that match the next character.






I use breadth first search for both printing out a text representation of the FSA and for deleting it since in both situations depth first will lead to infinite loops. Deletion is done by first putting pointers to every node in a separate list and then traversing the list and deleting everything.




Graphical representation was done via third party program Graphviz.

Edit: Thanks to Gavin, Chris, Carlos, Julian, and everyone in the Burrow that helped me learn C++ despite having homework to do themselves.

Wednesday, May 11, 2011

Scheme: Image Altering

My code : image-altering.ss
IU scheme library : c211-lib.s
 
Occasionally I will decide I want to write image altering scheme methods.

(vortex 150 5 (read-image "grid.gif"))
Vortex is probably my favorite. Each pixel references a pixel a certain offset away on a radial line, the offset being governed by a quadratic equation that smoothly goes to zero at the edges.

(wave-sin 40 (read-image "image.jpg))

Wave-sin fades in and out red, green, and blue based on a sin wave of the specified wavelength in pixels. I made this in 3 hours while I was waiting for a class.

I also did stuff for c211 including seam carving, image smoothing, and creating images whole cloth like this one I made to visualize power projection on a hexagonal grid when I was fleshing out plans for a Civ5 AI.

This is where I am posting actual code for right now

The most interesting stuff will be up top.