Citation
SIMPACKJ/S: A WEB-ORIENTED TOOLKIT FOR DISCRETE EVENT SIMULATION

Material Information

Title:
SIMPACKJ/S: A WEB-ORIENTED TOOLKIT FOR DISCRETE EVENT SIMULATION
Copyright Date:
2008

Subjects

Subjects / Keywords:
Architectural models ( jstor )
Java ( jstor )
Labor costs ( jstor )
Modeling ( jstor )
Naming conventions ( jstor )
Plotters ( jstor )
Simulations ( jstor )
Tours ( jstor )
Translation rules ( jstor )
Web browsers ( jstor )

Record Information

Source Institution:
University of Florida
Holding Location:
University of Florida
Rights Management:
Copyright the author. Permission granted to the University of Florida to digitize, archive and distribute this item for non-profit research and educational purposes. Any reuse of this item in excess of fair use or other copyright exemptions requires permission of the copyright holder.
Embargo Date:
5/4/2002
Resource Identifier:
51739918 ( OCLC )

Downloads

This item is only available as the following downloads:


Full Text

PAGE 1

SIMPACKJ/S: A WEB OR IENTED TOOLKIT FOR DISCRETE EVENT SIMULATION By MINHO PARK A THESIS PRESENTED TO THE GRADUATE SCHOOL OF THE UNIVERSITY OF FLORIDA IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF MASTER OF SCIENCE U NIVERSITY OF FLORIDA 2002

PAGE 2

COPYRIGHT 2002 by MinHo Park

PAGE 3

To my parents, my fianc, Suwon, and my sisters, Hyewon, Hyekyung, Hyeryun, Hyejung, and Hyejoo

PAGE 4

iv ACKNOWLEDGMENTS I would like to thank my advisor, Dr. Paul A. Fishwick, for his continuous advice, guidance, and support in this research work and for giving me the opportunity to work on this good topic. I am grateful to Dr. Sumi Helal and Dr. Joachim H ammer for serving as my committee members. I really thank Taewoo Kim and Jinho Lee for their technical help and fruitful discussions. I will never forget their invaluable help. Last but most importantly, I am deeply indebted to my parents and my fianc, Su won, for their encouragement, love and understanding. My gratitude is to them.

PAGE 5

v TABLE OF CONTENTS page ACKNOWLEDGMENTS ................................ ................................ ................................ .. iv LIST OF FIGURES ................................ ................................ ................................ ............ vii ABSTRACT ................................ ................................ ................................ ........................ x CHAPTERS 1 INTRODUCTION ................................ ................................ ................................ ........... 1 Introduction to SimPack ................................ ................................ ................................ .. 2 Introduction to SimPackJ/S ................................ ................................ ............................. 4 Organization of This Thesis ................................ ................................ ............................. 6 2 TRANSLATION RULES FOR SIMPACKJ/S JAVASCRIPT ................................ ...... 7 Overview ................................ ................................ ................................ .......................... 7 Translation Rules ................................ ................................ ................................ ............. 7 Naming Convention ................................ ................................ ................................ .. 7 Basic Type ................................ ................................ ................................ ................. 8 Struct Type ................................ ................................ ................................ ................ 8 Array ................................ ................................ ................................ ......................... 9 Basic t ype a rray ................................ ................................ ................................ . 9 Multidimensional a rrays ................................ ................................ .................. 10 Arrays of s truct ................................ ................................ ................................ 11 Constants ................................ ................................ ................................ ................. 11 Pointer ................................ ................................ ................................ ..................... 12 Parameter Passing ................................ ................................ ................................ ... 14 Basic t ype and s truct ................................ ................................ ........................ 14 Pointer ................................ ................................ ................................ .............. 16 Limits of Translation ................................ ................................ ................................ ..... 18 File Handling ................................ ................................ ................................ ........... 18 Goto Statement ................................ ................................ ................................ ........ 18 Putting It All Together ................................ ................................ ................................ ... 19 3 TRANSLATION RULES FOR SIMPACK J/S JAVA ................................ .................. 22 Overview ................................ ................................ ................................ ........................ 22 Translation Rules ................................ ................................ ................................ ........... 22

PAGE 6

vi Naming Convention ................................ ................................ ................................ 22 Basic Type ................................ ................................ ................................ ............... 23 Struct Type ................................ ................................ ................................ .............. 23 Array ................................ ................................ ................................ ....................... 24 Basic ty pe ................................ ................................ ................................ ......... 24 Multidimensional a rrays ................................ ................................ .................. 25 Arrays of s truct ................................ ................................ ................................ 25 Constants ................................ ................................ ................................ ................. 26 Pointer ................................ ................................ ................................ ..................... 27 Parameter Passing ................................ ................................ ................................ ... 29 Basic t ype and s truct ................................ ................................ ........................ 30 Pointer ................................ ................................ ................................ .............. 31 Putting It All Together ................................ ................................ ................................ ... 33 4 3D DYNAMIC EXAMPLES ................................ ................................ ........................ 36 Overview ................................ ................................ ................................ ........................ 36 DEQ Model ................................ ................................ ................................ .................... 36 FSA Model ................................ ................................ ................................ ..................... 42 5 CONCLUSION ................................ ................................ ................................ .............. 49 6 RELATED WORK ................................ ................................ ................................ ........ 51 APPENDIX A OBTAINING A COPY OF SIMPACKJ/S ................................ ................................ ... 52 B SETTING AN ENVIRONMENT FOR SIMPACKJ/S ................................ ................ 53 C EXPLANATION FOR EACH MODEL PROVIDED BY SIMPACKJ/S ................... 54 D BLOCK MODEL SIMULATION IN C ................................ ................................ ....... 57 E BLOCK MODEL SIMULATION IN JAVASCRIPT AND JAVA ............................. 60 F HOW TO GET A JAVASCRIPT CODE IN DEQ ................................ ....................... 65 LIST OF REFERENCES ................................ ................................ ................................ ... 68 BIOGRAPHICAL SKETCH ................................ ................................ ............................. 69

PAGE 7

vii LIST OF FIGURES Figure page 1 1. The organization of SimPack ................................ ................................ ....................... 3 1 2. The organization of SimPackJ/S ................................ ................................ .................. 4 1 3. The XML based rube architecture ................................ ................................ ............... 6 2 1. Example of naming convention ................................ ................................ .................... 8 2 2. Example of converting basic types of C into the Java types ................................ ........ 8 2 3. Example of functions used as structures ................................ ................................ ...... 9 2 4. Example o f converting arrays of C into arrays of JavaScript ................................ ... 10 2 5. Example of converting a multidimensional array of C into JavaScript ..................... 10 2 6. Example of converting an array of a struct in C into JavaScript ............................... 11 2 7. Constant declaration ................................ ................................ ................................ ... 12 2 8. The example for declaring a multidimensional array with a constant ....................... 12 2 9. Rule 1 for pointer translation methods in JavaScript and Java ................................ .. 13 2 10. Rule 2 for pointer translation methods in JavaScript and Java ................................ 13 2 11. Example of pointer manipulations ................................ ................................ ........... 14 2 12. Rule 1 for parameter passing ................................ ................................ .................... 15 2 13. Example of parameter passing for basic type ................................ ........................... 15 2 14. Rule 2 for parameter passing ................................ ................................ .................... 15 2 15. Example of parameter passing for struct ................................ ................................ .. 15 2 16. Example of para meter passing – pointer ................................ ................................ .. 17 2 17. Example of handling a goto statement ................................ ................................ ..... 18

PAGE 8

viii 2 18. Sample program (C and corresponding JavaScript) ................................ ................. 21 3 1. Example of naming convention ................................ ................................ .................. 22 3 2. Example of converting basic types of C into the Java types ................................ ...... 23 3 3. Example of converting a struct in C into a class in Java ................................ ........... 24 3 4. Example of converting arrays of C into a rrays of Java ................................ ............. 25 3 5. Example of converting multidimensional arrays of C into Java ................................ 25 3 6. Example of converting arrays of a struct of C into Java ................................ ........... 26 3 7. Constant declarat ion ................................ ................................ ................................ ... 27 3 8. Rules for pointer translation methods in JavaScript and Java ................................ .... 27 3 9. Example of a pointer declaration ................................ ................................ ............... 28 3 10. Example of pointer manipulations ................................ ................................ ........... 29 3 11. Rules for parameter passing ................................ ................................ ..................... 30 3 12. Example of parameter passing for basic type ................................ ........................... 30 3 13. Example of parameter passing for struct ................................ ................................ .. 31 3 14. Example of p arameter passing for a pointer ................................ ............................ 32 3 15. Example for declaring a pointer variable of a struct type ................................ ........ 32 3 16. Sample program (C and corresponding Java) ................................ .......................... 35 4 1. deq_for_3d.js ................................ ................................ ................................ .............. 38 4 2. A fragment of the VRML program ................................ ................................ ............ 38 4 3. The initial state of the 3D virtual plotter ................................ ................................ .... 39 4 4. The 3D virtual plotter ................................ ................................ ................................ . 40 4 5. The result of t he Lorenz System 1 ................................ ................................ ........... 40 4 6. The result of the Lorenz System 2 ................................ ................................ ........... 41 4 7. The result of the Lorenz System 3 ................................ ................................ ........... 41 4 8. Transitions ................................ ................................ ................................ .................. 42

