|
|
|
 |
|

April 1st, 2005, 12:21 AM
|
First Lieutenant
|
|
Join Date: Dec 2003
Location: Calgary, Canada
Posts: 762
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: Reading maps from .map files
Your algorithm looks reasonable, but sometimes it will fail. Consider a small map with a chokepoint that splits map in 2. If you need to allocate 2 somewhat equal areas your algorithm will fail is the first province will be at the chokepoint. You can also fail on step 3 before finding 5-8 provinces. I think your algorithm will work well on open wraparound maps with few impasses, but not on highly segmented maps.
Generally, this kind of tasks is considered in graph theory. I would suggest some modification to your algorithm:
- the first step is to build a graph. Initially you have connected graph (at least usually)
- find simple chokepoints (nodes, which if removed would make the graph unconnected). This is easy to do by iterating through all nodes and checking if the graph is still connected or not if all incoming edges to this node are removed.
- or optionally find complex chokepoints (pair of nodes, which if removed would make the graph disconnected). This is similar to the previous step.
- Now consider graphs produced by removal of chokepoints. Each of those graphs is a "mega-area". Those are suitable for area placement. Count number of provinces in each mega-area (number of nodes) and see if there's a reasonable way to divide them in required number of area. There's no need for exact match, because some of the areas can overflow through chokepoints. This step may fail. For example, if you have 2 equal areas connected through the chokepoint, you can't make 3 "equal" areas. So you have to decide something. (see more in the following step).
- Now you have number of areas to create out of each "mega-area". Start from the most densely populated "mega-area"
(one that have least provinces per required area). Start from the most remote point from any of chokepoints. Use your original algorithm, but in step 2,3 give more preference to the province further from the chokepoint. Degree of preference should depend on density of "mega-area" population. More densely it is populated, the more preference you should give to the outward provinces.
This will let the last area overflow through the chokepoint, if necessary.
- Update the graphs to take into account possible overflow, and repeat previous step for the next densest "mega-area".
If you have larger map and fewer required areas, you may want to execute this algorithm for the size of the area approaching to total of "mega-area" areas divided by number of required areas, and after it is complete, remove outward provinces from each of the areas to reach your original target size.
Concerning implementation, I don't see any problems implementing it in Java, but this algorithm may be resource intensive (I have no idea actually), so it may be better to do it in C++. Besides you'll probably have easier time finding libraries to use (like for graph handling).
|

April 1st, 2005, 02:38 AM
|
 |
Major General
|
|
Join Date: Nov 2000
Location: 500km from Ulm
Posts: 2,279
Thanks: 9
Thanked 18 Times in 12 Posts
|
|
Re: Reading maps from .map files
programming language
At first -considering the fact that you ask if something like your pseudocode could be implemented in Java- let me say, that if you start learning Java now it will be quite a long time before you actually can do what you want. Are you thinking about taking Java courses at University? That would make time less of an factor as far a learning is concerned, but they're not known for starting with the "practical side" of things.
I would wholeheartedly suggest using (and learning) a scripting language - Ruby, Pearl, Tcl. Those are freely available, have bindings to GUI-Toolkits (like TK) which make building a graphical interface a matter of tens of lines of code and are usuable cross-plattform. What is a thing to consider as DOM is, too. And the scripts can be "wrapped" into standalone .EXEs which you can distribute.
I don't think they would pose too much of a performance problem in the time of 3 Ghz processors.
If you're interested in details, PM me. I could supply you with links etc. to a good bunch of free ressources on the net, trainers and manuals included.
algorithm
As alexti already pointed out, there are some "flaws" in your algorithm. His, on the other hand, looks overly complex to me. Something I would expect from a C++ programmer  Think he overlooked the fact that some -how do you call it?- "boundary conditions"? are already know at start:
E.g. you could can the map file for all provinces which have only 1 or 2 neighbours - those are the choke points. A "capital" must have at least 3, better 4 land neighbours, so if the number of desired "capitals" is known, you can simply compare it ot the number of "4"s and if those are sufficient, I think you needn't do much more besides checking for duplicates among the neighbours.
Don't have the time to go into further detail now, will look into it later...
__________________
As for AI the most effective work around to this problem so far is to simply use an American instead, they tend to put up a bit more of a fight than your average Artificial Idiot.
... James McGuigan on rec.games.computer.stars somewhen back in 1998 ...
|

