UPD: Solved it.
Hi, thank you for wanting to help!
So I’m implementing a very hard (for me) script that should schedule the work of devices based on cost of kilowatt-hour in particular time of a day, combined power requirement as well as other factors. Of course it’s for training purpose, not production!
I don’t yet know fundamental sorting algorithms, so the script is kinda crappy, but it also kinda works.
What is not working is the final part, where I’m creating a schedule for the day, where all of the devices should be corresponded to hours of the day. I’m trying to loop through each device, it’s hours to work, and for each hour push it to the array of this hour operating devices. There is also a power requirement that forbids device to be planned in the hour if it’s power consumption combined with already pushed devices will exceed the maximum allowed power consumption.
So I need a way to check if max power is exceeded (done), and if it is — redirect current device to the next hour. If in the next hour max power is also exceeded — redirect further and so on until there is no hours in a day left or if the device finally got scheduled.
I’m sorry for the amount of text and code in the example below, it’s really hard for me, but I refuse to give up on this problem. Please have a look at the code, specifically at the part at the bottom. Any additional critique, no matter how harsh, is also welcome!