Docsity

DEVSJAVA: Understanding Containers, Classes, and Methods in DEVS Java Implementation, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
DEVSJAVA CLASSES AND METHODS
Before going further, we will briefly discuss the implementation of DEVS in Java. A more complete
description of the implementation is in the DEVSJAVA reference guide available from the web site
www.acims.arizona.edu under Software. You will need to know the basic class hierarchy and methods to
be able to write DEVS models in DEVSJAVA. We’ll close this chapter with a discussion of the
implementation of the siso class which will give you a little more insight into how both the generic devs
classes and the siso class work.
Container Classes
bag
function
set
relation
add(entity)
remove(entity1,entity2)
assoc(entity) -> entity
assoc_all(entity)->set
replace(entity1,entity2)
entity
add(entity1,entity2)
is_in(entity) -> boolean
container
add(entity)
get_length()-> int
list
queue stack
insert(entity,int)
list_ref(int)
remove(int)
front()->entity
order
top()->entity
pop [=remove]
push [=add]
greater_than(entity)-> boolean
get_max -> entity
pair
get_key()->entity
get_value()->entity
container()
remove(entity)
number_of(entity) -> int
bag()
set()
relation()
function()
remove(entity)
get_name() -> String
equal(entity) -> boolean
entity(String)
eq(String) -> boolean
pair(entity1,entity2)
add(entity)
order()
remove()
queue() stack()
list()
Figure 1 Class hierarchy of container classes
DEVSJAVA employs two packages to implement the DEVS concepts. Container classes, used to hold
instances of objects, are. implemented in the Package Zcontainer. The inheritance hierarchy of container
classes is shown in Figure 1. The classes are roughly characterized as follows:
entity - the base class for all classes of objects to be put into containers
pair - holds a pair of entities called key and value
container - the base class for container classes, provides basic services for the derived classes
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download DEVSJAVA: Understanding Containers, Classes, and Methods in DEVS Java Implementation and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

DEVSJAVA CLASSES AND METHODS

Before going further, we will briefly discuss the implementation of DEVS in Java. A more complete

description of the implementation is in the DEVSJAVA reference guide available from the web site

www.acims.arizona.edu under Software. You will need to know the basic class hierarchy and methods to

be able to write DEVS models in DEVSJAVA. We’ll close this chapter with a discussion of the

implementation of the siso class which will give you a little more insight into how both the generic devs

classes and the siso class work.

Container Classes

bag function set relation add(entity) remove(entity1,entity2) assoc(entity) -> entity assoc_all(entity)->set replace(entity1,entity2) entity add(entity1,entity2) is_in(entity) -> boolean container add(entity) get_length()-> int queue stack list insert(entity,int) list_ref(int) remove(int) front()->entity order top()->entity pop [=remove] push [=add] greater_than(entity)-> boolean get_max -> entity pair get_key()->entity get_value()->entity container() remove(entity) number_of(entity) -> int bag() set() relation() function() remove(entity) get_name() -> String equal(entity) -> boolean entity(String) eq(String) -> boolean pair(entity1,entity2) add(entity) order() remove() queue() stack() list()

Figure 1 Class hierarchy of container classes

DEVSJAVA employs two packages to implement the DEVS concepts. Container classes, used to hold

instances of objects, are. implemented in the Package Zcontainer. The inheritance hierarchy of container

classes is shown in Figure 1. The classes are roughly characterized as follows:

 entity - the base class for all classes of objects to be put into containers

 pair - holds a pair of entities called key and value

 container - the base class for container classes, provides basic services for the derived classes

 bag - counts numbers of object occurrences

 set - only one occurrence of any object is allowed in.

 relation - is a set of key-value pairs, used in dictionary fashion

 function - is a relation in which only one occurrence of any key allowed

 order - maintains items in given order

 queue - maintains items in first-in/first-out (FIFO) order

 stack - maintains items in last-in/first-out (LIFO) order

 list - maintains items in order determined by an insertion index

DEVS Classes

The DEVS system, proper, is implemented in a package called Zdevs as a layer over the Zcontainer

package. The inheritance hierarchy illustrated (somewhat simplified) in Figure 2. Atomic and coupled are

the main derived classes of devs ,. the base class of the DEVS sub-hierarchy. Class digraph is a main

subclass of class coupled which has a query, get_component(). This returns the components as a