PAGE 9

ix 4 9. The ini tial state of AWACS FSA model ................................ ................................ .... 43 4 10. S1 ................................ ................................ ................................ .............................. 43 4 11. S2 – Color change ................................ ................................ ................................ .... 43 4 12. S3 – Turning on radar ................................ ................................ ............................... 44 4 13. S4 – Communication_1 ................................ ................................ ............................ 44 4 14. S5 – Communication_2 ................................ ................................ ............................ 44 4 15. fsa_for_3d.js ................................ ................................ ................................ ............. 47 4 16. A fragment of the VRML program ................................ ................................ .......... 48 4 17. The result of the AWACS FSA model ................................ ................................ ..... 48 D 1. Block.c program ................................ ................................ ................................ ........ 58 E 1. JavaScript and corresponding Java programs ................................ ............................ 62 F 1. An initial status of DEQ ................................ ................................ ............................. 65 F 2. Example of the Lorenz System ................................ ................................ .................. 66 F 3. A JavaScript code for the Lorenz System ................................ ................................ .. 67

PAGE 10

x Abstract of Thesis Presented to the Graduate School of the University of Florida in Partial Fulfillment of the Requirements for the Degree of Master of Science SIMPACKJ/S: A WEB ORIENTED TOOLKIT FOR DISCRETE EVENT SIMULATION By MinHo P ark May 2002 Chair: Dr. Paul A. Fishwick Department: Computer and Information Science and Engineering SimPackJ/S is the JavaScript and Java version of SimPack, which means SimPackJ/S is a collection of JavaScript and Java libraries and executable prog rams for computer simulations. The main purpose of creating SimPackJ/S is that I allow existing SimPack users to expand simulation areas and provide future users with a freeware simulation toolkit to simulate and model a system in web environments. One of the goals for this thesis is to introduce SimPackJ/S. The other goal is to propose translation rules for converting C to JavaScript and Java. Most parts demonstrate the translation rules with examples. In addition, I discuss 3D dynamic system models and ov erview an approach to 3D dynamic systems using SimPackJ/S. I explain an interface between SimPackJ/S and the 3D language -Virtual Reality Modeling Language (VRML). This thesis shows how to translate C to JavaScript and Java and how to utilize SimPackJ/S to a 3D web environment.

PAGE 11

1 CHAPTER 1 INTRODUCTION Our lifestyle has changed dramatically with the appearance of the Internet. Due to the expansion of the Internet, the boundaries of politics, economics, education, and culture have disappeared. Only 10 years ago, nobody thought of ge tting an education, operating a business, or appreciating masterpieces with a small “iron box” in his room. The Internet has made the impossible become possible. Another new world inside computers was created by Internet technology that is encompassing we b technology and 3D technology: Cyber world or Virtual world. The idea of infinite possibility in a virtual reality world has its attractions. It is made possible with Java and JavaScript representing Internet technologies, web browser standing for web tec hnology, and 3D language -Virtual Reality Modeling Language (VRML). Computer simulation combined with the new technologies has also greatly changed, and it has created a new term, web based simulation . Web based simulation represents the connection between the web and the field of simulation [1]. Web based simulation is the most important part of computer simulation. The main purpose of converting SimPack of C and C++ into SimPack of Java and JavaScript is to provide existing SimPack users with the new vers ion of SimPack to extend their simulation areas, help future new users who want to simulate a system in a web based environment, and create an XML based rube architecture [2] using a Multimodel Exchange Model (MXL) [3] and Dynamic eXchange Language (DXL) [ 4]. SimPackJ/S is laying a foundation for the XML based

PAGE 12

2 rube architecture. Laying the foundation requires the translation for SimPack to SimPackJ/S. Introduction to SimPack SimPack is a collection of C and C++ libraries and executable programs for computer simulation [5]. SimPack has been widely distributed, especially in computer science and mathematics, since it was constructed in 1990 as freeware including a wide variety of modeling types, as shown in Figure 1 1. There are four reasons to create SimPack [5]: 1. To increase the variety of available model types: SimPack provides the Queuing.c file as a library consisting of useful procedures and functions to design a model. 2. To create template algorithms for many cases: SimPack includes template algorithms in each model directory to assist students and professionals solve a specific problem. 3. To avoid learning a special language syntax: All libraries and programs in SimPack are coded with C and C++, popular languages among researchers. Without wasting the ir time to learn a new language syntax, researchers can begin creating simulations. 4. To develop a freeware simulation package.

PAGE 13

3 SimPack Declarative Models Functional Models Constraint Models Multi Models Spatial Models Finite State Automata, Markov, Petri Net, Warehouse Queuing Library Block, Cpudisk, Logic, Network, Qnet, Route, Airport, Iterate, Single Server Queue Difference Equation Differential Equation Boiling Water Multimodel Gas Dynamics Logistic Equation DEQ Figure 1 1. The organization of SimPack

PAGE 14

4 SimPa ckJ/S SimPackJava SimPackJavaScript Block Cpudisk FSA LOGIC Markov Network Petri Net Qnet SimPackLib Block Cpudisk Dqn FSA Logic Markov Network Petri Net Qnet Queuing Introduction to SimPackJ/S SimPackJ/S is the Java and JavaScript version o f SimPack. In other words, SimPackJ/S is a collection of Java and JavaScript libraries and executable programs for computer simulation. However, SimPackJ/S Version 1.0 includes some parts of SimPack, which means I convert typical model types for simulation classes at the University of Florida and necessary model types for an XML based rube architecture for the first stage, as shown in Figure 1 2. SimPackJ/S includes the following models: Declarative Models: Finite State Automaton, Markov, and Petri nets Fun ctional Models: Block, Cpudisk, Logic, Network, Qnet, and Queuing library. Constraint Model: Differential Equation Figure 1 2. The organization of SimPackJ/S

PAGE 15

5 There are three reasons for converting SimPack to SimPackJ/S: 1. To adapt SimPack to a w eb based environment: SimPack cannot attract simulationists who want to simulate a system in a web based environment. Therefore, we need to enable SimPack to adjust to the new circumstances. 2. To provide students with a simulation toolkit for learning 3D dynamic models: SimPackJ/S was provided in both the undergraduate and graduate computer simulation classes (CAP 4800 and CAP 5805) for a final project. 3. To use a new modeling and simulation paradigm: Recently, in a simulati on research group at the University of Florida, the XML based modeling architecture using the Multimodel Exchange Language and SimPackJ/S was proposed. Another XML based modeling architecture using Dynamic eXchange Language is currently being developed. This DXL project is also employing SimPackJ/S. Refer to Figure 1 3.

PAGE 16

6 MXL DXL SIMPACKJ/S (3D scene) X3D XSLT Java DOM XSLT XML (X3D) Figure 1 3. The XML based rube architecture Organization of This Thesis At the beginning of this chapter I introduce SimPack a nd SimPackJ/S and state reasons for creating SimPack and issues for converting SimPack to SimPackJ/S. I discuss the rules for translating C into JavaScript in Chapter 2. Translation rules for converting C into Java are also discussed in Chapter 3. In Chapt er 4, I present the examples with SimPackJ/S in VRML. The conclusion and related work are discussed in Chapter 5 and 6, respectively. Finally, I provide documents and a source code to understand SimPackJ/S in the Appendix.

PAGE 17

