This week saw a rewrite of the whole rule system. Based on my reflections of last time, I mostly worked it out on paper first. Yesterday and today I coded it together, and lo and behold, it worked. Few small changes from what I had on paper of course, but the main idea seems right. The commit can be found on gitweb.
So, what is left? First of all, I'll do some parsing. The rules and constraints are currently rather verbose to create. It should be possible to ease that a bit to allow easy creation of rules - that is the entire point of the project after all :). I tried my hand at it earlier but I couldn't really come up with something elegant. Anyway, I'll just code up something that does the job (= regular expressions) and if it turns out to give problems later on, I can always change it to something more powerful. Context free grammars or something, I don't have much experience with parse tree generation.
There's also a few more bugs to clear and some tests to run. Performance tests might also be useful, as I doubt the current system will be able to handle complex rules in big universes. Then again, there might be a load of speedups possible. Stress tests and profiling should help out if the need arises.
Goals for next week are: 1) getting a few more important cases to run, mostly make rules not fire infinitely and allow a constraint to be multiple times in the head. And 2) get the parsing to work. The parsing should be fairly straightforward, but part 1 might be a bit more troublesome. And I'm not entirely sure I'll be able to make it, as I'll be away most of the week to prepare the next year of our student organization. I'm not sure how much free time we'll get, neither how much of it I'll be sober enough to code. ;)
Friday, June 27, 2008
A new hope (week 4 status report)
Saturday, June 21, 2008
Trouble along the way (week 4 status report)
It's been such a long time... Let's see. Plans for this week were getting back on track and start with the rule representation. It worked out a bit differently though.
As noted earlier, the weekend was "lost" to studying, with an exam on Monday. That leaves just one exam left, next Monday. Data Mining this time around. Not too much work, still I'll be glad when it is over.
Then, Tuesday I managed to get some work done. I added the constraint store which seems to be in working order, and I made the bot send out a few random order to prove the whole structure can actually behave like a bot.
Wednesday, I sadly had to go to a funeral of a colleague student. Someone who is three years younger than me, in perfect health, just bam, the end. Heart attack. A professor nailed it perfectly in his speech: "this is a contradiction". Makes you think for a while...
And while I think (and hope) it's a coincidence, I've had loads of trouble with my SoC from Wednesday onwards. I've started on the rule representation, and it just doesn't seem to work out. It seems as if my class structure is wrong, I need references to all sorts of objects at the most illogical places, I have tons of code I don't seem to need, etc. Really bad signs. For example, I have pretty much no idea how my logical variables are holding up. They have a dependency with Context which seemed like a good idea at the time, but it currently means I have to create Contexts every time I want to create a unique variable, and that might spell trouble when two variables actually should be unified. Two unified variables in different contexts, only trouble can follow. There's a whole load of other small things in the current state of the code that confuse me.
Today I've been mostly thinking about that mess and especially how I got into it. It seems I got the focus on the wrong things. I thought the unification and constraint representation would be the central area with the most risk, so I started there. It now turns out I can't really use it the way it's been written. It made me think about my design process. I usually code "bottom up", in the way that I start with the small objects or the high risk parts, test them extensively, and once I know they work I'll link them together to create the bigger structure. This has always worked for me. However, not now. Now, I have interface gaps and strange dependencies. And that in <400 lines of code. I still can't grasp it.
So, back to the drawing board it was, "top down" now. I identified the external interface I need from my rule system. However, I'm not much further than that at the moment. There's a few things interacting in ways that make me twitchy. I think I'm trying to cling too much to my old code and carry those mismatched concepts into the new design, which therefor keeps failing. Or something. I'll just try to take a look at it tomorrow with a fresh head.
So this weekend, I'm going to crack down on that design. By next week, I want to have it coded and done with. Really, if that works, it's the central framework done and I can begin filling in the pieces as required.
Oh well, it's all part of the design process. At least I'm starting to know the domain pretty well by now.
Saturday, June 14, 2008
Nothing to see here, move along (week 3 status report)
Exams, not much done. If you want information about routing protocols on the internet (from VLAN over link state to BGP), DNS spoofing, block designs, Polya theory or deadlock prevention I'm all here though.
Although, Wednesday, I did take a look at trying to get the constraint store working. Thinking my design wasn't really going to cut it, I started to read some papers about other CHR implementations, realizing that I'm actually getting far away from pure CHR. Well, doesn't matter. It'll be a system inspired by CHR and other expert rule systems then. I also realized there might be a bit more work to it than I thought. Oh well, I love a challenge.
So, next weekend will still be spent studying. Exam Monday, after that a bit more work on a paper that has to be handed in Tuesday. From Tuesday on I should finally be able to work on SoC again.
Also something to keep in mind: next time I'll write a 3D client. I mean, seriously, look at this beauty. All I might have to show off eventually is a bunch of spreadsheet graphs.
Friday, June 6, 2008
EX-TER-MI-NATE! U-NI-FI-CATE! (week 2 status report)
I'm sorry. The new season is going very strong, even without Daleks. Thinking about it, dalek-ai would also have been a cool and fitting name. But we're here to discuss other matters...
The goal for this week was to have a working constraint store implemented in Python. I got about 90% of that. I finished the representation of the constraints, variables and various Python terms. It is possible to parse a string like "pred(C,3,pred(C))" and match it with "pred('ab',3,A)". Variables will be bound correctly, impossible unifications will be detected, etc. This is a huge step forwards, I think: matching is central in the system I want and it was one of the more tricky things to get right. My notes of a course on AI I followed have helped me nicely here - never thought I'd have to implement the Martelli-Montanari algorithm but good thing I keep my notes :). I also added a whole load of testcases because I wasn't really sure about getting all of this right. I might have some regressions later on if I have to tweak the design, so I'll be able to notice and resolve that quickly with the tests. It seems unit testing fits into Python nicely, "batteries included" is a good selling point indeed.
So what I didn't implement was a fully working constraint store. Now, I don't think it'll be really hard to do, I just need to store a collections (a Python set should do) of those constraints and I should manage to get them out again by matching (which already works). However, I just didn't find the time anymore to actually implement it.
I have exams right now, and they're pretty much taking all my time from me. First time ever I'm actively exploiting the timing of my exam (whether it's before or after noon) in my schedule. Previous years I'd always take the rest of the day off, but that won't be possible this year... So I'm slowing down a bit on TP. Next week, I just plan to finish the constraint store. After next week, I should have a few days to work on TP (assuming I can keep myself awake), so I'll be doing a bit more, but right now, it's just not possible.
I've also improved the wiki page a bit. It now has some milestones and, perhaps more important, my current planning. I had to change it around a bit because I'll be spending more time on designing the rule engine and less time on individual rules. Which is all in all a good thing, as that should allow fairly rapid development of new AI variations. I'm sure you're all waiting for the epic battle of the Human and the 7 slightly-different-yet-indistinguishable AIs: Doc-AI, Grumpy-AI, Happy-AI, Sneezy-AI, Bashful-AI, Sleepy-AI, and Dopey-AI.
Actually, that might be cool.
Sunday, June 1, 2008
After a week... (week 1 status report)
After a week of SoC, I haven't actually done really much. Well, I've done a lot, but not much to show off.The plans for last week were to create a connecting client and to finalize the design. I've finished the first and half-finished the second, read on...
The connecting client was fairly trivial given the amount of work that is done by libtpclient-py. Still, I had to study libtpclient-py extensively and I now think I know how to use it. I'm not the only student to use this library, and the research by jmingtan (who is working on a new client using pyOgre) and his correspondence with mithro (the creator and until recently only user of the library) has helped me a lot. They started some documentation on the wiki that summarizes the exact information I needed: how to connect to the server and how to use the cache. The information is already slightly out of date, even - the ("long" awaited) separation between the threading and the connection is done. So with all that information, I made the client by actually just copying some code from tpsai-py. It's a start.
Most of the start of the week, I tried to understand the way object, orders, the cache and the server interact in libtpclient-py. I made small changes in tpsai-py (a client using an old version of the library, and in need of updates) to get it working with the newest version. Not having any knowledge of how exactly tpsai-py works or what the changes between the old and new lib are, I didn't really dare to change a lot. I think I got it to send orders to the server eventually, but I got a bit confused about whether I was doing things right. Especially the new "create before" and "create after" commands, deprecating the older "create" command (which takes a slot where to place it, if I got it right), made me feel unsure about what I was doing. While I could probably sort it out, that would take too much work. I've got a more advanced bot to write. If it's finished, I can reimplement the tpsai-py reasoning in daneel-ai if that's still wanted. ;)
I spend today thinking about the design and writing about my idea on the wiki (comments always welcome!). I've done research on CHR, the language I plan to use/steal ideas from/... It's mostly an academic language, so I've read a few papers to gather ideas. Most of CHR is done in Prolog which gives a really powerful combination, and there's also a Java implementation which looks fairly cumbersome. Since Python (unfortunately?) leans closer to Java than to Prolog, I have to think carefully about how to design CHR in Python. Some things I'm used to from the SWIProlog implementation are not a given: non-ground variables, backtracking, matching, ... Backtracking will probably have to be dropped, but the other two (and probably a lot of other things) are a requirement for a working CHR implementation. So I suppose I'll have some happy fun time coding these declarative concepts in Python.
The design isn't really finished (see the wiki page for status), but I think it's a bit hard to continue at the moment. I have the big parts, so I think it's time to start coding on the small parts and see where I get blocked.
All in all, I didn't have that much time this week, and it won't be better the next few weeks. Thursday to Friday I worked on a school project. Fairly interesting thing: a comparison of a few very high level AI languages for constraint problems (yep, including CHR). Not finished yet, I'm afraid, but we did the hard work (implement a sudoku/kuromasu solver and run some tests), now we just have to write the report. Saturday we had a family gathering for a birthday. And inbetween I'm still studying, operating systems at the moment.
Next week, I'll start on the CHR implementation. I plan to have the constraint store with the ability to add knowledge to it. This will involve creating a few classes to represent the store, constraints, logical variables, and who knows what else I'll encounter. After that, I'll see if I can get the entries of the cache into the constraint store, which is essentially the initialization phase. Apart from that, I'll spend my time with computer networks, as I have exam of it next week Monday, the 8th. And we still need to write that paper on constraint languages. Busy times...