Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
XyFreak

Big Reactors Grid Control

Recommended Posts

@XyFreak 20x20x8 with control rods every other block with a single block between them and the wall, full of copper blocks from ic2 on the inside. glass on all sides, solid top and bottom, with the computer port, reactor controller, and an in and output. IT is on the extreme reactors mod.

Link to post
Share on other sites

Ok, while I wasn't able to gather the exact reactor design from what you described, I managed to build a somewhat similar reactor that triggers something that I believe is the same issue.

I can't believe I've overlooked that >_>. I dunno how long this is going to take me to fix but i'm working on it.

Link to post
Share on other sites

Okidoki, I fixed it!

Unfortunately, you'll have to redownload the installer to upgrade to 4.1.

I'll post the story tomorrow, I need some rest now. Have this changelog in the mean time:

4.0.1 -> 4.1
 - Fixed a bug where turbines that are being calibrated can be suspended
 - Fixed a design bug where the performance prediction for passive reactors was based on linear regression.
   BRGC now has the ability to do polynomial interpolation.
 - Because the polynomial interpolation is THAT GOOD we can do numerical reactor optimization based on the polynomial.
   OPTIMIZATION-mode has been removed. This also fixes all issues of the OPTIMIZATION-mode (obviously).

 

-XyFreak

Link to post
Share on other sites
2 hours ago, BatouOfNexus said:

This fixed the problem I was having with a 3x3x3 and a 21x21x21 (including casing) not finishing optimization. You fixed it before I could post about it!

This later crashed on line 174 of libGUI with a nil paramater when a string was expected.  The post with the exact details got eaten as apparently you can't copy text out of the edit box to the clipboard...

Link to post
Share on other sites

WARNING! This post is long and contains math! Continue at your own risk!
There's also a TL;DR!

Once upon a time, XyFreak tried to came up with ideas how to predict the energy/steam output of a Big Reactor.
His test reactor was a small 7x7x2 reactor.
He played around with some settings and thought "cool! If I pull out the rods by 10, the output goes up by roughly 10%. There HAS to be a linear correlation!". Not knowing what he's doing, he just went on and wrote some code for his Big Reactors Grid Control program.
In his attempts to make BRGC work out of the box, he came up with a way to figure out the sweet spot of passive reactors. He knew that with really unbalanced reactors the algorithm may have some issues but...who uses unbalanced reactors anyways, right?
His ideas seemed to work perfectly. He and his friends used his program with many different actively cooled generators and everything worked as intended.
Time passed, Minecraft 1.7.10 was nearing the end of its lifespan. Minecraft 1.10.2 emerged!
Suddenly, "Gelid Cryotheum" was gone! Reactors have become a lot less balanced and many people emerged that found actively cooled reactors to be a hassle.
But there was a problem: For some reason, less balanced reactors didn't quite work as intended.
"Yeah right... I'm an idiot.", XyFreak thought. His past lazyness came to bite him in the a**. He opened up his Visual Studio Code (Use it! It's great!) and started reworking his algorithm. But something was not right. For some reason, all his attempts to improve the algorithm failed! Either the controller undershoots the power target or overshoots it by... a lot.
He looked at the calibration data of his (now bigger) test reactor and saw a value twice as large as it should've been (again, http://br.sidoh.org is your friend).
And this is where the tale of advanced mathematics begins for real.

And this is also where I stop writing in story telling mode :P

So, I told you above that I assumed the reactors output (be it energy or steam) to be linear in regards to the rod level.
Well... for actively cooled reactors this is true (or at least a near perfect approximation). And since I mostly used actively cooled reactors (both in my real playthroughs and my test worlds) everything worked fine.
And since my passive test reactor was so small and well balanced, it worked there as well.
Now.... look at this image here:

samples.png

This graph shows the energy output plotted against the (inverse) rod level. Doesn't look linear, does it? It's not linear at all!
I assumed the energy production to be linear, but the fuel consumption would go up dramaticaly as heat increases. Turns out it is the other way around! (Stupid me!)
Fuel consumption is linear with rod level but energy production decreases greatly as heat increases.

So... if it's not linear, what is it? Well... a polynomial 3rd degree seems to fit extremely well.
samples_polynomial.png

But how do you get such a polynomial? "Heh! Easy! We did this at high school!" you may think and that's what I thought as well.
<MATH WARNING!>
If you have N samples for x and f(x) you can easily create a polynomial of degree N-1. There're a couple of different methods to do it.
Now.. I don't have 4 samples, I have 17! "Easy! Just leave out some!". Yeah right....
I tried that and all polynomials sucked. Also, the polynomial libreoffice calculated seemed to fit perfectly. I wanna do that too!

After a while it struck me: It's a linear optimization problem (Of course it is! But it's been a while since I last worked with those, sorry.)
So...how to solve it?... ... ... QR decomposition...
Great! Now I'll have to do linear algebra in lua.

