Another try of implementing Power Loss

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

Post Reply
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Another try of implementing Power Loss

Post by ssilk »

EDIT:
If you are not familiar with this idea, please read that article before this one
viewtopic.php?f=80&t=15546 Cable Resistance / Non-looseless Power Transmission


I thought a bit and have found this solution:

1. We need to split the power (Watts) between Voltage and Ampere. A first simple step would be to have a standard Voltage of 1000 Volts. So the produced Amperes you need to generate is just the current power divided with 1000.

2. The calculation of the total power usage now depends on the needed power of each entity divided by Voltage level at the entities place. ... Or something like that. The principle is, that the total power depends on total voltage levels: The higher it is, the lower the needed power. You see: You don't need to go into the details it's enough to calculate an average power level for each device type. This is important for performance!

3. In the ideal case, that there is no power used, the network will have everywhere 1000 Volts. This is also the level the network tries to "fall back" to.

4. We need to calculate Voltage-Levels in the network. This is done by sending "random packets" through the network, like a token.

The algorithm to generate this regeneration will look like so:

a) Randomly choose one pair of a generator and a consumer by chance, depending on it's level of production/consumption. In other words: An inserter or solar panel has a much lesser chance to be picked than a turbine or laser tower (while fireing).

b) calculate the "shortest" path from producer to consumer. This path calculation will take into amount the existing voltage levels of former calculations: If a path has a lower voltage a path around this is eventually "shorter".

c) calculate the amount of amperes (the siye of the package) needed to supply the destination depending on voltage levels between source and destination. This takes into account the amount of already calculated Voltage decrease from previous calculations.

d) Each cable (and/or pole) on the way from consumer to producer will reduce the Voltage on the network a bit, depending on the package size.

For example: If a package size is 10 Amperes, the voltage level of the wires this package needs to be going through is decreased by 10 Volts.

5. Now go through the whole electric network and increase the voltage logarithmic in very small steps back to 1000 Volts.

6. The power consumption is not dependent on this calculations. It will take some while to "weight out" a network, until it doesn't change anymore. This inertia can be explained with "cable temperature". :)

That's it.


Example:

Step 0
In step 0 the network will look like so:

Code: Select all

[Generator - 1000 MW]   ---- 1000 V ---- [Consumer A - 10 MW] --- 1000 V ---  [Consumer B - 500 MW]
                        \                                                  /
                         \-------------------- 1000 V --------------------/
One producer, 2 consumers which are connected in a circle. Each wire has initially 1000 Volts

Step 1
Calculating the chances for a pair of the radom package:
Generator -> Consumer A: 1000 + 10 = 1010
Generator -> Consumer B: 1000 + 500 = 1500

Average:
1010 + 1500 = 2510; Average is 2510 / 2 = 1255

Chance of pairs:
A) Generator -> A: 1010/1255 = 0.8
B) Generator -> B: 1500/1255 = 1.2

Randomly picking path A.

Calculating path:
Generator -> A: 1000
Generator -> B -> A: 2000 / 2 (two cables) = 1000
(just adding voltages as path-length and divide through number of cables it runs through)
In this case both path are equal so it takes the first (G->A).

Calculating of package size: 10 MW / 1000 V = 10000 Ampere
Let"s say 1000 Ampere reduce voltage by 1, then the network will look in this next step like so:

Code: Select all

[Generator - 1000 MW]   ----  990 V ---- [Consumer A - 10 MW] --- 1000 V ---  [Consumer B - 500 MW]
                        \                                                  /
                         \-------------------- 1000 V --------------------/
Step 2:
Now it randomly chooses path B and picks the lower cable. At the same time the upper path will be increased back to 1000 by 1 Volt (this is just a number to calculate easier):
Needed power is 5000000 Ampere -> Reduction of 500 Volts.

Code: Select all

[Generator - 1000 MW]   ----  991 V ---- [Consumer A - 10 MW] --- 1000 V ---  [Consumer B - 500 MW]
                        \                                                  /
                         \-------------------- 500 V --------------------/
As you see: Quite strong reduction. If implemented this needs of course to be balanced. But for now it is easier to calculate with it.

Step 3:
Now things get complicated to follow (the algorithm does not change):

The randomly choosen pair is G->B again.

Calculating path:
Generator -> B: 500
Generator -> A -> B: (991 + 1000) / 2 = 995.5

