Tuesday, July 2, 2013

Communicating with PRISM / Days 21-23

Day 21 - Wednesday June 26
Today I did complete the goal I set on the last blog post: getting JPF-v7 and jpf-probabilistic to work well together. It (sadly) still took the whole day. After doing everything "by-the-book" several times, looking through compiler and debugging logs, and even resorting to putting a bunch of println calls in everywhere to debug, I was still getting really odd errors. At first they were compiler and JDK-based, but in the end resulted in run-time errors (JPF having Null pointer exceptions at start-up!). I don't know what plagued the latter few: I could never resolve that build. However, I decided to try a fresh install of Eclipse and JPF, and after installing all the appropriate plug-ins and extensions, I rebuilt all the code and it worked. I think this is a terrible fix, but it's one that works: I'm happy. I'm disappointed that I didn't try this earlier (would have saved two days) and that I didn't find the root-cause of the issue, but honestly, that was taking too long so I'm glad something worked. I also don't want to rely on this in the future, so I hope whatever caused it before doesn't re-appear.

Day 22 - Thursday June 27 & Friday June 28
I'm splitting this day in two because I was fairly distracted both days by external events, and I don't think either was really worth more than a half-day's work. That being said, I've cleared my next weekend to make up the time; I don't want to get into the habit of not putting in the time this project needs. However, I did do some work as I mentioned: the next task after repairing the code was to get a Markov chain passed into PRISM so that PRISM can check the model. Although I had played around with interfacing with PRISM, the first real task is never as smooth as when you're just having fun. So this took some time, but the end result was a success: PRISM takes in a Markov chain from the JPF listener, creates a class with it, and then prints the text representation of it. However, due to my distraction I forgot all I read before, and did this poorly: I created another running Java program, connected to it through ports, and ran the PRISM code there (because I forgot all about class-paths from my earlier reading in my distraction). It worked (as the native Java libraries didn't seem to have compilation issues like using external programs), but I wasn't proud. Read on to see that I fixed that!

Day 23 - Monday July 1
Today was also not as focused on the project because it was a national holiday here (Canada Day), and while I didn't really go out, I was often called away by family or friends for short periods of time, so this is part of the reason why I want to work both days next weekend (and given the time lost to getting v7 to work, I may very well work the weekend after that too!).  That being said, I did spend time coding: I was working towards removing the sloppy connection between JPF and PRISM: I didn't want to use ports and so I remembered that you can just modify what JPF considers as part of the native classes to load: I spent all day undoing the old code and making the much, much simpler connector: only a listener (and whatever classes I've used from jpf-probabilistic). I also spent some time cleaning up the code, and the day ended when I pushed a new update--which is a habit I want to make daily (and these posts, since I have been slacking on writing them on same-day).

For an example, jpf-probabilistic generates the following Markov chain of a Biased Die:
0 ------> 1
1 -0.30-> 2
2 -0.30-> 3
3 -0.30-> 2
3 -0.70-> 4 *
2 -0.70-> 5
5 -0.30-> 4 *
5 -0.70-> 4 *
1 -0.70-> 6
6 -0.30-> 7
7 -0.30-> 4*
7 -0.70-> 4*
6 -0.70-> 8
8 -0.30-> 4*
8 -0.70-> 6
which I then use to create a basic model in PRISM, and I call toString() on, and that gives me:
trans: [ 0: {}, 1: {2=0.3, 6=0.7}, 2: {3=0.3, 5=0.7}, 3: {2=0.3, 4=0.7}, 4: {}, 5: {4=1.0}, 6: {7=0.3, 8=0.7}, 7: {4=1.0}, 8: {4=0.3, 6=0.7}, 9: {}, 10: {}, 11: {}, 12: {}, 13: {}, 14: {}, 15: {} ]
It's not much--but it shows that PRISM and JPF are connected--which was the goal here. Up next will be some more interesting things.

1 comment:

  1. Note: this one is missing a transition "0--->1". This has since been corrected.

    ReplyDelete