Friday, 25 February 2011

Transportation: Road Networks Part 1

I've been working flat out on working out what I think would be good for a transport network within the game, and then (for the most part) trying to work out if it's technically achievable.  The end-result is that I have a billion ad one technical notes and code snippets that test out some practical points, but this probably won't shine through in this format!

So we start with road networks - an arbitrary choice, perhaps, but it's an important part of realistic city simulation and is probably the more complicated of the network types we have to create.  This is because, unlike say rail or air that have fixed entry/exit points (stations and airports), a car driving along the street can stop at buildings along the street.

And that statement has somewhat given the game away - individual cars will be simulated with individual departure points and individual destinations.  Overcoming the performance issues of this has caused the largest headaches for the past month or two, but I made it in the end!  Not only that, but we'll also be simulating driver behaviours on roads, such as:

  • overtaking
  • tailgating
  • individual speed decisions
These are quite complex, but will add a level of realism to the simulation, and will include a large number of parameters that could be tweaked externally.

The roads will also come with several static properties attached to them, such as:

  • number of lanes
  • maximum speed
  • surface properties (e.g. initial quality of surface, etc.)
These are coupled with dynamic properties that can be determined by several aspects of the simulation such as:

  • surface quality - the more cars that drive over it, the more the surface degrades and the harder it is to drive over.  Might be restored by some form of re-surfacing...
  • friction - if weather is simulated, then rain or ice might also make it harder to drive, influencing the driving behaviour of road users.
So over the next couple of posts, I'll expand on these, ideally with some diagrams - and if you're unfortunate, I'll include some small mathematical points about how some of these things will be done.  I'll also cover (in a very high-level way) the way that I can do all of this while not requiring each of you to buy a Cray Supercomputer to play this game!

I should point out that I'm now programming a lot of this while I type.  I'll want to show things off to you folks during development.  Question is, could you cope with really horrible and crude graphics while I get the underlying detail good?  If not, I'll sort out some nicer 3D stuff for the journey - but I might ask if any of you know anyone who can do some 3D graphics work!  Let me know!

Cheers,
Fred

Tuesday, 11 January 2011

Introduction to Transportation

Happy New Year!

Today is a short post as I'm still mulling this issue over a little bit.  I've started writing an early prototype of the economy code, and am quite happy with it.  I've paused just before the virtual companies in the simulation have to calculate their costs.  The reason is that the cost of transporting goods from place-to-place needs to be included, and that means we need a transport network!

This post won't go into huge details, but there are some early points that I'm pretty set on:


  • Transport conduits (be they roads, train tracks, etc.) will be layable as splines, straight lines, etc. and vehicle speed will respond to the curvature.
  • Conduits and intersections will have configurable properties relating to lanes, traffic lights, etc.
  • Traffic will be based on real journeys by real people or cargo - that is, vehicles will be travelling between locations based on a need to travel there rather than some random event for prettiness.
Some of these points pose some odd problems - how for example, do I calculate the curvature of a spline?

More importantly, how to I simulate traffic?  Road transport will be relatively simple, albeit not without its challenges because cars travel sequentially.  I'm looking in particular at some microsimulation techniques such as those described at http://www.myhomezone.co.uk/project/Report.htm to help with this.  

More complicated is allowing train networks to be built, because railways have awkward and different rules to obey.  Consequently, although all transport networks can fundamentally be represented in similar ways, their simulation will need to be handled differently.  I need to find a good way of doing these things in a way that meets the goals of this little project.

So over the next few posts, we'll deal with the issue of transportation.  Good news is that this means pictures! The bad news is that I'll have to draw them! :)

If anyone has any good resources or ideas, I'm all ears!

Fred

Friday, 31 December 2010

Economy: Product Nets 3/3

This post concentrates on alternative economies.  One option within the simulation will be to allow individuals to access more than one product net or economy.  There are two use profiles that can be imagined for this feature:  access to other city or world economies and introducing a criminal economy.


Access Cost and Control
This will use the existing product net model, with one additional variable.  This variable denotes the access cost for using the economy - this could be transport costs in the case of dealing with the economy of an adjacent city or a percentage mark-up if simulating some kind of black economy to represent the additional cost (or if a negative value, the discount).  The product properties such as frequency can be re-used to denote, for example, poorer quality products that are procured because they are cheaper.


Policies implemented by the player can also influence the access to these nets.  One can conceive of import tariffs to artificially increase costs, and the obvious influence of police in targeting suppliers and purchases from an economy specified to be illegal.


Effect on social model
Additional properties on products can be envisaged as influencing the social model within the simulation.  Supply of illegal weapons can influence crime rates, for example.  These additional properties can also be exploited by the "normal" product nets - buying our burger was a complicated process, but it could also lower a property called "health" in the purchasing population.


Again, it is worth emphasising that these nets can be as simple or as complicated as needed.  These additional nets and these additional properties will not be necessary to create a game, but can be used to tweak the behaviour of the game.  All part of the mad customisation kick!
The simulator will be able to cope with as many of these economies as desired, although some high internal limit will probably be placed for technical reasons.