7 CHAPTER 2 TRANSLATION RULES FO R SIMPACKJ/S JAVASCR IPT Overview Microsoft Internet Explorer (IE) 6.0 as a web browser and JavaScript1.2 for the translation are utilized. In most cases, C language can be translated into JavaScript directly except for the str ucturally or conceptually different parts, such as “pointer,” a multidimensional “array,” and “struct.” For example, JavaScript does not provide the “pointer” concept. To manage “pointer” in JavaScript, a “pointer object” is created. In the case of the mul tidimensional “array” and the “struct,” a “function” structure in JavaScript is utilized. In this chapter, we discuss the translation rules for C to JavaScript and limitations of conversion . Finally, a program with the C and JavaScript version is demonstr ated to compare the differences between C and JavaScript. I categorize the translation rules for C to JavaScript into several types, such as “Naming convention,” “Basic,” “Struct,” “Array,” “Pointer,” and “Parameter passing.” Translation Rules Naming Conve ntion Most identifiers in C can be converted as they are into JavaScript. If reserved words of JavaScript were used as identifiers in C, we would attach a “ _ ” symbol in front of the identifiers in JavaScript.

PAGE 18

8 Figure 2 1. Example of nami ng convention Basic Type An important difference between JavaScript and C is that a variable in JavaScript accepts all data types, which means JavaScript conveniently and automatically converts values from one type to another, as necessary. In JavaScript, after declaring a variable, I assign all data types to the single variable. In Figure 2 2, I assign three data types: “char,” “int,” and “float,” to one variable named all_variable . Figure 2 2. Example of converting basic types of C into the Java types Struct Type I use a keyword “function” in JavaScript to create a structure like “struct” in C. The “function” provides a structure, as well as an original function, in functional programming, which means the “function” can be utilized as a n “object” in object oriented programming. Therefore, I define a “function” to represent a structure. When I //C cahr name; int count; float c; name = ‘C’; count = 10; c = 0.78; //JavaScript var all_variable; all_variable = ‘C’; all_variable = 10; all_variable = 0.78; //C int event; int list; //JavaScript var _event; var _list;

PAGE 19

9 //C typedef struct { float attr[MAX_NUM_ATTR]; } TOKEN; typedef struct item { float time; int event; T OKEN token; int priority; } ITEM; ITEM item1; ITEM item2; //JavaScript function TOKEN() { this.attr = new Array(MAX_NUM_ATTR); } function ITEM() { this._time=0.0; // float this._event=0; // int this.token = new TOKEN(); // TOKEN this.priority; // int } var item1 = new ITEM(); var item2 = new ITEM(); use the “function,” I can create an “object” of the “function” with a “ new” operator. In Figure 2 3, “function TOKEN()” and “function ITEM()” a re applied as structures. With a “new” operator, we can create the “object” of each “function.” Figure 2 3. Example of functions used as structures Array Basic type array With an “Array” constructor and a “new” operator, I can create an “array” i n JavaScript. I can assign all types to the array, because JavaScript is a loosely typed language. Consider the example of Figure 2 4. N ote that arrays of “ char ” in C are converted to a “string” type of JavaScript with a string manipulating method like str ing library functions in C.

PAGE 20

10 //C int job_count[20]; char job_id[25]; //JavaScript var job_count = new Array(20); job_id = new St ring(); Figure 2 4. Example of converting arrays of C into arrays of JavaScript Multidimensional arrays JavaScript does not support multidimensional arrays directly. However, I create the multidimensional arrays with “arrays of a n array.” In Figure 2 5, I create an array with a “ new ” operator and assign each array element to another array constructor. To approach a particular number within the two multidimensional server_info arrays, we would write server_info[x][y] . Figure 2 5. Example of converting a multidimensional array of C into JavaScript //C int server_info[10][2]; //JavaScript server_info = new Array(10); // int[][] for(var i=0; i<10; i++) server_info[i] = new Array(2);

PAGE 21

11 //C struct tokenstruct { int event; float time; float first_arg; float second_arg; } token_li st[MAX_TOKENS+1]; //JavaScript function tokenstruct() { this._event; // int this._time; // float this.first_arg; // float this.second_arg; // float } function tokenstruct_array(length) { this.l ength = length; for(var i=0; i
PAGE 22

12 //C #define MAX_TOKENS 20000 #define MAX_SERVER 1000 # define MAX_FACILITIES 1000 int const_var = (int)MAX_SERVER; //JavaScript var constant = { MAX_TOKENS : 20000, MAX_SERVER : 1000, MAX_FACILITIES : 1000 } var const_var = constant.MAX_SERVER ; //C typedef struct { LIST queue; int status; char name[25]; int total_servers; int busy_servers; float total_busy_time; float start_busy_time; int preemptions; int server _info[MAX_SERVER][2] ; } FACILITY; //JavaScript function FACILITY() { this.queue; // LIST this.status; // int this.name; // char [] this.total_servers; // int this.busy_servers; // int this.total_busy_time; // float this.start_busy_time; // float this.preemptions; // int this.server_info = new Array(constant.MAX_SERVER); // int[][] for(var i=0; i
PAGE 23

13 “pointer to pointer” in C. “Pointer” in C is a variable that occupies memory space in order to store an address. Therefore, I create a “pointer object” to overcome this problem. I want to introduce “Rules for pointer translation methods in JavaScript and Java” with examples. Figure 2 9. Rule 1 for pointer translation methods in JavaScript and Java (Example) //C //JavaScript *tmp => tmp.ptr **temp => temp.ptr.ptr // temp is pointer to pointer Figure 2 10. Rule 2 for pointer translation methods in JavaSc ript and Java (Example) //C code //JavaScript tmp.field = 3; => tmp.field = 3; // tmp is a structure temp >field = 3; => temp.ptr.field = 3; // temp is pointer to struc t In Figure 2 11, I create a “function Pointer ()” to manipulate the “pointer” of C. In case of a “pointer to pointer” of C, I manage with passing a “pointer” constructor with a “new” operator as a parameter to the “pointer” constructor itself, new Pointer (new Pointer ()) . Rule 1 . The ‘*’, a symbol representing the value of the variable pointed by a pointer variable, can be converted to ‘.ptr’. Rule 2. Both a direct(.) and an indirect( >) operator in C language can be converted to a ‘. ’ in JavaScript and Java.

PAGE 24

14 //C main() { int *count; int **counter; int sum; *count = 1; **counter = 2; sum = *count + **counter; } //JavaScript function Pointer() { this.ptr = null; } var count = new Pointer() ; // int * var counter = new Pointer(new Pointer()) ; // int ** var sum; // int count.ptr = 1; counter.ptr.ptr = 2; sum = count.ptr + counter .ptr.ptr; Figure 2 11. Example of pointer manipulations Parameter Passing The C language provides “call by value” concept as a parameter passing mechanism. On the other hand, JavaScript supports two parameter passing mechanisms, “call by value” and “call by reference.” In JavaScript, “call by value” is utilized as a basic type (= a primitive type) parameter passing method. “Call by reference” is used when a parameter is an “object.” Basic type and struct Since C provides only a “call by value” mechanism, I have to create a “call by value” mechanism when C passes “struct” as a parameter. Even though there are additional lines added in JavaScript, I implement a similar “call by value” mechanism. The following rules are for a parameter passi ng mechanism with examples.

PAGE 25

15 Rule 1. Basic Type: we utilize the same approach as the C language. Rule 2. Struct : before assigning passed values to a parameter, we create parameter variables. We then copy the values of the passed reference to the created variables with a temporary referen ce. //C typedef struct token { int id; float value; } TOKEN; void test( TOKEN token ) { .. } //JavaScript function TOKEN() { this.id; this. value; } function test( tmp_param ) { var token = new TOKEN(); token.id = tmp_param.id; token.value = tmp_param.value; } //C schedule(int event, float inter_time) { . } //JavaScript function schedule(int event, float inter_time) { .. } Figure 2 12. Rule 1 for parameter passing Figure 2 13. Example of parameter passing for basic type Figure 2 14. Rule 2 for parameter passing Figure 2 15. Example of parameter passing for struct

PAGE 26

16 When C p asses “struct” as a parameter, we need additional operations in JavaScript to implement a “call by value” mechanism of C. In Figure 2 15, for the statement void test(TOKEN token) in C, I create a temporary variable, named tmp_param. I assign a TOKEN constr uctor with a “new” operator to a variable, named token . Finally, I incorporate passed values to newly created parameter variables. Pointer The same translation scheme as the parameter passing method for ”struct” is utilized, because parameter passing mecha nisms for “ s truct” and “pointer” in C use “ call by value. ” Figure 2 16 seems like a complicated C program, including “pointer to pointer” and “pointer parameter passing.” But if we apply the parameter passing for the “struct” mechanism and the “pointer” sc heme, we can convert to JavaScript.

PAGE 27