April 1st, 2005, 03:43 AM
|
First Lieutenant
|
|
Join Date: Dec 2003
Location: Calgary, Canada
Posts: 762
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: Reading maps from .map files
I suspect that this is kind of problem where it is easier to find some available bike with round wheels rather than invent your own with rectangular ones  If you take something like Goblin, probably you'd get most of the code you need. You can also look at http://www.kurnikov.org/links/math_links.htm in the Graph Theory section. Or just google 
|

April 1st, 2005, 04:33 AM
|
 |
Major General
|
|
Join Date: Nov 2000
Location: 500km from Ulm
Posts: 2,279
Thanks: 9
Thanked 18 Times in 12 Posts
|
|
Re: Reading maps from .map files
Alexti, I think you're missing the point. Someone who is an experienced programmer, maybe software engineer or with an degree in computer science or something, will have little trouble understanding what those libraries do, and how to use them.
Then think of a novice:
He still has to learn the basic syntax of the language.
He can barely do a command line programm, I/O will be a major obstacle.
The concept of OO-programming (C++, Java) is new to him, integrating pre-made libraries into his programm is quite a task for him.
He'll have to delve into the mathematical background of solving problems using computer algorithms, and that of the suggested theorems in particular.
So, it seems to me, you suppose someone should learn how to operate a particle accelerator to poke a hole into a sheet of paper. May work, but won't be the most effective way unless he's going for a degree or two in atomic physics anyway
And we're talking about a real thin sheet of paper: 100-300 provinces (nodes) at best, with less than 750 interconnects.
A short script will really do. If you're fancy, you may implement a graph algorithm in that script language, too (haven't checked if it's already available, but it might be)
__________________
As for AI the most effective work around to this problem so far is to simply use an American instead, they tend to put up a bit more of a fight than your average Artificial Idiot.
... James McGuigan on rec.games.computer.stars somewhen back in 1998 ...
|

April 1st, 2005, 05:50 AM
|
 |
National Security Advisor
|
|
Join Date: Sep 2003
Location: Eastern Finland
Posts: 7,110
Thanks: 145
Thanked 153 Times in 101 Posts
|
|
Re: Reading maps from .map files
That "Could a Java program using this work" line: it was originally "Would this (algorithm) work". I changed the line to make clear I'm going to make a program utilizing this, not change maps by hand, and managed to translate it to Gibberish. Confusing language, that.
I have already made a working program, ModConverter, which has a GUI and can handles Dominions's mod (text) files. However, I don't have much programming experience besides that and school stuff, and while ModConverter works without crashes it has some annoying input/output bugs, and I'm not going to reuse much code from it. So it seems I didn't plan/implement it properly.
I'm not sure if I understand that "graph" stuff, but hopefully it is just a term I don't know in English. I'll check that.
Okay, I have heard of that. I have to ask my Math teacher a few things, but I think it's doable.
|

April 1st, 2005, 06:26 AM
|
 |
Major General
|
|
Join Date: Nov 2000
Location: 500km from Ulm
Posts: 2,279
Thanks: 9
Thanked 18 Times in 12 Posts
|
|
Re: Reading maps from .map files
Doing a fast scan through the ressources, this is what I found what may be a good starting point:
http://www.cs.sunysb.edu/~algorith/info/view.html
In the 7th line, there's something called "edge-vertex-connectivity" what resembles our problem to some extent.
http://www.cs.sunysb.edu/~algorith/f...ectivity.shtml
__________________
As for AI the most effective work around to this problem so far is to simply use an American instead, they tend to put up a bit more of a fight than your average Artificial Idiot.
... James McGuigan on rec.games.computer.stars somewhen back in 1998 ...
|