Concluding remarks
We're at the stage where I could probably start coding the economic aspect of the simulation, which obviously centre on the available goods and services.  The economy is an essential part of the simulation and is likely to be at the centre of other models within the game pertaining to society, crime and urban development.  All these models will feed into each other in a complex way, producing an interesting challenge for the player as influences in one area have different effects on the development of the city.


I want to be sure there's enough time for the economic model to settle in, and to get feedback, before moving onto other models.  I know it's unlikely given how quiet you folks were and how quiet I've been of late, but I'll give you a day or so to get to me on here or by e-mail.


I'll also check that I've actually covered everything about the economic model that I meant to!


Next post will be one of a clarification post for any queries or suggestions I get, a graphics post where I talk front-end specifications or a post about the society model for WorldSim.


Happy New Year!


Fred

Economy: Product Nets 2/3

Note:  Apologies for the enormous delay - some sad family news kept me occupied after my last post, but now back up to speed - hope to do the specification by the end of the month now


In the last substantive post, we began looking at product nets and how costs propagate between interrelated items.  We left several things hanging:  transport and energy costs, company definitions, demand and multiple economies.  I'm going to cover all but the last (somewhat cryptic) item in this post, and very shortly post up the remainder.  Since these are somewhat minor extensions to the basic concept, the description will be necessarily brief, but if you're happy to stick with me after these awkward interruptions, I'll be glad to clarify anything you have to ask in any comments to this!


Company Definitions
The product net gives us a set of things that people or companies could buy.  Unfortunately, that's not enough for the simulation to do anything other than generate companies selling random combinations of goods.  That might be fine - even desirable - in a simple product model.  However, if you're at a lower level of definition, you might be irritated to find a shop called "Smith and Sons" selling brocolli and socks under one roof!


This is simply done - we add to our net definition a set of company types that can be defined with the kinds of the products they sell, and whether that's to individuals, other companies or both.  When the simulator decides that a new company is going to be established, it chooses from these categories and arranges for that company to be set up.


I imagine that other attributes and properties will be useful to help control the simulation.  I'm not going to define these now, but will leave expansion open-ended within the simulator.


Demand
Demand is also partially specified as part of the product net, although the wider definition of demand within WorldSim is probably a subject for another post.  Lovely as it would be to simulate individual demand, this is too high a computational burden for us to bear until computers get a wee bit faster.


So instead, we'll be centring demand on the social groups I talked about in an earlier post.  This will allow us to specify product demand by individual groups.  Specifically, we need properties for:
  • frequency of purchase - how often do we need to buy this?
  • necessity - some kind of scale to indicate how necessary this is to possess. Bread might be 100% necessary, for instance, whilst a Ferrari would be maybe 1% necessary
  • desirability - another scale to indicate how much a social group desires this.  This needs to be sensible - a poor man might *want* a fast sports car, but he has no *desire* to bankrupt himself buying it
There may be others as well, and I'm open to other suggestions.  The use of social groups will allow us to exploit other variables such as average income to determine prices and demand.  This does mean, however, that a product net might end up tied to a particular set of social divisions - this could be awkward, but I think it's manageable.


We now have a way of defining purchases by individuals, can determine their demand and so begin the calculation of the supply-and-demand model that will drive the simulation forward.  There are quite a few loose ends though - how do products move around, and what ongoing costs of ownership might we need to simulate?  


We'll only worry about energy use for this latter portion.  The other aspect is transportation and the associated cost of moving things around.  Since the player can directly control transport and influence its cost, this can add an interesting additional dimension to the economic model of the game.


Transport and Energy
Energy for the purposes of this discussion can simply be thought of as electricity.  Something generates electricity, it is transmitted and then something uses it.  Products within a net can require energy, and this will feed into their base cost.


Each source of energy will require definition, including the minimum cost of producing a unit of energy.  Demand will cause the cost to vary according to the laws of supply and demand.  The energy cost according to the product net will be a weighted average of all the available supply prices.  This doesn't require energy sources to be specified within the product net, but the net needs to have an awareness of this as a raw material.


This allows us to start considering realistic effects - we might have energy sources that produce lots of pollution, but produce cheaper electricity than their clean or renewable alternatives.


Transport is not included in the product net directly, since it relies on geographic quantities that are obviously not known before the game begins.  This cost is added by the companies that supply the goods within the net - this will introduce another pricing differential between companies.  Technically, the code will need to link these costs together to allow a market to form correctly - within the simulation, the product net will therefore co-exist with the company definitions.


Next steps...
We're almost there for economic drivers, but there is another dimension to add before we can wrap up.  This is the concept of alternative or multiple economies.  We'll see this in the next post...


Fred

Saturday, 6 November 2010

Update: At last!

Just a quick note to those of you following here: Two months on and the PhD thesis is done.  I will continue the updates as of Monday, and will aim to finish the simulation model specification by the 20th November.  Then we can get onto graphics specification.

Just so you can start thinking about it, I'm looking at a 3D freeform model, initially generated from the world heightmap data available from NASA et al. The graphics engine will probably be OGRE3D, for a variety of reasons, mostly because it is (a) portable, (b) powerful and (c) takes a lot of pressure away from me in trying to program the user interface.

