Given something similar to this.
Where you have blocks (the squares) and entries (the circles). Each block has a rating (the number inside the blocks) and is connected to other blocks. This topology is always fixed and cannot change, the ratings neither.
An entry can ask for a given rating. The algorithm then should try to assign N connected blocks to that entry so the rating provided is above or as close as possible to what the entry requires. It needs to be considered that the block to which the entry is 'conected' will always be asigned to him. An example:
We have two entries requiring a limit (green and blue entry). Green requires 300, and he receives 300 (3 blocks of 100 assigned to him), while blue asks for 275 and receives 250 (125+75+25). This solution is the optimal one; deviations are of all entries are minimized. Green has |1-(300/300)|=0 and blue |1-(250/275)|=0.09.
Mind that the third entry is not active, so his 'entry block' can be used by another entry group of asigned blocks. If we activate the third entry and require 200 as follows.
Note that the optimum solution changes. Green cannot use the 'entry block' from orange (as orange is connected).
The algorithm should assign to each entry the best possible connected path, taking into account the other paths too. And the best path is the one with a value (sum of blocks) equal, above or closest to the entry desired value.
The algorithm should output the solution that minimizes the deviation |1-(recived/required)|
in each entry. In other words, the blocks assigned to each entry such that the rating received per entry is the closest to the desired value (for all the entries combined).
minimize: |1-(recived_1/required_1)| + |1-(recived_2/required_2)| + ...
- What could be an algorithm to solve such a problem. I am quite sure it involves linear/constraint programming. But I cannot see a clear way of doing it.
Edit: Context of question: Circles are EV charge stations, the squares are energy blocks connect between each other. When a car is connected to a station, the car requires some energy to charge (in the diagram, they ask for 300kW, 250kW and 200kW), and the blocks have ratings of 125kW, 100kW, 100kW, ... The algorithm has to say which group of power blocks go to which station. Aiming at satisfing as much as possible every car (i.e. kW provided by the sum of blocks is closest to how much kW the car wants, i.e the value in the circles in the diagram).
In real life, each edge has a contactor, it is either opened or closed to drive the energy of the blocks to the stations (but this can be ignored, knowing which blocks go to which station is enough). The doted line is the acces connection of the station to the networks of blocks. If the station has a car charging, the block to which the station is conected (doted line) will always be closed (i.e. that block assigned to him). This way every station when active has at least one block asigned so the car can charge.