April 1st, 2005, 01:17 PM
|
 |
Second Lieutenant
|
|
Join Date: Feb 2005
Location: Central Illinois
Posts: 434
Thanks: 7
Thanked 3 Times in 3 Posts
|
|
Re: Reading maps from .map files
Guys,
Mike Milchior has done a program similar to that one for another program. You can find a link to it at this site:
http://www.slooflirpa.com
|

April 1st, 2005, 01:16 PM
|
First Lieutenant
|
|
Join Date: Dec 2003
Location: Calgary, Canada
Posts: 762
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: Reading maps from .map files
Quote:
Endoperez said:
I'm not sure if I understand that "graph" stuff, but hopefully it is just a term I don't know in English. I'll check that.
Okay, I have heard of that. I have to ask my Math teacher a few things, but I think it's doable.
|
You can get some basic info at MathWorld: http://mathworld.wolfram.com/Graph.html But if you aren't familiar with graphs at all, you may be for a hard time. Either you implement your own algorithm (like the one you originally suggested) which will work on one maps, but not on others (and ti will keep you puzzled why it didn't work on a particular map). Or you have to go through some learning to find existing algorithm you could use. Your problem is more of a mathematical problem than a programming one. There isn't much to program there if you've figured out the right algorithm. But you can be proud of finding yet another interesting Dominions-related problem  Good luck!
|

April 1st, 2005, 01:35 PM
|
First Lieutenant
|
|
Join Date: Dec 2003
Location: Calgary, Canada
Posts: 762
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: Reading maps from .map files
Quote:
Arralen said:
Alexti, I think you're missing the point. Someone who is an experienced programmer, maybe software engineer or with an degree in computer science or something, will have little trouble understanding what those libraries do, and how to use them.
Then think of a novice:
|
He isn't exactly a novice. Didn't he wrote some tools for Dom2? Anyway, if the primary idea is to learn some basics of the language and not to solve the problem of finding the "areas", it doesn't matter which algorithm to use.
Quote:
Arralen said:
The concept of OO-programming (C++, Java) is new to him,
|
I think that concept of OO-programming can be new only to old-school programmers  Meaning that C++ (and Java, to some extent) concepts match modelling languages almost exactly, so the step of converting the model into procedures is effectively removed.
Quote:
Arralen said:
And we're talking about a real thin sheet of paper: 100-300 provinces (nodes) at best, with less than 750 interconnects.
A short script will really do.
|
I wouldn't be so optimistic. For example, check http://domino.research.ibm.com/Comm/...arch2005.html. Just 6x6x6 cube with 2 possible values in a cell and its way beyond the computing power of modern computers.
Getting back to our particular task, the simple algorithm that would check for chokepoints would apparently have to verify if the graph is connected for each single and pair of nodes, which for province with N=200 nodes gives you about O(N^2)=40000 verifications for graph connectivity. And checking graph connectivity is not particularly fast operation. It may or may not be a problem, it's kind of estimation, where you can't say for sure without actual test. So to avoid frustration of discovering that your nicely written program can't handle large maps in reasonable time it may be better to look up for more efficient solutions from the start.
Of course, all this doesn't matter if the primary goal is to learn programming.
|

April 1st, 2005, 02:28 PM
|
First Lieutenant
|
|
Join Date: Mar 2004
Location: Seattle
Posts: 771
Thanks: 0
Thanked 3 Times in 2 Posts
|
|
Re: Reading maps from .map files
Actually I would figure that validating whether a graph is connected or not would be an O(n) operation since you simply walk the graph from any randomly selected node and if the number of nodes in the walk is equal to the number of nodes in the graph then it is connected.
So the whole operation you described would be O(n^3).
|
Thread Tools |
|
Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
|
|