Reactor Breeder - A Genetic Algorithm for Reactor Design

    Joined
    Jun 20, 2013
    Messages
    9
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    Greetings,

    As many of us know, there are several subtle nuances that go into reactor design. It can be very taxing to scale reactor output with reactor dimensions. What's worse, one minor change results in a significant reduction in power production, making the debugging process a bit of a nightmare.

    Fortunately, the world of biology has a solution for this. By using a process called a genetic algorithm and by entertaining the notion that reactors might be able to mate and have offspring, one is able to "breed" a population of reactors which approach optimal power output with each successive generation. This program essentially refines initially random reactor designs to meet some fitness function (by default, power generation), filtering out poorly performing reactors and preferring those with the highest yield.

    If this sounds awesome to you, here's something even better: the program is both Free as in Beer and Free as in Freedom. The project, source code and all, can be found here: https://sourceforge.net/projects/reactorbreeder/. The more StarMade players can benefit from this, the better; the hope is that some day, you might get involved in improving this program, too!

    Usage/Requirements:

    This program requires Java JRE 1.7 to run. This should be no problem if you are running StarMade; you probably already have the prerequisites covered. Simply download the JAR (), or, if you do not trust the binary on SourceForge, review the source code and compile. There are two versions available:



    To begin using Reactor Breeder, you need to first create a population. Do so by using the File > Create... command. You will be presented with a dialog that allows you to enter your reactor dimensions and population size. Block dimensions can theoretically be up to some 2 billion cubed; however, more practically, this is limited by the amount of memory you have (for instance, a 100x100x100 reactor requires 1000 times more memory than a 10x10x10 one). You can also set the population size, which is the number reactors pitted against each at any given time. Once you are satisfied, click the "Create Button" and you can start the experiment.

    The parameters (by default) are probably good enough to get started. However, if you want to play around with the options, these are the parameters:


    • Mutation Rate - The number of changes to a child reactor outside of the consequences of mating.
    • Crossover Rate - The relative genetic contribution of the "donor" parent to the child. The initial population of reactors is brought by the stork; however, after that, each new child has a "ma" and "pa" reactor. The child's initial genome is copied over from a random selection of either ma or pa. The child then randomly inherits configuration from the parent that was not selected for this (the donor) at the specified rate. Note that a reactor can mate with itself.
    • Unfit rate - The number of reactors that will be weeded out by virtue of not being fit enough. These are systematically executed so that the fit reactors can mate and produce new offspring.
    • Victim rate - The number of the remaining reactors (after removing unfit reactors) that will be removed due to unfortunate circumstances unrelated to fitness. In most cases, it's best to leave this at 0.
    • Fitness function - The criterion for selecting fit reactors. Reactor Breeder will attempt to push this score as high as possible. By default, it is power generation.
    • Epochs - The number of generations to run the simulation for. Each successive generation attempts to refine the population of the previous one, so a high value for this results in better reactors; however, if you are content with a suboptimal but "good" reactor, the default should be fine; after all, you might be trying to crank this out while you're playing Star-made.

    Once you are ready, hit the "Start simulation" button to begin the vicious cycle of life. When the simulation is running, you can "cancel" the simulation at any point without losing your current progress. Regardless of how the simulation has ended, you can always restart the simulation without worrying about losing your progress; it will simply pick up where it left off.

    Finally, you can view your reactors with the "Visualization". The reactors are ranked by fitness, such that the best reactor in the population. A depiction of that reactor's layout will appear on the screen. The grid that has been displayed is an X,Y slice of the reactor; the slider to its right controls the Z coordinate of the slice.

    Please keep in mind that this is pre-alpha software that has been released to the public at no cost. Bugs are bound to happen. However, with that having been said, your feedback is greatly appreciated. Of particular need is power output statistics on any reactor configuration, include explicitly designed ones.

    Regards,

    -- ThyLordRoot, a player on wazuclan.to.us

    Notes:


     
    Joined
    Jun 20, 2013
    Messages
    9
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    And this, good gentlemen and ladies, is why science is freaking awesome.


    That this was the first response makes it absolutely worth it for me to work on something like this. Nature (and biology in particular) is an astounding process; it can be so efficient that this sort of approach is sometimes used in engineering problems now, where the factors that affect a design are so great that it is difficult to create an optimal design. This problem just happened to lend itself to the GA solution, and I am pleasantly surprised with the results so far.




    There any examples of the output from this?



    I have run a few simulations on this. The first to mention is the 3x3x3 reactor, which is quickly solved for by Reactor Breeder because of it\'s small search space of 27 possible reactors. For the purposes of this discussion, and N-cluster will refer to an NxNxN reactor which minimizes block dimension to block count ratio. A N-Lshape refers to a reactor such that is in the shape of an L no matter what perspective you look at (i.e., half of such a cube\'s perimiter). ReactorBreeder quickly converges on the following design:


    • X - X
      - X -
      X - X
    • - X -
      X X X
      - X -
    • X - X
      - X -
      X - X

    This configuration yields 2051.6 e/s. Compare this to two 3-Lshapes with a cube in the center, which yields 1990.6 e/s. Thus, the counterintuitive conclusion here is that it is possible to have one reactor with a single max-dimension cluster outperform one with two. This is probably no big surprise: The 8 1-clusters yield 139.8 e/s each, so it is more efficient to use them than two 3-Lshapes.

    But you probably already learned that from experimentation, so let\'s talk about a reactor for which the search space is bigger, which is 5x5x5. This design was found in about 25000 epochs and yields 9149.8 e/s:


    • X X X X X
      - X - - X
      X - X - X
      - X - X X
      X - X - X
    • - - - X -
      X - X - X
      - X X X -
      X - X - X
      X X - X X
    • X - X - X
      - X - X -
      X - X - X
      X - - X -
      - - X - X
    • - X - X -
      X - X - X
      X - X - X
      - X - - -
      X - - X X
    • X - X - X
      X - X X X
      - X - X -
      X - X X -
      - X X - X

    Is this the most optimal reactor design for 5x5x5? I\'m heding my bets on no, but I\'m uncertain of this fact because people have claimed in excess of 10K power generation, but have not shared their reactor designs so it\'s can\'t be verified independently on that front. However, the search space for 5x5x5 reactors is still small (5x5x5 = 125), so this is possible to verify through brute force; I just haven\'t done so yet.

    The thing to remember about genetic algorithms (and evolution in general) is that the output strongly depends on the population, so some tweaking of the above parameters may cause your mileage to vary. However, it is also worth noting that the search space scales cubically when you increase the dimensions: There are 343 possible reactor configurations for 7x7x7, and 729 for 9x9x9. If you want to build a 21x21x21 reactor, you now have 9261 possible reactors to consider; and for 31x31x31, it grows to 29791. So the question becomes one of scale. The nice thing about this algorithm is that it converges to a good solution quickly. In the future, though, I made add support for brute force search.

    At any rate, what I think the GA is doing is looking for spots where it can determine that plugging gaps with reactors leads to more efficient power generation. In the above design, we see something that might be considered \"sloppy\" by most people, but which does yield more power (as each additional power generator that does not contribute to block dimension adds 25 e/s).

    This is where having the additional data comes in. The current formula for power generation (AFAIK) is unknown, so I had to do regression for it by hand. I had some 31 samples I used; obviously, more samples would probably yield a better regression in this case. I hope this helps!
     
    Joined
    Jun 19, 2013
    Messages
    2
    Reaction score
    0
    On attempt to run the program I get the error: Could not find the main class: com.wheelfun.reactorbreeder.Driver. Program will exit.

    However, I think making a genetic algorithm for reactor breeding is a brilliant idea! I\'ve played waaay too much Boxcar2D to try and breed a car perfect for Sisyphus. It makes me happy that it won\'t have to be me doing the trial-and-error next time I want a 10*10 reactor to get max regen from it.
     
    Joined
    Jun 20, 2013
    Messages
    9
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    On attempt to run the program I get the error: Could not find the main class: com.wheelfun.reactorbreeder.Driver. Program will exit.


    Weird; I downloaded the binary I uploaded to Sourceforge and it works normally for me; the jar also seems to contain the file that it says it is missing. Is anyobdy else having this issue?

    I\'d like to resolve this issue so that you can start using it for your projects, so I am going to request a small amount of information:


    • What operating system are you using? Java shouldn\'t care, but it might be important.
    • Can you paste the output of \"java -version\" for me? I have only tested it with Sun \'s 1.7 JRE. OpenJDK 1.7 should work; not sure about other versions of Java.
    • How did you run the file? Did you double click on it, or did you use the command line?

    If you will get back to me, I will do what I can to update this so that you can run the program. Thanks in advance!
     
    Joined
    Jun 29, 2013
    Messages
    9
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    It only took me 2 days to learn the optimal, scalable reactor configuration. I have no need for this. But i have to say \"Damn\", i totally applaud this and props to all involved!
     
    Joined
    Jun 29, 2013
    Messages
    9
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    It only took me 2 days to learn the optimal, scalable reactor configuration. I have no need for this. But i have to say \"Damn\", i totally applaud this and props to all involved!
     
    Joined
    Jun 20, 2013
    Messages
    9
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    Greetings,

    Here is another reactor design for 5x5x5 that I evolved in 10000 epochs. What\'s bizarre about it? Well, it consists of only 1, 2, and 3-Clusters, yet outperforms the previous 5x5x5 reactor with a score of 9294.6 e/s! Here\'s the layout:

    • X X - X X
      X - X - X
      - X - X -
      X - X - X
      X X - X X
    • X - X - X
      - X X X -
      X - X - X
      - X - X -
      X - X - X
    • - X - X -
      X - X - X
      - X - X -
      X X X - X
      - X - X -
    • X - X - X
      - X - X -
      X - X X X
      - X - X -
      X - X - X
    • - X - X X
      X - X - X
      - X - X -
      X - X - X
      - X - X X

    That\'s something, isn\'t it? Conventional wisdom tells us that we should maximize block dimension, but as it turns out, that is apparently not always appropriate. This is using the 0.0.1 build I uploaded last night, by the way; more to come when I improve the regression with Lix\'s data.
     

    Winterhome

    Way gayer than originally thought.
    Joined
    Jun 29, 2013
    Messages
    1,929
    Reaction score
    636
    Maximum block dimensions for the furthest out layers, perhaps, but not necessarily in the same branch pattern we always use.

    As we get further in, we use smaller and smaller boxes to handle the space.
     
    Joined
    Jul 2, 2013
    Messages
    17
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    This design is from milkman25 in a reply post on this forum page http://star-made.org/content/most-efficient-power-reactor-pattern It shows a 5x5x5 design that generates about 9724.7 e/sec, most efficient 5x5x5 I have seen.
     
    Joined
    Jun 22, 2013
    Messages
    52
    Reaction score
    0
    It would be nice to have some sort of readout on the estimated value of the desired function from the fittest design displayed in the simulation window. Other than that, this a great tool.
     
    Joined
    May 25, 2013
    Messages
    228
    Reaction score
    16
    It doesn\'t make for easy to build reactors due to the large number of single power blocks , however.

    I hope it\'s possible to combine fitness criteria into gradients , to obtain a good compromise between energy output , block and cluster numbers for a given volume.

    Being able to tag reactor spaces as empty/unusable or mandatory power cores would also come in handy , especially to optimize space usage between longer power lines.
     
    Joined
    Jul 1, 2013
    Messages
    10
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    Loving the work you\'re doing on this, ThyLordRoot! I\'ve been spending quite a bit of time trying to work out all the power algorithms and designing optimal setups, especially optimizing the 5x5x5 cube. Glad we can all put out heads together to try to solve this thing. I have a few things to add, questions, and clarifications.

    1. The most regen from a 5x5x5 cube that I know of at the moment is 9927.5 e/sec. I detailed the blueprint for this design in this topic: http://star-made.org/comment/15378#comment-15378

    2. Regarding the 5x5x5 cube, you stated:


    However, the search space for 5x5x5 reactors is still small (5x5x5 = 125), so this is possible to verify through brute force; I just haven\'t done so yet.


    Am I misunderstanding what you are refering to here when you are talking about brute force solving the 5x5x5 cube problem? It sounded like you were saying there were only 125 possible combinations so you could go through and check each one. But 125 only is the number of power blocks in the cube. The number I came up with for possible reactor designs was a bit more daunting.

    total reactor design possibilities = sum(125 choose n,n,1,125) with n being the number of power blocks used in the cube

    When run through WolframAlpha (as my calculator isn\'t around) gives me 4.25*10^37 possibilities!

    Granted, this includes many designs that are objectively identical (e.g. 125 of those are just a single block in the 5x5x5 space in any of the 125 different positions). While many of these options at lower numbers of n blocks are redundant, due to the grouping nature of the bonus power regen, I don\'t think these different positional choices can be discounted for larger values of n.

    Anyways, someone please tell me if I\'m thinking about this wrong in some way, because as of now, as far as I can tell, there is simply no possible way to brute force design the optimal reactor for even a cube as small as 5x5x5.

    3. I had a formula for accurately modeling the power regen of a group of power blocks that was accurate up to at least total box dimensions totally 1000. I did forget one small factor though, so when I get a chance tonight I\'m going to try to fix my equations, as I think I might need a small tweak to the constants. If it seems to be working, I\'ll post it or at least send you the formula, if you want to see it.

    Sorry for the wall of text, I\'ll stop now. I just wanted to say that I\'ve been struggling a lot trying to brute force solve the power design problem, and I really love the different approach you\'ve taken here. Keep up the fantastic work!
     
    Joined
    Jun 22, 2013
    Messages
    53
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    Best app ever.

    Can\'t wait for saving and loading of reactor gens so I can really get serious with producing some reactors for Dervish :D

    Great job, Root ;)

    ~TheSol
     
    Joined
    Jun 20, 2013
    Messages
    9
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    I have to go to work pretty soon, but I thought that I might post a couple of replies before I left. I\'d definitely like to thank everybody for all of their positive feedback and constructive criticism. First, mrwhite:


    It would be nice to have some sort of readout on the estimated value of the desired function from the fittest design displayed in the simulation window. Other than that, this a great tool.


    I am considering the best way to do this. I might make this a tooltip in the graph display, as available space is somewhat constrained in that context. Testing does provide direct readouts for things such as block dimension and power regeneration, however, and this will be incorporated into the next version.

    Next, Stakhanov:


    It doesn\'t make for easy to build reactors due to the large number of single power blocks , however.


    That is probably because the default fitness function takes block count into account only insomuch that it becomes a factor for the linear +25 contribution of each generator block. I might add a Power Regen : Block Count ratio function for this, although it may not work the way we want it to. Alternately,. the Box Dimension function should do something similar to this IIRC: it takes the ratio of the sum of the block dimensions to power blocks.


    I hope it\'s possible to combine fitness criteria into gradients , to obtain a good compromise between energy output , block and cluster numbers for a given volume.


    These are good ideas and are something I will take into account in future development.

    Next, shadowman615:


    1. The most regen from a 5x5x5 cube that I know of at the moment is 9927.5 e/sec. I detailed the blueprint for this design in this topic: http://star-made.org/comment/15378#comment-15378


    This is currently the best reactor design I know of as well. After I get saving and loading implemented, I want to try to provide a way to do import so we can possibly see if there is any way of improving this reactor; it may in fact be optimal.


    Am I misunderstanding what you are refering to here when you are talking about brute force solving the 5x5x5 cube problem? It sounded like you were saying there were only 125 possible combinations so you could go through and check each one. But 125 only is the number of power blocks in the cube. The number I came up with for possible reactor designs was a bit more daunting.

    total reactor design possibilities = sum(125 choose n,n,1,125) with n being the number of power blocks used in the cube

    When run through WolframAlpha (as my calculator isn\'t around) gives me 4.25*10^37 possibilities!


    You\'re absolutely right: 125 yields the number of reactors with a single power block. Your method using combinatorics is the proper way to go, and may make brute force search (that is, exhausing the entire search space to find the optimal reactor) much more difficult.


    3. I had a formula for accurately modeling the power regen of a group of power blocks that was accurate up to at least total box dimensions totally 1000. I did forget one small factor though, so when I get a chance tonight I\'m going to try to fix my equations, as I think I might need a small tweak to the constants. If it seems to be working, I\'ll post it or at least send you the formula, if you want to see it.


    That would be great! My current equation has relative error under 1%, but I\'ve not tried it with box dimension as high as 1000. If you have any additional data points you would like to contribute, or if you have a better formula, I think it could be worked into the program to yield a better prediction.


    Finally, TheSol:

    Can\'t wait for saving and loading of reactor gens so I can really get serious with producing some reactors for Dervish :D


    Saving has been completed although not uploaded to testing yet; loading will be completed soon, at which point I will probably make another major release.
     
    Joined
    Jun 20, 2013
    Messages
    9
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    I thought I would mention there is a new version in the testing branch that will allow you to load and save your populations.
     
    Joined
    Jul 2, 2013
    Messages
    23
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    This program is amazing! It is a great tool, especially when building large ships that need a means of efficient power generation. I know nothing about code, but i am suggesting to make the visual representation of the reactor evolutions easier to comprehend, it should go something like this:


    Instead of having It be represented as each increment on the scroll is a layer, it should be different pages. So have it be like this: (X = Power block)

    x x - x x

    x x x - x

    x x x - x

    x x x x x

    x x x x x


    Click the next arrow and it displays the next layer, from the bottom up. There should also be a note saying \"Top viewpoint\" To let you know what your perspective on the layer is.

    I hope this was good feedback! i cant wait to see this program near its peak!
    (I hope you liked my attempt at flawless prose cx)
     
    Joined
    Jul 28, 2013
    Messages
    1
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    This program is really useful for people who are build reactors for massive ship, but the problem is how do i use this program i mean i\'m still figuring out how the the view look like even after 3 days of googling but don\'t a guide on it, would kind soul care to guide me?



    You start the program then go to create theres a population size what is that?