The CarryDrop Model (Steps 4-9) : A RePast Tutorial by John Murphy by Junjie Sun 8/2/2004 Department of Economics Iowa State University.

Slides:



Advertisements
Similar presentations
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Advertisements

CSCI 160 Midterm Review Rasanjalee DM.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Road Map Introduction to object oriented programming. Classes
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Terms and Rules Professor Evan Korth New York University (All rights reserved)
1 One-Dimensional Arrays  What are and Why 1-D arrays?  1-D Array Declaration  Accessing elements of a 1-D Array  Initializer List  Passing Array.
Programming Languages and Paradigms Object-Oriented Programming.
More Object Concepts Chapter 4.  Our class is made up of several students and each student has a name and test grades  How do we assign the variables.
The CarryDrop Model (Steps 19-24) : A RePast Tutorial by John Murphy by Junjie Sun 8/16/2004 Department of Economics Iowa State University.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
ECE122 Feb. 22, Any question on Vehicle sample code?
Case study Students. Array of objects Arrays can hold objects (ref to objects!) Each cell in an array of objects is null by default Sample: from student.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Objects & Classes Weiss ch. 3. So far: –Point (see java.awt.Point) –String –Arrays of various kinds –IPAddress (see java.net.InetAddress) The Java API.
Multithreading in JAVA
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Using classes. One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow;
Continuation of John Murphy’s RePast Tutorial Steps Charlie Gieseler
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Classes - Intermediate
Topics Instance variables, set and get methods Encapsulation
Creating a RePast Model Introduction, (Sim)Model Object, CarryDrop.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Methods, classes, and Objects Dr. Jim Burns. Question  Which of the following access modifiers is the default modifier?  public  private  protected.
Java: Base Types All information has a type or class designation
Constructors and Destructors
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Objects Real and Java COMP T1 3
Multithreading Lec 23.
Lecture 3 John Woodward.
3 Introduction to Classes and Objects.
Static data members Constructors and Destructors
Java: Base Types All information has a type or class designation
Java Course Review.
Software Development Java Classes and Methods
Yanal Alahmad Java Workshop Yanal Alahmad
Intro To Classes Review
CSE 413, Autumn 2002 Programming Languages
Chapter 3: Using Methods, Classes, and Objects
Implementing Classes Yonglei Tao.
JavaBeans and JSP CS-422.
This pointer, Dynamic memory allocation, Constructors and Destructor
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.
Chapter Three - Implementing Classes
Phil Tayco Slide version 1.0 Created Oct 16, 2017
CSC 113 Tutorial QUIZ I.
An Introduction to Java – Part I, language basics
Classes & Objects: Examples
Implementing Classes Chapter 3.
Assignment 7 User Defined Classes Part 2
Constructors and Destructors
JAVA Constructors.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Tonga Institute of Higher Education
ArrayLists 22-Feb-19.
JAVA CLASSES.
Java Programming Language
More on Creating Classes
Presentation transcript:

The CarryDrop Model (Steps 4-9) : A RePast Tutorial by John Murphy by Junjie Sun 8/2/2004 Department of Economics Iowa State University

Review of the Story Agents move around a grid spaceAgents move around a grid space Move in one of the eight directionsMove in one of the eight directions Each cell may contain money; agents pick it up and carry it with themEach cell may contain money; agents pick it up and carry it with them Collision compensation; then the agent chooses a new directionCollision compensation; then the agent chooses a new direction Agent has lifespan; when agent dies, its wealth is spread randomly onto the grid, and the dead agent is replaced with a newly born in a diff. location with a diff. lifespanAgent has lifespan; when agent dies, its wealth is spread randomly onto the grid, and the dead agent is replaced with a newly born in a diff. location with a diff. lifespan

Review of Model Structure CarryDropModel - a class that instantiates the SimModel objectCarryDropModel - a class that instantiates the SimModel object CarryDropAgent - a class specifying the agentsCarryDropAgent - a class specifying the agents CarryDropSpace - a class describing the spaceCarryDropSpace - a class describing the space

What ’ s been done in Step 1-3 CarryDropModelCarryDropModel –Variables: schedule, numAgents –Methods: setup(), begin(), buildModel(), buildSchedule(), buildDisplay(), getName(), getSchedule(), getInitParam(), getNumAgents(), setNumAgents(), main() CarryDropAgentCarryDropAgent CarryDropSpaceCarryDropSpace

Add User-Settable Parameters (Step 4-1) Number of Agents (NumAgents)Number of Agents (NumAgents) Size of World X (WorldXSize)Size of World X (WorldXSize) Size of World Y (WorldYSize)Size of World Y (WorldYSize)

Add User-Settable Parameters (Step 4-2) Add worldXSize & worldYSize as class variablesAdd worldXSize & worldYSize as class variables private int worldXSize; private int worldYSize; Add WorldXSize & WorldYSize to the getInitParam functionAdd WorldXSize & WorldYSize to the getInitParam function String[ ] initParams = { "NumAgents", "WorldXSize", "WorldYSize"}; Add the get and set methods for these variables, for example,Add the get and set methods for these variables, for example, public int getWorldXSize(){ return worldXSize; }

