Example:  Running the C Major Scale

 

In music the C Major scale starts at C and runs through the alphabet to G then continues from A to C (i.e., CDEFGABC). The following starts the model in C and gives each successive note the same duration. There is no input or output to this model as it stands.

to start hold in noteC for time 1 !

from noteC go to noteD !

from noteD go to noteE !

from noteE go to noteF !

from noteF go to noteG !

from noteG go to noteA !

from noteA go to noteB !

from noteB go to noteC !

 

hold in noteA for time  1!

hold in noteB for time  1!

hold in noteD for time  1!

hold in noteE for time  1!

hold in noteF for time  1!

hold in noteG for time  1!

An example of a compound statement that combines tow of the above is:

    hold in noteA for time  1 then go to noteB !


This text is automatically translated into the XML specification of FDDEVS.

 

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<atomicType host="localHost" modelName="scale" xmlns="http://www.saurabh-mittal.com/NewXMLSchema">

<states>

       <state>noteA</state>

       <state>noteB</state>

       <state>noteC</state>

       <state>noteD</state>

       <state>noteE</state>

       <state>noteF</state>

       <state>noteG</state>

</states>

<TimeAdvance>

       <ta>

         <state>noteA</state>

         <Timeout>1.0</Timeout>

       </ta>

       <ta>

         <state>noteB</state>

         <Timeout>1.0</Timeout>

       </ta>

       <ta>

         <state>noteC</state>

         <Timeout>1.0</Timeout>

       </ta>

       <ta>

         <state>noteD</state>

         <Timeout>1.0</Timeout>

       </ta>

       <ta>

         <state>noteE</state>

         <Timeout>1.0</Timeout>

       </ta>

       <ta>

         <state>noteF</state>

         <Timeout>1.0</Timeout>

       </ta>

       <ta>

         <state>noteG</state>

         <Timeout>1.0</Timeout>

       </ta>

</TimeAdvance>

<LamdaSet>

</LamdaSet>

<inports>

</inports>

<outports>

</outports>

<deltint>

       <InternalTransition intTransitionID="1">

         <transition>

              <StartState>noteA</StartState>

              <NextState>noteA</NextState>

         </transition>

       </InternalTransition>

       <InternalTransition intTransitionID="2">

         <transition>

              <StartState>noteA</StartState>

              <NextState>noteB</NextState>

         </transition>

       </InternalTransition>

       <InternalTransition intTransitionID="3">

         <transition>

              <StartState>noteB</StartState>

              <NextState>noteC</NextState>

         </transition>

       </InternalTransition>

       <InternalTransition intTransitionID="4">

         <transition>

              <StartState>noteC</StartState>

              <NextState>noteD</NextState>

         </transition>

       </InternalTransition>

       <InternalTransition intTransitionID="5">

         <transition>

              <StartState>noteD</StartState>

              <NextState>noteE</NextState>

         </transition>

       </InternalTransition>

       <InternalTransition intTransitionID="6">

         <transition>

              <StartState>noteE</StartState>

              <NextState>noteF</NextState>

         </transition>

       </InternalTransition>

       <InternalTransition intTransitionID="7">

         <transition>

              <StartState>noteF</StartState>

              <NextState>noteG</NextState>

         </transition>

       </InternalTransition>

       <InternalTransition intTransitionID="8">

         <transition>

              <StartState>noteG</StartState>

              <NextState>noteA</NextState>

         </transition>

       </InternalTransition>

</deltint>

    <deltext>

    </deltext>

</atomicType>

 

 

This XML file then can be opened up in the FDDEVS GUI to show the following:

The DEVSJAVA model generated from this XML is depicted by the following code segment:


 

public scale(){

this("scale");}

 

public scale(String nm){

super(nm);

}

public void initialize(){

holdIn("noteA",1.0);

}

 

public void deltint(){

if(phaseIs("noteE")){

holdIn("noteF",1.0);

}

else

if(phaseIs("noteD")){

holdIn("noteE",1.0);

       }

       else

       if(phaseIs("noteC")){

              holdIn("noteD",1.0);

       }

       else

       if(phaseIs("noteB")){

              holdIn("noteC",1.0);

       }

       else

       if(phaseIs("noteA")){

              holdIn("noteB",1.0);

       }

       else

       if(phaseIs("noteA")){

              holdIn("noteA",1.0);

       }

       else

       if(phaseIs("noteG")){

              holdIn("noteA",1.0);

       }

       else

       if(phaseIs("noteF")){

       holdIn("noteG",1.0);

       }

       else   passivate();

}

}

 

 

Adding input and output

 

To illustrate the use of external input and output in the natural language specification of an FDDEVS, we will replace the automatic start up in C by an input GoUp that will start the model from  a waiting state  when it is received. At the end of the scale an output Done will be emitted. The changed part of the text appears as:

 

 

to start passivate in waitForStart!

when in waitForStart and receive GoUp then go to noteC !

after noteB then output Done !

 

The corresponding tables look like this:

 

 

 

 

 

The changed XML file is illustrated below:

 

<TimeAdvance>

       <ta>

         <state>waitForStart</state>

         <Timeout>INF</Timeout>

       </ta>

      

</TimeAdvance>

 

 

<LamdaSet>

       <lamda>

         <state>noteB</state>

         <outport>outDone</outport>

       </lamda>

</LamdaSet>

<inports>

       <inport>inGoUp</inport>

</inports>

<outports>

       <outport>outDone</outport>

</outports>

 

 

<deltext>

       <ExternalTransition extTransitionID="1">

         <IncomingMessage>inGoUp</IncomingMessage>

         <transition>

              <StartState>noteC</StartState>

              <NextState>noteC</NextState>

         </transition>

         <scheduleIndicator>true</scheduleIndicator>

       </ExternalTransition>

</deltext>

 

 

The DEVSJAVA files are illustrated here:

 

 

public scaleUpDown(String nm){

super(nm);

       addInport("inGoUp");

       addTestInput("inGoUp",new entity());

       addTestInput("inGoUp",new entity(),1);

}

 

public void initialize(){

passivateIn("waitForStart");

}

 

public void deltext(double e, message x){

       Continue(e);

       for(int i=0; i<x.getLength(); i++){

              if(this.messageOnPort(x, "inGoUp", i)){

                     if(phaseIs("pas waitForStart sive" )){

              holdIn("noteC",1.0);

                     }

              }

       }

}

 

public message out(){

       message m = new message();

       if(phaseIs("noteB")){

              m.add(makeContent("outDone",new entity("Done")));

       }

       return m;

}

}