Introduction to DEVSJAVA

Slides:



Advertisements
Similar presentations
1 Various Methods of Populating Arrays Randomly generated integers.
Advertisements

Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Introduction to Computers and Programming Lecture 8: More Loops New York University.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Develop DEVS Models Using DEVSJAVA Dr. Feng Gu. DEVS atomic model Elements of an atomic model input events output events state variables state transition.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
ECE 449/549 Class Notes # 4 DEVS Models for Processing and Coordinating Workflow / System Entity Structure Sept
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Method Overloading  Methods of the same name can be declared in the same class for different sets of parameters  As the number, types and order of the.
Simulator Protocol. coordinator simulator Component tN tN. tL After each transition tN = t + ta(), tL = t simulator Component tN tN. tL simulator Component.
How do you do the following? Find the number of scores within 3 points of the average of 10 scores? What kind of a tool do you need? Today’s notes: Include.
ECE 449/549 Class Notes #3 DEVS Simulators and Executors / Methodology : How to model and simulate Sept
DEVS-based Modeling and Simulation References: 1.B. P. Zeigler, Hessam S. Sarjoughian, Introduction to DEVS Modeling and Simulation with JAVA: Developing.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
ECE 449/549 Class Notes #2 Introduction to Discrete-Event Systems Specification (DEVS) Sept
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Chapter 1.2 Introduction to C++ Programming
Before we start Literature review abstract DEVSJAVA license form
Continue the car washer example Experimental frame
Modern Programming Tools And Techniques-I
Topic: Classes and Objects
The need for Programming Languages
Chapter 7 User-Defined Methods.
Chapter 7: User-Defined Functions II
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
“Form Ever Follows Function” Louis Henri Sullivan
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Introduction to Computer Science / Procedural – 67130
Continue the car washer example Experimental frame
Chapter16 Methodology: How to Model and Simulate
Java Review: Reference Types
User-Defined Functions
Continuing Chapter 11 Inheritance and Polymorphism
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
DEVS Background DEVS = Discrete Event System Specification
Introduction interface in Java is a blueprint of a class. It has static constants and abstract methods only. An interface is a way to describe what classes.
Chapter 6 Methods: A Deeper Look
Atomic Model Simulator
Week 6 Object-Oriented Programming (2): Polymorphism
6 Chapter Functions.
Inheritance.
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
Introduction to Data Structure
DEVS Background DEVS = Discrete Event System Specification
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Lecture 25: Inheritance and Polymorphism
Chapter 8 Class Inheritance and Interfaces
In this class, we will cover:
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
Chapter 9 Introduction To Classes
CSE 143 Lecture 23 Inheritance and the Object class; Polymorphism
Standard Version of Starting Out with C++, 4th Edition
Presentation transcript:

Introduction to DEVSJAVA Entity and Collection Classes Introduction to Sending and Receiving Messages in DEVSJAVA RealDevs - Restricting Inputs and Outputs to Real Values Friendly Atomic Methods and the restrictions they impose

