User Tools

Site Tools


public:i-700-abms-08-1:final_system

Industry

The industry class is a skeleton for all of the industries since all of them have the same functionality. The only difference comes from the psySpec.xml file, which in a way behaves like the Government sending out rules and initial values to the other modules.

Functionality

The industries start by connecting to Psyclone, and initializing variables by getting the parameters from the psySpec.xml file. These variables distinguish different industries from each other.

  • Spec Parameters
    • industry - What industry it is.
    • country - We might need this if in the future we would like to simulate markets for many countries.
    • sellTo - What countries is this industry going to sell.
    • capital - The initial capital of the industry.
    • startQuota - What the industry has much carbon quota in the beginning.
    • fixedCosts - What the fixed cost of running the industry is.
    • revenues - The approximated revenues per unit produced. The revenues are then calculated by a revenue curve with a little variation depending on the number of units sold.
    • inputCost - How much the input cost is per unit produced.
    • carbonRelease - How much carbon is released while producing a unit.
    • capacity - The maximum amount of units the industry can produce.
    • profitAvarage - This is intended to be used in future speculations of maximizing profit.
  • Other global variables
    • BUY - The type of the buy message.
    • SELL - The type of the sell message.
    • plug - The connection to pshyclone which connects us to the whiteboard.
    • ownedQuota - How much quota we own.
    • boughtCarbonCost - How much the carbon we bought cost.
    • unitsBought - How many units we bought.
    • avaragePrice - What the average price of carbon units bought and sold is.
    • wb - The name of the whiteboard.
    • sold - To compare with the response message.
    • bought - To compare with the response message.
    • units - How many units of carbon we want to sell or buy and how many units of carbon we bought or sold.
    • price - The price we are offering or bidding with for carbon quota.
    • a - The number of times we have rethought our bidding or offering price.
    • sleepTime - How many milliseconds we will wait.
    • startStop - The thread.
    • name - The name of the industry, taken from the arguments string of the module or the default value is “Fishing”.
    • host - The name of the computer where the psyclone is running with our Spec.
    • port - The port that psyclone is running on.
    • date - To keep track of time.
    • expDate - To set the expiration time of offers and bids.
    • dayCounter - Counts the days of the simulation.
    • soldUnits - How many units of carbon we have sold.
    • y - Used in the demand function and is incremented by one daily.
    • demands - How many product units can be sold.
  • Functions
    • post - Sends a message to the whiteboard.
    • main - Parses the arguments sent to the Industry and calls the constructor.
    • newDay - Is called when a new day starts. In this function the variables ownedQutoa and capital are updated, and here the Industry quits if the ownedQutoa or capital go below 0.
    • cut - Is called when we receive messages. Depending on the type of the message different things are done. If the message signals a new day the dayCounter is incremented and the newDay function is called. If the message is to this industry, we get the content from the message(bought, sold, units, price) and the variables updated according to that.
    • printout - Is called in the constructor prints out the name, capital, and the amount of carbon quota.
    • cost_per_unit - Calls the carbonCost function and calculates the operational cost of producing one unit depending on the current situation.
    • carbonCost - Returns the averagePrice of the quota we own. The carbon cost changes when new quota is bought or sold.
    • profit - Calculates the profit. Uses revenues, cost_per_unit, unitsSold and fixedCosts
    • maxProduced - Calculates how many units can be produced with the owned quota.
    • carbonUsage - Calls unitsSold and calculates how much carbon is release producing these units.
    • unitsSold - Calls maxProduced and demand and returns the minimum number of maxProduced, capacity and demand.
    • getRevenues - Calculates the revenues depending on how many units are sold.
    • demand - Calculates the demand of produced units. This is used since the market for produced units is not simulated.
    • buySell - The decision if carbon quota should be bought or sold is made here. If the cost of the carbon that is released is higher than the difference of revenues and inputCost, we may assume that it is more profitable to sell the quota than to produce units. Then we calculate the amount of carbon we need for the whole simulation by extending the unitsSold to the end of the simulation. The extra quota is offered for sale and a bid is made for for a shortage of quota. The initial price offered is higher than the average price and the initial price bid is lower than the average price.
    • waitingPeriod - Waits for response from the market. Calls cut if right message is received before the expiration of the offer or bid. Otherwise it rethinks the price of the offer or bid.
    • run - Keeps looping and receiving messages.

The industries can send two kinds of messages: carbon.quota.buy and carbon.quota.sell.

<buy
    name="The buyers name same as in type of industry"
    units="How many units(tons) it wants to buy"
    price="The Max price it is willing to pay"
    exp="The expiration time of the bid"

/>

<sell
    name="The sellers name same as in type of industry"
    units"How many units(tons) it is willing to sell"
    price="The Min price it is willing to sell for"
    exp="The expiration time of the bid"

/>

The industries listen to all messages from the market of the form: carbon.quota.response, but they are only interested in the messages that have the sentTo with their name in it. The industries also listen to the message simulation.time from the timer.

