Now I was thinking maybe I'd code a market
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Now I was thinking maybe I'd code a market
Well, I am thinking about coding a market trading in standardized commodities, notwithstanding that it is years since I coded in C++.
The market will work like a real market as far as I know and will be a reusable module. I'm not sure that Vegastrike will be able to use it immediately, but my next step would be to add "automated factories" so that there actually would be something to buy on the market. In any case, it would be a cool project.
So far I svn-downloaded the vegastrike module and noticed the boost library, but I haven't located one of the datastructures/algorithms that I think I need yet, which is sorting using a heap. I'm also stuck downloading a version of visual c++ for windows 2000, since the download site of microsoft offers the newest visual c++. It wouldn't really matters at this point, since my module probably will compile with g++ as well, but I'm still curious to see it all compile.
Tell me what you think.
The market will work like a real market as far as I know and will be a reusable module. I'm not sure that Vegastrike will be able to use it immediately, but my next step would be to add "automated factories" so that there actually would be something to buy on the market. In any case, it would be a cool project.
So far I svn-downloaded the vegastrike module and noticed the boost library, but I haven't located one of the datastructures/algorithms that I think I need yet, which is sorting using a heap. I'm also stuck downloading a version of visual c++ for windows 2000, since the download site of microsoft offers the newest visual c++. It wouldn't really matters at this point, since my module probably will compile with g++ as well, but I'm still curious to see it all compile.
Tell me what you think.
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Coding a market: got stuck with C++ ]8o)
Now I don't know whether someone can provide an answer to C++ riddles and whether it will pay off but here is one :
I have:
I want to do(where m_payload is of type Value):
and
I get market.cpp:
Is there a chance to use the existing candidate = operator (maybe using a cast?) or should I go and just assign the value .first .second each by themselves?
I have:
Code: Select all
//An element contains: +-price,+-time,<+-amount,bidderid>
typedef pair<int,string> Value;
typedef Element<double,int,Value> Elem;
Code: Select all
found.m_payload = smallest_in_subtree.m_payload;
Code: Select all
(*right_sib)[0].m_payload = new Value(0,"");
Code: Select all
In member function `Node* Node::rotate_from_right(int)':
market.cpp:930: error: no match for 'operator=' in 'right_sib->Node::operator[](0)->Element<double, int, Value>::m_payload = ((((const int&)((const int*)(&0))), ((const std::string&)(&string(((const char*)""), ((const std::allocator<char>&)((const std::allocator<char>*)(&allocator<char>()))))))), (((Value*)operator new(8u)), (<anonymous>->std::pair<_T1, _T2>::pair [with _T1 = int, _T2 = std::string](<anonymous>, <anonymous>), <anonymous>)))'
market.cpp:890: note: candidates are: std::pair<int, std::string>& std::pair<int, std::string>::operator=(const std::pair<int, std::string>&)
-
- Elite Venturer
- Posts: 725
- Joined: Mon Feb 26, 2007 6:01 pm
- Location: France, Paris
Re: Now I was thinking maybe I'd code a market
i m sorry i understand nothing at coding .......
you should wait a little bit for answer but i m sure you will have a answer
you should wait a little bit for answer but i m sure you will have a answer
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
I think the answer is to derefence the pointer returned by new:
I tried it out after getting home and it compiles. Also using a static initializer avoids a memory black hole.
Code: Select all
static Value null_value = *(new Value(0,""));
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
market coding progress
Hello, I believe I have coded the core of the market now, although two helper functions and the necessary destructors are still missing. The code is a bit raw, it is all in one file atm., but the headers are kept separately.
How would you like the code preview, as a zip attachment? to a post? Also what license are you using "GNU GPL version 2 or above" ? The code is based on a btree data structure that may be "freely copied", so I will provide a copy of that as well.
Maybe I should explain what I mean by a "market": Not a GUI, it is just a mechanism implementing relatively efficiently how trading for example on a stock market works. You have two graphs/plots of price(x-axis) vs amount(y-axis), one for demand, one for offers and the resulting price is the price where the two graphs meet.
This is implemented by maintaining open orders books for sellers and for buyers. The books never overlap, because all orders that overlap are executed at the moment that the overlapping order is given. You can view such a market in operation at dreamlords or idea futures.
How Vegastrike could use this:
For multiplayer, the market would solve the problem how players can (indirectly) trade with each other and interact.
For single player, it makes prices more dynamic without introducing an annoying random factor:
Factories would produce and replenish the market almost exactly like they do now, except that they would put sell orders on the market across a certain price range. This could eventually be used for a more fullish economic simulation, for example like the one railroad tycoon is using: if there is a factory at a station, it will produce its output if you provide the inputs.
Back to the topic of more dynamic prices, if you keep buying more than the planet produces prices will rise because only the more costly sell orders dominate the market, but if the planet produces more than is being traded away, prices will drop.
The tasks to solve for this is how the planets will refill the market.
In addition one beneficial change would be to save the market and other economic data when the player exits the game and load it upon start and creation of the universe. This would also help existing tools that work out trade routes to keep working by reading the saved data.
Vegastrike could also eventually display cool graphics of buy/sell orders or of market price evolution.
There are on the other hand some few drawbacks to this: Buying and selling stuff will get more complicated because the price changes basically whenever a trade is made, so the player can't simply calculate the prices as amount times price. This is what the two helper functions that I stll have to code will make easy, so that vegastrike can display for each button(buy all, buy 100, buy 10, buy 1) the highest price that will result as well as the total of money needed, similar to what it is doing now for the "buy all" button. Also, a player who buys 1000 gold and then decides he doesn't actually want to transport it will make a small loss when he trades it back to the market, as the sell prices will always be lower than the buy prices.
I hope I have raised your interest in this.
How would you like the code preview, as a zip attachment? to a post? Also what license are you using "GNU GPL version 2 or above" ? The code is based on a btree data structure that may be "freely copied", so I will provide a copy of that as well.
Maybe I should explain what I mean by a "market": Not a GUI, it is just a mechanism implementing relatively efficiently how trading for example on a stock market works. You have two graphs/plots of price(x-axis) vs amount(y-axis), one for demand, one for offers and the resulting price is the price where the two graphs meet.
This is implemented by maintaining open orders books for sellers and for buyers. The books never overlap, because all orders that overlap are executed at the moment that the overlapping order is given. You can view such a market in operation at dreamlords or idea futures.
How Vegastrike could use this:
For multiplayer, the market would solve the problem how players can (indirectly) trade with each other and interact.
For single player, it makes prices more dynamic without introducing an annoying random factor:
Factories would produce and replenish the market almost exactly like they do now, except that they would put sell orders on the market across a certain price range. This could eventually be used for a more fullish economic simulation, for example like the one railroad tycoon is using: if there is a factory at a station, it will produce its output if you provide the inputs.
Back to the topic of more dynamic prices, if you keep buying more than the planet produces prices will rise because only the more costly sell orders dominate the market, but if the planet produces more than is being traded away, prices will drop.
The tasks to solve for this is how the planets will refill the market.
In addition one beneficial change would be to save the market and other economic data when the player exits the game and load it upon start and creation of the universe. This would also help existing tools that work out trade routes to keep working by reading the saved data.
Vegastrike could also eventually display cool graphics of buy/sell orders or of market price evolution.
There are on the other hand some few drawbacks to this: Buying and selling stuff will get more complicated because the price changes basically whenever a trade is made, so the player can't simply calculate the prices as amount times price. This is what the two helper functions that I stll have to code will make easy, so that vegastrike can display for each button(buy all, buy 100, buy 10, buy 1) the highest price that will result as well as the total of money needed, similar to what it is doing now for the "buy all" button. Also, a player who buys 1000 gold and then decides he doesn't actually want to transport it will make a small loss when he trades it back to the market, as the sell prices will always be lower than the buy prices.
I hope I have raised your interest in this.
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
*bump* since the forum server was down for almost a day
-
- Lead Network Developer
- Posts: 2560
- Joined: Sun Jan 12, 2003 9:13 am
- Location: Palo Alto CA
- Contact:
Re: Now I was thinking maybe I'd code a market
No, don't do that. You're thinking too much into this. You just want to doRedAdder wrote:I think the answer is to derefence the pointer returned by new:
I tried it out after getting home and it compiles. Also using a static initializer avoids a memory black hole.Code: Select all
static Value null_value = *(new Value(0,""));
Code: Select all
static Value null_value = Value(0, "");
Code: Select all
static Value null_value(0, "");
Note that if you do not use static, C++ will nicely allocate it at the beginning of the function and deallocate it before the end brace. However you will want to make sure you don't keep pointers to it around past the end of the function.
Sorry about the whole MSVC thing--the project has not been kept up to date because very few of the developers use windows. I have been unsuccessful at producing a working executable using visual C++ 2008 (Python will just keep crashing on load), but I can try again if people are interested. 2003 (msvc 7.1) should work as of December 12 if you can find an old version of that somewhere.
Sure, a zip attachment is fine. As to license I think "v2 or above" is the standard, but to be honest I don't really know since isn't not like there was any inkling of a difference 8 years ago when the license was chosen. I'm pretty sure the FSF authors tried to keep backwards compatibility when they wrote the new license.
Sounds great to have something like this. Since it's C++, and because this could be used for a lot of cargo and economy-related things it would be nice if you could document the interface.
Also, not sure if you have considered this, but it may be a lot easier to write something of this nature in Python rather than C++ (don't have to worry about memory management, and you get access to all the dynamic universe code). Also the C++ code in the engine is a huge mess that may take a bit of work to figure out.
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
Here is the market.
The documentation is in market_documentation.txt
An executable testing the btree, btree iterator, and the market can be created directly from market_main.cpp .
There is also a file btree_free_as_in_beer.cpp which contains a slightly modified version of the btree I started out with by toucan. This file documents which parts of the code may be freely copied.
The documentation is in market_documentation.txt
An executable testing the btree, btree iterator, and the market can be created directly from market_main.cpp .
There is also a file btree_free_as_in_beer.cpp which contains a slightly modified version of the btree I started out with by toucan. This file documents which parts of the code may be freely copied.
You do not have the required permissions to view the files attached to this post.
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
I am currently in the process of writing an economic simulation that uses the market.
I am currently testing my code using mingw commandline and g++
I have the following problem: Somewhere there's a bug, and an error dialog pops up and writes data to drwtsn32.log. I am compiling with -g so I would like to see symbols in there, but the only halfway useful part of the .log for me would be the assembler Also gdb doesn't work even as I am compiling with -g
So do I have to change my toolchain to vc++? I would rather not since I find processing the output of my test program, using grep etc, rather easy to use ..
I also used gdb with other programs, I am not sure why it doesn't work now.
Hints are welcome!
I am currently testing my code using mingw commandline and g++
I have the following problem: Somewhere there's a bug, and an error dialog pops up and writes data to drwtsn32.log. I am compiling with -g so I would like to see symbols in there, but the only halfway useful part of the .log for me would be the assembler Also gdb doesn't work even as I am compiling with -g
So do I have to change my toolchain to vc++? I would rather not since I find processing the output of my test program, using grep etc, rather easy to use ..
I also used gdb with other programs, I am not sure why it doesn't work now.
Hints are welcome!
-
- Venturer
- Posts: 555
- Joined: Sun Jan 18, 2009 5:18 am
- Location: Quito, Ecuador.
- Contact:
Re: Now I was thinking maybe I'd code a market
I find it a little difficult to install that... will that be part of SVN sometime?
My Machine: OS: Ubuntu 8.10 (intrepid) 64 bit in a 500GB Maxtor HD @ 7200 RPM, Windows Vista PsyChoses Edition 2009 32 bit in a 500GB Samsung HD @ 7200 RPM CPU: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz GPU: nVidia GeForce 9400 GT @ 1024 MB RAM: 3891 MB
Earthlings|The End of the Internet?|FreeWebsite
Earthlings|The End of the Internet?|FreeWebsite
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
MC707 wrote:I find it a little difficult to install that...
I made it so that it is easy to run on the command line using g++. I saved me the work of creating a makefile by including the *.cpp files instead of including the *.hpp files and doing linking in the final step, but I took care to properly split up the .hpp files and the .cpp files so that it is easy to fix. You are probably not missing out much, since it is just a demonstration of setting up the market and buying and selling something and the cool parts of using btree's to store the order books don't make much of an impression.
To be part of SVN eventually is the idea yes.MC707 wrote:will that be part of SVN sometime?
But it might turn out too difficult to create a working automated economy based on the market(s). Since you have no direct control over prices. I programmed this so far in my working copy that the "farms" that I specified make profit, but my "factories" don't work at all yet. I also haven't worked out how to achieve monetary balance - the factories just keep on accumulating capital as they are programmed to either make profit or do nothing when they can't make a profit. I think I'll try to solve this by having them pay out dividends to the populace. And then I have to set up the populace to simply consume stuff instead of producing "workforce" when they consume goods.
-
- Venturer
- Posts: 555
- Joined: Sun Jan 18, 2009 5:18 am
- Location: Quito, Ecuador.
- Contact:
Re: Now I was thinking maybe I'd code a market
LOL sorry I didnt get anything!RedAdder wrote:I made it so that it is easy to run on the command line using g++. I saved me the work of creating a makefile by including the *.cpp files instead of including the *.hpp files and doing linking in the final step, but I took care to properly split up the .hpp files and the .cpp files so that it is easy to fix. You are probably not missing out much, since it is just a demonstration of setting up the market and buying and selling something and the cool parts of using btree's to store the order books don't make much of an impression.
Hopefully that will save me the installing stepRedAdder wrote:To be part of SVN eventually is the idea yes.
You know... if you have problems with economics, you can rely on me (PM i guess). I'm studying that (apart from what I already studied in HS).RedAdder wrote:But it might turn out too difficult to create a working automated economy based on the market(s). Since you have no direct control over prices. I programmed this so far in my working copy that the "farms" that I specified make profit, but my "factories" don't work at all yet. I also haven't worked out how to achieve monetary balance - the factories just keep on accumulating capital as they are programmed to either make profit or do nothing when they can't make a profit. I think I'll try to solve this by having them pay out dividends to the populace. And then I have to set up the populace to simply consume stuff instead of producing "workforce" when they consume goods.
My Machine: OS: Ubuntu 8.10 (intrepid) 64 bit in a 500GB Maxtor HD @ 7200 RPM, Windows Vista PsyChoses Edition 2009 32 bit in a 500GB Samsung HD @ 7200 RPM CPU: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz GPU: nVidia GeForce 9400 GT @ 1024 MB RAM: 3891 MB
Earthlings|The End of the Internet?|FreeWebsite
Earthlings|The End of the Internet?|FreeWebsite
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
Here is a new version of the market.
I removed a really bad bug resulting from a misunderstanding of ownership of "Elem" objects.
It compiles now with Visual C++.
There is now a Code::blocks workspace, which is still a little weird. Try the factory and market targets.
A test economy has been set up, and I believe the code is ok, although what it does might not work.
Problems are factories producing just once or never, etc.
The masterplan is:
I removed a really bad bug resulting from a misunderstanding of ownership of "Elem" objects.
It compiles now with Visual C++.
There is now a Code::blocks workspace, which is still a little weird. Try the factory and market targets.
A test economy has been set up, and I believe the code is ok, although what it does might not work.
Problems are factories producing just once or never, etc.
The masterplan is:
Factories work like this:
A factory has a number of production options. There should not be too many because the factory collects and stores resources that it needs for production.
A factory is calculating the supplies it needs to buy from the market by taking the max over the required inputs for each production options respectively. A factory will calculate the price it is willing to pay by taking what it will get for selling its output, discounting it by the profit rate, and distributing the money over all resources in proportion to the current market value of the resources. Now a buy order can be placed on the market if there is enough money. If there isn't enough money, divide up the remaining money to place buy orders.
Upon receiving new supplies the factories reserve is check whether any production option may be executed fully or partially. Of the executable options, the one with the highest absolute profit is chosen and executed.
You do not have the required permissions to view the files attached to this post.
-
- Venturer
- Posts: 555
- Joined: Sun Jan 18, 2009 5:18 am
- Location: Quito, Ecuador.
- Contact:
Re: Now I was thinking maybe I'd code a market
Correct me if I am wrong, but isn't Visual C++ for windows? (note my signature (linux) ).RedAdder wrote:It compiles now with Visual C++.
My Machine: OS: Ubuntu 8.10 (intrepid) 64 bit in a 500GB Maxtor HD @ 7200 RPM, Windows Vista PsyChoses Edition 2009 32 bit in a 500GB Samsung HD @ 7200 RPM CPU: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz GPU: nVidia GeForce 9400 GT @ 1024 MB RAM: 3891 MB
Earthlings|The End of the Internet?|FreeWebsite
Earthlings|The End of the Internet?|FreeWebsite
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
I meant to say:
Where I used the g++ of mingw, but it should work the same on linux, and yes, visual C++ is on windowsIt compiles now with Visual C++, in addition to g++
-
- Venturer
- Posts: 555
- Joined: Sun Jan 18, 2009 5:18 am
- Location: Quito, Ecuador.
- Contact:
Re: Now I was thinking maybe I'd code a market
works in linux... nice. Hope I can install it though gonna do some research
My Machine: OS: Ubuntu 8.10 (intrepid) 64 bit in a 500GB Maxtor HD @ 7200 RPM, Windows Vista PsyChoses Edition 2009 32 bit in a 500GB Samsung HD @ 7200 RPM CPU: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz GPU: nVidia GeForce 9400 GT @ 1024 MB RAM: 3891 MB
Earthlings|The End of the Internet?|FreeWebsite
Earthlings|The End of the Internet?|FreeWebsite
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
Here's an update.
This time I'm not as happy with it as with the previous posts, because almost all pieces are in place, the factories are working, but there is still something going on that interrupts the economy.
You can compile it with:
g++ -Wall factory_main.cpp -o factory.exe
This works because I abused factory_main.cpp instead of writing a makefile.
Run with:
factory.exe
or use the code::blocks workspace
This time I'm not as happy with it as with the previous posts, because almost all pieces are in place, the factories are working, but there is still something going on that interrupts the economy.
You can compile it with:
g++ -Wall factory_main.cpp -o factory.exe
This works because I abused factory_main.cpp instead of writing a makefile.
Run with:
factory.exe
or use the code::blocks workspace
You do not have the required permissions to view the files attached to this post.
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
There were two reasons that the factories got stuck:
A programming mistake involving sequencing two "parallel" assignments the wrong way. Fixed.
And that the marketprices dropped too low for some goods to be able to trigger production, and that because the new price was set according to the last deal price, and there were no deals, so there was no change.
I've now made it so that it is more likely that factories will produce a little just in order to influence the market price in their favor. The downside is that some factories will make losses, or more accurately they will have lots of outstanding sell orders on the market. Which OTOH happens to be a good thing if you want see some activity on the market.
A programming mistake involving sequencing two "parallel" assignments the wrong way. Fixed.
And that the marketprices dropped too low for some goods to be able to trigger production, and that because the new price was set according to the last deal price, and there were no deals, so there was no change.
I've now made it so that it is more likely that factories will produce a little just in order to influence the market price in their favor. The downside is that some factories will make losses, or more accurately they will have lots of outstanding sell orders on the market. Which OTOH happens to be a good thing if you want see some activity on the market.
You do not have the required permissions to view the files attached to this post.
-
- Elite Venturer
- Posts: 725
- Joined: Mon Feb 26, 2007 6:01 pm
- Location: France, Paris
Re: Now I was thinking maybe I'd code a market
It will be going in the VS game engine/system ???
-
- The Shepherd
- Posts: 5841
- Joined: Fri May 13, 2005 8:37 pm
- Location: Ottawa
- Contact:
Re: Now I was thinking maybe I'd code a market
I would hope so but i think he has a bit more testing to do and then he has to figure out how to hook it into the engine.
Enjoy the Choice
Enjoy the Choice
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
I am offering it to VS. However it still has to prove that it can create a working economy. It remains to be seen whether this is simply a problem of fine-tuning or whether I have to create additional entities; For example, at the moment I am using a "factory" to provide "population" and "workforce". This might be better solved with special entities to represent these. Also, the spending policy of the "consumer" could be more polished, at the moment I think it spends all on "beer" and the rest on "wine". It is a big task to set up an simulated economy that works since you have to think of everything; for example if you wish to have a factory requiring 3 goods as inputs you have to set up factories for these 3 inputs, which in turn require other inputs etc.Fendorin wrote:It will be going in the VS game engine/system ???
The other problem is that I am setting up a "fully" simulated economy, and this means that it is hard to have full control of prices, since prices are the result of the simulation. This means integration with VS requires work, and that there is a conflict with existing methods of controlling production. Also, some situations that are in the current game are completely incompatible: It makes no sense that ice planets pay huge sums for AI Cores, unless they can use these AI Cores for example to produce lots of research which pays for the AI Cores. This means, with a simulated economy, you would more often have a cargo for your return trip.
It also is a big task to integrate this into VS, maybe too big. If I receive some positive feedback, which I believe is possible with version v0.0.4, I would as the next step add XML saving and loading functions. Here it would help me if someone pointed me at the modules VS uses for reading XML; As I am developing this separately however I would prefer to use some separate files and it shouldn't involve the almighty "VS file system".
It would help if someone tried to create his own economy to give me feedback, but that requires a little simple C++ programming, until the XML functions are in place.
Maybe I will host this as a separate module on sourceforge.
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
Here's a new version with two smaller bugs fixed.
All kinds of interesting things are happening within the test economy, like cars getting cheaper than beer for some reason. I'll have to calculate how that works
Here is how the statistics look after 333 turns of the economy:
(Market with last deal price, lowest and highest price)
All kinds of interesting things are happening within the test economy, like cars getting cheaper than beer for some reason. I'll have to calculate how that works
Here is how the statistics look after 333 turns of the economy:
(Market with last deal price, lowest and highest price)
Code: Select all
========
Market:barrel Last deal price:8.82 [8.30,150.00]
Market:beer Last deal price:190.00 [10.00,190.00]
Market:bottles Last deal price:14.18 [10.00,110.00]
Market:cars Last deal price:34.11 [34.11,1200.00]
Market:grapes Last deal price:170.00 [70.00,170.00]
Market:hop Last deal price:160.00 [50.00,160.00]
Market:lands Last deal price:318.34 [9.67,380.44]
Market:machinery Last deal price:10.00 [10.00,110.00]
Market:pipes Last deal price:10.00 [10.00,110.00]
Market:population Last deal price:0.00 [0.00,100.00]
Market:seeds Last deal price:80.00 [80.00,110.00]
Market:steel Last deal price:8.82 [3.86,160.00]
Market:tractors Last deal price:100.00 [100.00,1200.00]
Market:unused lands Last deal price:110.00 [100.00,110.00]
Market:wine Last deal price:50.00 [50.00,130.00]
Market:workforce Last deal price:42.24 [10.00,536.71]
========
Factory:assembly line capital:922574.57 output cars price=34.113234 activity[sss]:659.33 dividends:3255.33
Factory:brewery capital:960899.74 output wine price=50.000000 activity[sss]:1010.73 dividends:284653.42
Factory:factory capital:929078.73 activity[sss]:1036.18 dividends:82514.33
Factory:farm capital:869406.66 activity[sss]:263.92 dividends:14798.58
Factory:iron mine capital:995558.30 activity[sss]:656.35 dividends:22273.45
Factory:lands capital:1000000.00 activity[sss]:184.68 dividends:147476.20
Factory:population capital:998185.38 output population price=0.000000 activity[sss]:341095.00 dividends:63055.00
Factory:workers capital:999703.29 output workforce price=42.242073 activity[sss]:673.31 dividends:137743.88
========
Consumer:the populace capital=0.22
333
You do not have the required permissions to view the files attached to this post.
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
Well, I have been making progress by fixing a problem in the Consumer code:
The economy is still fluctating wildly, but at least it appears it is consistently producing stuff(prices between turn 111 to 333):
Now I am sort of stuck because when I tried to pull the xml handling stuff of VegaStrike in, basically that led to pulling a lot of Vegastrike in, more than I want to at this stage. I looked at expat but it appears to be pretty basic, so I am wondering whether using something like SCEW which compiles under both Visual Studio and ./configurable systems is a good idea
Code: Select all
void Consumer::tick(){
if(capital<=0.0)
return;
capital *= 1.0 + subsidyrate;//the government is basically printing money to match economy growth
//spend money progressively
for(Products::const_iterator pitr = (this->consumption).begin(); pitr != (this->consumption).end(); ++pitr){
if(this->capital<=0.0)
break;
string aname = (*pitr).first;
double amount = (*pitr).second;
double amoneyneed;
double marketprice = this->economy->markets[aname]->max_market_price_when_buying_n((int)ceil(amount),amoneyneed);
if(marketprice == 0.0||marketprice>= std::numeric_limits<float>::max()){
marketprice = this->economy->markets[aname]->last_deal_price();
amoneyneed = marketprice*amount;
}
double factor= capital/(marketprice*amount);//amoneyneed here does not work (leads to negative capital)
if(factor>4.0){
factor= 4.0;
}
if(factor>0.25){
double price= marketprice*sqrt(factor);
int aamount= (int)floor(amount*sqrt(factor));
this->economy->buyProduct(aname, aamount, price, this->name);
this->capital-= aamount*price;//pay deposit immediately
}else{
break;
}
}
}
Code: Select all
========
Market:barrel Last deal price:170.00 [10.00,170.00]
Market:beer Last deal price:83.33 [10.00,170.00]
Market:bottles Last deal price:21.06 [10.00,102.43]
Market:cars Last deal price:507.63 [136.25,1600.00]
Market:grapes Last deal price:130.16 [54.29,180.00]
Market:hop Last deal price:52.58 [15.31,63.73]
Market:lands Last deal price:249.69 [212.90,298.41]
Market:machinery Last deal price:13.06 [10.00,40.32]
Market:pipes Last deal price:37.94 [10.00,40.00]
Market:population Last deal price:0.00 [0.00,0.00]
Market:seeds Last deal price:43.82 [340282346638528859811704183484516925440.00,0.00]
Market:steel Last deal price:15.72 [2.81,232.55]
Market:tractors Last deal price:200.00 [200.00,200.00]
Market:unused lands Last deal price:110.00 [340282346638528859811704183484516925440.00,0.00]
Market:wine Last deal price:52.71 [36.61,53.29]
Market:workforce Last deal price:120.02 [10.00,1019.64]
========
Factory:assembly line capital:946923.73 output cars price=507.632605 activity[sss]:1158.00 dividends:164645.57
Factory:brewery capital:951605.03 output beer price=83.333333 activity[sss]:1233.34 dividends:119025.29
Factory:factory capital:908435.34 activity[sss]:892.19 dividends:25221.22
Factory:farm capital:850200.12 activity[sss]:857.95 dividends:44186.75
Factory:iron mine capital:991729.14 activity[sss]:717.04 dividends:101622.06
Factory:lands capital:1000000.00 activity[sss]:1078.28 dividends:158170.32
Factory:population capital:998470.07 output population price=0.000000 activity[sss]:451555.00 dividends:62945.00
Factory:workers capital:999666.67 output workforce price=120.022407 activity[sss]:1062.49 dividends:276289.42
========
Consumer:the middle class capital=353.49
Consumer:the working class capital=62.66
-
- Lead Network Developer
- Posts: 2560
- Joined: Sun Jan 12, 2003 9:13 am
- Location: Palo Alto CA
- Contact:
Re: Now I was thinking maybe I'd code a market
This looks pretty cool--would be nice to have a real market system. Now what does it do to make sure things don't crash and burn? Or will there be government bailouts if anything goes sour :-p
Vega Strike uses Expat for most of the xml parsing--look at the *_xml.cpp files, such as star_system_xml or even mesh_xml or communication_xml. (I think most of the XML in vegastrike has been deprecated in favor of CSV but there is still a lot of it). So there should be a couple of good examples. Try to avoid pulling all of Vegastrike in if at all possible--I know it's hard. If you have to, you can maybe make a copy of a couple of VS files without the dependencies.
I noticed it doesn't compile in Linux mainly because of that "high resolution timer" code from market_main.cpp--I'm going to try changing that to use gettimeofday on non-windows systems. (Any reason we need that, and can't use pseudo-random numbers like rand()
Anyway with those few changes it compiles fine:
Vega Strike uses Expat for most of the xml parsing--look at the *_xml.cpp files, such as star_system_xml or even mesh_xml or communication_xml. (I think most of the XML in vegastrike has been deprecated in favor of CSV but there is still a lot of it). So there should be a couple of good examples. Try to avoid pulling all of Vegastrike in if at all possible--I know it's hard. If you have to, you can maybe make a copy of a couple of VS files without the dependencies.
I noticed it doesn't compile in Linux mainly because of that "high resolution timer" code from market_main.cpp--I'm going to try changing that to use gettimeofday on non-windows systems. (Any reason we need that, and can't use pseudo-random numbers like rand()
Anyway with those few changes it compiles fine:
Code: Select all
g++ market_main.cpp -o market
g++ factory_main.cpp -ofactory
Code: Select all
diff -u Market v0.0.5/factory.hpp Market v0.0.b/factory.hpp
--- Market v0.0.5/factory.hpp 2009-02-15 22:42:34.000000000 -0800
+++ Market v0.0.b/factory.hpp 2009-02-23 01:19:43.359272347 -0800
@@ -189,7 +189,7 @@
double calculate_moneyresulting(ProductionOption &po,double production_units);
//build another factory of this type, if possible
- void Factory::growSector(double production);
+ void growSector(double production);
};
class Consumer{
Only in Market v0.0.b: market
diff -u Market v0.0.5/market.hpp Market v0.0.b/market.hpp
--- Market v0.0.5/market.hpp 2009-02-15 23:10:50.000000000 -0800
+++ Market v0.0.b/market.hpp 2009-02-23 01:19:29.167271909 -0800
@@ -43,7 +43,7 @@
vector<Payback*>getPaybacks();
//dump the executed sell/buy order vectors and elements
- void Market::dumpExecutedOrders();
+ void dumpExecutedOrders();
//reset the executed sell/buy order vectors and elements
void resetExecutedOrders();
diff -u Market v0.0.5/market_main.cpp Market v0.0.b/market_main.cpp
--- Market v0.0.5/market_main.cpp 2009-02-06 22:14:32.000000000 -0800
+++ Market v0.0.b/market_main.cpp 2009-02-23 01:20:56.639271687 -0800
@@ -21,9 +21,9 @@
// for the high-resolution timer
-
+#ifdef _WIN32
#include <windows.h>
-
+#endif
int main(int argc, char* argv[])
@@ -33,13 +33,13 @@
// the main function is just some code to test the btree and the market.
-
+#ifdef _WIN32
__int64 frequency, start, end, total;
QueryPerformanceFrequency( (LARGE_INTEGER *)&frequency );
QueryPerformanceCounter( (LARGE_INTEGER *)&start );
-
+#endif
Elem elem;
@@ -169,12 +169,13 @@
market.addSellOrder(0.20,222,"Seller A");
market.dumpExecutedOrders();
+#ifdef _WIN32
QueryPerformanceCounter ( (LARGE_INTEGER *)&end);
total = (end-start)/(frequency/1000);
cerr << "total millisec for all operations: " << (int)total << endl;
-
+#endif
//getchar();
return 0;
-
- Bounty Hunter
- Posts: 149
- Joined: Sat Jan 03, 2009 8:11 pm
- Location: Germany, Munich
- Contact:
Re: Now I was thinking maybe I'd code a market
What currently is cool and works is the market, and the single factory by itself also works ok, although I still should work on the re-investment(growing) feature.ace123 wrote:This looks pretty cool--would be nice to have a real market system. Now what does it do to make sure things don't crash and burn? Or will there be government bailouts if anything goes sour :-p
The entire economy is still being weird, but well, so is our world economy right now.
I tried to simulate the populace and the workforce using markets too, but that didn't work out, the factories tended to get all blocked because they couldn't produce with profit. Now I am making them produce a little even if there is no matching demand on the market.
In addition I went socialist/keynesian and hooked up the factory with the consumers by assuming that the consumers were owning shares in the production facilities, and that instead of hogging up money, every profitable factory would pay out all the profit as dividends. This resulted in a working economy, but with big swings in market prices that I still have to understand so I can learn how to avoid them.
In respect to the danger of "crash & burning", the factories are programmed to try and sell stuff at a profit, and they don't have a capital as such that needs to be earn dividends. This leads to losses only when trying to sell stuff on the market and not finding a buyer. The factories are quite thrifty, the worst "factory" was the farm which had only a capital of 850200.12 with 44186.75 dividends being paid over the course of 333 turns, so the farm sort of lost 317 monetary units each turn.
I'm working on using scew+expat now to produce and then read xml.
I don't think csv is up to the job of storing an economy.