Entity Interface/entity class public interface EntityInterface{ public String getName(); public Object equalName(String name); } Object entity public class entity extends Object implements EntityInterface{ protected String name; public entity(){name = "anEntity";} public entity(String nm){name = nm; } public boolean eq(String nm){ return getName().equals(nm); public Object equalName(String nm){ if (eq(nm)) return this; else return null; //overrides pointer equality of Object public boolean equals(Object o){ if (!(o instanceof entity))return false; else return eq(((entity)o).getName()); } public String toString(){ return getName(); } //overrides hashCode of Object /* public int hashCode(){ return name.hashCode();} */

GenDevs Collection Classes Relation RelationInterface BagInterface Bag entity doubleEnt User Defined Classes intEnt DrawEntity

Port, Content and Message Collection 0-n ContentInterface MessageInterface content 0-n message 1 1 port value PortInterface EntityInterface ensembleBag ensembleCollection

Sending/Receiving/Interpreting Messages how to use casting to receive instances of arbitrary entity subclasses SimpArc .procQ coupled model entity out in A B doubleEnt doubletEnt(double) double double getv() → double coupling: (A,”out”,B,”in”) public message out( ){ message m = new message(); m.add( makeContent("out", new doubleEnt(1.2)); return m;} “in” val p content “out” cast message doubleEnt add p getv() doubleEnt val deltext(double e,message x){if (somethingOnPort(x,"in"){ entity val = getEntityOnPort(x,"in"); doubleEnt f = (doubleEnt)val; double v = f.getv();}} double v v This assumes there is only one message on port in. casting the received entity down to the doubleEnt subclass content double

realDevs output passive x realVar = x Output realVar realDevs – a template for handling simple real valued data realDevs – an example of working with real number inputs, states and outputs Its behavior – wait for an input, store it, and output it immediately wait in phase passive until receive input receive a number as input and store it in realVar Transition to phase “output” realDevs x realVar = x output passive pulseModels realDevs Output realVar realVar wait for 0 seconds before outputting.

realDevs – implementation in DEVSJAVA realDevs illustrates how to receive a real number, store it, manipulate it, and output the result public void deltcon(double e,message x){ deltint(); deltext(0,x); } public message out(){ if (phaseIs("output")) return outputRealOnPort(realVar,"out"); else return new message(); public String getTooltipText(){ return super.getTooltipText() +"\n"+"realVar :"+ realVar; } public static void main(String args[]){ realDevs re = new realDevs("real"); re.initialize(); atomicSimulator s = new atomicSimulator(re); s.simInject(0,"in",new doubleEnt(10)); s.simulate(2); //should print //Time: 0.0 ,input injected: //port: in value: 10.0 //port: out value: 10.0 //Terminated Normally at ITERATION 2 ,time: Infinity }} pulseModels realDevs public class realDevs extends ViewableAtomic{ protected double realVar; public realDevs(String nm){ super(nm); addInport("in"); addOutport("out"); addRealTestInput("in",10); addRealTestInput("in",10,5); } public realDevs(){ this("realDevs"); public void initialize(){ realVar =0; super.initialize(); passivate(); public void deltext(double e,message x){ Continue(e); if (phaseIs("passive")&& somethingOnPort(x,"in")){ realVar = getRealValueOnPort(x,"in"); if (signOf(realVar) ==1) realVar = inv(realVar); holdIn("output",0); }} public void deltint(){ if (phaseIs("output")) transition then get input declare an instance (state) variable to hold the received input specify how to generate output add input and output ports add test inputs for use in the viewer specify the tool tip contents for the viewer specify how the variable will be initialized and re-initialized how to simulate a model outside the viewer specify how to get and manipulate the input public static int signOf(double x){ if (x == 0) return 0; else if (x > 0) return 1; else return -1; } public static double inv(double x){ if (x == 0) return Double.POSITIVE_INFINITY; else if (x >= Double.POSITIVE_INFINITY ) return 0; else return 1/x; some useful methods that can be used outside the class specify what to do after receiving and outputing

s s’ RealDevs -- illustrating how to use DEVS primitive methods in Internal Transition /Output Generation output= realVar pulseModels realDevs Generate output Time advance = ta(“output”) =0 ta(“passive”) = infinity outputRealOnPort(realVar,"out") s s’ passivate() Make a transition phase = “passive” sigma = “infinity”

RealDevs (continued) – illustrating how to specify the response to external input pulseModels realDevs realVar = getRealValueOnPort(“in”) input Make a transition if something is on the “in” port{ treat it as a real and store it in realVal; phase = “output” sigma = 0 } otherwise sigma = sigma - e somethingOnPort(“in”) holdIn(“output’,0) elapsed time, e Time advance, ta continue()

Class friendlyAtomic Methods public boolean somethingOnPort(message x,String port) : is there a value on the given port, e.g., somethingOnPort(x,”in”) public double geEntityOnPort(message x,String port): get the entity on the given port, e.g., getEntityOnPort(x,”in”) public double getIntValueOnPort(message x,String port): get the integer value on the given port, e.g., getIntValueOnPort(x,”in”) Note – assumes that the port only receives integer values public double getRealValueOnPort(message x,String port): get the real (double) value on the given port, e.g., getRealValueOnPort(x,”in”) Note – assumes that the port only receives real values public double sumValuesOnPort(message x,String port): sum up all the real values on the given port, e.g., sumValuesOnPort(x,”in”) Note – assumes that the port only receives real values public double getNameOnPort(message x,String port): get the name (string) value on the given port, e.g., getStringOnPort(x,”in”) Note – assumes that the port only receives name values public message outputNameOnPort(String nm,String port): output a name (string) on the given port, e.g., outputNameOnPort(“hello”,”out”) public message outputRealOnPort(double r,String port): output a real value (double) on the given port, e.g., outputRealOnPort(5,”out”) public message outputIntOnPort(int r,String port): output an integer value on the given port public void addNameTestInput(String port,String name,double elapsed): add a test which inputs the given name on the given port after an elapsed time, e.g., addNameTestInput(“in”,”hello”,5) public void addRealTestInput(String port,double value,double): add a test which inputs the given value on the given port after an elapsed time, e, e.g., addRealTestInput(“in”,10,5) pulseModels realDevs

friendlyAtomic Methods - Relation to Full-up Atomic Methods Besides being easy to use, these definitions suggest how to use the full-up methods pulseModels realDevs public boolean somethingOnPort(message x,String port){ for (int i=0; i< x.getLength();i++) if (messageOnPort(x,port,i)) return true; return false; } public entity getEntityOnPort(message x,String port){ if (messageOnPort(x,port,i)){ return x.getValOnPort(port,i); } return null; public double getRealValueOnPort(message x,String port){ doubleEnt dv = (doubleEnt)x.getEntityOnPort(port); return dv.getv(); public int getIntValueOnPort(message x,String port){ intEnt dv = (intEnt)x.getEntityOnPort(port); public double sumValuesOnPort(message x,String port){double val = 0; doubleEnt dv = (doubleEnt)x.getValOnPort(port,i); val += dv.getv(); return val;} public message outputNameOnPort(String nm,String port){ message m = new message(); m.add(makeContent(port,new entity(nm))); return m; } public message outputRealOnPort(double r,String port){ m.add(makeContent(port,new doubleEnt(r))); public message outputRealOnPort(message m,double r ,String port){ public void addNameTestInput(String port,String name,double elapsed){ addTestInput(port,new entity(name),elapsed); public void addNameTestInput(String port,String name){ addTestInput(port,new entity(name),0); public void addPortTestInput(String port,double elapsed){ addTestInput(port,new entity(),elapsed); public void addRealTestInput(String port,double value,double elapsed){ addTestInput(port,new doubleEnt(value),elapsed); This only puts one value on one port Note how this is a strong restriction on full-up Devs: it pulls off only one value on the port regardless of how many there may be. This allows accumulating any number of contents (port, value pairs) in a message This shows how multiple values on a single port can be captured. This case does so by summing them up.

Avoiding Some Common Formalism Violations This means that the state after receiving a bag of inputs is uniquely determined by the current state, the elapsed time, and in particular the bag of inputs. Since a bag is an unordered collection, the result cannot depend on the order used in examining the inputs In the example on the left, the order of examining the bag {“a”,”b”} matters since if “a” is in the first content to be examined the result is to do A, while if “b” is thein first conent, the result is to do B. The example on the right completely examines the bag for occurrence of “a” and then occurrence of “b”. The resulis always do A first and B next for the bag {“a”,”b”}. public void deltext(double e, message x) { Continue(e); for (int i = 0; i < x.getLength(); i++){ if (messageOnPort(x, “a", i)) <do A>} for (int i = 0; i < x.getLength(); i++) if (messageOnPort(x, “b", i)) <do B> } public void deltext(double e, message x) { Continue(e); for (int i = 0; i < x.getLength(); i++) { if (messageOnPort(x, “a", i)) <do A> else if (messageOnPort(x, “b", i)) <do B> } result is undefined result is uniquely defined

Avoiding Some Common Formalism Violations SimpArc .procQ This means that the output function does not have an effect on the state – it can’t change it,it can only look at it. The following violates this requirement. public message out( ) { message m = new message(); if (phaseIs("transmit")){ m.add(makeContent("out", new entity("packet " + count+';'+destination))); count = count + 1; } Here the intent is that the state variable, count is incremented by the call to the output function. But DEVS simulator is guaranteed only to use the return result of the call as specified in the DEVS simulation protocol, not to obey the side-effect of changing the count The correct way to update the count is in the internal transition function which is called immediately after the output function: public void int( ) { if (phaseIs("transmit")) count = count + 1; }

Sending/Receiving/Interpreting Messages (cont’d) multiple copies of an object are needed to avoid hard-to-find dependencies. SimpArc .procQ coupled model entity out in A B job job(procTime) update(e): procTime += e; copy(): return new job(procTime); job job coupling: (A,”out”,A,”in”) This instance of job is now shared in common by both A and B – if either makes a change to its state, then the other will also be subject to it. For example, if B does: job.update(10); then the instance at A will be similarly altered. This can lead to mysterious effects (similar to quantum entanglement) where components of a model can influence each other outside of their interface couplings. It is difficult to trace this kind of non-modularity. Suppose A sends its instance of job directly to B: public message out( ){ message m = new message(); m.add( makeContent("out", job) return m;} The right way: B stores a copy of its input: deltext(double e,message) x){ if (somethingOnPort(x,"in“)){ job temp = getEntityOnPort(x,"in"); myJob = temp.copy(); where copy() is a method you define to create a new instance of job and give it values of an existing one. “out” and B stores it as its instance: deltext(double e,message) x){ if (somethingOnPort(x,"in")){ myJob = getEntityOnPort(x,"in"); The cure is simple: create a new instance as a local copy of an entity if it is to be altered (this happens automatically when using toString() and toObject(), see chap. 12)

SimView: Using toString() to display an entities contents, and getTooltipText () to show component state information. receiver sender SimView displays the value returned by getToolTipText: public message out( ){ message m = new message(); m.add(makeContent("out", new vect2DEnt(x,y))); return m; } SimView displays the value returned by toString() in the moving window that represents transmitting a message The modeler must define toString() for the simulator to use polymorphically. For example: public String toString(){ return doubleFormat.niceDouble( x ) + ","+doubleFormat.niceDouble(y); } public String getName(){ return toString(); public String getTooltipText () { return super.getTooltipText() + "\n" + "Cost: " + linkCost; }

Using toString() and toObject() to facilitate deploying models in distributed simulation receiver sender DEVS simulator uses toString() to encode the entity as a String which is sent across the wire public message out( ){ message m = new message(); m.add(makeContent("out", new vect2DEnt(x,y))); return m; } public void deltext(double e ,message x){ for (int i=0; i< x.getLength();i++) if (messageOnPort(x,“in",i)) { entity en = x.getValOnPort(“in",i); position = vect2DEnt.toObject(en); } The modeler must define toString() for the simulator to use polymorphically. For example: public String toString(){ return doubleFormat.niceDouble( x ) + ","+doubleFormat.niceDouble(y); } public String getName(){ return toString(); The modeler also needs to define toObject() and use this method in decoding the message. public static vect2DEnt toObject(String nm){ int commaIndex = nm.indexOf(","); String xs = nm.substring(0,commaIndex); String ys = nm.substring(commaIndex+1,nm.length()); return new vect2DEnt(Double.parseDouble(xs),Double.parseDouble(ys)); } public static vect2DEnt toObject(entity ent){ return toObject(ent.getName());

Look into the DEVSJAVA packages The hierarchical model Example The simpleArc Example

Multiprocessor Architecture (chapter 7) Single Processor Multi-Server Pipeline Divide and Conquer Turn around time and throughput

Architecture Model proc coord Job_in Job_finished

Multiprocessor Architecture (chapter 7) SimpArc in DEVSJAVA – efp.java Single Processor – proc.java Multi-Server – multiServer.java Pipeline – pipeSimple.java Divide and Conquer – DandC3.java

Workflow Coordinator Models public class Coord extends proc{ public Coord(String name){ super(name,1); inports.add("setup"); inports.add("x"); outports.add("y"); public void initialize(){ passivate(); super.initialize();; } protected void add_procs(devs p){ //use devs for signature System.out.println("Default in Coord is being used"); }} Coord Atomic model I/O Behavior Description divide and conquer coordinator breaks incoming jobs into parts for processing and compiles the results into a final output pipeline coordinator routes incoming jobs through a series of processing states and outputs the results Multiserver coordinator routes incoming jobs for processing and collects the results for final output SimpArc divideCoord SimpArc pipeCoord divide Coord pipe Coord multi Server Coord SimpArc multiServerCoord

Workflow Architecture Models in out x y co p0 p1 p2 Architecture SimpArc DandC3 Coupled model Divide and conquer divide and conquer coordinator with processors Pipeline pipeline coordinator with processors Multiserver multiserver coordinator with processors SimpArc pipeLine SimpArc multiServer

Performance of Simple Workflow Architectures Processing Time Average Turnaround Time Maximum Throughput Simple Processor p 1/p Multiserver homogeneous p1,p2,p3 p1=p2 = p3 =p 3/thruput 1/p+1/p2+ 1/p3 3/p Pipeline p1 + p2 + p3 = p p1=p2 = p3=p/3 1/max{p1,p2,p3} Divide and Conquer p1=p2 = p3 =p/3 max{p1,p2,p3} p/3 SimpArc .proc SimpArc multiServer SimpArc pipeline SimpArc DandC3 Average turnaround time and maximum throughput as a function of processing time

Research Statement