I always wanted to avoid using advanced math in brgc and now I have to work with matrices... great!

So...what do I need first? Right... matrices in lua. So I wrote a small library to work with matrices and the operations (and only those) I'm going to need to get QR decomposition working.
Next up? QR decomposition! But how does it work again? It's been a while since I last did something with that (at least 4 years).
Fortunately, Google is your friend (I'll append the links to the end of this post in case you're interested).
After 4 hours of implementation and debugging, everything worked. Well that was easy...not.

Next up: We're going to have to work with polynomials. So we need a library for that as well, right? 10 Minutes later: done.
I fed everything with my sample reactor values aaaaand....perfect!

Now...we got a nice way to interpolate functions. Maybe we can use it for the optimization as well?
Let's see...

Let the reactors efficiency denoted by E(p) = O(p) / C(p)
Where p is the percentage of the inverted rod insertion level, O(p) is a function that gives us the energy generation for rod level p and C(p) gives us the fuel _c_onsumption for rod level p.
O(p) is a polynomial of degree 3 and C(p) is of form C(p) = a * p. So we just devide two polynomials, right? How bad can it be.
I'll spare you the details, it's not worth it. The result is NOT a polynomial (well duh!).

BUT! Turns out we can use polynomial interpolation if we feed the interpolator the rod level and the efficiency values as samples (we already got those from the calibration).
Now we have a polynomial that describes the reactors efficiency!

efficiency.png
(We want to figure out the peak of that little mountaint)

For optimization purposes we're interested in the local maxima of that polynomial between 0 and 1 (0 = reactor off, 1 = reactor max). Thankfully, this is easy!
Thanks to the QR decomposition, the numerical calulus lecture was still on my mind and we did that stuff as well.
And when I'm saying "easy" I mean it. Take this code:

function polynomial.converge(polynomial, x, iterations)
	local df1 = polynomial:derivate()
	local df2 = df1:derivate()

	local dx = 0 - df1:eval(x) / df2:eval(x)
	for i=1, iterations do
		x = x - df1:eval(x) / df2:eval(x)
	end
	return x
end

That's the code. Here's some background, if you like: https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization

DONE! Does everything work? Hell yes it does! This time I tested it with multiple designs and on 1.7.10 and 1.10.2.


TL;DR

XyFreak assumed stuff about reactors that's complete bullshit. It never came to light because his testing sucked.
Magic (math) happened. Stuff now works perfectly fine. Optimization-mode is gone. Everything is awesome.

Also:
I'd like to mention that I've now officially used more university knowledge to develop Big Reactors Grid Control than I've ever used in my day job.
So kids...keep this in mind: Pay attention in school! You may not need it in real life. But you may need it in Minecraft someday!

If you read everything, thanks for staying with me :)

-XyFreak


QR decomposition links (german)
http://www.math.uni-frankfurt.de/~numerik/lehre/Seminare/ProSem_MA_SS11/qrzerlegung.pdf
http://numerik.uni-hd.de/~lehre/SS12/numerik0/12-la-5.pdf
http://www.mathematik.uni-muenchen.de/~lerdos/SS08/Num/trans4.pdf

Link to post
Share on other sites

Haha yeah. But this is a game and I've been told I put way too much effort in this already :P

I mean..comeon...who does that kinda stuff "just for minecraft", right? ;)

 

EDIT:

I wrote an entire gui library for this program as well. And there's some secure networking stuff I've been working on but never got around to finish.

Link to post
Share on other sites

That's a valid point but from personal experience, once should not mention "minecraft" on your resume. Just putting up "has expierience in programming language x with y, z" works better :P

But yeah, it's fun. However the fun ends if critical bug reports come in. I released this code to everyone so I feel obligated to fix code-breaking bugs ASAP.

This was one of these where I essentially stopped doing everything else and focused on fixing this problem.

It was worth it though ;) (Getting everything back running again is incredible rewarding)

Link to post
Share on other sites

