Changed lines at line 5
5: - [ICFP 2004/Screenshots]
6: - [ICFP 2004/Survey]
7: 1 General {anchor:General}
8: ICFP stands for International Conference on Functional Programming. They organise an anual interational programming contest. See the
9: {link:ICFP 2004 Contest Website|http://www.cis.upenn.edu/proj/plclub/contest}
10: [Jörg|Joerg], [Allan] and [me|georg] attended the contest. Our team name was Formicoideas and we used primary haskell. Sorry, but we used also java to implement a graphical user frontend to be able to test our solutions.
11: 1.1 Why Formicoideas?
12: Well the contest was about ants and the biological name for family is Formicoidea.
13: 1.1 Teamwork
14: Because [Allan] lives in Edinburgh and we live in Leipzig we have been forced to program territorial distributed.
15: This worked great since we used CVS, {link:Teamspeak|http://www.teamspeak.org/} and ICQ. I would say the productivity was larger than if we all would have worked together in the labs of the university or somewhere else. The reason is that you know you computer and the enviroment and it is calm if you need it.
16: 1 The Task {anchor:The_Task}
17: The task description and some maps can be downloaded from the ICFP contest webpage or from the panel beside ({link:task.tgz|http://www.flexman.homeip.net/space/ICFP+2004/task.tgz}).
18: Here a rough decription what it was about:
19: The task was to write a program that controls an ant. It was basicly a finite state machine (FSM) that had to be developed. The programming language was very low level with absolute jumps and so on. Please note that there is no memory in a FSM, so cannot store anything.
20: There are two teams the red and the black colony. Every colony has an anthill of the same size and the world consists of hexogonal cells. There are rocky cells where you can't go on and there are cells with food. The overall goal was to bring as many food as possible to your anthill. In order to perform that the ant can mark a cell with 6 different markers and is able to sense the own cell and the ahead, left and right cell.
21: 1 Our Approach {anchor:Our_Approach}
22: In order to simplify this task we decided to build a translator from a
23: slightly higher level language than that of the ant finite state machine
24: language. This language is called pheromone and the compiler is phec for
25: pheromone compiler.
26: We also built a Simulator as described in the task description to evaluate
27: our ant programs, and a Java front end to visually deploy the simulator in
28: order to aid debugging of the ant programs.
29: Here the modules we have written:
30: - [Phec (Pheromone Compiler)|ICFP 2004/Phec]
31: - [ICFP 2004/Simulator]
32: - [ICFP 2004/Frontend]
33: 1.1 Formicoideas strategy
34: 1.1 Usage
35: You can type
36: __make all__
37: in the tools directory to compile everything. The other option you have is to compile modules (Phec, Simulator and Frontend) seperatly be typeing __make__ inside their directories. You will need ghc (haskell compiler) version 6.2
38: and the java sdk installed. Note that the java sdk is just needed if you want to recompile the frontend. Because the class files are included a java runtime is sufficient.
39: In the tools directory is a ./run.sh shell script to run
40: the simulator with the graphical front end, this can be used with
41: {code:bash}
42: ./run.sh task/sample0.world --red=source2/initial.phec
43: --black=Simulator/test.prog
44: {code}
45: Please note that the world files have to be downloaded sperately ({link:task.tgz|http://www.flexman.homeip.net/space/ICFP+2004/task.tgz}).
46: In the above example the file __source2/initial.phec__ is compiled first whereas the __Simulator/test.prog__ is allready compiled and is used just as it is.
47: There are a plenty of commandline switches of the main program. Start __run -h__ for a usage information.
48: For example there is a console front end included. The following call
49: makes the simulator run for 100 steps:
50: {code:bash}
51: ./run --world=task/sample0.world --red=testing/initial.phec
52: --black=Simulator/test.prog --console -s100
53: {code}
54: To run the simulator without any frontend use:
55: {code:bash}
56: ./run --world=task/sample0.world --red=testing/initial.phec
57: --black=Simulator/test.prog
58: {code}
59: In any case you will get a final result, who as won and so on. Here the compete list of parameters:
60: {code}
61: Usage: run [OPTION...]
62: -r FILE --red=FILE red brain file. There are 2 possible endings: .phec and .prog.
63: If it ends with .phec it is compiled to .prog and .ant
64: -b FILE --black=FILE black brain file. There are 2 possible endings: .phec and .prog.
65: If it ends with .phec it is compiled to .prog and .ant
66: -c --justcompile just compile don't simulate
67: -w[FILE] --world[=FILE] world file to load (default: tiny.world)
68: -d[FILE] --dump[=FILE] write dump output to FILE (default: dump.trace)
69: -s[NUM] --steps[=NUM] number of simulation steps to run (default: 1000)
70: -f --frontend writes the output for the frontend to stdout
71: -t --console uses console output (xterm tested colors)
72: --random[=NUM] randomseed to use (default: 12345)
73: {code}
74: 1.1 Submission
75: We submitted our submission 3 minutes before the deadline and - how to say - I was really nervous. It is every year a last minute hack!
76: The submission can be downloaded from the panel beside ({link:formicoideas.tgz|http://www.flexman.homeip.net/space/ICFP+2004/formicoideas.tgz}).
77: 1.1 A bit Statistic
78: I let {link:sloccount|http://www.dwheeler.com/sloccount/} run over the whole code we produced in the 3 days. Here the results:
79: {code}
80: SLOC Directory SLOC-by-Language (Sorted)
81: 747 Simulator haskell=747
82: 677 Phec haskell=677
83: 440 Frontend java=438,sh=2
84: 209 top_dir haskell=187,perl=16,sh=6
85: Totals grouped by language (dominant language first):
86: haskell: 1611 (77.71%)
87: java: 438 (21.13%)
88: perl: 16 (0.77%)
89: sh: 8 (0.39%)
90: Total Physical Source Lines of Code (SLOC) = 2,073
91: Development Effort Estimate, Person-Years (Person-Months) = 0.43 (5.16)
92: (Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
93: Schedule Estimate, Years (Months) = 0.39 (4.66)
94: (Basic COCOMO model, Months = 2.5 * (person-months**0.38))
95: Estimated Average Number of Developers (Effort/Schedule) = 1.11
96: Total Estimated Cost to Develop = $ 58,086
97: (average salary = $56,286/year, overhead = 2.40).
98: {code}
99: Additionally we have written 536 lines of phec code. I have counted that with:
100: {code:bash}
101: cat *.phec | grep -v "^[ ]*$" | grep -v "^--" | wc
102: - [ICFP 2004/Survey]
103: 1 General {anchor:General}
104: ICFP stands for International Conference on Functional Programming. They organise an anual interational programming contest. See the
105: {link:ICFP 2004 Contest Website|http://www.cis.upenn.edu/proj/plclub/contest}
106: [Jörg], [Allan] and [me|georg] attended the contest. Our team name was Formicoideas and we used primary haskell. Sorry, but we used also java to implement a graphical user frontend to be able to test our solutions.
107: 1.1 Why Formicoideas?
108: Well the contest was about ants and the biological name for family is Formicoidea.
109: 1.1 Teamwork
110: Because [Allan] lives in Edinburgh and we live in Leipzig we have been forced to program territorial distributed.
111: This worked great since we used CVS, {link:Teamspeak|http://www.teamspeak.org/} and ICQ. I would say the productivity was larger than if we all would have worked together in the labs of the university or somewhere else. The reason is that you know you computer and the enviroment and it is calm if you need it.
112: 1 The Task {anchor:The_Task}
113: The task description and some maps can be downloaded from the ICFP contest webpage or from the panel beside ({link:task.tgz|http://www.flexman.homeip.net/space/ICFP+2004/task.tgz}).
114: Here a rough decription what it was about:
115: The task was to write a program that controls an ant. It was basicly a finite state machine (FSM) that had to be developed. The programming language was very low level with absolute jumps and so on. Please note that there is no memory in a FSM, so cannot store anything.
116: There are two teams the red and the black colony. Every colony has an anthill of the same size and the world consists of hexogonal cells. There are rocky cells where you can't go on and there are cells with food. The overall goal was to bring as many food as possible to your anthill. In order to perform that the ant can mark a cell with 6 different markers and is able to sense the own cell and the ahead, left and right cell.
117: 1 Our Approach {anchor:Our_Approach}
118: In order to simplify this task we decided to build a translator from a
119: slightly higher level language than that of the ant finite state machine
120: language. This language is called pheromone and the compiler is phec for
121: pheromone compiler.
122: We also built a Simulator as described in the task description to evaluate
123: our ant programs, and a Java front end to visually deploy the simulator in
124: order to aid debugging of the ant programs.
125: Here the modules we have written:
126: - [Phec (Pheromone Compiler)|ICFP 2004/Phec]
127: - [ICFP 2004/Simulator]
128: - [ICFP 2004/Frontend]
129: 1.1 Formicoideas strategy
130: According to the task the ants are controlled by a final state machine described by an assembler like low level code. Alls ants work independend. The ants have no memory, their state is defined by the current line of code that is executed. Of couse it is possible to simulate something like a memory by splitting the program into special address ranges. And therefor it is necessary to have an high level language with macros, the possibility to multiply blocks and more, see Phec language. Ants can leave marks on fields they run over, there are six markers that can be turned on or off. That means we can save 6 bits of information on every field.
131: The basic behaviours of an ant are:
132: 1. explore and search for food
133: 2. bring food back home
134: It is necessary that an ant easily finds the way to home. Our approach is an initial spreading of path information. Initially all ants start at the home base. The idea is that some ants are choosen to run nearly straigth away from the home base and on every field thay mark the direction to go back to the home base. First we thought about writing a number 0..5 in every field and code to give the direction within a hexagon. The disadvantage of this approache is that we need 3 bits (we have only 6) and every ant would have to remember its direction through its whole live. Normally ant's don't know the direction they are looking, it would have been necessary to split the whole code into 6 address ranges and keep tracking of the current direction whatever the ant is doing.
135: We choose an different approach hat overcomes this problems. The idea is to code an gradient field descending with more distance from the home base. For this field only 2 bits are needed. Like described at the start of the match some ants will start running away from the home base and write gradient information 3,2,1,3,2,1,3,... and so on. The value 0 is reserved for an empty field without way mark. If an ant has found food and searches for the home base it runs straigt until it finds a field with gradient information. Then it starts turning arround and searching for neigboring field with (gradient + 1), the field is ascending in direction towards the home base.
136: The same idea is reused for faster finding the food hills. If an ants finds food, it picks it up and then moves back to the home base. During walking back it marks the way to the food with the gradient information. We wanted to have someting like in nature: unused food tracks should get weaker over time. Therefor we use the last free 2 bits to give the food track an strength information. Ants that carry food will write the gradient with strength 3.
137: Normal ants are randomly exploring the landscape and hope to find food. If they find an food track they will follow it and decrement the strength of the track in every step. If the food at a certain place is empty the tracks that lead the this place will be removed over time.
138: Yes that is our approach: 2 bits for home base gradient, 2 bits for food gradient and 2 bits for food path strength. The approch is tested and works. For the given sample maps the average time to collect all food and bring it to the home base is 50,000 steps.
139: Unfortunatelly we didn't get the algorithm to work until the contest submission stop. We would have needed 4 hours more :( We submitted two unfinished versions. One that can't follow food tracks and the other follows that but with a bug that lieds to ant dead lock. Nevertheless we finished the algorithm, now it works fine and we are looking for testing it against the winner ant :)
140: 1.1 Usage
141: You can type
142: __make all__
143: in the tools directory to compile everything. The other option you have is to compile modules (Phec, Simulator and Frontend) seperatly be typeing __make__ inside their directories. You will need ghc (haskell compiler) version 6.2
144: and the java sdk installed. Note that the java sdk is just needed if you want to recompile the frontend. Because the class files are included a java runtime is sufficient.
145: In the tools directory is a ./run.sh shell script to run
146: the simulator with the graphical front end, this can be used with
147: {code:bash}
148: ./run.sh task/sample0.world --red=source2/initial.phec
149: --black=Simulator/test.prog
150: {code}
151: Please note that the world files have to be downloaded sperately ({link:task.tgz|http://www.flexman.homeip.net/space/ICFP+2004/task.tgz}).
152: In the above example the file __source2/initial.phec__ is compiled first whereas the __Simulator/test.prog__ is allready compiled and is used just as it is.
153: There are a plenty of commandline switches of the main program. Start __run -h__ for a usage information.
154: For example there is a console front end included. The following call
155: makes the simulator run for 100 steps:
156: {code:bash}
157: ./run --world=task/sample0.world --red=testing/initial.phec
158: --black=Simulator/test.prog --console -s100
159: {code}
160: To run the simulator without any frontend use:
161: {code:bash}
162: ./run --world=task/sample0.world --red=testing/initial.phec
163: --black=Simulator/test.prog
164: {code}
165: In any case you will get a final result, who as won and so on.
166: 1.1 Submission
167: We submitted our submission 3 minutes before the deadline and - how to say - I was really nervous. It is every year a last minute hack!
168: The submission can be downloaded from the panel beside ({link:formicoideas.tgz|http://www.flexman.homeip.net/space/ICFP+2004/formicoideas.tgz}).
169: 1.1 A bit Statistic
170: I let {link:sloccount|http://www.dwheeler.com/sloccount/} run over the whole code we produced in the 3 days. Here the results:
171: {code}
172: SLOC Directory SLOC-by-Language (Sorted)
173: 747 Simulator haskell=747
174: 677 Phec haskell=677
175: 440 Frontend java=438,sh=2
176: 209 top_dir haskell=187,perl=16,sh=6
177: Totals grouped by language (dominant language first):
178: haskell: 1611 (77.71%)
179: java: 438 (21.13%)
180: perl: 16 (0.77%)
181: sh: 8 (0.39%)
182: Total Physical Source Lines of Code (SLOC) = 2,073
183: Development Effort Estimate, Person-Years (Person-Months) = 0.43 (5.16)
184: (Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
185: Schedule Estimate, Years (Months) = 0.39 (4.66)
186: (Basic COCOMO model, Months = 2.5 * (person-months**0.38))
187: Estimated Average Number of Developers (Effort/Schedule) = 1.11
188: Total Estimated Cost to Develop = $ 58,086
189: (average salary = $56,286/year, overhead = 2.40).