1 / 12

Java Basics for AnyLogic 6

Java Basics for AnyLogic 6. Dang van son. Agenda. Development Environment Types & Expressions Calling Methods and Accessing Fields Replicated Objects Built-in Functions Main Language Constructs Example. Development Environment.

kelly-moody
Télécharger la présentation

Java Basics for AnyLogic 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Basics for AnyLogic 6 Dang van son

  2. Agenda • Development Environment • Types & Expressions • Calling Methods and Accessing Fields • Replicated Objects • Built-in Functions • Main Language Constructs • Example

  3. Development Environment • Development environment is Java and Eclipse based application • Simulation applets run in any Java-enabled browser with the following version of JRE • Simulation Application is pure Java application

  4. Types & Expressions • Primitive Types • Double –represent real numbers: 1.43, 3.6E18, -14.0 • Int –represents integer numbers: 12, 16384, -5000 • Boolean –represents Boolean (true/false) values • Compound Types –Classes • String –represents textual strings • ArrayList, LinkedList –collections of objects • HyperArray –represents multi-dimensional array in System Dynamics models • …many others.

  5. Types & Expressions • Arithmetic operations • Notation: +, –, *, /, %(remainder) • In integer divisions, the fraction part is lost, e.g. 3 / 2 equals 1, and 2 / 3 equals 0 • Multiplication operators have priority over addition operators • The ‘+‘operator allows operands of type String • Comparison operations • Notation: >, >=, <, <=, ==, != • Boolean operations • Notation: &&(AND), ||(OR), !(NOT) • Conditional operator • Notation: condition ?value-if-true :value-if-false • Assignments and shortcuts • Notation: =, +=, -=, *=, /=, %=, ++, -- • Example: a+=b is equivalent to a = a + b

  6. Calling Methods and Accessing Fields • Method call • Type its name followed by parenthesis. If necessary, put parameters separated by commas within the parenthesis. Ex: x = time(); • Accessing object fields and methods • Use the model element name followed by dot ‘.’followed by the field/method name. Ex: statechart.fireEvent( “go”);

  7. Replicated Objects • Replicated objects are stored in a collection • Items are indexed from 0 to N-1 • Getting the current size of the collection: people.size() • Obtaining i-thitem of the collection: people.get( i ) • Adding a new object to the collection: add_people(); • Removing an object from the collection: remove_people( person );

  8. Built-in Functions • System functions • time(), getOwner(), pause(), isStateActive(…), etc • Mathematical functions • Basic: sqrt, sin, cos, tan, exp, log, round, zidz, xidz, etc–Array: add, sub, mul, sum, avg, min, max, get, etc • Special functions • Random numbers: uniform, exponential, bernoulli, beta, etc–Time related: delay, etc • And more… • See Utilities, Presentable, ActiveObjectand Agentclasses in AnyLogic Class Reference

  9. Main Language Constructs • Assignment / action statement: y = f(x1,x2) + 5*z; event.restart( uniform( 10, 20 ) ); • Decision statement: if ( friendsRatio> attackConstant)attack(); else {escape();} • Loop statement: double total = 0; for ( Person p : people ) total += p.income; for( inti=0; i<100; i++ ) send( msg, RANDOM );

  10. Example

More Related