edit: looks like I needed all tier3, downloaded ok now.

 

Hi, would love to test out this reactor code, but I'm having a little issue... not sure if its my side or server side... I've tried new disks, upgraded the computer, (was using all tier1)... (are there any prereqs? a df shows there is plenty of space..).

failed_to_download.png

Link to post
Share on other sites
On 1/30/2017 at 4:27 AM, Magik6k said:

You can use braille Unicode characters to give the bars more resolution as with OC font they are exactly 1/4 vert and 1/2 horiz of a full character block(the characters are "⣀", "⣤", "⣶", "⣿", "⡇")

It's better to use block symbols:

▁▂▃▄▅▆▇█
▏
▎
▍
▌
▋
▊
▉
█

http://www.unicode.org/charts/PDF/U2580.pdf

Link to post
Share on other sites

Hi guys,

regarding the unicode fonts - i might do that.

The bigger battery thing has been in planning phase since the start of this year but I wasn't able to find the time to actually do it. It's going to be done at some point. I just don't know when. Sorry.

 

@sedstr you need all tier 3 ram? holy i think i need to work on that then... >_>

 

-XyFreak

Link to post
Share on other sites

Okidoki.

Status update:

I just implemented drawing the ends of the bar widgets with block symbols and I REALLY REALLY like it. Look forward to the next release ;)

Regarding the whole external energy storage, here's the plan:

Not having any energy storage blocks connected to the computer is having the controller run like it does right now (makes sense, huh?)

Having energy storage blocks connected is going to change everything:

  • If your total energy consumption can be satisfied by having all reactors run at optimal levels, your reactors will be in PWM mode. HOWEVER the controller will only use as many reactors as neccessary to keep your storage from draining. The reactors which are going to be onlined/offlined are decided by each of the reactors fuel efficiency. I'm going to implement a simple greedy algorithm here that tries to balance out things (having your really small but efficient reactor running all the time and your really big but slightly less efficient reactor turn on and off is not neccessarily what you want, right?).
  • If your total energy consumption can no longer be satisfied by having all reactors run at optimal levels, some (up to all) of your reactors are being switched to LOAD mode. I've not yet decided on how to switch them iteratively but efficiency is key here so I've gotta come up with something. Suggestion appreciated.
  • If you have turbines, those will be used as really efficient reactors (because they essentially are) and thus will have highest priority. I'm propably getting rid of LOAD mode for turbines here and just have them run like PWM reactors (that's more efficient anyways if you have a larger energy storage).

Since it might be possible that not all of your connected components are connected to the same energy storage, you're going to be able to set passive reactors to "independent" mode like you can do with turbines right now.

Initially I also wanted to implement multiple grids but configuring those is going to be too hard (remember this thing is supposed to be Plug&Play) so... that's not going to happen ;)

 

-XyFreak

Link to post
Share on other sites

First of all, Hello OC Community.

 

I'm am an absolutely noob in Lua, i install your program and its work well. The best is it looks cool and i like it. Great work!

But the reason of my post is, i get some problems / crashes. If the program Control my Reactor and Turbines  first its run without any issues. Than the reactor switch from calibrate to (Run Mode)  90% chance to crash my Server.

it is not all the time but ... 90 %  :-)  

 

attach my crash report maybe someone can help me.

 

- Marc

crash-2017-02-05_16.02.47-server.txt

Link to post
Share on other sites

Hi @MaSch

An OpenComputers program should never be able to crash your server.

Lets do a quick breakdown.

Here's your stacktrace:

Description: Exception in server tick loop

java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextNode(Unknown Source)
	at java.util.HashMap$KeyIterator.next(Unknown Source)
	at java.util.AbstractCollection.toArray(Unknown Source)
	at com.google.common.collect.ImmutableSet.copyOf(ImmutableSet.java:374)
	at elec332.core.grid.internal.GridEventInputHandler.tickEnd(GridEventInputHandler.java:91)
	at elec332.core.grid.internal.GridEventHandler.serverTick(GridEventHandler.java:49)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_304_GridEventHandler_serverTick_ServerTickEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185)
	at net.minecraftforge.fml.common.FMLCommonHandler.onPostServerTick(FMLCommonHandler.java:261)
	at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:657)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:471)
	at java.lang.Thread.run(Unknown Source)