17 Figure 2 16. Example of parameter passing – pointer //C typed ef struct { float attr[10]; } TOKEN; typedef struct item{ float time; int event; TOKEN token; int priority; } ITEM; typedef struct calist *calptr; struct calist { ITEM entry; calptr next; }; calptr *calendar; void count1( calptr *co unt_event ) { ( *count_event) >event = 5; } void count2 (struct calist *count_event ) { count_event >event += 7; } struct calist top; calptr = ⊤ calendar = &calptr; count1(calendar); count2(calptr); //JavaScript function TOKEN() { this.attr = new Array(10); } function ITEM() { this._time=0.0; // float this._event=0; // int this.token = new TOKEN(); this.priority; // int } function Pointer(ptr) { this.ptr = ptr; } var calptr = new Pointer(); // calist * function calist() { this.entry= new ITEM(); this.next = new Pointer(); } var calendar = new Pointer(); function count1( tmp_ptr ) { function count2( tmp_ptr ) { var count_event = new Pointer(); count_event. ptr = tmp_ptr; count_event.ptr.event += 7; } var top = new calist(); calptr.ptr = top; calendar.ptr = calptr; count1(calendar); count2(calptr);

PAGE 28

18 Limits of Translation File Handling For security reasons, JavaScript does not allow the reading or writing to files. However, it is possible to read or write to a file using “ActiveX” embedded into JavaScript. Unfortunately, we cannot expect JavaScript to handle files like C. In SimPackJ/S, I hardcode input data in each program. Goto Statement JavaScript reserves the “ goto” keyword for future use. However, it does not currently have a “goto” functionality. Because of that reason, I convert to JavaScript differently. Figure 2 17. Example of handling a goto statement //C while (1) { if (2*parent > heap_count) goto exit; else child = 2*parent; if (c hild+1 <= heap_count) if (heap[child+1]._time < heap[child]._time) child++; if (heap[parent]._time < heap[child]._time) goto exit; heap_swap(heap[parent], heap[child]); parent = child; } /* end while */ exit: ; //JavaScript var temp_true = 1 ; while ( temp _true ) { if (2*parent > heap_count) { temp_true = 0; break; } else child = 2*parent; if (child+1 <= heap_count) if (heap[child+1].time < heap[child].time) child++; if (heap[parent].time < heap[child].time) { temp_true = 0; break; } heap_swap(heap[parent],heap[child]); parent = child; } // end of while

PAGE 29

19 Putting It All Together I summarize all translation rules for C and corresponding JavaScript programs discussed in this chapter. Figure 2 18. Continued //C (Logic.c) #include #include "../queuing/q ueuing.h" #define NUM_BLOCKS 100 #define NUM_TYPES 6 #define MAX_INPUTS 5 #define MAX_OUTPUTS 5 #define MAX_PARAMS 5 /* Blocks */ #define GEN 0 #define AND 1 #define NAND 2 #define OR 3 #define NOR 4 #define INV 5 float f[4],savevar[4],last_time,delta_ti me, delay[NUM_BLOCKS]; int num_blocks,out_block,block_num,event; int in[NUM_BLOCKS][MAX_INPUTS], out[NUM_BLOCKS][MAX_OUTPUTS]; int block_type[NUM_BLOCKS]; float param[NUM_BLOCKS][MAX_PARAMS], end_time; float value[NUM_BLOCKS]; char type_ string[20]; char types[NUM_TYPES][20] = {"gen","and","nand","or","nor","inv"}; int param_num[NUM_TYPES] = {0,0,0,0,0,0}; int input_num[NUM_TYPES] = {0,2,2,2,2,1}; int output_num[NUM_BLOCKS]; TOKEN block_token; //JavaScript (Logic.js in Logic.html) Figure 2 18. Sample program (C and corresponding JavaScript)

PAGE 32

22 CHAPTER 3 TRANSLATION RULES FO R SIMPACKJ/S JAVA Overview For the translation, the 1.02 version of the Java Development Kit (JDK) for Windows NT/Windows 95 is used. Most of the same schemes used in converting C into JavaScript could apply to translating int o Java as well, except for the special language syntactic cases. In Java, for example, we properly substitute the keyword “class” for the keyword “function” used in JavaScript. “Procedures” and “functions” used in C are replaced by “methods” in Java. Howe ver, in case of a “ pointer,” each “ pointer object” per type is created since Java is one of the strongly typed languages . On the other hand, just one “pointer object” in JavaScript is created to substitute for the “pointer” concept in C because JavaScript is a loosely typed language . I categorize translation rules for C to Java into several types, such as “Naming Convention,” “Basic,” “Struct,” “Array,” “Constants,” “Pointer,” and “Parameter Passing.” Translation Rules Naming Convention Figure 3 1. Ex ample of naming convention //C int event; int list; //Java INT _EVE NT; int _list;

PAGE 33

23 The same scheme employed in JavaScript applies to translation for Java. If reserved words of Java were used as identifiers in C, we would attach a “ _ ” symbol in front of the identifiers in Java. Basic Type Java is one of the str ongly typed languages . Every variable must have a declared type. That is, most basic types such as “int,” “char,” “long,” “float,” and “double” in C can be converted into the Java types directly. However, the “string” type in Java can replace the arrays of “char” in C. In Figure 3 1, an integer type variable named status and a float type variable named total_busy_time in C are directly converted into the Java type of the same name. However, arrays of “char” named status_name are converted to the “string” t ype of Java. Figure 3 2. Example of converting basic types of C into the Java types Struct Type In Java, I replace “ s truct” for “class” since “class” is a set of data and “methods.” Once “class” is created with a “new” operator, we can use and man ipulate elements of “class” whenever required. Consider the example of Figure 3 3. In the case of ITEM item1 in C, I first declare a data type -ITEM, and a variable -item1 . I create a “class” named ITEM to obtain memory with a ”new” operator. Moreover, I c an access and //C int status; char status_name[25]; float total_busy_time; //Java int status; String status_name; float total_busy_time;

PAGE 34

24 //C typedef struct { float attr[MAX_NUM_ATTR]; } TOKEN; typedef struct item { float time; int event; TOKEN token; int priority; } ITEM; ITEM item1; ITEM item2; //Java class TOKEN { float attr[]; TOKEN() { attr = new float[Const.MAX_NUM_ATTR]; } } class ITEM { float time; int event; TOKEN token; int priority; ITEM() { token = new TOKEN(); } } ITEM item1 = new ITEM(); ITEM i tem2 = new ITEM(); handle any data inside the ITEM “class.” Note that the constructor inside the “class” of ITEM is used for obtaining memory for a token variable. Figure 3 3. Example of converting a struct in C into a class in Java Array Basic ty pe array I translate an array defined in C into an array “object” with a “new” operator in Java. For arrays of “char” in C, I convert to the “string” type of Java.

PAGE 35

25 //C int job_count[20]; char job_id[25]; //Java int[] job_count= new int[20]; String job_id; //C code int multi_count[20][2]; char job_id[25][10]; //Java Code int[][] job_count= new int[20][2]; String[] job_id = new String[10]; Figure 3 4. Example of converting arrays of C into arrays of Java Multidimensional arrays Java supports multidimensional arrays with a form of “arrays of arrays.” I convert to a multidimensional array, as they are in C, and assign the multidimensional array with a “new” operator by specifying the number of elements for each dimension. However, for “arrays of arrays” of “char,” I translate into arrays of “string” in Java. Refer to Figure 3 5. Figure 3 5. Example of converting multidimensional arrays of C into Java Arrays of struct To translate arrays of “struct” in C, I first create “class ” with the same name as the “struct” name in C and then place all variables into the “class,” as they are in C. Outside the “class,” I declare a variable with the same name as the name of arrays of “struct” in C and reserve memory spaces with a “new” opera tor. Finally, I assign physical memory spaces to each element of the arrays . In the example of Figure 3 6, for the “struct” name, tokenstruct , I create a “class,” named tokenstruct , and then place all elements of the “struct” inside the “class.” I declare a variable of arrays , token_list , and reserve memory

PAGE 36

26 spaces with a “new” operator. To allocate physical memory spaces to each element of the arrays , we utilize a “for” statement. Figure 3 6. Example of converting arrays of a struct of C into J ava Constants I convert constants , defined by “#define” in C, into “class” consisting of static final variables named Const . We access all constants with “Const.constant_name.” //C struct tokenstruct { int event; float time; float first_arg; float second_arg; } token_list [MAX_TOKENS+1]; //Java class tokenstruct { int event; float time; float first_arg; float second_arg; } public static tokenstruct[] token_list = new tokenstruct[MAX_TOKENS+1]; .. for(i=0;i
PAGE 37

