Programming for Social Scientists Lecture 8 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.

Slides:



Advertisements
Similar presentations
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Advertisements

C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
Operating Systems Lecture 7.
Polymorphism Method overriding Method overloading Dynamic binding 1.
W 2 L 1 sh 1 Assignments Read the ‘overzicht’ document! OnderwerpV2CCPP1 x y x = student nummer y = nummer.
Chapter 2 Programming by Example. A Holistic Perspective Three sections separated by blank lines. Program comment File: FileName.java
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Chapter 4 (Horstmann’s Book) Interface Types and Polymorphism: Graphics, Timer, Animation Hwajung Lee.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
Next Generation MMI Requirements May 4, MMI - High Level Requirements run under UNIX and Windows NT (WNT) use a well defined ASCII definition for.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Automating Tasks With Macros
Programming for Social Scientists Lecture 4 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Programming for Social Scientists Lecture 9 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Programming for Social Scientists Lecture 5 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Programming for Social Scientists Lecture 7 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Programming for Social Scientists Lecture 6 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
14-Jul-15 Model-View-Controller. 2 Design Patterns The hard problem in O-O programming is deciding what objects to have, and what their responsibilities.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
CSE 380 – Computer Game Programming Scripting and Lua Lua.
Chapter 2 Classes and Methods I Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
SE 320 – Introduction to Game Development Lecture 4: Programming in Unity & Project Presentations Lecturer: Gazihan Alankuş Please look at the last two.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Writing Widgets & Custom Script API for BOY Xihui Chen
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Top-Down and Bottom-Up Scheduling in Swarm A comparison of implementations Paul E. Johnson University of Kansas.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Objective-C1 CS151 Presentation: Objective C Kai Tai Pang William Sze.
How to start Visual Studio 2008 or 2010 (command-line program)
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
2-D Shapes, Color, and simple animation. 7 Basic Shapes Ellipse :: ellipse() Arc :: arc() Line :: line() Point :: point() Rectangle :: rect() Triangle.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Chapter 5 Introduction to Defining Classes
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Often being different. Control flow By default Java (and therefore Processing) executes lines of a program one after the other –Doesn’t matter what happened.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
An Overview of Tcl/Tk Programming. Tcl/Tk Tcl (Tool Command Language) is used by over half a million developers worldwide and has become a critical component.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
C is a high level language (HLL)
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
FALL 2001ICOM Lecture 11 ICOM 4015 Advanced Programming Lecture 1 Computer/Human Interaction Readings: LMM 2.3 & 3.3 Prof. Bienvenido Velez.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Chapter Goals To be able to declare and use interface types
Swarm Idioms: Little Things Worth Knowing
Java Programming: From Problem Analysis to Program Design,
.NET and .NET Core 9. Towards Higher Order Pan Wuming 2017.
Object Oriented Programming (OOP) LAB # 8
Review Session Biggest discrepancy questions
Programs and Classes A program is made up from classes
Model, View, Controller design pattern
LCC 6310 Computation as an Expressive Medium
Introduction to Methods and Interfaces
Presentation transcript:

Programming for Social Scientists Lecture 8 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson

Today’s topics More graphics Using probes –With GUI –To get and manipulate data Probes in action: The Script class Overriding methods

Changing the raster graphics Want to put a black border around each square on the lattice In order to do so must “paint” each tile independently Solution: A new message in ObserverSwarm Raster from GridIPD New Raster

Changes in ObserverSwarm.m Need to catch the display message from each agent and implement new drawing method In -buildObjects: worldDisplay = [ModObject2dDisplay createBegin: self]; [worldDisplay setDisplayWidget: (id ) self]; [worldDisplay setDiscrete2dToDisplay: [modelSwarm getWorld]]; [worldDisplay setObjectCollection: [modelSwarm getPlayers]]; [worldDisplay setDisplayMessage: M(drawSelfOn:)]; [worldDisplay setSizeFactor: sizeFactor]; worldDisplay = [worldDisplay createEnd];

Changes in ObserverSwarm.m (2) Agents call the “displayWidget” which is actually the ObserverSwarm and we process the information before calling the raster -drawPointX: (int) posX Y: (int) posY Color: (int) type { [worldRaster fillRectangleX0: sizeFactor*posX Y0: sizeFactor*posY X1: sizeFactor*(float)(posX+0.9) Y1: sizeFactor*(float)(posY+0.9) Color: type]; return self; }

How it works Raster Object2dDisplay ObserverSwarm Agent ObserverSwarm -drawPointX:Y:Color: -fillRectangleX0:Y0:X1:Y1: -drawSelfOn: -makeProbeAtX:Y:

Useful methods in Raster - fillRectangleX0: (int)x0 Y0: (int)y0 X1: (int)x1 Y1: (int)y1 Color: (Color)color Fill a rectangle of given geometry and color. - ellipseX0: (int)x0 Y0: (int)y0 X1: (int)x1 Y1: (int)y1 Width: (unsigned)penWidth Color: (Color)c Draw an ellipse of given geometry, pen width, and color. - lineX0: (int)x0 Y0: (int)y0 X1: (int)x1 Y1: (int)y1 Width: (unsigned)penWidth Color: (Color)c Draw a line of given geometry, pen width, and color. - rectangleX0: (int)x0 Y0: (int)y0 X1: (int)x1 Y1: (int)y1 Width: (unsigned)penWidth Color: (Color)c Draw a rectangle of given geometry, pen width, and color.

Model Swarm bugList Graphical probes Observer Swarm Probe main