Will take now path G->A->B!

Needed power is now higher: 500MW / 995.5 V = 502260.2 Ampere -> Reduction of 502 Volts

Code: Select all

[Generator - 1000 MW]   ----  491 V ---- [Consumer A - 10 MW] --- 498 V ---  [Consumer B - 500 MW]
                        \                                                  /
                         \-------------------- 501 V --------------------/
Step 4:
Chosen pair is G->A

Calculating path:
Generator -> A: 491
Generator -> B -> A: (491+498) / 2 = 494.5

Will take now path G->B->A!

Needed power: 10MW / 494.5 V = 20222.5 Ampere -> Reduction of 20 Volts

Code: Select all

[Generator - 1000 MW]   ----  492 V ---- [Consumer A - 10 MW] --- 478 V ---  [Consumer B - 500 MW]
                        \                                                  /
                         \-------------------- 481 V --------------------/
Step 5:
Chosen pair is G->B

Calculating path:
Generator -> B: 492
Generator -> B -> A: (481+478) / 2 = 479.5

Will take now path G->B!

Needed power: 500MW / 492 V => Reduction of 1016 Volts.... ok, that is the equivalent of an electric shortage!

Here this algorithm needs obviously some kind of balancing. :) I will end here, cause I think you can see, how that can work.


What you see is this:

- I have choose a too big reduction and to slow rebound! --> This is part of balancing.
- Calculation is not needed for every tick! With a large network I think it is enough to calculate one pair per second, especially, cause a larger network will not change so fast as with a small network.
- Indeed I think the amount needed for calculation to guarantee a nice gameplay is only dependend on the amount of changes that is done to the networks: I think the time depends on the sum of all devices in all Networks and rises of course with the number of paths on which a device is connected.
- To increase speed more I think, that it is eventually not needed to calculate always the shortest path (which needs to calculate every possible path), but just one more or less random path; half random, half calculated for example.
- The amount of power needed for things more far away depends on the number of cables inbetween. The number of connections will add in sum a bigger resistance than a short connection, which drains more power then. Which is what we want.
- The resistance reduces, if less power is transported (cause not enough power available). Which is good: If you are near a power failure the network "recovers" in that case. Interesting effects can happen.
- This is also the case, if you turn parts of the factory off: Cables "recover" and can have suddenly much lesser power reduction. That gives a player more time.
- A device should turn of, if the voltage goes below some amount to enable recovering. This is also quite beginner friendly, cause you will see very early random power failures. Maybe you can configure this level per network?
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

bobucles
Smart Inserter
Smart Inserter
Posts: 1669
Joined: Wed Jun 10, 2015 10:37 pm
Contact:

Re: Another try of implementing Power Loss

Post by bobucles »

But what is the resistance between two arbitrary points on an unlimited grid composed entirely of 1Ohm resistors?

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Another try of implementing Power Loss

Post by ssilk »

Hm. Perhaps I should link to the older threads about this problem:

viewtopic.php?f=80&t=15546 Cable Resistance / Non-looseless Power Transmission

That should be read before this article.... :)

So, when you analyze all the suggestions, you can see, that the problem can be seen from quite different sides, but in the end as a player I want to have two effects:

1. The more "far away" the power is from the drain, the more "loss" I have.
2. It should be much more revealing to split networks for energy saving, to transport energy in form of accumulators and so on.
3. The net should have some "self-repairing" abilities, to prevent it from becoming too complex.

Both can be fulfilled with this, the first one with this "pathing", the third cause the algorithm is quite slow creating a stable network and the second follows automatically.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

bobucles
Smart Inserter
Smart Inserter
Posts: 1669
Joined: Wed Jun 10, 2015 10:37 pm
Contact:

Re: Another try of implementing Power Loss

Post by bobucles »

I'm not sure there's an easy way to implement this. By "easy" I mean a solution that is simple, readily understood by players and light on the CPU cycles.

Right now you have to calculate a complete electrical path for everything that exists. Those electrical paths have constantly fluctuating demand, the fluctuating demand will change the network's capacity, and there is no "single distance" from a power source because there are hundreds of power sources (or even thousands with solar panels). If a machine turns off, the network changes. If a machine turns on, the network changes. If the sun goes down or a steam pipe runs low or a boiler runs out of fuel, the network changes. Machines turn on and off a dozen times (or hundreds) every single tick. What happens if the same machine shares two electrical networks? What about laser turrets?

