A method of operating an electrical grid (102, 202) having at least one electrical consumer (111, 211) and a plurality of electrical producers (112, 212.1, 212.2, 214, 216), the method comprising: - providing a consumption prediction for the electrical consumer (111, 211), - providing respective production predictions for each electrical producer (112,212.1, 212.2, 214, 216), - determining the respective distances between the electrical consumer (111, 211) and each electrical producer (112, 212.1, 212.2, 214, 216), - allocating at least one electrical producer (112, 212.1, 212.2, 214, 216) to the electrical consumer (111, 211) in a first allocating step such that the provided consumption prediction of the electrical consumer (111, 211) matches to the provided production prediction of the at least one electrical producer (112, 212.1, 212.2, 214, 216) and such that the determined distance between the electrical consumer (111, 211) and the at least one electrical producer (112, 212.1, 212.2, 214, 216) is smaller than a first distance limit, characterized in that the method further comprises: - conducting a second allocating step if, in the first allocating step, the electrical producers (112, 212.1, 212.2, 214, 216) cannot be allocated to the electrical consumer (111, 211) such that the determined consumption prediction of the electrical consumer (111, 211) matches to the determined production prediction of at least one electrical producer (112, 212.1, 212.2, 214, 216) and such that the determined distance between the electrical consumer (111, 211) and the at least one electrical producer (112, 212.1, 212.2, 214, 216) is smaller than the first distance limit, - wherein the second allocating step comprises allocating at least one of the electrical producers (112, 212.1, 212.2, 214, 216) to the electrical consumer (111, 211) such that the determined consumption prediction of the electrical consumer (111, 211) matches to the determined production prediction of the at least one electrical producer (112, 212.1, 212.2, 214, 216) and such that the determined distance between the electrical consumer (111, 211) and the at least one electrical producer (112, 212.1, 212.2, 214, 216) is smaller than a further distance limit which is larger than the first distance limit, further characterized in that a - peer-to-peer network (118, 218, 518) comprising a peer-to-peer application (122, 222, 422) is provided, - wherein the allocating steps are performed by executing allocating means (124, 224, 424) of the peer-to-peer application (122, 222, 422) by nodes (120.1, 120.2, 120.3, 220, 504.1, 504.2, 506.1, 506.2, 520.1) of the peer-to-peer network (118, 218, 518). - providing a consumption prediction for the electrical consumer (111, 211), - providing respective production predictions for each electrical producer (112,212.1, 212.2, 214, 216), - determining the respective distances between the electrical consumer (111, 211) and each electrical producer (112, 212.1, 212.2, 214, 216), - allocating at least one electrical producer (112, 212.1, 212.2, 214, 216) to the electrical consumer (111, 211) in a first allocating step such that the provided consumption prediction of the electrical consumer (111, 211) matches to the provided production prediction of the at least one electrical producer (112, 212.1, 212.2, 214, 216) and such that the determined distance between the electrical consumer (111, 211) and the at least one electrical producer (112, 212.1, 212.2, 214, 216) is smaller than a first distance limit, - conducting a second allocating step if, in the first allocating step, the electrical producers (112, 212.1, 212.2, 214, 216) cannot be allocated to the electrical consumer (111, 211) such that the determined consumption prediction of the electrical consumer (111, 211) matches to the determined production prediction of at least one electrical producer (112, 212.1, 212.2, 214, 216) and such that the determined distance between the electrical consumer (111, 211) and the at least one electrical producer (112, 212.1, 212.2, 214, 216) is smaller than the first distance limit, - wherein the second allocating step comprises allocating at least one of the electrical producers (112, 212.1, 212.2, 214, 216) to the electrical consumer (111, 211) such that the determined consumption prediction of the electrical consumer (111, 211) matches to the determined production prediction of the at least one electrical producer (112, 212.1, 212.2, 214, 216) and such that the determined distance between the electrical consumer (111, 211) and the at least one electrical producer (112, 212.1, 212.2, 214, 216) is smaller than a further distance limit which is larger than the first distance limit, further characterized in that a - peer-to-peer network (118, 218, 518) comprising a peer-to-peer application (122, 222, 422) is provided, - wherein the allocating steps are performed by executing allocating means (124, 224, 424) of the peer-to-peer application (122, 222, 422) by nodes (120.1, 120.2, 120.3, 220, 504.1, 504.2, 506.1, 506.2, 520.1) of the peer-to-peer network (118, 218, 518).