Zcontainer set that contains devs instances. Such instances may be either from either atomic or

recursively, digraph classes. Typically, in developing an application, you derive classes from these basic

classes. Of course, instances of such user-defined classes can also be components. Since components of a

digraph may themselves by digraph instances, the implementation supports the fundamental concept of

DEVS  hierarchical construction.

Class message is derived from the Zcontainer class, bag. Messages are passed among components in a

coupled model. A message holds instances of class content, with slots for port, p , and val The latter

carries an entity instance transmitted from sender to receiver. Such a value can be an instance of any

derived class of entity whether defined by the system or the user. Since derived classes of devs are

included , we have the remarkable consequence that model components may also be transmitted from one

component to another!

devs entity atomic Legend inherits can hold container message content content atomic(String) message() p->String val->entity make_content(String,entity)->content message_on_port(message,String,int)->entity deltext(int,message) deltint() delcon(int,message) out()->message ta()->int digraph devs get_components()->set add(devs) digraph(String) entity entity coupled get_val_on_port(String,int);

Class devs

Class devs, the base class for the two main model classes atomic and coupled, is condensed in the

following:

public class devs extends entity { protected double tL , tN ; public final double INFINITY = Double.POSITIVE_INFINITY; public devs (String name){ super(name); … } public void initialize (){ tL = 0; tN = tL + ta(); output = null; } public void inject (String p, entity val, double e){ message in = new message(); content co = make_content(p, val); in.add(co); } public content make_content (String p, entity value){ return new content(p,value); } public boolean message_on_port (message x, String p, int i){ if (!inports.is_in_name(p)) System.out.println( "Warning: model :" + name + " inport: " + p + " has not been declared" ); return x.on_port(p, i); } }

Class message

Class message is derived from class bag and holds instances of class content, with slots for port, p ,

and valude, val (an entity).

public class message extends bag{ public message(){ super(); } public content read(int i) { // returns the i’th content in the message } public boolean on_port(String portName, int i) { content con = read(i); return portName.equals(con.p); } public entity get_val_on_port(String portName, int i) { if (on_port(portName,i)) { return read(i).val; } return null; } }

Class coupled

Coupled is the major class which embodies the hierarchical model composition constructs of the DEVS

formalism. A coupled model is defined by specifying its component models. Components are instances of

the devs class (hence, instances of coupled are allowed) thus enabling hierarchical composition.

public class coupled extends devs { set components; public coupled (String nm){ super(nm); components = new set(); set_parent(null); } public void add (devs b){ components.add(b); b.set_parent(this); } public set get_components (){ return components; } } Class digraph

Class digraph is a derived class of coupled which enables you to define a coupled model in an explicit

manner. In addition to components, it enables you to specify the coupling relation which establishes the

desired communication links among the components (internal coupling) and between them and the external

world (external input and external output coupling).

public class digraph extends coupled { couprel Coupling; public digraph (String nm){ super(nm); Coupling = new couprel(); inports.add("in"); outports.add("out"); } public void Add_coupling (devs d1, String p1, devs d2, String p2){ port por1 = new port(p1); port por2 = new port(p2); Coupling.ADD(d1, por1, d2, por2); } }

Implementing the Single Input/Single Output DEVS

The expressive power of DEVSJAVA enables atomic models to handle arbitrary simultaneous arrival of

arbitrary values on arbitrary ports. This power can be cut down to enable only one input at a time (as in

Classic DEVS) and even further, one number at a time. Why would we do so? The resulting classes are

much easier to work with for novices without much object-oriented programming experience. Further, the

definitions of the new classes are instructive in the underlying object-oriented approach taken in

DEVSJAVA implementation. The classes, classic and siso, are in inheritance order in Figure 3.

atomic

classic

siso

Figure 3 Derived Classes classic and siso

Classic introduces a new external transition function Deltext to restrict the deltext method inherited from

atomic to inputs containing a single content only. Siso then further restricts Deltext so that it expects

single number inputs.

Class classic public class classic extends atomic{ public classic(String name){ super(name); } public content get_content(message x){ entity ent = x.get_head().get_ent(); return (content)ent; } public void Deltext(double e,content con){ } //virtual for single input at a time public void deltext(double e,message x) { //deltext, as invoked by the simulator, calls Deltext (as defined by the modeler) Deltext(e,get_content(x)); } } Class siso