OPS フレームワークは物理系と観測量を実装したクラスを要求しますが、それに加えて、それらを構築するための「シミュレーション設計図」も必要とします。
前回、OPS フレームワークに定義されているインターフェース群の論理的な包含関係を見ましたが、これはシミュレーション設計図上での対応する要素の論理構造とほぼ同じです。
サンプル
物理系 (PhysicalSystem) と観測量 (ObservableSet) を表すクラスを以下のように実装したとしましょう:
package sample; public class RandomWalk1D implements PhysicalSystem{ @InitParamEntry(Integer.class) public static final String INITIAL_POSITION = "Initial Position"; ... }
package sample; public class Position implements ObservableSet{ @DataEntry(Integer.class) public static final String POSITION = "Position"; ... }
このとき、「10回反復をして、各状態をコンソールに出力する」シミュレーションのシミュレーション設計図は以下のように書きます*1:
<?xml version="1.0" encoding="UTF-8"?> <simulation xmlns="http://xmlns.org.waman/simulation/1.0"> <system class="sample.RandomWalk1D"/> <observable-set class="sample.Position"/> <init-params> <param name="Initial Position">100</param> </init-params> <iteration> <iteration-condition type="count" total="10"/> <output type="console" output-timing="all"> <entry>Position</entry> </output> </iteration> </simulation>
シミュレーション設計図のスキーマ
RELAX NG (コンパクトシンタックス)で書いたスキーマを載せておきます*2(幾つか上記のサンプルに現れていない要素を定義してますが、無くても大丈夫なものなので、読み飛ばして下さい):
default namespace rng = "http://relaxng.org/ns/structure/1.0" namespace sim = "http://xmlns.org.waman/simulation/1.0" start = Simulation Simulation = element sim:simulation{ System & ObservableSet* & Properties? & InitParams? & DataManager? & Iteration } System = element sim:system {AnyAttribute*, AnyElement*} ObservableSet = element sim:observable-set {AnyAttribute*, AnyElement*} Properties = element sim:properties { element sim:property {attribute name {text}, text}+ } InitParams = element sim:init-params{ element sim:param {attribute name {text}, text}+ } DataManager = element sim:data-manager {TypeOrClassAttribute, AnyAttribute*} Iteration = element sim:iteration{ AnyAttribute* & Iteration* & IterationCondition? & Output* } IterationCondition = element sim:iteration-condition { TypeOrClassAttribute, AnyAttribute*, IterationCondition* } Output = element sim:output { TypeOrClassAttribute, attribute output-timing {text}, AnyAttribute*, element sim:entry {text}* } TypeOrClassAttribute = (attribute type {text} | attribute class {text}) AnyAttribute = attribute * {text} AnyElement = element *{AnyAttribute* & AnyElement* & text}