Market

  • Variables:
    • plug = Is used to sign in to psyclone.
    • name = Is used when signing into psyclone. Default is “Market”
    • bids = Is a vector that stores all the bids that come to the market.
    • offers = Is a vector that stores all the offers that come to the market
    • DIM = Is used to set the dimention when initializing an array in the market class
    • bought = Is a boolean used for checking if something was bought or not.
    • sold = Is a boolean used for checking if something was sold or not.
    • content = Is used for the content of the response messages (type String)
    • type = Is the type of message going to be sent.
    • date = Stores the date of the simulation.
  • Functions:
    • auctionMatch() = Simply does the matching for bids and offers. If the price is ok then link them. At the end calls auctionImprove
    • auctionImprove() = This is meant to improve the current matches. If a bid has a better choice, repoints it to the nicer one.
    • checkExpiration() = Drops the offers and the bids with expired date
    • checkOut() = At the end of the day checkout the current matches for every offer and calculate the remaining amount of units per offer (if something left) and then notify the sellers/buyers
    • destroy() = Used by the OpenAIR plug
    • getIndex(String) = Returns the index in the offers vector of the element that has the given string
    • isConnected() = Used by the OpenAIR plug
    • post(type, content) = This function sends the messages to the white-board using type as the type of message and content is the content of the message
    • printVectors() = This function prints out the information of the status of the bids and offers in the vectors
    • startListening() = This function makes the market start waiting for messages
    • store(XMLElement,string) = Function used for parsing/storing the values of the messages received

For every bid that the market receives it stores it in the bids vector. It then checks daily if the bids have a matching offer or are expiring. If the bid is expiring it marks it in the removeListBid and then checks for the last time if it has any offers for it. If it has an offer for it it sends both the seller and the buyer a carbon.quota.response message saying that they have bought or sold some units and for the asking price of the offer.
If there are differences in the units the market checks the units number. If the offer units are higher then the bid, the market sells the offer the amount of units the bids are then renews the offer for the lasting units. This is also done for the other way around. That is if the bids number of units is higher then offer units, the bid gets renewed with the number of units left.
The bids and offer prices are a match if the bid price is higher or equal to the price of the offer. This means that the closest price always gets matched.

The market is able to send one kind of message. carbon.quota.response with the content:

<buyer sentTo=“The Buyer Is” bought=“Yes” units=“amount of units” price=“the selling price” />

and the seller gets similar message

<sell sentTo=“The Seller Is” bought=“Yes” units=“amount of units” price=“the selling price” />

The market can receive three kinds of messages: Two types from the Industries: carbon.quota.bids and carbon.quota.offer. It receives one kind of message from the Timer: simulation.time. When the market receives this type of message it starts by updating the date variable and then checks what bids and offer are expiring.

Timer

The Timer sends out message to tell everyone what day it is. Everybody gets a new message when a new day starts. It is best to start the timer last when running the simulation because everybody are just waiting until the timer sends out the initial date.

  • Global variables:
    • thread = This is used so that the Timer can be set to wait for whole: simulation day period
    • plug = Used to sign in with the white-board of psyclone
    • name = This is the name used so that psyclone knows which module it is. Default is “Timer”
    • timeWait = This is in milliseconds 2000 and is that how long the thread is told to wait. It is how long the simulation time period is in actual time.
    • aDay = is exactly 86400000 milliseconds. This is used with the date variable
    • date = This variable stores the date of the simulation (what day it is in the simulation)
    • mode = Command line argument. This can be set either to auto or manual if it is in manual you will have to press enter to let a day pass. Default is “auto”

Timer message

Type: simulation.time

Content:
<Time Date=“LongNumber” />


LongNumber: Is the date of the simulation represented in milliseconds since the 1st of January 1970.

Tester

Tester is just a module in psyclone that can be used for testing strange behavior or other tests with the numbers. To start a tester just start an Industry class with the name set to “Tester” then it automatically retrieves all the initial values from psySpec. This is very useful so you don't need to be changing the values in all of the other Industries while you are testing some strange behaviors or anything else you need to test.

GUIForKristinn

This class is based on the monitor class from the last year project. It uses JFreeChart to represent graphs. This class takes all of the messages it receives and uses the content to create graphs to display while the simulation is running.

RunGUI

This class signs into psyclone and triggers all the messages that are sent while the simulation is running. It creates an instance of the GUIForKristinn class and sends every message it receives to it the instance. This class is based on the MonitorRunner from last years project.

Debug

This class has no purpose for the simulation it only useful for the programming part where you write Debug.print(“The string you want to print out”) and when you want the debug messages to appear you do Debug.set(true) and Debug.set(false) when you don't want the debugging messages.

Newest Picture

This picture shows the messages how they go from the Industries to the white board and then to the market and wise versa. It also shows how the messages come from the Timer and go through the white-board to all of the modules

psySpec

The newest psySpec file has three new modules: Timer, Tester and the GUIForKristinn. The Timer module has one parameter name=“Timer” and only posts messages but triggers none. The Tester is just a copy of the Industry modules and it can be used for playing with the numbers and if you wanted someone to behave in a strange way then the Tester is good for that. GUIForKristinn module has no parameters and it triggers all of the message types since it is only going to be observing the simulation.

Messages

There are 4 kinds of message types:
carbon.quota.bid
This message is sent out by the Industries to the market. The content of this message is how much the Industry wants to buy of carbon quota units, for which price and expiration time in days.

carbon.quota.offer
This message is sent out by the Industries to the market. The content of this message is how much the Industry wants to sell of carbon quota units, for which price and expiration time in days.

carbon.quota.response
This message is sent by the market as an response to the buyer and sellers telling them how much they bought and how much they sold. The market does not send out messages if your bid/offer has expired or that they did not buy anything.

simulation.time
This message is sent to the white-board and it contains the date of the simulation in milliseconds. This message makes everybody know when new day is starting.

Screenshots of running system

Below screehshots of the running system are taken to show the trend of the prices during the simulation.

The next two images refer to the bids prices in two different moments.

The next two images show the trend of the offers prices.

The next two screenshots are taken from market responses.

/var/www/cadia.ru.is/wiki/data/pages/public/i-700-abms-08-1/final_system.txt · Last modified: 2024/04/29 13:33 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki