title: Algorithm for finding the best routes for food distribution in game
body: <p>I'm designing a city building game and got into a problem.</p>
  
  <p>Imagine Sierra's <em>Caesar III</em> game mechanics: you have many city districts with one market each. There are several granaries over the distance connected with a directed weighted graph. The difference: people (here cars) are units that form traffic jams (here goes the graph weights).</p>
  
  <p>Note: in Ceasar game series, people harvested food and stockpiled it in several big granaries, whereas many markets (small shops) took food from the granaries and delivered it to the citizens.</p>
  
  <p><strong>The task</strong>: tell each district where they should be getting their food from while taking least time and minimizing congestions on the city's roads.</p>
  
  <h2>Map example</h2>
  
  <p><img src="https://i.imgur.com/v4uif67.png" alt="Example graph diagram"></p>
  
  <p>Suppose that yellow districts need 7, 7 and 4 apples accordingly.
  Bluish granaries have 7 and 11 apples accordingly.</p>
  
  <p>Suppose edges weights to be proportional to their length. Then, the solution should be something like the gray numbers indicated on the edges. Eg, first district gets 4 apples from the 1st and 3 apples from the 2nd granary, while the last district gets 4 apples from only the 2nd granary. </p>
  
  <p>Here, vertical roads are first occupied to the max, and then the remaining workers are sent to the diagonal paths.</p>
  
  <h2>Question</h2>
  
  <p>What practical and very fast algorithm should I use? I was looking at some papers (<em>Congestion Games: Optimization in Competition</em> etc.) describing congestion games, but could not get the big picture.</p>