27 Figure 3 7. Constant declaration Pointer Recall “Rules for pointer translat ion methods in JavaScript and Java.” Figure 3 8. Rules for pointer translation methods in JavaScript and Java I apply the “rules for pointer translation” to a Java environment. The difference between JavaScript and Java related to the pointer concept is that Java has multiple “pointer objects,” because Java is a strongly typed language . On the other hand, JavaScript has just one “pointer object” named “ Pointer.” Whenever a pointer with a certain type is declared in the C program, I create a correspond ing “pointer object” with the certain type in Java. In the example of Figure 3 9, there are four pointer types: “int,” “TOKEN,” //C #define MAX_TOKENS 20 #define MAX_SERVERS 10 #define MAX_FACILITIES 10 #define MAX_NUM_ATTR 5 floa t attr[MAX_NUM_ATTR]; //Java public class Const { public static final int MAX_TOKENS = 20; public static final int MAX_SERVERS = 10; public static final int MAX_FACIL ITIES = 10; public static final int MAX_NUM_ATTR = 5 ; } .. float[] attr = new float[ Const.MAX_NUM_ATTR ]; Rule 1 . The ‘*’, a symbol representing the value of the variable pointed by a pointer variable, can be converted to ‘.ptr’. Rule 2. Both a direct(.) and an indirect( >) operator in C language can be converted to a ‘.’ in JavaScript and Java.

PAGE 38

28 “NODE,” and “LIST.” I create corresponding “pointer objects” with the specific types: “IntPointer,” “TokenPointer,” “NodePointe r,” and “ListPointer,” respectively. Figure 3 9. Example of a pointer declaration In Figure 3 10, two “pointer objects,” IntPointer and Int2Pointer , are used to handle a pointer variable and a pointer to pointer variable in C, respectively. To deal with the pointer to pointer scheme in Java, I first declare a basic “pointer object,” IntPointer, and another “pointer object,” Int2Pointer, representing a “pointer to pointer object.” //C next_event(event_ptr,token_ptr) int *event_ptr; TOKEN *token_ptr; { .. } int cancel_event(event) int event; { NODE *current_node; LIS T *list_ptr; .. } //Java class IntPointer { int ptr; } class TokenPointer { TOKEN ptr; } class NodePointer { NODE ptr; } class ListPointer { _LIST ptr; }

PAGE 39

29 Figure 3 10. Example of pointer manipulations Parameter Passing J ava provides two parameter passing schemes: “call by value” and “call by reference.” Otherwise, C has one parameter passing mechanism, “call by reference.” In Java, “call by value” is utilized when basic type variables are passed. However, “class” variable s are passed using “call by reference.” I discuss two parameter passing methods with examples. //C main() { int *count; int **counter; int sum; *count = 1; **counter = 2; sum = (int)*count + **counter; } //Java class IntPointer { int ptr; } class Int2Pointer { IntPointer ptr; Int2Pointer() { ptr = IntPointer ; } } public class Temp { public static void main(String[] args) { IntPointer count = new IntPointer (); Int2Pointer counter = new Int2Pointer (); int sum; count.ptr = 1; counter.ptr.ptr = 2; sum = count.ptr+counter.ptr.ptr; } }

PAGE 40

30 Basic type and struct We recall parameter passing rules for JavaScript and Java . Figure 3 11. Rules for parameter passing In the basic type, I convert int o Java according to Rule 1. See Figure 3 12. Figure 3 12. Example of parameter passing for basic type When the C program passes “struct” as a parameter, we need additional operations in Java to implement a “call by value” mechanism of C. Consider the e xample of Figure 3 13. For the statement heap_insert(ITEM item) in C, I create a temporary variable, tmp_item , with an ITEM type in Java. S ubsequently , I create an “ITEM object,” named item with an ITEM type, using a “new” operator: ITEM item = new ITEM() . Finally, I copy passed values to the newly created variables using Item_copy “method” : Item_copy(item,tmp_item). Rule 1. Basic Type: we utilize the same approach as the C language. Rule 2. Struct : before assigning passed values to a parameter, we create parameter varia bles. Then we copy the values of the passed reference to the created variables with a temporary reference. //C schedule(int event, float inter_time) { . } //Java public static void schedule(int event, float inter_time) { .. }

PAGE 41

31 Figure 3 13. Example of parameter passing for struct Pointer The same translation scheme as the parameter passing method for “struct” is uti lized since parameter passing processes for “ struct” and “ pointer” in C use “ call by value. ” In Figure 3 14, we see that event_ptr is declared as a pointer variable in C. I declare a temporary variable, event_ptr , and then create an “IntPointer object” wit h a “new” operator. Finally, I copy a passed pointer value to a newly created pointer variable. //C typedef struct item{ float time; int event; int priority; } ITEM ; . heap_insert(ITEM item) { .. } //Java class ITEM { double time; int event; int priority; } .. public static void heap_insert( ITEM tmp_item ) { ITEM item = new ITEM(); Item_copy(item,tmp_item); . } public static void Item_copy (ITEM Target, ITEM source) { target.time = source.time; target.event = source.event; target.priority = source.priority; }

PAGE 42

32 Figure 3 14. Example of parameter passing for a pointer The following is an example for when “struct” and “pointer” are used simultaneously. Figure 3 15. Exa mple for declaring a pointer variable of a struct type //C next_event(int *event_ptr) { .. } //Java class IntPointer { int ptr; } public static int next_event(int tmp_event_ptr ) { IntPointer event_ptr = new IntPointer(); event_ptr.ptr = tmp_event_ptr; .. } //C typedef struct { int size; } LIST ; create_list(list_ptr) LIST *list_ptr ; { .. } //Java class ListPointer { LIST ptr; } class LIST { int size; } public static void create_list( LIST tmp_list_ptr ) { ListPointer list_ptr = new ListPointer(); list_ptr.ptr = tmp_lis t_ptr; }

PAGE 43

33 Putting It All Together I summarize all translation rules for C and corresponding Java programs that are discussed in this chapter. Figure 3 16. Continued //C (CpuDisk.c) #include "../queuing/queuing.h" #define n0 6 /* no. class 0 tasks */ #define n1 3 /* no. class 1 tasks */ #define nt n0+n1 /* total no. of tasks */ #define nd 4 /* no. of disk units */ #define qd 1 /* queued req. return */ #define BEGIN_TOUR 1 #define REQUEST_CPU 2 #define RELEASE_CPU 3 #define REQUEST_DISK 4 #define RELEASE_DISK 5 struct token { int cls; /* task's class (& priority) */ int un; /* disk for current IO req. */ double ts; /* tour start time stamp */ } task[nt+1]; TOKEN a_token; int disk[nd+1], /* disk facility descriptors */ cpu, /* cpu fac ility descriptor */ nts=500; /* no. of tours to simulate */ double tc[2]={10.0,5.0}, /* class 0,1 mean cpu times */ td=30.0, sd=2.5; /* disk time mean, std. dev. */ main() { int icount,i,j,event,n[2]; double t,s[2],rn; struct token *p; //JavaScript (CpuDisk.java) import SimpackLib.*; import java.util.*; class TokenPointer { _token ptr; } class _token { int cls; int un; double ts; } public class CpuDisk { public static final int n0 = 6; public static final int n1 = 3; public static final int nt = n0+n1; public static final int nd = 4; public static final int qd = 1; public static final int Const.BEGIN_TOUR = 1; public static final int Const.REQUEST_CPU = 2; public static final int Const.RELEASE_CPU = 3; public static final int Const.REQUEST_DISK = 4; public static final int C onst.RELEASE_DISK = 5; public static int[] disk = new int[nd+1]; public static int cpu, nts=500, tt; public static double td=30.0, sd=2.5; public static double[] tc = {10.0, 5.0}; public static TOKEN a_token = ne w TOKEN(); public static _token[] task = new _token[nt+1]; public static void main(String[] args) { int icount,i,j,event=0; int[] n = new int[2]; double t,rn; double[] s = new double[2]; TokenPointer p = new TokenPointer(); for (i=0;i
PAGE 44

