I am trying to determine an objective way for a self-interested agent to calculate the optimal buying/selling price for goods in a multi-agent simulation not dissimilar to Sugarscape (http://en.wikipedia.org/wiki/Sugarscape). The simulation is as follows:

Each agent has a stock of food F, a stock of money G, a certain amount of "energy", E, and a position (x, y) on a square grid. Moving from one square to a neighboring square expends A units of energy, and energy is naturally expended at a rate of B units per simulation day. An agent has the following options available to it during each day: consume a unit of food to increase its energy by Q units; move to another location (provided it has sufficient energy), "forage" for food (expend P units of energy to obtain a [possibly unknown] quantity of food), or trade with a neighboring agent for a mutually-agreeable price.

Each agent's goal is to maximize its "utility function" U(E, F, G) without regard for that of other agents.

Right away, this seems to give a base "use value" of food: Vuse = U(E + Q, F - 1, G) - U(E, F, G), but if this was the whole story, this wouldn't be an interesting problem.

It seems the most general (but exponential-time) solution would look something like this:

Function SearchActions(State S):
    Add(consume food) to action set
    Add(forage for food) to action set
    For each other agent A
        For each possible trading price P
            Add(trade with A at price P) to action set
    For each action X in action set
        S' = Apply X to S
    Return optimal X
End function

However, the major difficulty gets swept under the rug by "for each possible price", because the price that agent A will buy/sell for is itself dependent on an identical calculation...e.g.

My calculation of the value depends on either what I can get from using it myself, or what someone else will pay for it...but what they will pay for it depends on what I will pay for it.

How do you cut this knot?

I know this problem has been solved before...but I cannot find any references to it, let alone any actual implementations. The closest I've come has been a paper about "Strategic Planning" in SugarScape, but it only seems to give the results of the planning, rather than explaining how the planning is done.

  • Is there a way for the agents to get more food without buying from other agents? If not, the price of food will sky rocket as the supply is consumed (and goes to zero).
    – poke
    Mar 3, 2014 at 2:35
  • @poke yes, oops: they can "mine" it. I'll ammend the question. Thanks. But -- even without a renewable supply, the problem still holds...how would they "know" to raise the price? Mar 3, 2014 at 6:10

2 Answers 2


The key to this is each agent's cost of mining. Presumably, at any given time, some agents will be closer to a food mine than others.

The cost of mining is energy + time. An agent further away from a mine will thus have a higher cost because it will have to use more energy and time to travel there.

Each agent will need to determine its maximum buying price based on its own current cost of mining and its current stock of energy, food, and money. Conversely, each agent will need to determine its minimum selling price based on those same four factors.

A trade happens when one agent's buying price is higher than another agent's selling price.

How do you set the prices then? The same way we humans do. An agent trying to sell will offer at a price higher than its minimum selling price. An agent trying to buy will propose a purchase at a lower price than its minimum buying price. The two will then negotiate until (or if) a price is reached that is agreeable to both.

  • Maybe I've been reading too much right-wing economics, but "value" has little to do with cost; say the only way we know how to make cotton candy costs $100/serving, and I make a few dozen batches. No one would care what it cost me to make; few would pay more than a few dollars per serving. So I would be better off (more likely to recoup some of my losses) by setting the price independent of the "cost". Jun 26, 2014 at 15:27
  • Of course, the cost to produce it yourself could set a floor on your bidding price, as would expected (discounted) future value-in-exchange and value-in-use...but it seems (generalized) cost can't be the only (or even primary) variable beyond the agent's own state. Jun 26, 2014 at 15:39
  • @MiltonManfried: I totally agree that market value isn't (directly) tied to cost. My answer doesn't go against this. The reason is that individual agents can't set the market value. As such, they must make their decisions based on the cost of each option.
    – poke
    Jun 27, 2014 at 1:57

I have my own implementation of Sugarscape and here's how I addressed the problem. My implementation with source code can be found at http://sugarscape.sourceforge.net/. Note, the implementation requires a JRE install to run within the browser. Alternately you can run it locally using the Jave AppletViewer.

Here's my take on this issue based on my implementation. Agents have two sources of food, Sugar & Spice. They also have consumption requirements (metabolism) for both items. An internal value is determined by each agent based on how many cycles their current stocks will allow them to survive. So if the agent has the following base values,

Agent x has 15 units of sugar and needs to consume 3 sugar units to survive each cycle.
Agent x has 30 units of spice and needs to consume 2 spice units to survive each cycle.

Their calculations go as described below,

Sugar Metabolic Rate (SuM) = 15 / 3 = 5.
Spice Metabolic Rate (SpM) = 30 / 2 = 15.

Time Until Death = Minimum of (SuM, SpM)

Marginal Rate of Substitution (MRS) = SpM / SuM

...MRS results less than 1 signify a preference for spice, results greater than 1 conversely indicate a preference for sugar.

Calculate Surplus:

if( MRS > 1  )
{   surplus = SpiceStocks - (SpiceMetabolism * TUD);
    //If surplus <= metabolism Then Set surplus to Zero
    surplus = surplus > (SpiceMetabolism * 2) ? surplus : 0;
else if( MRS < 1  )
{   surplus = SugarStocks - (SugarMetabolism * TUD);
    //If surplus <= metabolism Then Set surplus to Zero
    surplus = surplus > (SugarMetabolism * 2) ? surplus : 0;
    surplus = 0;    //MRS == 1, 

Once these calculations are determined, a list of potential trading partners is constructed by examining the adjoining cells for agents with a different MRS.

The list is sorted by the MRS gap between the agent & each trading partner.

A trade is consumated with the trading partner that has the highest MRS gap in relation to our agent. Multiple trades until the available surplus is consumed may be allowed within each cycle.

The surplus to be traded is the lower of the 2 surpluses between agent and trading partner.

BarterPrice = Squareroot( Agent MRS * Trading Partner MRS );

I know this answer is a bit late but I am hoping it helps the next person looking to implement this wonderful simulation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.