0

I created a dataset with the capacity and production of a product per country.

I am interested in calculating the balances between these different countries. For example, France has a positive balance of 50, Belgium a balance of 10, and Germany a balance of -50.

I am interested in creating a python function that calculates balances between these countries based on the distance to optimize these flows; E.G: Germany to Belgium 10, Germany to France 40, equilibrium reached! Are there any existing functions of which I am not familiar with?


output_folder = 'C:/Users/*/Desktop/Extr-act/Output/'
layer5 = QgsVectorLayer(output_folder + "Distance matrix.shp", "Distance matrix", "ogr")
layer6 = QgsVectorLayer(output_folder + "Centroids.shp", "Centroids", "ogr")

with edit(layer6):
    for f in layer6.getFeatures():
        if f["BC_Balance"] < 0:
            for i in layer5.getFeatures():
                if f["CNTR_CODE"] == i["InputID"]:

                    f["Dest"] = ["InputID"]
                    f["Amount"] = 0
            layer5.updateFeature(f)

I have added the question with the code I came up with so far.

enter image description here enter image description here

https://drive.google.com/drive/folders/1WCllWC2dgSCsqQ3TokB9obO90jd4ZAoT?usp=sharing

  • This sounds like a optimisation problem.. Don't you want to reach as-best-equilibrium as possible, with as less movements (KM) as possible? – Willem Hendriks Sep 21 '20 at 11:26
  • YES! completely true, could you help me with this? – Niels Janssens Sep 24 '20 at 06:53
  • Step 1 is describe your problem more mathematically. What is the cost of moving from country A to B, and what is the penalty for not having the average, and is it possible to split among neighbors, and perhaps other contraints like the distance or hops allowed to travel the goods – Willem Hendriks Sep 24 '20 at 07:33

0 Answers0