You can see there're two lines that don't look like they're not vanilla minecraft or forge related:

	at elec332.core.grid.internal.GridEventInputHandler.tickEnd(GridEventInputHandler.java:91)
	at elec332.core.grid.internal.GridEventHandler.serverTick(GridEventHandler.java:49)

A quick google reveals that the mod those methods belong to is (suprise suprise) eleccore.

I suggest you go to the github issue tracker and report your findings because this looks pretty much like the exact same thing that's happening to you.

 

Next up... what is eleccore used for and can we temporarily remove it? Well it looks like eleccore is used by Deep Resonance and that mod has worldgen. So removing it is a no-no. Duh....

So...what can we do?

Since we know that Deep Resonance is using eleccore, you can try to remove all your Deep Resonance machines and see if you're still able to reproduce the isse. Is it gone? Well... this means that you're no longer able to use DeepResonance without crashing your server... but at least you're no longer crashing the server so that's a start. Additionally go and look for the Deep Resonance issue tracker as well and tell them that using that there're some serious issues with the library they're using.

 

I hope this somehow helps you. Unfortunately there's nothing more I can do. Those are the joys of modded Minecraft ;)

 

-XyFreak

Link to post
Share on other sites
20 hours ago, XyFreak said:

Hi @MaSch

An OpenComputers program should never be able to crash your server.

Lets do a quick breakdown.

Here's your stacktrace:


Description: Exception in server tick loop

java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextNode(Unknown Source)
	at java.util.HashMap$KeyIterator.next(Unknown Source)
	at java.util.AbstractCollection.toArray(Unknown Source)
	at com.google.common.collect.ImmutableSet.copyOf(ImmutableSet.java:374)
	at elec332.core.grid.internal.GridEventInputHandler.tickEnd(GridEventInputHandler.java:91)
	at elec332.core.grid.internal.GridEventHandler.serverTick(GridEventHandler.java:49)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_304_GridEventHandler_serverTick_ServerTickEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185)
	at net.minecraftforge.fml.common.FMLCommonHandler.onPostServerTick(FMLCommonHandler.java:261)
	at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:657)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:471)
	at java.lang.Thread.run(Unknown Source)

You can see there're two lines that don't look like they're not vanilla minecraft or forge related:


	at elec332.core.grid.internal.GridEventInputHandler.tickEnd(GridEventInputHandler.java:91)
	at elec332.core.grid.internal.GridEventHandler.serverTick(GridEventHandler.java:49)

A quick google reveals that the mod those methods belong to is (suprise suprise) eleccore.

I suggest you go to the github issue tracker and report your findings because this looks pretty much like the exact same thing that's happening to you.

 

Next up... what is eleccore used for and can we temporarily remove it? Well it looks like eleccore is used by Deep Resonance and that mod has worldgen. So removing it is a no-no. Duh....

So...what can we do?

Since we know that Deep Resonance is using eleccore, you can try to remove all your Deep Resonance machines and see if you're still able to reproduce the isse. Is it gone? Well... this means that you're no longer able to use DeepResonance without crashing your server... but at least you're no longer crashing the server so that's a start. Additionally go and look for the Deep Resonance issue tracker as well and tell them that using that there're some serious issues with the library they're using.

 

I hope this somehow helps you. Unfortunately there's nothing more I can do. Those are the joys of modded Minecraft ;)

 

-XyFreak

 

Thanks for your answer XyFreak 

 

i have remove all DeepResonance Machines and try my luck ;-)

So let's wait , but normal it was between five min and one Hour ... i report if it's work or not. 

Thank you.

 

//Edit 

i think im unlucky the server is crashed again.

it is only if the Computer is running the Reactor Control Program.

it is Also weird i run "brgc_gui" nothing is showing. It starts only if i run "brgcctrl service all stop" than "brgcctrl service all start" and "brgc_gui" 

i attach the crash report again but i think it's the same like before :-( 

 

ss (2017-02-05 at 07.52.21).jpg

crash-2017-02-05_20.11.00-server.txt

//Edit2 

So i disable deep resonant and it is the same problem like befor maybe it is longer until the server crash.... 

i don't know anymore ... maybe 1.10.2 is to bug'y  at the moment.

Link to post
Share on other sites

Ok first of all I'm jelly at your 230fps in minecraft (and a texture pack). Just letting you know :P

Next I'm really really confused about this whole thing not starting up. How did you set up your computer (aka what components are in there) and are you using a modpack? If I'd have to guess it's the direwolf20 one but...just making sure.

 

-XyFreak

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.