34 Figure 3 16. Continued //C (CpuDisk.c) n[0]=n[1]=0; s[0]=s[1]=0.0; for (i=1; i<=nt; i++) task[i].cls=(i>n0)? 1:0; init_simpack(LINKED); cpu=cr eate_facility("CPU",1); for (i=1; i<=nd; i++) disk[i]=create_facility("disk",1); for (i=1; i<=nt; i++) { a_token.attr[0] = (float) i; schedule(BEGIN_TOUR,0.0,a_token); } /* end for */ icount = 0; while (nts) { icount++; next_event(&event,&a_token); i = (int) a_token.attr[0]; p = &task[i]; switch(event) { case BEGIN_TOUR: /* begin tour */ a_token.attr[0] = (double) i; p >ts=sim_time(); schedule(REQUEST_CPU,0.0,a_token); update_arrivals(); break; case REQUEST_CPU: /* request cpu */ j=p >cls; a_token.attr[0] = (double) i; if (preempt(cpu,a_token,j) == FREE) { rn = expntl(tc[j]); a_token.attr[0] = (double) i; schedule(RELEASE_CPU,(double) rn,a_token); } break; case RELEASE_CPU: /* release c pu, select disk */ a_token.attr[0] = (double) i; release(cpu,a_token); p >un=random(1,nd); schedule(REQUEST_DISK,0.0, a_token); break; case REQUEST_DISK: /* request disk */ a_token.attr[0] = (double) i; if (request(disk[p >un],a_token,0) == FREE) { rn = erlang(td,sd); a_token.attr[0] = (double) i; schedule(RELEASE_DISK, (double) rn ,a_token); } break; //JavaScript (CpuDisk.java) n[0]=n [1]=0; s[0]=s[1]=0.0; for (i=1; i<=nt; i++) task[i].cls=(i>n0)? 1:0; Queuing.init_simpack( Const.LINKED ); cpu=Queuing.create_facility("CPU",1); for (i=1; i<=nd; i++) disk[i]=Queuing.create_facility("disk",1); for (i=1; i<=nt; i++) { a_token.attr[0] = (double) i; Queuing.schedule(Const.BEGIN_TOUR,0.0,a_token); } /* end for */ icount = 0; while (nts>0) { icount++; tt=Queuing.next_event(event,a_t oken); event = tt; i = (int) a_token.attr[0]; p.ptr = task[i]; switch(event) { case Const.BEGIN_TOUR : /* begin tour */ a_token.attr[0] = (double) i; p.ptr.ts =Queuing.sim _time(); Queuing.schedule(Const.REQUEST_CPU, 0.0,a_token); Queuing.update_arrivals(); break; case Const.REQUEST_CPU : /* request cpu */ j=p.ptr.cls; a_token.attr[0] = (double) i; if (Queuing.preempt(cpu,a_token,j) == Const.FREE) { rn = Queuing.expntl(tc[j]); a_token.attr[0] = (double) i; Queuing.schedule(Const.RELEASE_CPU, (double) rn,a_token); } break; case Const.RELEASE_CPU : a_token.attr[0] = (double) i; Queuing.r elease(cpu,a_token); p.ptr.un =Queuing.random_(1,nd); Queuing.schedule(Const.REQUEST_DISK, 0.0,a_token); break; case Const.REQUEST_DISK : /* request di sk */ a_token.attr[0] = (double) i; if (Queuing.request( disk[p.ptr.un], a_token,0) == Const.FREE) { rn = Queuing.erlang(td,sd); a_token.attr[0] = (double) i; Queuing .schedule(Const.RELEASE_DISK, (double) rn ,a_token); } break;

PAGE 45

35 Figure 3 16. Sample program (C and corresponding Java) //C (CpuDisk.c) case RELEASE_DISK: /* release disk, end tour */ a_token.attr[0] = (double) i; release(disk[p >un] ,a_token); j=p >cls; t=sim_time(); s[j]+=t p >ts; p >ts=t; n[j]++; update_completions(); a_token.attr[0] = (double) i; schedule(BEGIN_TOUR,0.0,a_token); nts -; break; } } report_stats(); printf(" \ n \ n"); printf("class 0 tour time = %.2f \ n",s[0]/n[0]); printf("class 1 tour time = %.2f \ n",s[1]/n[1]); } /* end of main =================================== Queuing.c schedule( event,inte r_time,token) int event; double inter_time; TOKEN token; { double event_time; ITEM an_item; int i,token_id; token_id = (int) token.attr[0] % MAX_TOKENS; event_time = current_time + inter_time; if ((!remove_duplicates) || (token_list[token_id].event != event) || (token_list[token_id].time != event_time) || (token_list[token_id].first_arg != token.attr[1]) || (token_list[token_id].second_arg != token.attr[2])) { token_list[token_id].event = event; token_list[token_id].time = event_t ime; token_list[token_id].first_arg = token.attr[1]; token_list[token_id].second_arg = token.attr[2]; event,inter_time,(int) token.attr[0]); trace_update(); an_item.time = event_time; an_item.event = event; for (i=0;i
PAGE 49

39 3D virtual plotter world: a virtual plotter with two arms and the coordinate system, a start button, a line plot, and two text displayers. Figure 4 3. The initial st ate of the 3D virtual plotter To start the 3D virtual plotter, we press the start button. Once the 3D plotter is started, x and y values are generated by an equation of the Lorenz System, “deq_for_3d.js.” These generated x and y values are passed to two ar ms searching for a position fixed by generated x and y values within the coordinate system. At the same time, current x and y values are displayed in text areas and two curved lines are built by current x and y values in the line plot. Refer to a second fi gure, as shown in Figure 4 4.

PAGE 50

40 Figure 4 4. The 3D virtual plotter The resulting the Lorenz System world created from “ deq_for_3d.js ” is shown in Figures 4 5, 4 6, and 4 7. Figure 4 5. The result of the Lorenz System 1

PAGE 51

41 Figure 4 6. The result of th e Lorenz System 2 Figure 4 7. The result of the Lorenz System 3

PAGE 52

42 FSA Model I choose an Airborne Warning And Control System (AWACS) aircraft as a Finite State Automaton (FSA) model. The FSA model consists of states and transitions. We need to deci de the number of state and transitions. In the AWACS model, there are five states and five transitions: States S1: Ready state S2: Takeoff state S3: Surveillance state S4: Communication_1 state S5: Communication_2 state Transition s Figure 4 8. Transitions An initial state of the AWACS model is shown in Figure 4 9. There are three objects: five AWACS aircraft, a stop button, and a statistic button. State changes are represented by pulsating the current state and rotati ng radar. In addition, I include a different behavior in each state. Each state is represented in Figures 4 10, 4 11, 4 12, 4 13, and 4 14, respectively. . 1 2 3 5 4 S1 S2 S3 S5 S4

PAGE 53

43 Figure 4 9. The initial state of AWACS FSA model Figure 4 10. S1 Fi gure 4 11. S2 – Color change

PAGE 54

44 Figure 4 12. S3 – Turning on radar Figure 4 13. S4 – Communication_1 Figure 4 14. S5 – Communication_2 I employ an FSA template in SimPackJ/S to gather statistics of each state in the AWACS FSA model, assuming that an FSA JavaScript code is “ fsa_for_3d.js. ” To connect with VRML, we modify the FSA code. First, we include 10 short functions, related to statistics, and replace “function init()” with “function fsa_init().” “Function cnt_time1 (),” for instance, is used for acc umulating relative time on S1 and “function cnt_state1 ()” is for accumulating frequencies on S1. The other eight functions are the same method

PAGE 55

45 as the “Function cnt_time1 (),” and “function cnt_state1 ()” of S1. To set new states and transitions of the AW ACS FSA, “functin fsa_int()” is utilized. “Function touched()” is used for starting to calculate statistics. Consequently, I produce a modified JavaScript program, as shown in Figure 4 15. Likewise, I present a fragment of the VRML program, as shown in Fig ure 4 16.

PAGE 56