Compiling and Running the Basic Model (Step 5-1) Create a new project in IDE and add in three.java files, namely, CarryDropModel.java CarryDropAgent.java CarryDropSpace.javaCreate a new project in IDE and add in three.java files, namely, CarryDropModel.java CarryDropAgent.java CarryDropSpace.java The model won ’ t do anything, but it should compile and display part of the RePast GUIThe model won ’ t do anything, but it should compile and display part of the RePast GUI

Codes to be Added in main Method (Step 5-2) Creates a new obj. of type SimInit:Creates a new obj. of type SimInit: SimInit init = new SimInit(); Creates a new object of type CarryDropModel:Creates a new object of type CarryDropModel: CarryDropModel model = new CarryDropModel(); Loads the model using the loadModel method of the Init obj.:Loads the model using the loadModel method of the Init obj.: init.loadModel(model, "", false);

Default Values for User- Settable Parameters (Step 6) private static final int NUMAGENTS = 100;private static final int NUMAGENTS = 100; private static final int WORLDXSIZE = 40;private static final int WORLDXSIZE = 40; private static final int WORLDYSIZE = 40;private static final int WORLDYSIZE = 40; private int numAgents = NUMAGENTS;private int numAgents = NUMAGENTS; private int worldXSize = WORLDXSIZE;private int worldXSize = WORLDXSIZE; private int worldYSize = WORLDYSIZE;private int worldYSize = WORLDYSIZE;

Alerts in Subroutines (Step 7) System.out.println("Running setup");System.out.println("Running setup"); System.out.println("Running BuildModel");System.out.println("Running BuildModel"); System.out.println("Running BuildSchedule");System.out.println("Running BuildSchedule"); System.out.println("Running BuildDisplay");System.out.println("Running BuildDisplay");

The Space Object (Step 8-1) Define the variable for space object using RePast ’ s Object2DGrid:Define the variable for space object using RePast ’ s Object2DGrid: private Object2DGrid moneySpace; private Object2DGrid moneySpace; Fill moneySpace with Integer objects:Fill moneySpace with Integer objects: public CarryDropSpace(int xSize, int ySize){ public CarryDropSpace(int xSize, int ySize){ moneySpace = new Object2DGrid(xSize, ySize); moneySpace = new Object2DGrid(xSize, ySize); for(int i = 0; i < xSize; i++){ for(int i = 0; i < xSize; i++){ for(int j = 0; j < ySize; j++){ for(int j = 0; j < ySize; j++){ moneySpace.putObjectAt(i,j,new Integer(0)); } } } } moneySpace.putObjectAt(i,j,new Integer(0)); } } } }

Q: How can you know the args in the methods / constructors? A: See RePast/Java API (Step 8-2) Object2DGrid(int xSize, int ySize)Object2DGrid(int xSize, int ySize) Constructs a grid with the specified size. Integer(int value)Integer(int value) Constructs a newly allocated Integer object that represents the primitive int argument. putObjectAt(int x, int y, Object object)putObjectAt(int x, int y, Object object) Puts the specified object at (x,y)

Need another parameter, the amount of money (Step 8-3) In CarryDropModel.java, add:In CarryDropModel.java, add: private static final int TOTALMONEY = 1000; private static final int TOTALMONEY = 1000; private int money = TOTALMONEY; private int money = TOTALMONEY; String[ ] initParams = { "NumAgents", "WorldXSize", "WorldYSize", "Money" }; String[ ] initParams = { "NumAgents", "WorldXSize", "WorldYSize", "Money" }; public int getMoney() { return money; } public int getMoney() { return money; } public void setMoney(int i) { money = i; } public void setMoney(int i) { money = i; }

I ntegrate the Space Object into the Model (Step 9-1) Allocate a variable for the space object:Allocate a variable for the space object: private CarryDropSpace cdSpace; Create the space object in buildModel():Create the space object in buildModel(): cdSpace = new CarryDropSpace (worldXSize, worldYSize); Destroy the space object in setup():Destroy the space object in setup(): cdSpace = null;

Some Clarifications (Step 9-2) The space object is actually destroyed (set to null) in setup before it is created in the buildModelThe space object is actually destroyed (set to null) in setup before it is created in the buildModel Reason is that in each simulation run, the object needs to be reset to nothing before it gets ready to be builtReason is that in each simulation run, the object needs to be reset to nothing before it gets ready to be built

Overview : What ’ s been done in Step 1-9 CarryDropModelCarryDropModel Variables: schedule, cdSpace, numAgents, worldXSize, worldYSize, money Methods: setup(), begin(), buildModel(), buildSchedule(), buildDisplay(), getName(), getSchedule(), getInitParam(), getNumAgents(), setNumAgents(), getWorldXSize(), setWorldXSize(), getWorldYSize(), setWorldYSize(), getMoney(), setMoney(), main() CarryDropAgentCarryDropAgent CarryDropSpaceCarryDropSpace Variables: moneySpace Variables: moneySpace Constructors: CarryDropSpace() Constructors: CarryDropSpace()