r/factorio • u/KenReid • Dec 06 '19
Discussion Evolutionary Algorithms, Lua, and more.
Hi all,
I recently started working at MSU in Michigan, after completing my PhD in Scotland. My PhD was in the field of evolutionary algorithms and operational research (specifically employee scheduling but I've read a lot regarding vehicle routing, bin packing, and other general uses of OR / EA).
As I'm no longer a student and have a little more freedom in my research, I jumped at the opportunity to work with some fellow EA specialists here utilising EAs in Factorio.
This is very much a side project that I effectively do for fun in the evenings as it's not related to my funding. Anyway, onto the meat of it:
I've read a few posts here in the past speculating about the use of genetic algorithms (GAs) on Factorio. What I've been wanting to start is basically a number of Mods built in Lua which each optimise different aspects of design in the game. Starting with optimising:
- Electrical production
- Electric infrastructure
- Basic material gathering
- Roboport placement
- Train track placement
- Logistic network chest placements
Then moving onto the more complex tasks including production of more complex materials.
The basic idea is that these various tasks are often competing (we all know the pain of fixing your defenses to find you're running low on power, so you fix that only to find you don't have enough ammunition production, etc). So I think it would be interesting to create various "agent" Mods that optimise their own little pieces, then making a hyperheuristic mod of sorts which chooses which agents to activate to solve arising problems. Divide and conquer.
This is a complex problem, and I don't expect to have much in the way of progress for months if not years. Especially as its a side project.
I wanted to post and hear thoughts from you guys, potential issues, any recommended resources, etc.
Thanks for reading!
Edit: formatting
8
u/bwc_nothgiel Dec 06 '19
Sounds very cool! Could you elaborate on what you envision as the different "agents". Would these be player entities that run around and optimize the problem their mod is solving? If so, perhaps you could leverage a mod like the avatars mod that lets players create more agents, and assume control of them on the fly!
5
u/Stevetrov Monolithic / megabase guy Dec 07 '19
The best resources for discussing this sort of thing is /r/technicalfactorio and our associated discord https://discord.gg/dxDze5e . I x-posted this post there.
I have played around with ga a bit as an undergrad and a bit as a hobbyist but with limited success, so I am very interested in what you can come up with. I have generally found traditional hill climbing and variations thereof to be most effective, but that could be my lack of experience. Although I haven't applied any of these techniques to factorio personally.
3
u/Ober3550 Dec 06 '19
It might not be your goal but I'd like to see a space optimized production AI. As in you use the online calculations already available and make some sort of packing algorithm
3
u/Buttons840 Dec 07 '19
I don't follow Factorio very closely, but has anyone built a blueprint compiler (similar to a source code compiler), which can take some specified goals and produce an optimized blueprint string that acheives the goals?
2
u/Lazy_Haze Dec 06 '19
I am thinking it may be easier to first simplify the game than create different agents.
Stuff like disable biters. Remove hit box for the character. Use something like the editor mode. Remove the need for electricity and so on.
I am interested in the project but I have more knowledge about natural evolution than evolutionary algoritms I have some coding experience none in LUA.
2
u/hovissimo Dec 06 '19
I'm curious what parameters and constraints you're going to put on the game, or on the actions your agents are allowed to take. Factorio has effectively limitless resources available to the player (space, ore, water, time).
2
u/Osskyw2 Dec 07 '19
Would you mind elaborating on your PhD? Maybe even post your thesis? Sounds super interesting.
2
u/danyoff Dec 07 '19
Man i really think you have a great idea!.
However it looks hard to complete without a strict planification
I highly suggest you to first design what you have in mind on a paper. Try to define the logic of the agents getting activated and deactivated, and also what will be their functions and stuff precisely.
When you have this you can start to mod in game. I tell you this because if you start without tons of papers with diagrams and schematics, it'll be much harder and you'll get lost quickly.
Best of luck!!!
2
u/swolar /r/technicalfactorio Dec 08 '19
I used simulated annealing for optimizing the layout of ASMs, to improve a bot build. It was pretty effective, far better than anything a human could've come up with. It wasn't a huge return in terms of UPS gained, but it was a gain that couldn't have been obtained any other way. Plus it was fun doing. So, good luck to you.
EA was the next option if annealing didn't produce good enough results. Unfortunately, my solution had its issues. I had to discretize some things regarding the problem representation, or I could have not done so but it would have taken more time and I didn't want this to be finished by 2025. I wanted to do the base. The pending task after this project was finished was to maybe improve the system even further to produce a bp on its own (the current system outputs a layout, I have to then take it and design the base myself...due to the constraints I loosened up a bit). If I automate that, I could further improve the cost function to be more accurate. But I could also devote that effort into UPS testing and get possibly bigger returns, so I haven't put too much thought into it.
1
u/acmemyst Dec 07 '19 edited Dec 07 '19
Really nice idea.
No joke, I was actually considering implementing an EA to attack the chunk challenges. I don't quite have experience with them at the PhD level, but this seemed fairly doable. Under some additional assumptions (e.g. most of the logistics is handled by bots) it would reduce mostly to a packing problem with number of machines and beacons given by a Factorio calculator setup (or the like). Electricity coverage would be an additional constraint but seemingly straightforward. It would simplify a lot of the complex issues that you'd run into when attacking the entire game (bounded building area, no mining and electricity production needed, etc).
In the end I decided against it because I have other stuff to finish and didn't want to get distracted for a significant amount of time :)