2008年7月24日星期四

Repast Simphony “non-GUI” Tutorial

By Nick Malleson

Introduction
This is a short tutorial which looks at some of the major differences between Repast 3 and Repast Simphony and goes over how to start building a simple model in Simphony. I've also made a pdf: Nick's Repast no-GUI Tutorial. For some reason the Java code on this site isn't being displayed properly but I'm working on this, in the meantime the pdf is easier to read. You'll still need this shapefile later though: people_shapefile.zip.

I’m still learning how to use repast myself so I make no promises that the information here is correct! Feel free to edit/comment or email me (my email address is on my University of Leeds School of Geography site: http://www.geog.leeds.ac.uk/people/n.malleson/). I hope that my experiences will help you overcome Simphony’s relatively steep learning curve. By the end of you should understand:

What Repast Simphony is / what it does.
How to build a simple model without using the new GUI interface,
How to use contexts and projections to organise agents,
How to read in agents from an ArcGIS Shapefile.
How to make some agents move around a geographical environment.
If you have Simphony already installed the tutorial shouldn’t take more than an hour. I assume you know how to program with Java (at a beginner level).

So what is Repast S?

A bit of history
Repast is a free and open-source set of tools which was originally based Swarm. Initially Repast was implemented exclusively in Java, although Repast version 3 is now fully object-oriented and consists of three core implementations: Repast for Java ( RepastJ); Repast for the Microsoft .Net framework ( Repast.Net); and Repast for Python Scripting ( RepastPy). However, Repast 3 has recently been superseded by a significant development named Repast Simphony ( RepastS).

Repast Simphony
The main improvements that Simphony has made over Repast3 are:

Adding a new GUI for developing models. The ``official'' Simphony tutorial ( http://repast.sourceforge.net/docs/tutorial/SIM/index.html) uses this method but I prefer to code models manually.


Improving the runtime GUI. Now you use the GUI to build displays or charts, output data, interrogate agents, and interface with other programs (like R for stats or Weka for data mining). This means that these tasks are done after the model has been built and compiled, they don't feature in the underlying code at all. This seems quite unusual at first but I now find it much quicker than the old method.


Contexts and Projections
Before we get coding, it's worth quickly describing the biggest change to the underbelly of Repast: the addition of contexts and projections.

A context is basically a bucket which we can use to hold agents. It's like a ``soup'': it holds a population of agents but doesn't give agents any concept of space or relationships (Howe et al., 2006). Contexts are arranged hierarchically and can contain sub-contexts. Agents who exist in a sub-context also exist in the parent context, but the reverse is not necessarily true. There are excellent descriptions of what contexts and projections are on the Simphony reference webpage ( http://repast.sourceforge.net/docs/reference/SIM/index.html) and the in some of the papers ( http://repast.sourceforge.net/papers/papers_main.html).

Once we have agents in a context, projections can give the agents a space and can define their relationships. For example, ``GIS'' projections gives each agent an spatial location and ``Network'' projections allow relationships between agents to be defined (e.g. a social network). Projections are created for specific contexts and will automatically contain every agent within the context (so if you add an agent to a context it is also added to any projections which have been created in that context).

An Example: SimTutorial
Ok, enough reading, lets start! Simphony has been integrated with Eclipse so we're pretty-much forced to use this development environment. If you like Eclipse then this is fine and if you don't you can edit your model code using a different text editor later anyway.

Step 1: Get Simphony
Repast Simphony is distributed as a collection of Eclipse plug-ins. You can download Eclipse with the plugins already installed (recommended) or download the plugins separately from the Repast website.

Step 2: Start Eclipse
This one is fairly straightforward.

Step 3: Build a new Simphony Project
Go to File -> New -> Other
Select Repast Simphony -> Repast Simphony Project from the box which appears.
Give the project a name (we'll call it ``SimTutorial'').
Press next a few times and then finish, the default values should all be ok.
When Eclipse has finished creating the project you should see something a bit like this:



The model.score will be open automatically (if you need to re-open the model.score file it is in the simtutorial.rs folder). This is an xml file (displayed nicely in Eclipse) which describes the model components (agents, contexts, projections and attributes). The runtime GUI reads this file so it knows what the model contains. So, if we create a new type of agent/context/projection we add it to the model.score file and then write the Java code for it. This is what we'll do next.

Step 4: Creating the first context
We could just add agents to the root context (called SimTutorial), but I find it better to organise different types of agent into their own sub-contexts. So firstly we'll create a sub-context to hold People agents:

How to create a context in model.score file:
Right-click on ``SimTutorial'' and then Create Member -> Context. This will create a new context called ``SimTutorialContext''. We can now configure this new context:
Right-click on SimTutorialContext and go to Show Properties. The box at the bottom of Eclipse should now show all the properties of our context.
To change the name of the context to something more suitable, click on Label and type ``PeopleContext''. If you scroll down a bit you'll notice that there is a property called File Name for Source Code, this is where we implement the Java code for the context.
Implement the Java class for the context. We've told Repast that we want to create a new context, but at the moment it doesn't do anything (later we want to get the context to create some People). Here's how to create Java code which will make the context do what we want:
The box on the left of the Eclipse workspace shows all the different components of the project. Click on the (+) to expand the SimTutorial folder and then expand the src folder (this is where all our source code is kept).
Right-click on the default package (called ``simtutorial'') and go to New -> Class.
We need the class to have the same name as the context so type ``PeopleContext'' in the Name box.
Finally, we can define parent classes or interfaces here. As we're creating a context we need to extend ``DefaultContext''. Click on Browse next to the Superclass box and type ``DefaultContext'' into the box which appears. After a few seconds Eclipse should find the DefaultContext class (in the repast.simphony.context package). After clicking on OK you should have something that looks like:
Click on OK and then Finish.
Now we have created a new context and a Java class for it. Eclipse will have brought up an editor for this new class. We haven't made any agents yet so we'll ignore the implementation of the context for now. Don't worry about the yellow line underneath DefaultContext, this is Eclipse's way of telling us there will be a compile-time warning (if you hold your mouse over the yellow line you'll see what the warning is). Ignore this for now.

Step 5: Creating the first agent type
We've told repast about our main context, now lets tell it what agents we want to be part of the context (this is very similar to creating a new context).

Create the agent in the model.score.
Click on the model.score tab (near the top of the Eclipse window) to show the model.score file.
Right click on ``PeopleContext'' and then Create member -> Agent.
Change the label to "Person".
Implement the Java classes.
Right click on the ``simtutorial'' package and then New -> Class.
Call the class ``Person''. Then finish.
Again, Eclipse will bring up an editor window for our Person class. Now we've created a new context and a new type of agent who will exist in the context. Check everything's OK by running Simphony. To do this click on the little arrow next to the green button and then "Run SimTutorial Model"



After a few seconds the Simphony GUI should pop up (on the left near the bottom you should see the ``PeopleContext'' subcontext). This is the GUI that we can use to create charts, show displays, output data and so on. You can save the configuration by clicking on the little disk icon so you don't need to re-create everything each time you re-run the model. If everything worked OK (there were no errors) just close Simphony for now.

Step 6: Create a projection for the agents
We've created a context and told repast that we might create some people to exist in the context, but so far we haven't said anything about the space which the agents will inhabit. Repast uses projections to specify relationships between agents and their environment. The types of projection we can use include:

GIS Projections - agents have an location and can move around a geographic environment.
Grid Projections - traditional, CA-type, grid.
Network Projections - specify relationships between agents, i.e. social networks.
In this tutorial we'll create a GIS projection. Here's how:

Tell the model.score about the projection.
In the model.score file, right click on PeopleContext and then Create Member -> Projection - Geography.
Right click on the new projection and choose Show Properties.
Change the label to ``PeopleGeography''. We don't do anything with our projection yet, we''ve just told repast that we want to use one. Because the projection is part of our PeopleContext we'll write the code for the projection in this class so that when Repast creates the PeopleContext, it will also create our PeopleGeography.
Implement the projection
Open up PeopleContext.java (should still be open as a tab in Eclipse).
Add the following default constructor to the class:
public PeopleContext() { super( "PeopleContext"); // must match name in model.scoreGeographyParameters geoParams = new GeographyParameters();// These lines actually create our Geography. Tell Repast to create a new geography projection called "PeopleGeography" in this context.Geography peopleGeography = GeographyFactoryFinder.createGeographyFactory( null).createGeography( "PeopleGeography", this, geoParams); System.out.println( "Created PeopleGeography");}
The PeopleContext() constructor will be called when our model is initialised, so all the code inside it will be executed. The indentation is probably horrible, if you highlight all the code and press Control + I Eclipse will indent everything nicely.

You'll notice that lots of the code is underlined in red. This is Eclipse telling us that there will be compile errors, this is because we need to add some import lines at the top. Eclipse has a nice way of looking for the classes we might want to import, if you click on the tiny red on the left of the line with an error you should get an option to import a class file. Figure 4 illustrates this. Import all the required class files until all the errors have been corrected (check that you are importing classes from a repast simphony package, not a class with the same name from a different package).



Step 7: Create some agents
Ok we're almost there, we have a context to hold our agents and a projection which will give them all a spatial location. Now all that's left to do is create our agents and give them some simple actions.

The first thing we need to do is add a bit more code to our Person class. Open up the class and copy all this lot in (between the open/close curly brackets of the class):

private String name; private int age; public Person() { super(); } public String getName() { return name; } public void setName( String name) { this.name = name; } public int getAge() { return age; } public void setAge( int age) { this.age = age; }
Now we could just put a for-loop in our PeopleContext class which creates some agents, adds them to the context and gives them an location in our projection, something like:

for ( int i=0; i<10; i++) {Person p = new Person(); this.add(p); // `` this'' refers to PeopleContextpeopleGeography.move(p, new GeometryFactory().createPoint( new Coordinate(i,i+1)));}
But this isn't very useful so instead we'll make use of a fantastic feature of Simphony: reading in a shapefile. (If you added the lines above then comment them out now or the agents we load from a shapefile won't display properly).

Here's how to load agents in from an ArcGIS shapefile:

I've already created a little shapefile with some people in it here: people_shapefile.zip. Get it and unzip it into the root directory of the SimTutorial project which is probably here: "My Documents/eclipse_workspace/SimTutorial". It will create a directory called People which contains the shapefile and some other necessary files.
Then add this code after creating the geography in PeopleContext.java:
// Create some people from a shapefile:File shapefile = null; // NOTE: import java.io package!ShapefileLoader personLoader = null; try {shapefile = new File( "People/people.shp");personLoader = new ShapefileLoader(Person.class, shapefile.toURL(),peopleGeography, this);} catch (java.net.MalformedURLException e) {e.printStackTrace();} while (personLoader.hasNext()) {personLoader.next();}
The amazing thing about the shapefileLoader is that if you have an attribute in the shapefile and corresponding get/set methods in your agent, it will automatically create agents with the same values as the shapefile. For example, the people shapefile has ``name'' and ``age'' fields and our Person agent has get and set methods for ``name'' and ``age'' variables, so each Person is created with the correct name and age. Amazing!

The shapefile loader will have loaded every Person from the shapefile into the PeopleContext and given them an appropriate spatial location in the PeopleGeography. We can test this by running through all the agents in the geography and printing their location. If you want to do this you'll need to add these lines after the people have been loaded in PeopleContext.java (not compulsory):

// Get all agents in the geography and print their location: for (Person p:peopleGeography.getAllObjects()) {Geometry geom = peopleGeography.getGeometry(p);Coordinate coord = geom.getCoordinate(); System.out.println(p.getName()+ " is at: ("+coord.x+ ","+coord.y+ ")");}
Note: make sure you import the com.vividsolutions.jts.geometry package for the Geometry object.

Step 8: Get the agents moving
Now that we have loaded our agents into the context and given them a spatial location in the projection we can get them to move around. For now we'll just have them move in a random direction. Firstly, we need to create and schedule a method which will be called every iteration to control the agents:

There are a few ways to schedule things in Simphony, have a look at the ``Working with the scheduler'' section in the Simphony reference docs if you want more info ( http://repast.sourceforge.net/docs/reference/SIM/index.html). For now we'll use annotations, these take advantage of a nice new feature of Java and are good if we know, at compile-time, when we would like a method to be executed.

Put the following code after the setAge method in Person:

// Tell repast to run this function at every iteration@ScheduledMethod(start = 1, interval = 1, priority = 0) public void step() { System.out.println(name+ " has called step method");}
The step() method will now be called at every iteration. If you open the project now and run it (the little green arrow at the top of the Simphony GUI) you should see text telling us that the step() method is being called for each Person. This isn't particularly useful though as the agents don't actually do anything.

To make the agents move around the geography add the following code (put it after the System.out line in the step() method):

// Find the context this person exists in.Context context = ContextUtils.getContext ( this);// Get the GIS projection associated with the contextGeography projection = (Geography)context.getProjection( "PeopleGeography");// Move the agents a small distance in a random directionprojection.moveByVector( this, 5,RandomHelper.nextDoubleFromTo(0, (2* Math.PI)));
It's worth noting that in Simphony all the geographical information about each agent is stored in the projection, not in the agent (the Person class has no variables). This allows our agents to be more generic, you don't have to specifically give them any information about their relationship with each other or the environment. We could, for example, control our agents from another class and then the Person class wouldn't even need know about Repast Simphony!

Step 9: Create a Display
We've pretty-much finished now. You can run Simphony and the agents will move around their geography. To actually see this happen, however, we need to create a display:

Run the model. Remember that all displays, charts etc are created separately from the underlying model source code, we do this using the runtime GUI.
On the list on the left look for the ``Displays'' icon underneath the ``PeopleContext'' folder. Right click on it and choose Add Display.
In the new window which pops up you can configure the display.
Leave the default name (``A Display'') for now, anything will do.
The type of projection should be ``GIS''. Repast has detected that the only projection we have created in the PeopleContext is a GIS geography, this could be Network or Grid if we had created these types of projections as well.
Tell repast that we would like the display to show our PeopleGeography by clicking on it and then clicking on the right arrow to move it accross into the box on the right. You should have something that looks like:
Click Next.
Now we can configure how we would like the agents to be displayed. We can also add other shapefiles to be displayed (like roads, houses etc) by clicking on the + button. For now, just change the fill colour of our People agents (click on Edit) then click next.
The final box lets us configure how often the display will be updated. Click finish.
Finally, save the new model configuration by clicking on the floppy disk at the top. I'm not sure how repast remembers the configuration but it does! Now if we re-compile and/or re-run the model Repast will have remembered this display.
Press the play button and we're off!

You should see some agents wandering around aimlessly, something like this:

A quick note to Mac users: at the time of writing (May 2008) there is a small bug with the displays. This has been documented and a temporary work around can be found on the archives of the repast-interest email list under the title ``GIS in Simphony'' (I'm a Mac user and the workaround works fine for me).

So far we've created a context, added some agents into the context and created a GIS projection so the agents can have a location in a geographical space. Now we could create a Network projection to create a social network for the agents or create another context to hold House objects and give the agents a home.

That's the end of the tutorial, hopefully you've got a better idea of how to use Repast Simphony without using the development GUI. Once you get used to it it is a really great tool. As a quick plug have a look at my blog ( http://crimesim.blogspot.com) to see how I'm using repast to develop a simulation of a city which should predict the movements of burglars. I also intend to put some other tutorials up there. The complete code for the tutorial is also available: PeopleContext.java Person.java

[网文随录]一些复杂性网站

By Nick Malleson

Introduction
This is a short tutorial which looks at some of the major differences between Repast 3 and Repast Simphony and goes over how to start building a simple model in Simphony. I've also made a pdf: Nick's Repast no-GUI Tutorial. For some reason the Java code on this site isn't being displayed properly but I'm working on this, in the meantime the pdf is easier to read. You'll still need this shapefile later though: people_shapefile.zip.

I’m still learning how to use repast myself so I make no promises that the information here is correct! Feel free to edit/comment or email me (my email address is on my University of Leeds School of Geography site: http://www.geog.leeds.ac.uk/people/n.malleson/). I hope that my experiences will help you overcome Simphony’s relatively steep learning curve. By the end of you should understand:

What Repast Simphony is / what it does.
How to build a simple model without using the new GUI interface,
How to use contexts and projections to organise agents,
How to read in agents from an ArcGIS Shapefile.
How to make some agents move around a geographical environment.
If you have Simphony already installed the tutorial shouldn’t take more than an hour. I assume you know how to program with Java (at a beginner level).

So what is Repast S?

A bit of history
Repast is a free and open-source set of tools which was originally based Swarm. Initially Repast was implemented exclusively in Java, although Repast version 3 is now fully object-oriented and consists of three core implementations: Repast for Java ( RepastJ); Repast for the Microsoft .Net framework ( Repast.Net); and Repast for Python Scripting ( RepastPy). However, Repast 3 has recently been superseded by a significant development named Repast Simphony ( RepastS).

Repast Simphony
The main improvements that Simphony has made over Repast3 are:

Adding a new GUI for developing models. The ``official'' Simphony tutorial ( http://repast.sourceforge.net/docs/tutorial/SIM/index.html) uses this method but I prefer to code models manually.


Improving the runtime GUI. Now you use the GUI to build displays or charts, output data, interrogate agents, and interface with other programs (like R for stats or Weka for data mining). This means that these tasks are done after the model has been built and compiled, they don't feature in the underlying code at all. This seems quite unusual at first but I now find it much quicker than the old method.


Contexts and Projections
Before we get coding, it's worth quickly describing the biggest change to the underbelly of Repast: the addition of contexts and projections.

A context is basically a bucket which we can use to hold agents. It's like a ``soup'': it holds a population of agents but doesn't give agents any concept of space or relationships (Howe et al., 2006). Contexts are arranged hierarchically and can contain sub-contexts. Agents who exist in a sub-context also exist in the parent context, but the reverse is not necessarily true. There are excellent descriptions of what contexts and projections are on the Simphony reference webpage ( http://repast.sourceforge.net/docs/reference/SIM/index.html) and the in some of the papers ( http://repast.sourceforge.net/papers/papers_main.html).

Once we have agents in a context, projections can give the agents a space and can define their relationships. For example, ``GIS'' projections gives each agent an spatial location and ``Network'' projections allow relationships between agents to be defined (e.g. a social network). Projections are created for specific contexts and will automatically contain every agent within the context (so if you add an agent to a context it is also added to any projections which have been created in that context).

An Example: SimTutorial
Ok, enough reading, lets start! Simphony has been integrated with Eclipse so we're pretty-much forced to use this development environment. If you like Eclipse then this is fine and if you don't you can edit your model code using a different text editor later anyway.

Step 1: Get Simphony
Repast Simphony is distributed as a collection of Eclipse plug-ins. You can download Eclipse with the plugins already installed (recommended) or download the plugins separately from the Repast website.

Step 2: Start Eclipse
This one is fairly straightforward.

Step 3: Build a new Simphony Project
Go to File -> New -> Other
Select Repast Simphony -> Repast Simphony Project from the box which appears.
Give the project a name (we'll call it ``SimTutorial'').
Press next a few times and then finish, the default values should all be ok.
When Eclipse has finished creating the project you should see something a bit like this:



The model.score will be open automatically (if you need to re-open the model.score file it is in the simtutorial.rs folder). This is an xml file (displayed nicely in Eclipse) which describes the model components (agents, contexts, projections and attributes). The runtime GUI reads this file so it knows what the model contains. So, if we create a new type of agent/context/projection we add it to the model.score file and then write the Java code for it. This is what we'll do next.

Step 4: Creating the first context
We could just add agents to the root context (called SimTutorial), but I find it better to organise different types of agent into their own sub-contexts. So firstly we'll create a sub-context to hold People agents:

How to create a context in model.score file:
Right-click on ``SimTutorial'' and then Create Member -> Context. This will create a new context called ``SimTutorialContext''. We can now configure this new context:
Right-click on SimTutorialContext and go to Show Properties. The box at the bottom of Eclipse should now show all the properties of our context.
To change the name of the context to something more suitable, click on Label and type ``PeopleContext''. If you scroll down a bit you'll notice that there is a property called File Name for Source Code, this is where we implement the Java code for the context.
Implement the Java class for the context. We've told Repast that we want to create a new context, but at the moment it doesn't do anything (later we want to get the context to create some People). Here's how to create Java code which will make the context do what we want:
The box on the left of the Eclipse workspace shows all the different components of the project. Click on the (+) to expand the SimTutorial folder and then expand the src folder (this is where all our source code is kept).
Right-click on the default package (called ``simtutorial'') and go to New -> Class.
We need the class to have the same name as the context so type ``PeopleContext'' in the Name box.
Finally, we can define parent classes or interfaces here. As we're creating a context we need to extend ``DefaultContext''. Click on Browse next to the Superclass box and type ``DefaultContext'' into the box which appears. After a few seconds Eclipse should find the DefaultContext class (in the repast.simphony.context package). After clicking on OK you should have something that looks like:
Click on OK and then Finish.
Now we have created a new context and a Java class for it. Eclipse will have brought up an editor for this new class. We haven't made any agents yet so we'll ignore the implementation of the context for now. Don't worry about the yellow line underneath DefaultContext, this is Eclipse's way of telling us there will be a compile-time warning (if you hold your mouse over the yellow line you'll see what the warning is). Ignore this for now.

Step 5: Creating the first agent type
We've told repast about our main context, now lets tell it what agents we want to be part of the context (this is very similar to creating a new context).

Create the agent in the model.score.
Click on the model.score tab (near the top of the Eclipse window) to show the model.score file.
Right click on ``PeopleContext'' and then Create member -> Agent.
Change the label to "Person".
Implement the Java classes.
Right click on the ``simtutorial'' package and then New -> Class.
Call the class ``Person''. Then finish.
Again, Eclipse will bring up an editor window for our Person class. Now we've created a new context and a new type of agent who will exist in the context. Check everything's OK by running Simphony. To do this click on the little arrow next to the green button and then "Run SimTutorial Model"



After a few seconds the Simphony GUI should pop up (on the left near the bottom you should see the ``PeopleContext'' subcontext). This is the GUI that we can use to create charts, show displays, output data and so on. You can save the configuration by clicking on the little disk icon so you don't need to re-create everything each time you re-run the model. If everything worked OK (there were no errors) just close Simphony for now.

Step 6: Create a projection for the agents
We've created a context and told repast that we might create some people to exist in the context, but so far we haven't said anything about the space which the agents will inhabit. Repast uses projections to specify relationships between agents and their environment. The types of projection we can use include:

GIS Projections - agents have an location and can move around a geographic environment.
Grid Projections - traditional, CA-type, grid.
Network Projections - specify relationships between agents, i.e. social networks.
In this tutorial we'll create a GIS projection. Here's how:

Tell the model.score about the projection.
In the model.score file, right click on PeopleContext and then Create Member -> Projection - Geography.
Right click on the new projection and choose Show Properties.
Change the label to ``PeopleGeography''. We don't do anything with our projection yet, we''ve just told repast that we want to use one. Because the projection is part of our PeopleContext we'll write the code for the projection in this class so that when Repast creates the PeopleContext, it will also create our PeopleGeography.
Implement the projection
Open up PeopleContext.java (should still be open as a tab in Eclipse).
Add the following default constructor to the class:
public PeopleContext() { super( "PeopleContext"); // must match name in model.scoreGeographyParameters geoParams = new GeographyParameters();// These lines actually create our Geography. Tell Repast to create a new geography projection called "PeopleGeography" in this context.Geography peopleGeography = GeographyFactoryFinder.createGeographyFactory( null).createGeography( "PeopleGeography", this, geoParams); System.out.println( "Created PeopleGeography");}
The PeopleContext() constructor will be called when our model is initialised, so all the code inside it will be executed. The indentation is probably horrible, if you highlight all the code and press Control + I Eclipse will indent everything nicely.

You'll notice that lots of the code is underlined in red. This is Eclipse telling us that there will be compile errors, this is because we need to add some import lines at the top. Eclipse has a nice way of looking for the classes we might want to import, if you click on the tiny red on the left of the line with an error you should get an option to import a class file. Figure 4 illustrates this. Import all the required class files until all the errors have been corrected (check that you are importing classes from a repast simphony package, not a class with the same name from a different package).



Step 7: Create some agents
Ok we're almost there, we have a context to hold our agents and a projection which will give them all a spatial location. Now all that's left to do is create our agents and give them some simple actions.

The first thing we need to do is add a bit more code to our Person class. Open up the class and copy all this lot in (between the open/close curly brackets of the class):

private String name; private int age; public Person() { super(); } public String getName() { return name; } public void setName( String name) { this.name = name; } public int getAge() { return age; } public void setAge( int age) { this.age = age; }
Now we could just put a for-loop in our PeopleContext class which creates some agents, adds them to the context and gives them an location in our projection, something like:

for ( int i=0; i<10; i++) {Person p = new Person(); this.add(p); // `` this'' refers to PeopleContextpeopleGeography.move(p, new GeometryFactory().createPoint( new Coordinate(i,i+1)));}
But this isn't very useful so instead we'll make use of a fantastic feature of Simphony: reading in a shapefile. (If you added the lines above then comment them out now or the agents we load from a shapefile won't display properly).

Here's how to load agents in from an ArcGIS shapefile:

I've already created a little shapefile with some people in it here: people_shapefile.zip. Get it and unzip it into the root directory of the SimTutorial project which is probably here: "My Documents/eclipse_workspace/SimTutorial". It will create a directory called People which contains the shapefile and some other necessary files.
Then add this code after creating the geography in PeopleContext.java:
// Create some people from a shapefile:File shapefile = null; // NOTE: import java.io package!ShapefileLoader personLoader = null; try {shapefile = new File( "People/people.shp");personLoader = new ShapefileLoader(Person.class, shapefile.toURL(),peopleGeography, this);} catch (java.net.MalformedURLException e) {e.printStackTrace();} while (personLoader.hasNext()) {personLoader.next();}
The amazing thing about the shapefileLoader is that if you have an attribute in the shapefile and corresponding get/set methods in your agent, it will automatically create agents with the same values as the shapefile. For example, the people shapefile has ``name'' and ``age'' fields and our Person agent has get and set methods for ``name'' and ``age'' variables, so each Person is created with the correct name and age. Amazing!

The shapefile loader will have loaded every Person from the shapefile into the PeopleContext and given them an appropriate spatial location in the PeopleGeography. We can test this by running through all the agents in the geography and printing their location. If you want to do this you'll need to add these lines after the people have been loaded in PeopleContext.java (not compulsory):

// Get all agents in the geography and print their location: for (Person p:peopleGeography.getAllObjects()) {Geometry geom = peopleGeography.getGeometry(p);Coordinate coord = geom.getCoordinate(); System.out.println(p.getName()+ " is at: ("+coord.x+ ","+coord.y+ ")");}
Note: make sure you import the com.vividsolutions.jts.geometry package for the Geometry object.

Step 8: Get the agents moving
Now that we have loaded our agents into the context and given them a spatial location in the projection we can get them to move around. For now we'll just have them move in a random direction. Firstly, we need to create and schedule a method which will be called every iteration to control the agents:

There are a few ways to schedule things in Simphony, have a look at the ``Working with the scheduler'' section in the Simphony reference docs if you want more info ( http://repast.sourceforge.net/docs/reference/SIM/index.html). For now we'll use annotations, these take advantage of a nice new feature of Java and are good if we know, at compile-time, when we would like a method to be executed.

Put the following code after the setAge method in Person:

// Tell repast to run this function at every iteration@ScheduledMethod(start = 1, interval = 1, priority = 0) public void step() { System.out.println(name+ " has called step method");}
The step() method will now be called at every iteration. If you open the project now and run it (the little green arrow at the top of the Simphony GUI) you should see text telling us that the step() method is being called for each Person. This isn't particularly useful though as the agents don't actually do anything.

To make the agents move around the geography add the following code (put it after the System.out line in the step() method):

// Find the context this person exists in.Context context = ContextUtils.getContext ( this);// Get the GIS projection associated with the contextGeography projection = (Geography)context.getProjection( "PeopleGeography");// Move the agents a small distance in a random directionprojection.moveByVector( this, 5,RandomHelper.nextDoubleFromTo(0, (2* Math.PI)));
It's worth noting that in Simphony all the geographical information about each agent is stored in the projection, not in the agent (the Person class has no variables). This allows our agents to be more generic, you don't have to specifically give them any information about their relationship with each other or the environment. We could, for example, control our agents from another class and then the Person class wouldn't even need know about Repast Simphony!

Step 9: Create a Display
We've pretty-much finished now. You can run Simphony and the agents will move around their geography. To actually see this happen, however, we need to create a display:

Run the model. Remember that all displays, charts etc are created separately from the underlying model source code, we do this using the runtime GUI.
On the list on the left look for the ``Displays'' icon underneath the ``PeopleContext'' folder. Right click on it and choose Add Display.
In the new window which pops up you can configure the display.
Leave the default name (``A Display'') for now, anything will do.
The type of projection should be ``GIS''. Repast has detected that the only projection we have created in the PeopleContext is a GIS geography, this could be Network or Grid if we had created these types of projections as well.
Tell repast that we would like the display to show our PeopleGeography by clicking on it and then clicking on the right arrow to move it accross into the box on the right. You should have something that looks like:
Click Next.
Now we can configure how we would like the agents to be displayed. We can also add other shapefiles to be displayed (like roads, houses etc) by clicking on the + button. For now, just change the fill colour of our People agents (click on Edit) then click next.
The final box lets us configure how often the display will be updated. Click finish.
Finally, save the new model configuration by clicking on the floppy disk at the top. I'm not sure how repast remembers the configuration but it does! Now if we re-compile and/or re-run the model Repast will have remembered this display.
Press the play button and we're off!

You should see some agents wandering around aimlessly, something like this:

A quick note to Mac users: at the time of writing (May 2008) there is a small bug with the displays. This has been documented and a temporary work around can be found on the archives of the repast-interest email list under the title ``GIS in Simphony'' (I'm a Mac user and the workaround works fine for me).

So far we've created a context, added some agents into the context and created a GIS projection so the agents can have a location in a geographical space. Now we could create a Network projection to create a social network for the agents or create another context to hold House objects and give the agents a home.

That's the end of the tutorial, hopefully you've got a better idea of how to use Repast Simphony without using the development GUI. Once you get used to it it is a really great tool. As a quick plug have a look at my blog ( http://crimesim.blogspot.com) to see how I'm using repast to develop a simulation of a city which should predict the movements of burglars. I also intend to put some other tutorials up there. The complete code for the tutorial is also available: PeopleContext.java Person.java

2008年7月21日星期一

天涯回复

1.天*涯楼主:提名大陆扮演B社会老大最象的演员。
    天*涯**:古月。
  
    2.天*涯楼主:其实牛顿只是幸运地发现万有引力定律,要是早生三百年,我也可以!
    天*涯回复:牛顿的确是幸运儿,因为砸到他脑袋上的是苹果,而砸到可怜楼主脑袋上的不是榴莲就是椰子……
  
    3.天*涯楼主(男):小时候被叔叔W X过屁屁,现在长大的我该如何摆脱这种心理阴影?
    天*涯回复:犯我菊花者,虽远必诛!
  
    4.天*涯楼主:我和女朋友的照片,天涯朋友轻砸~
    天*涯回复:植物的性器官插在长角偶蹄类动物的排泄物上……
  
    5.天*涯楼主:大家见过公鸡下蛋吗?
    天*涯**:没有,不过我见过CCTV说真话。
    天*涯楼主:哎呀,你太牛了,我好崇拜你!
  
    6.天*涯楼主:我新买了一处庄园,有多大说出来吓死你——我开车绕一圈足足用了两个半小时!!!
    天*涯**:嗯,以前我也有这么一辆破车~  
  
    7.天*涯楼主:深圳南头一卖菠萝的女摊贩情急之下咬下城市管理者叔叔的小JJ……
    天*涯**:哼!你不让我生活,我就不让你享受生活!!
  
    8.天*涯楼主:每天对着单位那群白痴讲话让我觉得前途很渺茫……
    天*涯**:幸福吧你~因为对牛弹琴并不可怕,可怕的是一群牛每天对着你弹琴!
  
    9.天*涯楼主:你们女人大夏天的戴胸罩不热吗?
    天*涯回复:我们不带你们会热……
  
    10.天*涯楼主:和女友ML时,女友好像喊了另外一个男人的名字……
    天*涯**:你日了别人的女人你还有什么不满意的!!!
  
    11.天*涯楼主:为什么胡主席访问日本,日本方面比较冷淡,甚至机场连欢迎标语都没有挂?
    天*涯回复:怎么挂?热烈欢迎中国老朋友来日?
  
    12.天*涯楼主:去年到黑龙江谈生意,晚上找了个俄罗斯小姐狂干俩钟头,你猜射完后她对我说什么?嘿嘿~
    天*涯**:中国爷们真强?
    天*涯板凳:Are——you——ready?
  
    13.天*涯楼主:利用东西方信息不对称,很多国外地摊货到中国都变成了奢侈品,那中国有啥垃圾牌子在国外冒充高档货?
    天*涯**:章子怡。
  
    Copyright© 天涯社区开心乐园(C_chairman/chai2001),来自天涯杂谈、娱乐八卦、天涯真我、开心乐园、时尚资讯、国际观察等版面。
  
    14.天*涯楼主:征集骂人最狠且不露脏字的一句话。
    天*涯回复31:你妈生你的时候是不是把人扔了,把胎盘养大了?
    天*涯回复32:我电脑里有你妈300多张照片!
  
    15.天*涯楼主:从来都觉得蝎子精是整部《西游记》里最美的女人,当蝎子精把唐僧逼到床上撩拨时,我心下不住地为唐僧鼓劲:从了,从了,咱就从了吧!但关键时刻,可恶的悟空出现了……
    天*涯回复12:唉,要是换好色的八戒出现就好了~
    天*涯回复13:嗯,八戒出现了,这次改蝎子精不从了……
  
    16.天*涯楼主:老爸送我老公一根鹿鞭,大家说这是啥意思?还有照片的说~
    天*涯回复:这是老一辈对青年一代的鞭策啊~~~
  
    17.天*涯楼主:大家都来讲一个开头KB,中间好笑,结局悲惨的故事。譬如从前有个鬼,放了个屁,然后死了。
    天*涯回复:遇到芙蓉姐姐,爱上芙蓉姐姐,娶了芙蓉姐姐……
  
    18.天*涯楼主:怀疑老婆红杏出墙,但苦于没证据……
    天*涯回复:如果你没本事做陈冠希,那就做谢霆峰吧~
  
    19.天*涯楼主:《神雕侠侣》里小龙女胳膊上的守宫砂是什么东西,干什么用的?
    天*涯回复:守宫砂是处女的桌面快捷方式。
  
    20.天*涯楼主:新闻说某人被蟒蛇吞了,请问在野外真的遇到蟒蛇怎么办?
    天*涯回复1:掐七寸,捅肛门,两个很有效的方法,希望大家广为传播。
    天*涯回复2:捅蛇的肛门还是自己的肛门?
    ……
    天*涯回复47:屁话,荒郊野外的拿什么捅!
    天*涯回复48:许仙知道拿什么捅!

2008年7月10日星期四

女子超市偷肉被抓 称只想让儿子吃好点儿查看原文

网易广西桂林网友(222.84.*.*) 的原贴:
我是一星期吃一次猪肉

网易河北石家庄网友 [xiang04641] 的原贴:
我一星期去看次猪肉

网易湖北武汉网友(221.234.*.*) 的原贴:
俺们每星期去超市看一次肉价,再摸摸口袋的人民币,想想吃肉的害处,就义无反顾的回头~~~~~~

网易广东深圳网友(58.60.*.*) 的原贴:
你丫儿还不错呀,老子是一个月去看一次,三个月才吃上一次肉呢

网易上海杨浦网友(222.64.*.*) 的原贴:
呵呵,老子是3个月看一次,半年吃一次肉。

网易江苏苏州网友(222.92.*.*) 的原贴:
我是一看一个月 就在肉旁边转悠.....

网易北京网友(211.94.*.*) 的原贴:
我想去看来着,可是饿得出不了门

网易广东东莞网友(202.173.*.*) 的原贴:
到超市摸摸猪肉,回来洗洗手煮汤喝.

网易美国网友(128.171.*.*) 的原贴:
打死你个败家玩艺!楼上的,你怎么不在咱们村的井里洗洗手呢?!这样咱们整个村子的人都可以天天有猪肉味闻了!

网易四川遂宁网友(124.161.*.*) 的原贴:
楼上的咋这么自私呢?应该到沱沱河去洗手,这样整个长江中下游的广大群众都能有肉味闻了……

网易山东日照网友(122.6.*.*) 的原贴:
楼上的咋这么自私呢?应该到海边去洗手,这样整个地球上的广大无产阶级都能有肉汤喝了……

网易四川乐山网友(220.248.*.*) 的原贴:
上面的都是人才啊

网易福建泉州网友(125.78.*.*) 的原贴:
兄弟:你们真牛,一个比一个牛,有没有更牛的出来啊

网易重庆沙坪坝网友 [68410569] 的原贴:
能告诉我猪肉是什么味道么

网易广东深圳网友(116.25.*.*) 的原贴:
我很久没吃过了,我想猪肉应该是甜的吧.

网易山东济宁网友(60.211.*.*) 的原贴:
靠,你们每天晚上不看肉么?

网易上海网友(218.1.*.*) 的原贴:
什么是猪肉啊?大哥

网易广西柳州网友 [llsyao] 的原贴:
传说中的猪肉真的存在吗?

网易山东青岛网友(221.215.*.*) 的原贴:
每天在市场上捡菜叶的时候,我总能看见猪肉,但是我知道,我不可能吃到猪肉....上次吃猪肉饺子,是妈妈卖了捡了3天的塑料瓶子换的,味道真好....真希望你们大家都有钱,就可以都喝饮料,我和妈妈就能多捡点塑料瓶,我就能再吃到一次猪肉了....只是不知道,现在涨价了,人家还能不能答应只卖二两....
感谢网吧里这位去厕所的大哥,让我可以看新闻,还把喝完的瓶子给我了...

网易浙江绍兴网友(124.160.*.*) 的原贴:
我咋那么想哭喃

网易广东深圳福田网友(218.18.*.*) 的原贴:
楼上的楼上,你好可怜,

天堂里有没有猪来猪往?

2008年7月6日星期日

哈佛校长给2008届本科毕业生的毕业演讲

独角兽资讯 发表于 2008-6-21 14:28:00

译者: shog

按照这所古老大学的奇怪的传统,我应该是站在这儿,告诉你们那些永恒的智慧。我就站在这个讲坛上,穿得像个清教徒牧师一样——这个打扮也许已经吓到了我那些高贵的先人们,让他们以为是巫婆现身(校长是女的,译者注)。这会让英克利斯(Increase)和考特恩(Cotton)父子俩(他们反对清教,译者注)忍不住想审判我的。但是,我还是要站在这儿,跟你们聊聊。

你们已经上了四年的大学了,我当校长还不到一年;你们认识三任校长,我只认识大四一个班的学生。那么,经验是什么?也许你们应该搞清楚。也许我们可以互换一下角色,我可能就会以哈佛法学院惯有的风格,在接下来的一个小时里自说自话。

从这一点上说,我们似乎都做到了——不管程度多少。但我最近才知道,从5月22日开始你们就没有晚饭吃了。虽然我们会把你们比作已经从哈佛断奶的孩子们,但我从没想到会这么彻底。

再让我们来说说那个“自说自话”吧。让我们把这个演讲看作是一个答疑式的毕业生服务,你们来提问题。“浮士德校长,生活的意义是什么?我们为什么要在哈佛读四年?校长,四十年前你从学校毕业的时候,肯定学到不少东西吧?”(四十年了。我可以大声地说出我当时生活的每个细节,和我获得布林莫尔学位的年份——现在大家都知道这个。但请注意,我在班里还算岁数小的。)

其实,这个答疑环节你们早就从我这儿预定了。你们问的问题也大概就是这类的。我也一直在想该怎么回答,还在想:你们为什么为这么问。

听我的回答。2007年冬天,助理就告诉我要有这么一个演讲。当我在Kirkland听中午饭的时候,在Leverett吃晚饭的时候,当我在我上班时和同学们见面的时候,甚至当我在国外碰见我们刚毕业的学生的时候,同学们都会问我一些问题。你们问我的第一个问题,不是问课程计划,不是提建议,也不是问老师的联系方式或者学生的空间问题。实际上,也不是酒精限制政策。你们不停地问我的问题是:“为什么我们的学生很多都去了华尔街?为什么我们哈佛的学生中,有那么多人到金融、咨询和电子银行领域去?”

这个问题可以从好几个方面来回答,我要用的是威利萨顿(一个美国银行大盗,译者注)的回答。你们可能知道,当他被问到为什么要抢银行时,他说“因为那儿有钱”。我想,你们在上经济学课的时候,都见过克劳迪亚·戈丁和拉里·凯兹两位教授,他们根据七十年代以来他们所教学生的职业选择,提出了不同的看法。他们发现,虽然金融行业在金钱方面有很高回报,但还是有学生选择了其它的工作。实际上,你们中有37个人选择做教师,有一个会跳探戈的人要去阿根廷的舞蹈诊疗所上班,另一个拿了数学荣誉学位的人要去学诗歌,有一个要在美国空军受训作一名飞行员,还有一个要去作一名治疗乳房癌症的医生。你们中有很多人会去学法学、学医学、读研究生。但是,根据戈丁和凯兹的记录,更多的人去了金融和咨询行业。Crimson对去年的毕业生作了调查,参加工作的人中,58%的男生和43%的女生去了这两个行业。虽然今年的经济不景气,这个数字还是到了39%。

高薪、不可抗拒的招聘的冲击、到纽约和你的朋友一起工作的保证、承诺工作很有趣——这样的选择可以有很多种理由。对于你们中的一些人,也许只会在其中做一到两年。其他人也都相信这是他们可以做到最好的一份工作。但,还是有人会问:为什么要这样选择。

其实,比起回答你们的问题来,我更喜欢思考你们为什么会问。戈丁和凯兹教授的研究是不是正确的;到金融行业是不是就是“理性的选择”;你们为什么会不停地问我这个问题?为什么这个看似理性的选择,却会让你们许多人无法理解、觉得不尽理性,甚至有的会觉得是被迫作出的必要的选择?为什么这个问题会困扰这么多人呢?

我认为,你们问我生活的意义的时候,是带着指向性的——你们把它看成是高级职业选择中可见、可量度的现象,而不是一种抽象而深不可测的、形而上学的尴尬境地。所谓“生活的意义”已经被说滥了——它就像是蒙提·派森(Monty Python)电影里可笑的标题,或者说是《辛普森一家》里的那些鸡零狗碎的话题一样,已经没有任何严肃的涵义了。

让我们暂时扔掉哈佛人精明的处世能力、沉着和不可战胜的虚伪,试着来寻找一下你们问题的答案吧。

我想,你们之所以会焦虑,是因为你们不想只是做到一般意义上的成功,而且还想过得有意义。但你们又不知道这两个目标如何才能同时达到,你们不知道在一个大名鼎鼎的公司中有一份丰厚的起薪,并且前途很有保障,是不是就可以让你们自己满足。

你们为什么要焦虑?说起来,我们学校这方面也有错。从你们进来的时候,我们就告诉你们,到这里,你们会成为对未来负责的精英,你们是最棒的、最聪明的,我们都要依靠你们,因为你们会改变这个世界。这些话,让你们个个都胸怀大志。你们会去做各种不平常的事情:在课外活动中,你们处处体现着服务的热情;你们大力倡导可持续发展,因为你们关注地球的未来;在今年的总统竞选中,你们也表现出了对美国政治改革的热衷。

但现在,你们中的许多人迷惘了,不知道这些在做职业选择时都有什么用。如果在有偿的工作和有意义的工作之间做个选择,你们会怎么办?这二者可以兼顾吗?

你们都在不停地问我一些最基本的问题:关于价值、试图调和那些潜在竞争的东西、对鱼与熊掌不可兼得的认识,等等。现在的你们,到了要作出选择的转换阶段。作出一个选择——或工作、或读研——都意味着失去了选择其他选项的机会。每次决定都会有舍有得——放弃一个可能的同时,你也赢得了其他可能。对于我来说,你们的问题差不多就等于是站在十字路口时的迷茫。

金融业、华尔街、“招聘”就是这个困境的标志,它带来了比职业选择更广更深的一系列问题。不管你是从医学院毕业当了全科医生或者皮肤科医生,从法学院毕业进了一家公司或者作了一名公设辩护律师,还是结束了两年的Teach for America项目,在想要不要继续教书,这些问题总会在某种程度上困扰你们。你们之所以焦虑,是因为你们既想活得有意义,又想活得成功;你们知道你们所受的教育,让你们不只是为自己的舒适和满足而活,而且还要为你们周围的人而活。现在,到了你们想办法实现这个目标的时候了。

我想,还有一个原因使你们焦虑——这个原因和第一个原因相关,但又有所不同。你们想过得幸福。你们一拥而上地去选修“成功哲学”和“幸福的科学”,想从中找到秘诀。但我们怎么样才能幸福呢?我可以提供一个不错的答案:长大。调查数据说明,越老的人——比如我这个岁数的人——比年轻的人感到更幸福。但可能你们都不愿意等。

当我听着你们说你们面前有如何的选择时,可以听出来,你们在为搞不明白成功和幸福的关系而烦恼——或者更确切地说,什么样的成功,不仅能带来金钱和名望,还能让人真正地幸福。你们担心工资最高的工作,不一定是最有意义、最令人满足的工作。但你们想过没,艺术家、演员、公务员或者高中老师都是怎么过的?你们有没有思考一下,在媒体圈里该怎么生存?你们是否曾试想过,在经过不知道多少年的研究生学习、写了不知道多少篇论文之后,你们能否找到一个英语教授的工作?

所以,答案就是:只有试过了才知道。但是不管是画画、生物还是金融,如果你都不试着去做你喜欢做的事,如果你不去追求你认为最有意义的东西,总有一天你会后悔的。生活的路还很长,总有机会尝试别的选择,但不要一开始就想着这个。

我把这个叫作职业选择中的停车位理论,几十年来我一直在和同学们说这些。不要因为你觉得会没有停车位,就把车停在离目的地20个街区远的地方。先到你想去的地方,然后再到你应该去的地方。

你可能喜欢投资银行、喜欢金融、喜欢咨询,它们可能是最适合你的。也许你和我在Kirkland碰到的一个大四学生一样,她刚从西海岸一家很有名的咨询公司面试回来,她问:“我为什么要做这行?我讨厌坐飞机,我不喜欢住酒店,我不会喜欢这个工作的。”那就找个你喜欢的工作吧。要是你醒着的时间里,都在做你不喜欢的事情,你也不会感到幸福的。

但是,最最最最重要的是,你们要问出这个问题——问我或者问你们自己。你们选择了一条路,也就选择了一份挑战。你知道自己想要什么样的生活,只是不知道该怎样到达那儿。这是好事。我觉得,从某种程度上说,这也是我们的错。关注你的生活,思考怎样才能把它过好、怎样才能把事情做对:这些也许是博雅教育给你最宝贵的东西。通识教育让你自觉地生活,让你在你所作的一切中寻找、定义价值。它也让你成为一个自我的分析家和批评家,让你从最高水平上掌握你生活的展示方式。从这个意义上讲,博雅教育让你自由。它们赋予你行动、发现价值和作出选择的能力。不要静止不动,要随时准备接受改变。牢记那些我们告诉你们的远大理想,就算你觉得它们永远不可能实现,也要记住:它们可以指引你们,让你们到达那个对自己和世界都有意义的彼岸。你们的未来在自己手中。

我都迫不及待地想知道你们会做出什么样的成就了。无论如何,常回家看看,和我们分享你的幸福生活。

2008年7月5日星期六

超级变态的问题与答案

  1) 企鹅肉问题:
  一个女孩有一天给一个男孩做了一道菜,男孩吃完了,但是觉得味道怪怪的,于是他问那女孩,这是什么肉啊?女孩说,这是企鹅肉,男孩沉思了一会儿......痛哭了起来,自杀了,为什么?
  
  2) 跳火车问题:
  一个人坐火车去邻镇看病,看完之后病全好了。回来的路上火车经过一个隧道,这个人就跳车自杀了,为什么?
  
  3) 水草问题:
  有个男子跟他女友去河边散步,突然他的女友掉进河里了,那个男子就急忙跳到水里去找,可没找到他的女友,他伤心的离开了这里。过了几年后,他故地重游,这时看到有个老人家在钓鱼,可那老人家钓上来的鱼身上没有水草,他就问那老人家为什么鱼身上没有沾到一点水草,那老人家说:“你不知道啊,这河从没有长过水草。”说到这时那男子突然跳到水里,自杀了,为什么?
  
  4) 葬礼故事的问题:
  有母女三人,母亲死了,姐妹俩去参加葬礼,妹妹在葬礼上遇见了一个很型的男子,并对他一见倾心。但是葬礼后那个男子就不见了,妹妹怎么找也找不到他。后来过了一个月,妹妹把姐姐杀了,为什么?
  
  5) 半根火柴问题:
  有一个人在沙漠中,头朝下死了,身边散落着几个行李箱子,而这个人手里紧紧地抓着半个火柴,推理这个人是怎么死的?
  
  6) 满地木屑问题:
  马戏团里有两个侏儒,瞎子侏儒比另一个侏儒矮,马戏团只需要一个侏儒,马戏团里的侏儒当然是越矮越好了。两个侏儒决定比谁的个子矮,个子高的就去自杀。可是,在约定比个子的前一天,瞎子侏儒也就是那个矮的侏儒已经在家里自杀死了。在他的家里只发现木头做的家具和满地的木屑。问他为什么自杀?
  
  7} 夜半敲门问题:
  一个人住在山顶的小屋里,半夜听见有敲门声音,但是他打开门却没有人,于是去睡了,等了一会儿又有敲门声,去开门,还是没人,如是者几次。第二天,有人在山脚下发现死尸一具,pol.ice来把山顶的那人带走了。为什么?
   
  答案:
  
  1.企鹅肉问题
  心理严重变态答:男孩以前曾和女友一起去北极考察,因为没东西吃,女孩把自己的肉一片片割给男孩吃,骗他说是企鹅肉,结果男孩活下来了,女孩却饿死了。多年后男孩吃到了真正的企鹅肉,终于明白当时女孩的苦心,伤心之下,自杀徇情。
  
  2.跳火车问题
  心理变态答:此人原是瞎子,看好后终于得见光明,经过隧道时一片黑暗,他以为自己又下了,绝望之下,自杀而亡。
  
  3.水草问题
  心理变态答:男孩当时曾抓到女孩的头发,以为是水草,错失了救女孩的机会,后悔莫及。
  
  4.葬礼故事的问题
  心理极度变态答:因为她想再开一次葬礼,再见到那个男的。
  
  5.半根火柴问题
  心理变态答:他和伙伴一起乘热气球,途中出了故障,必须减轻分量,于是大家抽签决定由谁做出牺牲,跳下热气球。此人不幸抽中不祥的半跟火柴,连同行李一起被人扔下热气.
  
  6.满地木屑问题
  心理变态答: 另一个侏儒半夜溜到矮侏儒家,把所有家具的脚都削短了,瞎子矮侏儒早上起床,摸到所有的东西都变矮了,以为是自己长高了,绝望之下自杀身亡。
  
  7.夜半敲门问题
  心理变态答:有人身负重伤,好不容易爬到小屋门口,主人开门,又把他撞下去了,再爬,再开,又被撞下,如此反复,终于气绝身亡。

2008年7月4日星期五

元胞自动机与多智能体在城市规划中的应用

主持人:接下来发言者是中山大学的黎夏教授,他在地理信息分析、遥感信息分析等方面做出了很好的成就,他演讲的内容是怎样用计算机更快的进行模拟。
  黎夏:谢谢主持人。感谢大会邀请我做报告,我报告的主题是《元胞自动机与多智能体:辅助规划的工具》。分为几个方面的内容,GIS在城市规划中的应用、元胞自动机(CA)、CA在城市扩张模拟及规划的应用、多智能体与CA相结合及应用。要解决问题方案之一,就是我们这几年的研究,元胞自动机与多智能体。信息技术需要在发展中进行创新性的研究,这也是我们这几年在学校中做的研究方向,因为学校是以理论研究为主的,通过理论研究来提高信息技术的创新能力,希望提供一些服务。
  GIS在城市规划中的应用,主要体现在一个是改善地图的制作,提高现实性,提高对城市查询和检索的效率,帮助你快速的获取地理信息,更大范围的探讨多种规划方案的可能性,便于公众和政府来交流规划中遇到的问题,改善服务的质量。GIS在城市规划中起重要的作用,可以进行空间查询等等。由于信息化的程度提高,目前我们积累了大量的空间信息,随着GIS技术的越来越成熟,提供了大量的空间信息,这些空间信息怎样使用更有效,为城市规划服务,我们就要进行数据的挖掘,不仅仅是简单的将数据显示出来,我们还希望从数据中挖掘出金子,提取出知识来。
 我们城市是复杂的系统,存在着非限定性、不确定性,这些复杂的关系是我们城市系统所特有的,如果我们还是按照传统的思维来解决问题,就需要从新的角度去创新。过去是从上至下的研究方法,现在我们能不能从上至上的研究方法,引进复杂的信息技术。第一个方面方案,就是元胞自动机,元胞自动机是在四十年代在数字计算机的基础上提出来的,是研究复杂系统更有效的工具,到了八九十年代引起了重视。元胞自动机是二进制,最早四十年代是研究计算机实现的过程,后来八十年代,波夫是一个天才的物理学加将元胞自动机来研究复杂系统,我们城市规划系统也就是一个复杂系统,我们也逐渐采用元胞自动机研究城市规划系统。GIS积累大量的数据,如何从数据挖掘的角度来获取知识,然后进行转化,我们可以通过模拟来预测或者是来规划城市的发展,这是我们研究的方向之一。
  元胞自动机可以很有效的模拟复杂性,包括一些周期性的现象,紊乱现象,还有结构性的特征。可以模拟自然现象,揭示一些自然规律。这种模拟方法可以很有效的表示出城市的扩张现象,城市系统有一个分形现象。其实元胞自动机不仅仅是在我们城市规划系统中进行模拟,在很多领域都可以有使用,大家可以在网上查询,比如说地学、生态研究等方面都有应用。如果用传统的方法,我们来进行模拟是很困难的,因为有不确定性。这是模拟干旱时沙丘的移动情况(图)。元胞自动机还可以模拟城市交通时的情况,还可以模拟野火蔓延的情况,还可以模拟比如说传染病传播的情况。有人发现通过这种模拟方法,可以表示出很复杂的生命演变的过程。
  我们这几年将元胞自动机使用在城市扩张模拟及规划中。如果大家在珠江三角洲都知道,城市扩张的速度是非常快的,十几年前有很多农田和水稻田,但是现在基本上都不存在了,土地利用的方式有了很大的变化,这个变化过程是非常复杂的,我们怎样掌握和反映演变过程,我们就用元胞自动机,这是很有效的一个工具,通过模拟演示过程,来揭露其中存在的问题。这是深圳的情况(图),是动态的演变过程,要模拟这个过程是非常困难的,而且我们还要预测和评价它,就可以通过元胞自动机进行这方面的研究。这是我们模拟东莞城市的扩张过程(图),有一系列的地理变量和人为因素,如果我们按照传统的方法无法预测,我们希望通过元胞自动机进行很有效的城市扩张过程的预测。
  我们利用See5.0系统,对所获得的GIS和遥感数据进行数据挖掘,以发现知识,自动获得城市演变的转换规则。我们通过转换规则,挖掘出知识,我们看看转换规则和格局的关系,进一步看过程的关系。我们用DMA控制人与动物的生命过程,这些参数与控制城市演变的一个过程,不同的城市不同的乡不同的镇有不同的参数,我们用元胞自动机预测它评价它,最后看那些参数可以调控,希望找出更有效的利用土地资源的方式。我们通过不同参数的或缺,发现珠江三角洲内部的差异,演变的过程是不同的,不同城市的演变规律是不同的。我们更进一步通过评价来分析它,进一步进行调控,使得城市可以向着可持续发展的方向演变,我们提供一些规划的依据,使得更有效的利用土地资源,让我们将约束性的条件加进去,不仅仅是按照过去的确实演变,而且加入合理的约束条件,控制土地利用的方向,我们希望建立这样的模型,为城市规划或者土地规划做有效的工具,加入约束性的条件,这是我们开始考虑的初衷。我们一个模型,就是模拟农田保护区自动生成的过程,不同的城市不同的地方不同的干部可能规划的方案都不一样,存在着不协调不一致的情况,而且缺乏客观的依据,我们通过元胞自动机自动生成农田保护区,强调农业的重要性可能生成一种方案,如果强调其他方面又会生成一种方案,这是我们的规划模型。另外我们还可以进一步将城市发展的密度加进去,我们模拟不同城市密度的发展,高密度的发展,不同密度的人口情况。
  这几年我们开展了另外一个方面,元胞自动机与多智能体相结合,公众行为与政府决策怎样结合,我们将智能引进了模型中。城市演变的过程不仅仅是自然的过程,也受到各种角色在城市系统中起重要的作用,这些角色如何更有效的在模型中体现出来,那就是采用计算机发展前沿的多智能体系统,我们希望将多智能体系统与元胞自动机以及地理系统结合起来,对城市系统的演变提供规划辅助。智能体能够根据其内部状态和感知到环境的信息、决定和控制自身的行为,这就是自主性。它有反应性、交互性、主动性等等,我们通过数据的挖掘,规定多智能体行为,更好的描述模拟,也为规划提供依据,更有利于城市系统向可持续方向进行演变和发展,形成规范。
  多智能体与CA相结合的地学模型有环境因素往往是由元胞自动机所表达,还有个体与智能体,个体根据自己的编号及与其他个体的交流协商对周围环境的变化作出相应的反应。我们做研究是跟国际上同步的,站在同一个起跑线上。多智能体可以使用在城市土地利用变化等几个方面。这是我们建立的一个模型,来预测海珠区居民地的演变过程,涉及到几个不同类型的多智能体,政府、开发商、居民,居民有不同选择居住地的爱好,这些爱好取决于他们的收入情况、交流的水平、家庭有没有小孩等等,跟经济状况有关系,这些参数在统计年鉴上或者GIS共同挖掘出这些知识来。开发商有不同的投资行为,政府根据资源情况调控土地的价格,有不同的行为。多智能体包括政府、居民等他们有不同的决策行为,通过资源和环境的相互作用,导致政府比较复杂的演变过程。如果用传统的方程式,我们是无法进行这方面的研究。我们要根据不同的类型,有不同的参数。
  今天我的汇报内容就是这么多,谢谢各位专家领导。中国

2008年7月1日星期二

关于贵州事件的四点想法----引子牛博

都是骗银地 @ 2008-6-30 10:45:20 阅读(24485) 引用通告 分类: 谎言帝国
扫了一眼外电的报道,以路透社为范本,大同小异。YOUTUBE上有焚烧建筑物的长视频。可以读英文的同学只要GOOGLE “guizhou weng'an riot”就可以看到有关报道。据说当地居民已经在给受害者家庭捐款支持他们上诉了。

读我博客的人都知道我基本从不谈论“道德”,至于我相信不相信它是另一回事,只是我几乎从不用“道德”作为出发点思考问题,这篇也不例外。贵州的故事在中国从古到今都在天天发生,有未经证实的数据说近十年来每年中国都要“大小暴乱冲突”上万次,那是说每天都要发生几十次了,原因千奇百怪,有选举的、有征地的、有拆迁的。现在本来是普普通通的一起刑事案件,闹到如此地步,为什么?

1、如果我的儿子犯下伤天害理的滔天大罪,我会愤怒惭愧到极点,但我也一定会用尽自身资源不择手段来维护他的周全,道德不道德犯法不犯法都不重要。我成功或失败都是我家庭的不幸;但如果我成功了,是社会和法律的不幸。

在一个正常的不用家庭成员互相监视的社会中,除了少数丧心病狂之徒,绝大多数人不会干“大义灭亲”这种灭绝人性的事。所以一旦有冲突,无论对错,双方必各出招数搏个死活。钱、权力都可以上场表演发挥作用。而“公正”是一种商品,需要花费资源去获得。社会对有资源的人永远更公平一些,古今中外皆然,在美国请的起金牌大状就很有可能脱罪,请不起就乖乖里面呆着。先进之邦固然可以降低个体获得“公正”的门槛,但不能降低全社会获得“公正”所付出的代价。君不见美国的官司和律师数量乎?都是代价,只不过通过制度让全社会来分摊了。

所以,一旦遭遇了不幸的不公的事件,永远不要指望会有青天大老爷和活菩萨来主持正义,要尽一切力量去争取,要准备承担这过程中所要付出的代价,也要随时准备迎接一次又一次的失败。这不是世风日下苍天无眼,而是你心里的那个世界和苍天从来就没真正存在过,是你看主旋律电视剧看多了想象出来的罢了。


2、“人民”是个不存在的东西,自然“人民公仆”也是不存在的东西,任何一级官员都没有任何动力为虚构的“人民”服务。这是正常的,如果你认为这不正常,那是你自己的问题,不是官员的。这就是上世纪六七十年代兴起于弗吉尼亚的当代政治经济学的分析起点。

政府官员是一项职业,像任何职业一样需要树立个“职业形象和道德”,“为人民服务”是这个"构建的形象”之一。就像如果你身在服务行业,你的行规之一是“客户是上帝”,可你不会蠢到真的拿顾客当上帝,而官员,无论是中国共产党员还是美国共和党员,也不会蠢到真正“为人民服务”。温家宝一句“人民是你们的衣食父母,你们自己看着办”就让新闻媒体高潮了无数次;我要是个小贩,顾客才真是我的衣食父母,让我随便看着办么?我他妈宰死他们!

官员是职业,挣钱养家、职场升迁是行为的目的,对领导负责是达到目的的手段,古今中外皆然。只不过先进之邦可以把这行为更好的转化成“为社会服务”的职能,就像先进的市场可以把比尔盖茨个人的好奇心和赚钱动机转化为社会的财富一样,而落后之邦把这行为转化成了“上下其手”。落后之邦的官员可并不比先进之邦的官员更卑鄙,充其量一样卑鄙,都想把竞争升迁的对手置于死地,只不过先进之邦把这卑鄙变成了“互相监督”,落后之邦把这卑鄙变成了“官官相护”。


3、中央政府唬不了地方政府,如果青天老爷不在县衙里,那他也不会出现在金銮殿。

今日的中国特别流行上访,因为我国关于皇帝微服私访、宰相日理万机、钦差大臣铁面无私、尚方宝剑各种铡刀遇神杀神遇佛杀佛的故事和电视剧实在是层出不穷,给人造成了幻觉,以为庙堂之上一尘不染。那都是真理部的把戏,和各种“代表”、“荣辱”没有本质差别,你相信了只能说明你傻。而最近还开通了“上访热线”,演技真是越来越好了。


古代皇上就得拿地方大员封疆大吏当大爷,因为地方有钱有地很多时候还有军队,弄得不爽直接干到京城去。而今天的政治谱系里地方势力还在加强而没有减弱,虽然没有了军队,但钱可是大大地多。中组部中纪委双规几个干部,裁撤几个官员,根本撼不动地方势力的根本。想靠呆在北京一路高升的时代过去了,到经济大省锻炼锻炼才是飞升王道。

(关于这方面的研究,参加周黎安和李洪斌2005年发表在JPubE(公共经济学报)的论文《政途起伏与经济表现:中国人事控制的激励作用》(Political Turnover and Economic Performance: the Incentive Role of Personnel Control in China),北大光华的周黎安老师是我微观计量的启蒙老师,对我影响甚大,虽然今天我们的方法论可能已经不同,但我走上今天的研究路线是他打下的基础。他在斯坦福的导师青木昌彦先生的《比较制度分析》是煌煌巨著,懂数学的人千万不要错过)

所以地方自有其秩序,傻子才会抱住中央的什么工作组调查团拦路喊冤,浪费体力罢了。如果通过法律渠道无法申冤,想办法联系媒体或者勾结对头的政敌吧。如果你举报的某个官员倒台了,那一定是因为他在政治斗争中失败了,而不是你的举报材料太有道理太铁证如山了。


4、参与“打砸抢”的数千人,都为“公平正义”而来“路见不平一声吼”么?搞笑罢了。但其中折射的是这个社会广泛存在的不满和愤怒情绪。

几年前我在中国社会科学院读研究生的时候,知道社会学所(就是李银河老师所在的单位,牛人云集)陆学艺老师领导的一项大规模社会调查,大意是“中国各阶层生活满意程度调查”。把中国社会分为了十个阶层,上到高层官员商贾巨富,下到出租司机贩夫走卒,调查结果显示 --- 所有十个阶层都对社会不满。出租司机累死累活只不过是“为他人做嫁衣裳”,大部分赚钱所得都交给了公司(其实这实在太正常了,车可比人值钱多了,司机这种低技术含量的活,在竞争下也就得个普通体力劳动的回报);而大老板们人人自危随时怀揣数本护照准备跑路,也是提心吊胆怨气冲天。

后来这研究发表了么?不记得了。可紧接着又搞了个中国巨富们的调查,结果好像是其中90%以上的人和中共高层领导有关,也不知道发表了没有。他们社会学所有位老师的名言就是:“社科院的学者有两个特点:第一是说话没人听;第二是没人听还要继续说。”


中国这么大规模的社会转型历史上没见过,我们身在其中自然也是独一无二地体验,很多事情需要冷静的思考和研究。对于成年人,应该知道这世界不欠你任何希望,也不欠你任何美好的东西,所有的希望和美好都要靠自己打拼得到,小时候被一块红布蒙住了天是你幼稚,现在还蒙着就只能说明你瞎了,醒醒吧。先就说这些。
==============================================================
人是不是真的都精于算计?这个问题不重要。重要的是他们的行为怎么看怎么都像经过算计,所以就让我们假设他们精于算计吧

贵州女生遭奸杀 逾万人火烧公安局县政府

 
来源: 蓝魂博客 个人空间 周六下午(6月28日),贵州瓮安县逾万民众冲入县公安局、县政府和县委大楼,打砸办公室,点火焚烧多间办公室和数十辆车。起因是瓮安三中一名女生遭当地流氓强暴杀害,但因凶手与公安局和省、县政府领导有关系,因此获释,县长、公安局长宣称受害人是跳河自杀,并强行要毁尸灭迹,遭到当地民众群起反抗。

被害女生干爹谢新发及参与抗暴的几位当地民众刚刚接受大纪元采访时表示,这是官逼民反。被害女生家里无钱无势,没法讨公道。“当官的太坏了,成了恶势力的保护伞,想耍就耍,想搞就搞,有钱有势的胡作非为,没钱的老百姓没办法,根本没有活路。” 他们还披露,当地流氓素来与当官的勾结,横行霸道。“其实以前都发生过多起类似女孩被害的惨案,都不了了之了。这次是这些群众齐心,大家都愤恨。这次不仅是为李树芬讨个公道,也是为其他老百姓讨回公道。现在没有别的办法,只有请你们媒体关注。” 大纪元去电当地政府、公安局都无人接听。据谢新发介绍,目前贵州瓮安县一片混乱,当地民众义愤填膺,群体走上街头抗议。当地政府已全面封锁网络等通讯工具。有关这起事件的帖子出现在了大陆一些网站和论坛上,但很快就被删除。  

女生被奸杀 公安包庇凶手
据谢新发和几位民众介绍,受害女生名叫李树芬,今年15岁,老家是玉华乡,从小听话懂事,不仅人长得漂亮,而且勤奋好学,学习成绩很好,人缘也很好,深得同学和老师的喜爱。 谢新发介绍,上周六(6月21日)傍晚6点左右,李树芬班上有个女同学王骄(音),把李树芬叫出去,当晚李树芬被当地两个社会流氓强奸杀害并抛尸河中(瓮安县西门河)。当晚11点多,有民众听到有人喊“救命”。12点半左右,王骄打电话给李树芬的哥哥,说她“跳河自杀了”。 李树芬的哥哥及其他人一起赶到河边后,看见王骄和两个男子站在桥头,而且发现李树芬肚中无水,且事先无任何想要自杀的迹象,于是凌晨2点左右,将三人扭送公安局。但后来获悉,次日上午10点多,三人已被无条件获释,公安局没有进行任何调查和笔录工作,还声称,受害人是“自杀”身亡。 次日就有人告诉李树芬家人,李树芬是被人强奸后害死推入河中的,警方未作全面尸检,也未做强制措施,对家属提出的全面尸检要求不予理睬。李树芬家人从当地民众提供的信息中获知,王骄与两名男性凶手,与县公安局、县委领导、省委领导都有关系,因此在被拘押8小时后即获释。 王先生说:“听说凶手后台都很硬,那个王骄好像是县长的侄女。”




政府公安要强行埋尸 受害人家属被打死

本周一,法医鉴定也称是“自杀”,家人不服到县委上访。任职于玉华中学的教师、李树芬的叔叔,被6个便衣公安打成重伤,后医治无效死亡,李树芬的婶婶也被打成重伤,脸部破相,不省人事。李树芬的父母一直在西门河桥边的事发地守着那副装着女儿尸体的水晶棺材。 谢新发说:“公安局的还派人去偷尸体,抢尸,要强行下葬,树芬的家人拒绝,都遭到殴打。县长、公安局长都要强行埋人。现在好多群众守着尸体。尸体是树芬的家人自己捞起来的,公安局逼迫她家人说是消防队捞起来的。” 据谢新发披露,现在无法联系到李树芬的父母。他说:他们被警察追打,见了就挨打,可能也在四处逃亡。 他说:“太惨了!每个人见到都流泪,每个人听到都气愤。” 王先生说:“不仅她的叔叔被打死了,还有其他帮忙申冤的人也有被打死的,现在不知道具体有几个。还有几十名学生被打成重伤。”
学生、民众义愤烧政府大楼
该惨案引起当地民众义愤,瓮安四所中学学生到公安局请愿。公安局又出动武力镇压,至使学生和一些人民群众焚烧了公安局,掀翻和焚烧公安警车十多辆。公安被围困无法出来,各地警察纷纷调往瓮安县。
    
刘女士说:“开始一群学生拉着横幅为她申冤,去了政府,没人理睬,后来又去了公安局,公安用电棍打学生,学生和赶来声援的群众就把公安局的十几辆车都砸了,后来又点火烧公安局的办公室。” 参与今天抗暴的民众王先生说,后更多民众加入,至昨日事发,有数万民众聚集在公安局、县政府、民政局前抗议,火烧县公安局、县政府和县委大楼。 王先生说:“县长、公安局长等领导都躲起来了,几百个防暴警察也被火烧的在公安楼上下不来。政府和公安完全压不住了,最后公安警察都被赶出去了。消防队的来了也被群众围着不让进去。他们这次是见识了老百姓的厉害了。什么叫‘民不畏死,奈何以死惧之’!”
当地政府与黑社会勾结长期横行乡里
据当地民众向大纪元披露,该县政府、公安局胡作非为,无法无天,长期与黑社会伙同欺压乡里,动辄镇压拘捕民众,民众上访无门,怨声载道。 刘女士说:“很多女孩被害,这样的案子,不了了之,没抓住人。有一群跟政府勾结的社会流氓长期作案,很多。” 杨先生说:“矿山贪污的问题,还有水被污染,现在煮饭吃的水都没有。老百姓上访,就被抓。有7个人都被判刑了,说是扰乱社会治安,最重的还判了6年。” 他们说:所以这次不仅是为李树芬讨公道,也是为其他老百姓讨个公道。 他们一再表示,现在没有别的办法,只有请求媒体帮助引起社会关注。 组图:冲突现场过程图(大陆网友)