46 Figure 4 15. Continued function cnt_time1(value) { tt1=value;} function cnt_time2(value) { tt2=value;} function cnt_time3(value) { tt3=value;} function cnt_time4(value) { tt4=value;} fu nction cnt_time5(value) { tt5=value;} function cnt_state1(value) {ss1=value;} function cnt_state2(value) {ss2=value;} function cnt_state3(value) {ss3=value;} function cnt_state4(value) {ss4=value;} function cnt_state5(value) {ss5=value;} function fsa_init() { num_states = 5; state_time[0] = tt1; state_time[1] = tt2; state_time[2] = tt3; state_time[3] = tt4; state_time[4] = tt5; transition[0][0].state = 0; transition[0][0].time = 0; transition[0][1].state = 1; transition[0][1].time = 0; transition[1][0].state = 1; transition[1][0].time = 0; transition[1][1].state = 2; transition[1][1].time = 0; transition[2][0].state = 2; transition[2][0].time = 0; transition[2][1].state = 3; transition[2][1].time = 0; transition[3][0].state = 3; tr ansition[3][0].time = 0; transition[3][1].state = 4; transition[3][1].time = 0; transition[4][0].state = 4; transition[4][0].time = 0; transition[4][1].state = 5; transition[4][1].time = 0; transition[5][0].state = 2; transition[5][0].time = 0; transition[ 5][1].state = 99; transition[5][1].time = 0; state[0] = 'S1'; state[1] = 'S2'; state[2] = 'S3'; state[3] = 'S4'; state[4] = 'S5'; state_freq[0]=ss1; state_freq[1]=ss2; state_freq[2]=ss3; continued in the right column. state_freq[3]=ss4; state_freq[4]=ss5; control_len gth = 4; control[0] = 1; control[1] = 1;control[2] = 1;control[3] = 1; } var MAX_STATES = 50; var MAX_LINKS = MAX_STATES*MAX_STATES; var MAX_STRING_LEN = 20; var NUM_INPUTS = 2; var MAX_INPUTS = 20; var transition = new transition_array_1(MAX_STATES); var state = new Array(MAX_STATES); var control = new Array(MAX_STATES); var state_freq = new Array(MAX_STATES); var link_freq = new Array(MAX_LINKS); var index,current_state,num_states,control_len gth,tota l,i; var row,col,save_state,tr_index; var current_time; var state_time = new Array(MAX_STATES); var total_state_time = new Array(MAX_STATES); function touched() { main(); } function transition_struct() { this.sta te; this.time; } function transition_array_1(length) { this.length = length; for(var i=0; i
PAGE 57

47 Figure 4 15. fsa_for_3d.js function main() { //ini t(); fsa_init(); current_time = 0.0; current_state = 0; for (i=0;i 0) { row = Math.floor(i/num_states); col = i %num_states; print(' '+i+' '+row+' > '+col+' '+link_freq[i]+' '+link_freq[i] * 100.0/ total); } /* end if */ } /* end for */ } /* end main() */

PAGE 58

48 Figure 4 16. A fragment of the VRML program To produce a result of the FSA model, we press the stop button and then press the statistic button. A console window appears on a screen, as shown in Figure 4 17. Figure 4 17. The result of the AWACS FSA model DEF Sim Script { eventIn SFFloat cnt_time1 eventIn SFFloat cnt_time 2 eventIn SFFloat cnt_time3 eventIn SFFloat cnt_time4 eventIn SFFloat cnt_time5 eventIn SFFloat cnt_state1 eventIn SFFloat cnt_state2 eventIn SFFloat cnt_state3 eventIn SFFloat cnt_state4 eventIn SFFl oat cnt_state5 eventIn SFTime touched eventOut SFBool off_system field SFFloat tt1 0 field SFFloat tt2 0 field SFFloat tt3 0 field SFFloat tt4 0 field SFFloat tt5 0 field S FFloat ss1 0 field SFFloat ss2 0 field SFFloat ss3 0 field SFFloat ss4 0 field SFFloat ss5 0 url "fsa_for_3d.js" }

PAGE 59

49 CHAPTER 5 CONCLUSION My goal is to convert SimPack of C and C++ version into SimPack of JavaScript and Java version that allows existing SimPack users to extend their simulation areas. I also provide future users with a freeware simulation toolkit to model and simulate a system in a web environment. I have built translation rules for C to JavaScript and Java to accomplish that goal, and I displayed 3D dynamic system models containing SimPackJ/S to exhibit an applicable area. In the translation rules, I cann ot treat some types in C, such as enumerated types and unions . However, if we use a function or class concept as a structure, we convert to Java or JavaScript. For educational purposes, SimPackJ/S is a useful simulation toolkit to understand modeling and s imulation. SimPackJ/S was employed for a final project in simulation classes (CAP 4800 and CAP 5805) at the University of Florida. Currently, with the JavaScript translation mechanisms, I am researching another part using MathML that is an XML formation f or describing mathematics as a basis for machine to machine communication [7], XSLT , and JavaScript . In the case of simple MathML equations, I convert to JavaScript using XSLT. I will enlarge the areas of mathematics equations to differential and differenc e equations. The combination of "Java and web" or "JavaScript and web" makes simulation models larger, more complicated, and more dynamic. Although SimPackJ/S cannot cover all those models, libraries and templates provided by SimPackJ/S can help to approa ch

PAGE 60

50 them. SimPackJ/S has a potential for further improvements. We are continuing to ameliorate SimPackJ/S and introduce new model templates, as necessary.

PAGE 61

51 CHAPTER 6 RELATED WORK There are several other web based discrete simulation packages. Simjava is a process based discrete event simulation package for Java, similar to Jade's Sim++, with animation facilities [8]. A simjava simulation is a set of entities each running in its own threads. These entities are connected together by ports and can communicate with each other by sending and receiving event objects. A central system class controls all the threads, advances the simulation time, and delivers the even ts. The progress of the simulation is recorded through trace messages produced by the entities and saved in a file. Simkit is a small set of Java classes for creating discrete event simulation models [9]. The library is used to either implement stand alo ne models or Web page applets. Simkit models can easily be implemented as applets and executed in a Web browser . JSIM is a Java based simulation and animation environment [10]. In JSIM , simulation models may be built using either the event package (Event Scheduling Paradigm) or the process package (Process Interaction Paradigm). In addition, a graphical designer (jmodel package) allows process models to be rapidly built graphically. SimPackJ/S is an implementation of SimPack using both JavaScript and Java . We felt it necessary to support both languages, since each has a key role to play in our larger system, rube . Java is faster than JavaScript but not well supported in VRML plugins. Also, both major web browsers, Netscape and Internet Explorer, have good native support for JavaScript.

PAGE 62

52 APPENDIX A OBTAINING A COPY OF SIMPACKJ/S SimPackJ/S Version 1.0 is available on http://www.cise.ufl.edu/~fishwick/simpack/SimPackJS

PAGE 63

53 APPENDIX B SETTING AN ENVIRONME NT FOR SIMPACKJ/S 1. SimPack JavaScript Internet Explorer (IE) 5.0 or higher Netscape 6.2 2. SimPack Java Before using SimPack Java, JDK must be installed. I assume that SimPackJ/S is unzipped on C drive. Adding PATH SET PATH=C: \ jdk \ bin;%PATH% Adding CLASSPATH SET CLASSPATH=.;C: \ SimPackJS

PAGE 64

54 APPENDIX C EXPLANATION FOR EACH MODEL PROVIDED BY S IMPACKJ/S Block Model This functional model has three functions: a spiral accumulator, a lathe and an inspector which are connected in series. A set number of raw parts are sent through the accum ulator, and they wait there until the person operating the lathe is ready to accept them. After the parts have been processed through the lathe, they proceed to an inspector who determines the quality of the new processed part. It takes 2.0 seconds to trav erse the accumulator. The person operating the lathe takes 2 minutes per part and cannot handle any more than one part at a time (a queue size of zero). The inspector takes 15 seconds and can handle a queue of 3 processed parts. The lathe operator and insp ector times are sampled from a normal distribution. CPU/DISK Model CPU/DISK represents the simulation of 1 CPU and 4 disks. There are 9 jobs that move through the system. A single job alternately accesses CPU and a disk many times: this simulates the effec t of a real program using these types of resources. Of the 9 jobs, there are 6 low priority jobs and 3 high priority jobs. LOGIC Model This is a simple digital logic simulator with nominal gate delays. For available gate types, note the program logic.js it is easy to add new gates after seeing this template.

PAGE 65

55 MARKOV Model Consider a simple cycle composed of 5 states. This is a Markov implementation of the dining philosophers. We will simulate a set of dining philosophers (numbered 1 through 5) by letting philosopher 1 and 3 eat simultaneously, and then 2 and 4, and so on. We will let each eating action (the time associated with a state) be 3 minutes. A state, then, is specified as a pair (such as (1,3)). We will specify each arc to be 1 minute. The arc re presents a probabilistic change in state. Probabilities are shown in the following 5 state Markov process. We can see, for instance, that philosophers 2 and 4 (the second state) have a greater chance of eating again (probability = 0.4) right after their 3 minute eating activity. NETWORK Model This code is used to simulate a bi directional network of nodes. It uses a purely static routing scheme for messages. Each message starts at a node and has a fixed path of arbitrary length through a set of adjacent nod es. Each node has as many transceivers as it has in links from other nodes connected to it. Each transceiver is modeled as a resource (facility) that contains a queue if messages are waiting. PETRI NET Model This simulates a time Petri network composed of places and transitions. Transitions can take time while places do not take time. The simulator builds an 'outset' table first to reduce the iterative lookup for transitions that can fire. QNET Model QNET is a queuing network simulator that takes as its inp ut the topology (and node information) of a queuing network. There are six kinds of blocks available for modeling

PAGE 66

56 using the queuing network simulator: gen, request, release, join, fork and sink. A combination request/release connection is used to simulate the behavior of a queue/facility.

PAGE 67

57 APPENDIX D BLOCK MODEL SIMULATI ON IN C Figure D 1. Continued //C (Block.c) #include "../queuing/queuing.h" #define GENERATE_PARTS 1 #define REQUEST_ACC 2 #define BLOCK_ACC 3 #define RELEASE_ACC 4 #define REQUEST_LATHE 5 #define BLOCK_LATHE 6 #define RELEASE_LATHE 7 #define REQUEST_INSPECTOR 8 #define RELEASE_INSPECTOR 9 #define NUM_PARTS 100 TOKEN a_token; main() { int i,event,id,accumulator,lathe,inspector,count_parts=N UM_PARTS; int acc _waiting,lathe_waiting,acc_waiting_id,lathe_wait ing_id; float lathe_to_release,blocking_time; float cost_part_gen, cost_labor_server1, cost_labor_server2; float total_cost; init_simpack(LINKED); accumulator=create_facility("ACC",1); lathe=create_facility("LATHE",1); inspector=create_facility("INSPECTOR",1); for (i=1; i<=count_parts; i++) { a_token.attr[0] = (float) i; schedule(GENERATE_PARTS,0.0,a_token); } /* end for */ count_parts = NUM_PARTS; while (c ount_parts > 0) { next_event(&event,&a_token); id = (int) a_token.attr[0]; switch(event) { Continued in the right column. case GENERATE_PARTS: schedule(REQUEST_ACC,0.0 ,a_token); update_arrivals(); break; case REQUEST_ACC: if (request(accumulator,a_token,0) == FREE) schedule(BLOCK_ACC,2.0,a_token); break; case BLOCK_ACC: a cc_waiting = TRUE; acc_waiting_id = id; if (facility_size(lathe) == 0) { acc_waiting = FALSE; schedule(RELEASE_ACC,0.0,a_token); } break; case RELEASE_ACC: acc_waiting = FALSE; release(accumulator,a_token); schedule(REQUEST_LATHE,0.0,a_token); break; case REQUEST_LATHE: if (request(lathe,a_token,0) == FREE) schedule (BLOCK_LATHE,normal (120.0,3.0),a_token); break; case BLOCK_LATHE: lathe_waiting = TRUE; lathe_waiting_id = id; if (facility_size(inspector) <= 3) { lathe_ waiting = FALSE; schedule(RELEASE_LATHE,0.0,a_token); } break; case RELEASE_LATHE: lathe_waiting = FALSE; release(lathe,a_token); if (acc_waiting) { a_t oken.attr[0] = (int) acc_waiting_id; schedule(RELEASE_ACC,0.0,a_token); }

PAGE 68

58 Figure D 1. Block.c program //C (Block.c) schedule(REQUEST_INSPECTOR, 0.0,a_token); break; case REQUEST_INSPECTOR: if (request(inspector,a_token,0) == FREE) schedule(RELEASE_INSPECTOR, normal(15.0,1.0),a_token); break; case RELEASE_INSPECTOR: release(inspector,a_token); if (lathe_waiting) { a_token.attr[0] = (int) lathe_waiting_id; schedule(RELEASE_LATHE, 0.0,a_token); } count_parts -; update_completions(); break; } } Continued in the right column. printf("Costs for Part Processing \ n"); cost_p art_gen = NUM_PARTS*0.40; cost_labor_server1 = (busy_time(lathe)/3600.0)*15.50; cost_labor_server2 = (busy_time(inspector)/3600.0)*14.00; total_cost = cost_part_gen+cost_labor_server1+cost_labor_server2; printf("Cost for part generation: $%.2f \ n", cost_part_gen); printf("Cost of labor for server 1: $%.2f \ n", cost_labor_server1); printf("Cost of labor for server 2: $%.2f \ n", cost_labor_server2); printf("Total Cost is $%.2f \ n",total_cost); report_stats(); printf(" \ n \ n"); }

PAGE 69

59 C Output

PAGE 70

60 APPENDIX E BLOCK MODEL SIMULATI ON IN JAVASCRIPT AND JAVA Figure E 1. Continued //JavaScript (Block.js in Block.htm) //Java Queuing.schedule(REQUEST_INSPECTOR, 0.0,a_token); break; case REQUEST_INSPECTOR: if (Queuing.r equest(inspector,a_token,0) == Const.FREE) Queuing.schedule(RELEASE_INSPECTOR, Queuing.normal(15.0,1.0),a_token); break; case RELEASE_INSPECTOR: Queuing.release(insp ector,a_token); if (lathe_waiting==0) { a_token.attr[0] = (int) lathe_waiting_id; Queuing.schedule(RELEASE_LATHE, 0.0,a_token); } count_parts -; Queuing .update_completions(); break; } } System.out.println("Costs for Part Processing"); cost_part_gen = NUM_PARTS*0.40; cost_labor_server1 = (Queuing.busy_time(lathe)/ 3600.0) *15.50; cost_labor_server2 = Queuing.busy_time(inspector) /3600.0)*14.00; total_cost = cost_part_gen+cost_labor_server1 +cost_labor_server2; System.out.println("Cost for part gene ration: "+cost_part_gen); System.out.println("Cost of labor for server 1: "+cost_labor_server1); System.out.println("Cost of labor for server 2: "+cost_labor_server2); System.out.println("Total Cost is "+total_cost); Queuing.report_stats(); System.out.println(" "); } }

PAGE 73

63 JavaScript Output

PAGE 74

64 Java Output

PAGE 75

65 APPENDIX F HOW TO GET A JAVASCR IPT CODE IN DEQ I assume that SimPackJ/S is installed on G drive. 1. Double click a “DEQ.html” on G: \ SimPackJS \ SimPackJavaScript \ Deq \ deq.html. A window appears on a screen, as shown in Figure F 1. Figure F 1. An initial st atus of DEQ

PAGE 76

66 2. Enter data related to the Lorenz System on each field. Consider Figure F 2. Figure F 2. Example of the Lorenz System

PAGE 77

67 3. Press a Submit button on a screen. We can get a JavaScript code to simulate the Lorenz System. To use the JavaScript code in VRML, we have to copy and paste it. Figure F 3. A JavaScript code for the Lorenz System

PAGE 78

68 LIST OF REFERENCES [1] P. A. Fishwick, “Web Based Simulation: Some Personal Observations,” Proceedings of Winter Simulation Conference, pages 772 779, 1996. [2] P. A. Fishwick, “ rube project,” http://www.cise.ufl.edu/~fishwick/rube/ , 2/15/2002 [3] T. Kim and P. A. Fishwick, “A 3D XML Based Customized Framework for Dynamic Models,” Web3D Conference, 2002. [4] J. Lee and P.A. Fishwick, “A Dynamics Exchange Language Layer fo r RUBE,” in Enabling Technologies for Simulation Science , SPIE, 2002. [5] P. A. Fishwick, “SIMPACK: Getting Started with Simulation Programming in C and C++,” Proceedings of Winter Simulation Conference, pages 154 162, 1992. [6] P. A . Fishwick , Simulation Model Design and Execution: Building Digital World , Prentice Hall, Englewood Cliffs, New Jersey, 1995 [7] World Wide Web Consortium , “W3C's Math Home,” http://www.w3.org/Math /, 02/15/2002 [8] Institute of Computer System Architecture, “simjava,” http://www.dcs.ed.ac.uk/home/hase/simjava/ , 02/15/2002 [9] Arnold H. Buss and Kirt A. Stork, “ Discrete Even t Simulation on the World Wide Web using Java,” Proceedings of Winter Simulation Conference, pages 780 785, 1996. [10] J. A. Miller, “JSIM,” http://chief.cs.uga.edu/~jam/jsim/ , 02/15/2002

PAGE 79

69 BIOGRAPHICAL SKETCH MinHo Park was born on August 25, 1968, in Jejoo do, Korea. He received his Bachelor of Science degree in computer engineering from Hong Ik University, Seoul, Korea, in March 1994. After his graduation, he worked in HP, Korea, LG Infor mation and Communication Corporation, Korea Securities Computer Corporation (KOSCOM), and Good Morning Securities Company, respectively. In 2002, he received his Master of Science degree in computer and information science and engineering at the University of Florida. His major research areas are modeling for computer simulation and web based simulation.