The end result is... well what exactly? The player uses more electricity. So... what does this mean for gameplay? Just like build more electrical power. Meh? It seems like a lot of work for something the player can solve by building more and being slightly annoyed.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Another try of implementing Power Loss

Post by ssilk »

Well, I'm sure this will not be implemented like this and if then the second question is, if it really increases the gameplay.

The point (and reason why I wrote this suggestion) is, that I see a way to have electric resistance in Factorio and I hope there will be others, that take this idea and enhance their own. So maybe sometimes we will have it. :)
bobucles wrote:Right now you have to calculate a complete electrical path for everything that exists.
No, not everything. Or maybe this is a misunderstanding. You have to find a path from a random producer to a random consumer.
Which is not so complicated.
Those electrical paths have constantly fluctuating demand, the fluctuating demand will change the network's capacity, and there is no "single distance" from a power source because there are hundreds of power sources (or even thousands with solar panels). If a machine turns off, the network changes. If a machine turns on, the network changes. If the sun goes down or a steam pipe runs low or a boiler runs out of fuel, the network changes. Machines turn on and off a dozen times (or hundreds) every single tick.
The reaction to changes is slow. It depends on, how many times per second you calculate a step. Let's say between one and ten times per second.

Even with 100 or 1000 such calculations per second the system is far away from calculating "correct" results.

And that is not really needed! Cause I think it is not needed to implement the wanted behavior. That behavior (I said above) can be explained with the heat of the cables (the more power runs through a cable, the "hotter" it will be and so they have bigger resistance). And to heat (cool) something takes a while...
And what it simulates is in endeffect not the exact resistance from all generators to all consumers, but it calculates the power that is needed to heat the cables. :) (*)
So reacting to changes is not the strength of this is not the target.
What happens if the same machine shares two electrical networks?
Interesting question. But I see no problem. A device in two networks tries to get 50% from each side. That would be step 0 (first post) and after some steps the voltage goes down in one network. So when the connected voltage of network A is only 500 volts and 1000 Volts in network B the device tries to get more power from network B.
What about laser turrets?
The more often the lasers fire, the "hotter" the cables will become with the time. I think this is a fair behavior: The power fails if the player just adds more and more power, instead of increasing the network.
The end result is... well what exactly? The player uses more electricity. So... what does this mean for gameplay?
Also very good question. I must say I'm not quite sure yet. And I haven't thought it thru.
Just like build more electrical power. Meh?
No. :)
Ahh. Now I understand you problem with that suggestion.

Here the explanation:
As you see in the example there is - dependend on the balancing - a point, where we need to deliver exponential amounts of power. This goes so:
The devices need more power. Voltage goes down. More power is needed. Voltage goes much more down. Much more power is needed.
And there is a point, when there is so much power needed, that the network sucks such much energy, that the voltage cannot recover. Shortage!

Such shortage may take only some seconds, networks goes on and off. What you need then is to split the network is reduction of the cable lengths. and more, see down.

Here are some things you need to do to avoid such crisis:
- as you see in the example you can build more poles (and with that more cables)
- you need to create smaller power plants at more places, the reduces the average cable length.
- very effective is splitting the power networks into many small parts and turning them off, if voltage gets too low.

But that is not all. There are useful new entities, that should be added, namely
- Special cables with lower resistance, but that cannot only be used to connection with other (current) poles. That would enable to a "nicer power-layout", where you have long-range electric network and short-range (the current poles).
- transmission and transporting energy in different forms is much more useful then: Steam, Solid fuel, Uranium, Accumulators. Not all is possible yet.
- More clever ways to separate networks (accidentally connecting two networks).
- Transmission of energy not only by wires (Lasers? which would be from graphical design aspect a very cool feature)
It seems like a lot of work for something the player can solve by building more and being slightly annoyed.
Well, I hope I could open a small window of what is possible with this feature and how the game will change.
There is still a big questionmark, if the gameplay would really profit from this, but this is with any suggestion about power loss. :)


(*) So maybe it would be a better idea, that instead of decreasing the voltage of a cable we could increase the resistance of a cable?
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2631
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Another try of implementing Power Loss

Post by steinio »

Do we need this? In my opinion, no.
Image

Transport Belt Repair Man

View unread Posts

