Announcement

Collapse
No announcement yet.

The First Economy Model Prototype

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • The First Economy Model Prototype

    Hi all!

    I have now finished the first phase of making this first prototype, so I felt like sharing it with the rest of you. Get the zip from here! http://www.kolumbus.fi/amjayee/economy.zip

    Actually this is not yet the prototype version 0.1, but something like 0.09; I was planning to make it a little better, but I think it's good to finish it together.

    The program runs now stable, I couldn't crash it; but of course I didn't have time to test it for very long time. So, if it crashes, send me email and include the text that is on the screen when it crashes, and the possible error messages. At least divisions by zero may occur, since I didn't have time to make very extensive exception-handling.

    Also the program works much like expected; at least during my short tests the prices found an equilibrium, and the demands balanced around the supplies. Though it seems that clothing producers were getting clearly the poorest and the housing producers clearly the richest. The largest problem I want to fix is that demands are changing too rapidly; they jump back and forth around the supplies, instead of holding still. But otherwise I'm quite satisfied with the new demand algorithm; it is actually the first piece of AI in our game, since it analyzes the situation, reacts to events and tries to find the best solution to a situation. It is by far the most complex thing in the prototype.

    There are of course many funny things in the program. First of all, it is kinda ridiculous that the balance is found by adjusting the prices so they fit the wealthiness of the people. But that's the limitation of the set for this prototype. Later it will be corrected.

    I am going to send here a summary of the algorithms I'm using in the program, but now I haven't time, I'm at school and lectures are starting. This evening I will send those things. Until that, test the program, and if you like, check the code out. Though it is quite complex, and only partially commented right now. Also send me comments how I should improve the program for the real "version 0.1" of the prototype. I was going to add the possibility to change the program variables via a text file. What things should be change-able? And what things should be shown as results on the screen?

    After my second message you can comment the algorithms also. They are mainly the same as presented by Joker; the demand system is re-made, and I made a change to the elasticity calculation. In its old form, the prices were changing very slowly, so I divided the elasticity by 1000. Now it seems fine.

    I hope the link is working. As said, I will come back to this this evening. Enjoy that piece of programming s***.

  • #2
    Nice!

    I've just downloaded it, and I am checking it out right now!

    ------------------
    Vote Gore. For the sake of people, not god.

    GGS Website
    "It is not enough to be alive. Sunshine, freedom and a little flower you have got to have."
    - Hans Christian Andersen

    GGS Website

    Comment


    • #3
      Yes, like Guildmaster I see some problems in the demo.

      At least concerning the supply algorithm. In stead of all the prices moving towards being the same for all goods (which they should) they move away from each other.

      But I, too, am too tired to think more about it right now.

      It is really, really great that you, Amjayee, have posted the formulas you have used here at the forum. I tryed to check the sourcecode to see if I could find the bugs, but there was just too much of it and it was too advanced for me to understand it. This is a great way to improve the demo.

      And BTW, Amjayee, you wrote in the econ thread that you had never programmed anything as complex as this, and that you had learned a lot from the experience. Isn't this great? I mean, this is one of the things I like best about GGS, that you have a task, that you pretty much define yourself with the rest of the group, and then you have to figure out a way to do it. It usually seems WAY to hard to do it when you start, but then you think and think and think about it, and you manage to break the task into smaller, easier done tasks, and when you finally see how things can be done it is just fantastic! Even though I don't go to school this year (I am taking a year off to work between highschool and university) I feel I have learned a lot of really great things thanks to GGS.

      Also, Guildmaster, it is pretty wild the stuff going on in the US at the moment. I can't believe 1700 votes are deciding it all (you really should change your electorial system). So who did you vote for? And cool new sig you have got!

      ------------------
      Vote Gore. For the sake of people, not god.

      GGS Website
      "It is not enough to be alive. Sunshine, freedom and a little flower you have got to have."
      - Hans Christian Andersen

      GGS Website

      Comment


      • #4
        I just wanted to say that I think it's wonderful that Florida (My home) has become thee deciding factor in this presidential election. =)
        And now the eyes of the world are upon us as we get our recount in... (Go third party!)

        ------------------
        How will you make it if you never even try?
        -Macy Gray
        He's spreading funk throughout the nations
        And for you he will play
        Electronic Super-Soul vibrations
        He's come to save the day
        - Lenny Kravitz

        Comment


        • #5
          I noticed that there is no equilibrium...

          When the income of a certain field goes down, no one wants to go into that field, that's why no one wants to be a teacher in America. So in the demo I noticed that when the number of clothing producers went up, their income went down with the demand. But when the income goes down so should the number of producers.
          Also same thing when the income of a field is high, a lot more people want to go into that field. There are for example, more people going into business management, law, and medicine than there are people who actually want to be business managers, lawyers and doctors simply because they want to make more money.

          Other than that I see no real problems.

          ------------------
          How will you make it if you never even try?
          -Macy Gray
          He's spreading funk throughout the nations
          And for you he will play
          Electronic Super-Soul vibrations
          He's come to save the day
          - Lenny Kravitz

          Comment


          • #6
            Actually no, I see more... let me play with it a while and I will get back to you

            ------------------
            How will you make it if you never even try?
            -Macy Gray
            He's spreading funk throughout the nations
            And for you he will play
            Electronic Super-Soul vibrations
            He's come to save the day
            - Lenny Kravitz

            Comment


            • #7
              When I tested it more I also noticed that clothing price keeps going down for some reason. Right now I'm too exhausted to find out why, but later I will go back to it. Keep testing and report all problems! Also if you notice why the problem occurs, that is nice!

              It is also possible that all problems cannot be solved simply because the system is so limited. But we will find out about that. Also send comments about how to make the demo better!

              Now I'm sending the formulas I use in the demo, so you can track problems more easily. These are mostly the ones presented by Joker, slightly modified by me. I have also combed the thread for smaller bits of information and used them in creating this, so it's a creation of all of us!

              The demo consists of unlimited number of "turns". Each "turn" of economic consists of separate things that are done in this order:

              -supplies of all goods are calculated
              -elasticities of all goods are found
              -all prices are adjusted
              -demands of all goods are decided
              -goods are sold to the people
              -people's incomes are adjusted
              -people changing classes are calculated

              Then how these tasks are done? Here is a short explanation of each one of those.

              Supply:

              This is the amount of units each good is produced per turn.

              S = w * u

              w = number of workers producing this good, in population units
              u = good units produced per PU per turn

              A population unit means a group of 10000 people, and it is just an utility figure to allow calculations with smaller numbers.

              The amount of goods made per PU is 20 in this demo. It is the same for all goods. Later we might want to make that different for all goods. Also I'm planning to make this figure adjustable by the user so we can easily test different situations.

              Elasticity:

              This describes how the price of the good will change.

              First we find the price index. This means the total amount of money on the move divided by the total supply of all goods.

              E = D * e * PI / 1000.

              D = total demand of the good
              e = elasticity constant
              PI = price index

              The elasticity constant is characteristic for each good; for food it is 0.3, for housing 0.7 and for clothing 1.0. This should perhaps be made adjustable, since I think at least for clothing it is too high. And it might be good to be able to test different combinations. Also the figure with which the whole crap is divided should be made adjustable.

              Price:

              This is the price per good unit in credits.

              P = Pp + ((S - D) / (D * E))

              Pp = previous price of this good
              S = total supply of the good
              D = total demand of the good
              E = elasticity

              In the beginning, price = price index and then it will start to be adjusted by supply and demand. The workings of this formula are clear; when demand is greater than the supply, price will lower, and when supply is greater, it will rise. The speed of price changes depends mostly on elasticity.

              Demand:

              This is much more complicated than the previous ones. There is no simple formula to determine the demands; that is impossible, since we have to take into account all goods simultaneously.

              Instead, we first analyze the situation using a figure I call Finances: I tells the amount of money left, if all demanded goods are bought with current prices. This can of course be also negative. It is calculated like this:

              F = 100 * ((I - C) / I)

              I = income per PU
              C = total cost of goods

              C is calculated by multiplying the demand of each good with the price of that good, and then summing those figures. So you see this is indeed the percentage of money left after the purchases.

              Then the finances figure is used to determine how to change the shopping habits. If it is negative, demands are dropped, if it is positive, demands are rised. I will later explain this in full length, but first I need to balance it, since now it works too "eagerly" and demands jump back and forth around the supply figure.

              Selling Goods:

              There are two kinds of situations: either the demand is smaller than the supply, in which case everyone can buy the amount he wants. But if supply is smaller than demand, there are not enough goods to sell. So, how I did this is:

              B = S * (d / D)

              S = supply of the good
              d = demand of the class in question
              D = total demand of the good

              So, everyone gets the same percentage of the supply as his demand is of the total demand. This is done for every class and every good.

              Income:

              This is the amount of money available per PU.

              I = ((f / F) * M) / a

              f = the amount of money produced by that class
              F = the amount of money produced all in all
              M = the total amount of money on the move
              a = amount of population units in that class

              The f - figures are calculated by multiplying the supply of that class' product with its price. The big F means the figures of all classes summed up. So, each class gets the same share of the total money as the money he has produced id from the total amount of money produced.

              This is kinds funny of course. I tried a system where people got just the amount the had earned with their work (supply multiplied with price), but for some reason the incomes kept getting smaller and smaller until they were reduced to zero. I think this is because the set in this demo is quite limited, we can't use very fancy systems because they don't work.

              People changing classes:

              At the end of turn we assume that 3% of the people want to change their class. This is done like this:

              A = 0.97 * Ap + ((r / R) * p)

              Ap = previous amount of people in that class
              r = ratio of that class' product's demand / that good's supply
              R = total of every classes r's
              p = the amount of people changing classes = 0.03 * total population.

              The r - figures are greater than 1 if supply is smaller than demand (-> supplly needs increasing -> more people are needed) and smaller than 1 if demand is smaller and less people are needed.

              So, each class gets the share of the people it "needs".

              ----------------

              Well, that's about it for now. I will work with the demand system and then explain it in greater detail. The greatest addition I have been thinking is some kind of simple "immigration". The current system does not find very good balance between the figures; if some people could get out of the region if there are too much people, or more would come if needed. I will think how this would be done.
              [This message has been edited by amjayee (edited November 08, 2000).]

              Comment


              • #8
                Kick ass, Amjayee, I'm downloading it now.

                Joker
                -------
                I agree. I am learning C++, but instead of from a book (which I also use), I try programming things, i.e. I am working on the disease model, and you will soon see it where it has a limited interface, customizable diseases(in the game, and text file), and the ability to create your own disease.
                If I can get it to work that is!

                Comment


                • #9
                  About prices becoming the same, it's funny that it _used_ to do just that. But I thought that it is unrealistic if all goods have the same price, so I changed the algorithm just to get them different. If we replace the last price with price index in the price formula, we get all prices balancing on the price index when supply equals demand; but I don't see why the prices should be the same. I mean, don't different goods have different prices also in reality? Or is it that I just don't understand something?

                  About learning while working with this project, I agree! It is a fantastic feeling to get something ready after lots of work, if you really care about the work you are doing. Myself, I was quite angry when the economy program did some foolish things, but when I solved those problems, I felt very happy. It's the same with programming in general; it gives unlimited satisfaction to succeed in some task, rising exponentially with the complexity of the task.

                  I'm quite sure that we are able to solve all the problems with our game; it just needs trying, and learning new things. It may take long, but if we don't give up, we will eventually reach our goals. This far every idea presented is completely within reach with current technology. We just need to do what needs to be done.

                  Heardie: Great! I'm sending you a function reading the text file this evening.

                  About the US elections, I agree it's a little odd that those two guys got almost the same amount of votes. I don't think that's because of the voting system, but just that they are so close to each other that people don't know which one to vote. About the voting system itself, I think it is about perfect for the kind of country the US is; with that system, the states get more power, and I think one of the keys to succes of the US is that the states are quite independent. So, with current system, every state chooses their favorite candidate, and the amount of states supporting each (balanced with factors depending on the state population) decides the winner. But what is bugging me is why didn't they vote for the third guy? He seemed to have at least some opinions. Having only two parties in power doesn't sound very good for democracy.
                  [This message has been edited by amjayee (edited November 09, 2000).]

                  Comment


                  • #10
                    Ok this is my thought...

                    Fluctuations is prices, incomes, supplies, demands, etc. All this happens because of forces that can be totally outside the base economy model. If we use the economy model as a simple object for determining stuff like that, then as a stand-alone demo it should reach a point of perfect equlibrium where nothing changes. That is, if it is all by itself. When you plug the Econ model into the population model you should see the numbers go haywire.

                    So this is I think on the next agenda:
                    Program an economy model that will reach perfect equliibrium, and then accept input from the user which may change the outcome of the next phase, something like "food-supply-minus4" or something like that. Then it should change accordingly and after a while of recieving no further input it should go back to the original state.

                    ------------------
                    How will you make it if you never even try?
                    -Macy Gray
                    He's spreading funk throughout the nations
                    And for you he will play
                    Electronic Super-Soul vibrations
                    He's come to save the day
                    - Lenny Kravitz

                    Comment


                    • #11
                      Heardie:

                      Say, what book are you using? I saw your disease program source code, and your comments seemed a lot like those the auther have made in the book I'm using. My book is called 'Teach yourself C++ in 21 days'.


                      Amjayee:

                      Prices:
                      Well, they should become similar, since if the price on one good is high then more people will invest money in the production of that good, supply will rise and the price will drop. And vice versa. So in this demo the prices on all goods should become the same within a few turns.

                      Later on when we have a labour market and raw materials these things will most likely mean that the prices can't become the same, even though the price algorithm will try to make them that.

                      You also said that it didn't seem right to have all goods cost the same. I can see your point there. But on the other hand we are not using real goods. 1 unit of a good is highly an abstraction. And in the game, when you want to decide whether buying some good is a good idea, it will be a lot easier to figure that out if all goods at least have the same "basic" price. So if the conditions are similar (in many areas) one car unit could cost the same as one food unit. Maybe later on we could change the unit size, to have more realism, but we should definately NOT change the price algorithm so the prices will not become similar. That is not how a market works.

                      US elections:
                      Well, what I meant was, that it is not very democratic to have Gore get the most votes, but not winning the election. That is why I think they should change their electorial system. But I agree that more people should have voted for Nader. He made a lot of sence, and was propably more suited for the job than both Gore and Bush.

                      Ok, now I will comment on the functions you are using:

                      Supply:
                      This is all good. You are completely right that productivity should of cause not be the same for all goods, and that it should change as tech levels rise. We need to find out some actual productivities at different tech levels, and use them.

                      Elasticity:
                      Yes, it is ok. But in stead of using an elasticity constant and then dividin the whole shabang with 1000, I think we should just have a really small elasticity constant. The constant shouldn't change in the game. Generally the more basic the good is, the lower the constant. So luxury goods would have higher constants. And I agree that the constant for clothing is too high, since clothing is a basic good. It is just that with only 3 goods I thought it would be good to see how they react with different elasticities, and I found clothing to be the least basic of the 3. Again we need to find some actual elasticity constants in the game.

                      But I am not completely sure you have used the right constants. In my econ code I used this formula:

                      E(food) = D(food) * 0.003 * PI
                      E(housing) = D(housing) * 0.007 * PI
                      E(clothing) = D(clothing) * 0.01 * PI

                      Where PI is price index or (total amount of money in the province) / (total supply of goods)

                      I think your function have divided this number by 10. I know that in your model the prices seem to be pretty good, but I think you should at least try and change it to this, and see what happens.

                      Price:
                      Ok, here is, as I explained before, the main problem. Not only does this explain why the prices move away from each other, it also explains why you had to divide the elasticity function with 10 to get sane results. Here is what it should look like:

                      P = PI + (D - S) / E

                      P is price, PI is price index, D is demand, S is supply and E is elasticity.

                      First, using PI as the basic price is required, since this would be the price if supply and demand is the same. Second S - D should be changed to D - S, since E is positive. So if demand is higher than supply then the last part of the function will be positive, and it will mean that the price will be higher than PI, since there are more buyers than there are sellers of the good. And if supply is higher than demand the price will be lower than PI, since there are more sellers than buyers, which pushes the price downwards. And in the last part of the function D * E should be replaced with E, since D is already included when calculating E. This is the reason why you had to divide E with 10 in your function, since it would be multiplyed with D two times in stead of one.

                      Demand:
                      Yep, this is a tricky one. I had made it a long list of 'if''s, but of cause when people demand 100s of goods this wont work.

                      I can't really figure out how your algorithm for it would work, though.

                      I am trying to make the amount of calculations needed in my version smaller, so it could work with many more goods. That is mainly because I REALLY, REALLY like how it has turned out. I have spent virtually months trying to figure out how to make the econ model work, and the demand thing was the most dificult of all. I finally managed to make demand independant of income (and just dependant of the amount of goods, in stead), and I made sure that people spent the same amount of money that they earned, which I really liked.

                      Selling goods:
                      Yes, this is how I thought demand with different classes should work. But it should also function when supply is higher than demand. In that situation price will drop, which will encourage people to buy more of the good that they originally thought they would. And there, too would the amount of goods they get depend on their demand compared to the total demand.

                      Income:
                      Hmm. When I read it I thought the same as you wrote later on - that it would be simpler to just have this be the amount of money they earn. But wont the result in this case the the same than if the simpler system was used? In other words, isn't F and M the same? I mean, M is the amount of money spent on goods. And F is the amount of money earned from selling goods. And aren't these two exactly the same?

                      People changing classes:
                      Yes, this is pretty much the system I suggested. But one thing: In stead of using r's, it would be simpler, and more accurate, to use the prices of each goods. So in stead of using

                      A = 0.97 * Ap + ((r / R) * p)

                      we should use

                      A = 0.97 * Ap + ((p(good) / P) * p)

                      where p is the price on that good the last turn, and P is the prices of all goods added (P = p(food) + p(housing) + p(clothing)). The results are pretty similar, only this is a bit better, since the price is actually what should decide what people want to produce.

                      Later on, when we have capital and raw materials, I would like to have a more elegant "people changing classes" function. But for now this is great.


                      Ok, finally I am done. Please don't take all this critique the wrong way. The econ demo is a fantastic tool, and it has put us far ahead in the project. Sure, some algorithms should be changed. But that shouldn't take long to do. And the demo still have a lot of really, really useful features, like population and other things. This will make it much easier to put the model on to a map, when it is ready for it.

                      So generally it is a great program. When the minor bugs are gone we are ready to play around with it, and we can proceed!

                      ------------------
                      Vote Gore. For the sake of people, not god.

                      GGS Website
                      "It is not enough to be alive. Sunshine, freedom and a little flower you have got to have."
                      - Hans Christian Andersen

                      GGS Website

                      Comment


                      • #12
                        quote:

                        Originally posted by The Joker on 11-09-2000 12:32 PM
                        Heardie:

                        Say, what book are you using? I saw your disease program source code, and your comments seemed a lot like those the auther have made in the book I'm using. My book is called 'Teach yourself C++ in 21 days'.


                        LOL
                        Same as me. I just copied it from the book and then modified it for my needs. Although the new version does a bit more

                        Comment


                        • #13
                          About US elections: on federation scale it sounds undemocratic, but I think it makes sense considering the high level of independence of the states, as I said in the earlier. And I agree about Nader, he should have won. It seems that the Americans are too fixed on the republican-democrat axis so they can't think of any other parties or candidates.

                          About your feedback: No, I think it was great! It's good to have someone who has spent more time thinking about the model to comment the formulas. I had the problem that I didn't understand the model very well, so I just had to make it work somehow. I think I will do just as you said for the final formulas.

                          About demand&selling: actually the selling thing only sells the people what they want. The demand thing finds out what the people want to buy, and this depends on supply and their financial situation. Basically the algorithm is one large if -if else - else statement, that goes through several options of the financial situation (what is the value of finances variable). Then for each option it adjusts the demands of the goods so that the finances are positive. If they are positive right from the beginning, demands are rised slightly. But in the demo demands change too rapidly, which I intend to fix. But if a better way to do this is found, it can be replaced.

                          Guildmaster: I agree that equilibrium should be the goal. When combined with population and other models, the situation will change every turn, so each turn we would need to make corrections to remain as close to the equilibrium as possible. That should be the duty of the economy model; try to "normalize" the situation. I just today read some interesting things about a modeling tool used by economists, which was said to find an equilibrium in a system modeling flow of goods. It uses linear equations, and I'm certain that would be well within reach of my mathematical skills. And since computers are just like made for handling linear systems, we might get somewhere with that kind of system. Also that way the amount of calculations needed by the machine might be lowered. I'm examining that possibility.

                          Comment


                          • #14
                            Guildmaster:

                            Yep, this is what I had in mind, too. The econ model will be sort of an object that simply logs on to a region's stats and returns some new ones.

                            In itself it will move towards equilibrium, but with technological advancements, pop changes, trade etc equilibrium will be really, really rare in the game.

                            And I agree that a txt file with the econ model, in which everything could be changed (including pop, supply, income, amount of money in the game etc etc) so it is possible to "save" the stats from the econ demo, and then go to the txt file and change something - like productivity or pop, and see what happens.

                            I hope this wont take too long to program, cause I am really eager to add to the demo - a pop model where mortality is based on the amount of food people eat, capital, capitalists and workers etc etc!

                            I really look forward to all this!

                            And also: Who did you vote for?


                            Heardie:

                            Yeah, I thought you were! It's a pretty good book, BTW (not that I have anything to compare it with, but still...). So how far have you come in it? UI am on day 7 now, but of cause I have spent more than 7 days to do that, since I can't read all day. Unfortunately I have been to buissy to read further in it for the last few weeks.


                            Amjayee:

                            Elections:
                            Hmm... I see your point, but I think the president should be elected by the people, not the states (electing a president without a majority of the pop voting for him isn't very good democratically), and then the states would have some rights and be in charge in some areas (like they are).

                            My feedback:
                            Thanks!

                            Selling goods:
                            Do you mean that if supply is higher than demand then the goods that are left over wont be bought? If so then I must disagree with you. It is all a matter of price. Demand is really just the demand when the price of the good equals the price index. If supply is higher than demand then the price will drop, and people will buy more of it, untill they buy the same amount as the supply.

                            And that econ thing you read about:
                            Is it possible that you could post the system here or mail it to me? I have been searching the web for hours and hours without finding anything very useable, so eventually I just made up a system myself (the one we are using now), but if there is a better system out there we should use that! So I would really like to see it.

                            ------------------
                            "It would sharpen you up and make you ready for a bit of the old ultra-violence."
                            - A Clockwork Orange

                            GGS Website
                            "It is not enough to be alive. Sunshine, freedom and a little flower you have got to have."
                            - Hans Christian Andersen

                            GGS Website

                            Comment


                            • #15
                              Anyone else's program crash at turn 106?

                              Comment

                              Working...
                              X