If you want to tell me your hopes/dreams in terms of graphics, interacting with the game and anything else, comment on this post and I'll see how I can fit them in, or explain why they will/won't work!

Thanks for your patience!

Fred

Friday, 10 September 2010

Economy: Product Nets 1/3

Like many people in the world, I like burgers.   If I were living in WorldSim, this is the burger I would like to buy (thanks to my wife, who liked the smiley burger clip art):


But how much would this magnificent treat cost me?  Well, in our economic model, we could assign it an arbitrary value, but making this consistent across many types of product would be quite tricky.  So instead, we define how the burger is made as follows:


If we can assign a cost to these components, then we can work out the base cost of making a burger.  A company can then just add a profit margin determined by its Decider to try and earn some money.  In reality, I can decide that these components can be further subdivided, to give a complete history of all the things that went into making the burger that I like so much:


Notice though, that from a real-world perspective, this is still quite incomplete:  where are the energy costs, travel costs, the cost of water?  Well, I've ignored these - I can make the product net as complicated or as simple as I like.

And this is what I propose for WorldSim - designers can define an economy based on creating networks of goods and how they feed into each other - at the base of the network there will probably be raw materials - in the above food example, the raw materials are raw ingredients that would emanate from farms.  For non-consumables, you can imagine having iron ore, gold, etc. as the base that might be supplied by mines.  These base costs, coupled with work costs and profit added by companies in the chain leading to the burger give a base cost for the burger.

Two things need to be highlighted:  there should be no need to have the raw materials within the city, nor should the player necessarily have to do any work to obtain them.  A market in raw goods should be simulated, as in real life where supply and demand drive commodity prices.  If lots of people suddenly start eating my happy burgers, the price of flour is going to go up and that will feed into the price of the burger.  Suddenly, we have inflation and the beginnings of a realistic economy.

The other thing that needs to be highlighted is the absence of certain necessary features from the product net definition.  We need a way of defining the kind of company that produces certain things.  For instance, a baker that might make burger baps, but is also able to make cakes, loaves of bread, etc. if these are available within our economy.  Finally, if we want to be able to  feed energy or travel costs into the price, we need a simple way of defining these costs since they can have multiple, mutually exclusive sources.  We will discuss the definition of company types and the expression of costs in the next post.

We also need a way of defining the demand for each output product:  how many people want to buy my burger?  This will mean generating demand from people, and this will require us to return to our social grouping definitions.  We'll have a look at this in one of the next two posts, depending on space.

I plan to bundle in an application to help define product nets graphically as above, so noone is going to be confined to defining an economy with some horrible text editor - the first of several tools that I'll have to provide!

Let me know what you think!

Fred

PS.  Apologies for the delays posting, but I'm currently writing up my thesis, and won't be done until the end of the month - consequently, writing in the evening doesn't inspire me a lot.  It isn't a loss of interest  though!

Saturday, 4 September 2010

Economy: Companies

This post briefly describes another structure within the economy - the company.  This is simply an entity required to provide good and services within the economy, and in the larger picture provides the simulation with a way of getting money into the pockets of the simulated population.  The basic structure of a company is shown below and has various elements that should be explained.


The basic idea is simple:  a company provides one or more goods and services, for which it may require the services of suppliers, it will require customers and it may need employees to perform work to produce the good or service.

The Decider is simply the operating mechanism of the company - it determines what the company provides and will have knowledge of what it needs from other sources to produce those goods and the manpower necessary.  It takes two general inputs, the request for contracts from suppliers which it can accept or reject, and the request for goods and services from customers, which are also processed as contracts.  By processing the provision of products as a contract (see the previous post), this same structure can be used for a company providing isolated products, like shopping, or for providing services that may last beyond a single purchase.

The Employees structure simply retains a list of who is employed, and a payment amount.  Since we don't actually have to simulate employees' work, this money is simply distributed monthly unless the Decider chooses, for example, to lay that person off.

As described above, the Contracts structure simply maintains the list of current contracts to be processed until the contracts expire.  For single shop-like transactions the contracts will be eradicated quite quickly but others, such as those pertaining to suppliers may be more persistent.

Finally, assets refers to any other object that the company owns, such as buildings, transport infrastructure, or indeed any simulated object. This provides the ability for the company to own property to act as a shop front, for example, or to be something as complex as a landlord.  It also provides the necessary capability for a transport company to operate.

The most important component is the Decider, which determines the entire behaviour of the company.  It is the entry point for scripting as a result of this, or can be overridden to be replaced by direct player control.  There is no current intention for direct support of company takeovers, shareholding or other constructs in this version, but it may well be possible to implement these without my directly supporting them.

The Decider can also, ultimately, decide if the company should close down, which can be done in an objective rules-based method, probably based on the account balance.  The other important feature will be to provide the scripts with the ability to query the model to find out things like the current state of the economy, etc.

This has been a necessarily dry and vague post, because all I've essentially done is describe a container with very little detail.  If you want more, just ask!

The company is an important structure to the economy, which is why it gets described here, but the question is always going to be:  what products  and services are going to be necessary, and how do we describe them?  That's the next post, and that's Monday's job...

Fred