bobucles
Smart Inserter
Smart Inserter
Posts: 1669
Joined: Wed Jun 10, 2015 10:37 pm
Contact:

Re: Another try of implementing Power Loss

Post by bobucles »

You're still talking about a power network where any two arbitrary connections are relevant. A solar panel may potentially interact with any power consumer on the map, and vice versa. The code burden of such a system easily becomes O(squared) and maybe more because the wires and relevant data are growing in complexity as well. What a load of CPU cycles being consumed for such a simple outcome!

There simply has to be an easier way to achieve a similar goal. I can give a functioning radius to power producers and that will also force consumers to stay close to their power systems. But even that becomes a massive mess of a thousand overlapping AoE networks. That won't work well either.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Another try of implementing Power Loss

Post by ssilk »

All correct. Again, the target of this suggestion was to walk the rough path of handling power loss once more to make that path more even. :)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

leitk
Fast Inserter
Fast Inserter
Posts: 115
Joined: Wed Jun 21, 2017 7:20 pm
Contact:

Re: Another try of implementing Power Loss

Post by leitk »

A fairly simple solution to adding cost to the network is to have every pole have a power cost, I would suggest that the cost be the same regardless of type to encourage larger poles. However, as Qon and I discussed, either the cost would be a major pain, or it wouldn't be enough to matter, and is probably not a good idea in general.

VinWij
Burner Inserter
Burner Inserter
Posts: 10
Joined: Thu Jun 05, 2014 8:26 am
Contact:

Re: Another try of implementing Power Loss

Post by VinWij »

So, what this will mean for my average base is that I move my solar farms to the remote laser-defended walls and connect them by 10 lines of big power poles to the main base. That backup-line will only activate when the lasers have depleted the accumulators during the night and more power is needed, though at loss due to the transport. Or I build a backup steam generator at the remote wall.

I don't think I will dig into discovering how to optimize a power network. The only network I truly care about is the rail network, for belts I use a main-bus design. I find circuit networks with combinators and deciders incredibly obscure and difficult to use, and I don't know if I want yet even more complexity in invisible networks (wires). I prefer the visible, easy to debug networks such as belts and rails. Sorry, but these are my two cents.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Another try of implementing Power Loss

Post by quyxkh »

Surprised not to see this here yet....
Image

Engimage
Smart Inserter
Smart Inserter
Posts: 1067
Joined: Wed Jun 29, 2016 10:02 am
Contact:

Re: Another try of implementing Power Loss

Post by Engimage »

I think this is as unnessessary overcomplication.
Factorio is widely used in education because everything in it is clear and predictable. You can do math and understand stuff.
You new implementation refers to "random pair selection" etc which effectively means unpredictable results.
For this to be more strict we would need something like fluid physics but for electricity. Where high voltage cables (between large poles and substations) would have low resistance and common cables would have higher resistance. And cables themselves will consume electricity based on "flow" (effectively meaning electric current) inside them - squared and multiplied by resistance of the cable - or something alike.

However this effectively means that all simplifications devs went are largely ineffective - you just can't "unite" solar panels and accumulators into single entities due to their different locations and connections.
On a small scale base all this will be barely noticable and on a large scale base this will require considerable amount of CPU resources to process.

So while the idea itself is fine but I would consider CPU+complexity vs game value. And imo game value is too low for the drawbacks we get.

Xeorm
Fast Inserter
Fast Inserter
Posts: 206
Joined: Wed May 28, 2014 7:11 pm
Contact:

Re: Another try of implementing Power Loss

Post by Xeorm »

I don't think your current implementation would work. It's a scaling problem limited heavily by the way Factorio handles individual entities. The complexity in managing power goes up very, very quickly as we add more generators and consumers. Successfully managing a power grid is complex. One solar panel = one generator like it is in Factorio wouldn't work on a large scale. That's far, far too many generators. Instead, you'd need some way to group them up like you do in practice. That adds a fair amount of complexity to the player, for no real gain.

Similarly you'd need more power as a player on how to transfer electricity. You'd want tools similar to reality: large, long distance power lines with step-down locations to provide localized power, and ways to manage that power such that power is available as needed with little waste. Which adds more decisions for the player, more entities required on the map, and different design rules that aren't easily simplified. You can't place a power pole near another and automatically connect, because that might upset design. Manually placing wires would be required, and it all just snowballs.

Post Reply

Return to “Ideas and Suggestions”