Observer Swarm How the probes come in... Model Swarm A custom ProbeMap with 4 MessageProbes A custom ProbeMap with 1 MessageProbe ControlPanel is provided by kernel

Brief overview of probes Two major uses for probes –To interface with an object –To create a GUI to an object Interface with an object of two types –VarProbe: Probes an instance variable –MessageProbe: Probes a method GUI utilities: –ProbeMap: Collection of Var and MessageProbes

Major Probe classes Probe Map Complete Probe Map Complete Var Map Custom Probe Map Message Probe VarProbe Object Base Probe Library

Creating graphic probe to object Check out instance of EmtpyProbeMap Attach VarProbe or MessageProbe to each variable or message to appear on GUI Put each probe on ProbeMap Ask probeDisplayManager to create actual widget Object VarProbes MessageProbe A ProbeMap

Code for previous example probeMap=[EmptyProbeMap createBegin: aZone]; [probeMap setProbedClass: [self class]]; probeMap=[probeMap createEnd]; [probeMap addProbe: [probeLibrary getProbeForVariable: ”someVar" inClass: [agent class]]];... [probeMap addProbe: [probeLibrary getProbeForMessage: ”someVar" inClass: [agent class]] setHideResult: 1]]; [probeLibrary setProbeMap: probeMap For: [self class]]; [probeDisplayManager createProbeDisplayFor: modelSwarm]; Model Observer

probeMap = [EmptyProbeMap createBegin: self]; [probeMap setProbedClass: [self class]]; probeMap = [probeMap createEnd]; [probeMap addProbe: [probeLibrary getProbeForVariable: "worldXSize” inClass: [self class]]]; [probeLibrary setProbeMap: probeMap For: [self class]]; (also must execute CREATE_PROBE_DISPLAY macro in ObserverSwarm) Example: A variable probe

probeMap = [EmptyProbeMap createBegin: self]; [probeMap setProbedClass: [self class]]; probeMap = [probeMap createEnd]; [probeMap addProbe: [[probeLibrary getProbeForMessage: ”setWorldXSize:” inClass: [self class]] setHideResult: 1]]; [probeLibrary setProbeMap: probeMap For: [self class]]; (also must execute CREATE_PROBE_DISPLAY macro in ObserverSwarm) Example: A message probe

A probe for ModelSwarm in IPD +createBegin: (id) aZone {... probeMap = [EmptyProbeMap createBegin: aZone]; [probeMap setProbedClass: [self class]]; probeMap = [probeMap createEnd]; [probeMap addProbe: [probeLibrary getProbeForVariable: "randomSeed" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "worldSize" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "pALLC" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "pTFT" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "pATFT" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "pALLD" inClass: [self class]]]; [probeLibrary setProbeMap: probeMap For: [self class]];...

Code for the ModelSwarm probe [probeMap addProbe: [probeLibrary getProbeForVariable: "randomSeed" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "worldSize” inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "pALLC" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "pTFT" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "pATFT” inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "pALLD" inClass: [self class]]];

Graphical and non-graphical probes ProbeMaps are collections of variable and message probes that can be displayed graphically Probes can also be used without the graphical component to construct method calls dynamically at runtime

Dynamic message calling Probe library allows you to construct method calls dynamically Here selector and target are data to be determined at runtime theProbe=[MessageProbe createBegin: zone]; [theProbe setProbedSelector: theSelector]; theProbe=[theProbe createEnd]; anIndex=[aCollection begin: zone]; while((aMember=[anIndex next])) { theData=[theProbe doubleDynamicCallOn:aMember]]; [self doSomething: theData]; }

Using probes to collect statistics Averager object can probe collection of objects and return average, total, min, max and count One use: Use data as argument to printf() statement to collect statistics Averager EZGraph EZBin Objectbase Entropy EZ Distribution Probe

Printing out data using Averager Creating: averager =[Averager createBegin: zone]; [averager setCollection: theCollection]; [averager setProbedSelector: theSelector]; averager=[anAverager createEnd]; Using: [averager update]; printf(“%4.3f %4.3f %4.3f\n”, [averager getMin], [averager getAverage], [averager getMax]);

Scripting with method probes Script class reads script file from disk and creates message probes Each line of script defines: access t method arg1 … argN Where access is either –method name (get target obj) –model (target is model) Creating a script: script=[Script create: self]; [script setFile: "scriptfile"]; [script logEvents: ”logfile"]; [script buildActions: self]; [script activateIn: self]; Sample script: # A model 2 printX:Y: 1 2 model 4 printX:Y: 2 4 # Another comment model 8 shockMarketTo: -1 getMarket 20 setAlpha: 70 getMarket 30 setAlpha:

Example: Scripting the IPD In ModelSwarm.m: -activateIn: (id) swarmContext { [super activateIn: swarmContext]; script=[Script create: self]; [script setScriptFile: "script.txt"]; [script buildActions: self]; [script activateIn: self]; return self; } -invadeWithAllD: (int) n { int i; id agent,index; if(n > [playerList getCount]) n=[playerList getCount]-1; [self shuffle: playerList]; index=[playerList begin: self]; while(i<n && (agent=[index next])){ [agent setPlayerType: 3]; i++; } return self; }

Example:Scripting the IPD (cont) Activate ModelSwarm in ObserverSwarm Example script triggers an invasion of ALL-D at time step 15 and 20 script.txt # model 15 invadeWithAllD: 100 model 20 invadeWithAllD: The script searches in ModelSwarm for selector Time step for action