Create a more interesting network flow model that exercises slicing and sparsity.


In [1]:
from netflow import input_schema

In [2]:
inf = float("inf")
dat = input_schema.TicDat(**{'arcs': [[u'warehouse_0', u'customer_4', inf],
  [u'plant_12', u'warehouse_1', inf],
  [u'warehouse_2', u'customer_8', inf],
  [u'warehouse_1', u'customer_3', inf],
  [u'warehouse_2', u'customer_6', inf],
  [u'plant_6', u'warehouse_1', inf],
  [u'warehouse_0', u'customer_9', inf],
  [u'warehouse_1', u'customer_7', inf],
  [u'warehouse_1', u'customer_5', inf],
  [u'plant_4', u'warehouse_2', inf],
  [u'plant_9', u'warehouse_0', inf],
  [u'warehouse_0', u'customer_7', inf],
  [u'warehouse_1', u'customer_2', inf],
  [u'warehouse_1', u'customer_0', inf],
  [u'warehouse_0', u'customer_1', inf],
  [u'warehouse_0', u'customer_6', inf],
  [u'warehouse_2', u'customer_3', inf],
  [u'plant_14', u'warehouse_0', inf],
  [u'plant_1', u'warehouse_1', inf],
  [u'plant_5', u'warehouse_0', inf],
  [u'warehouse_0', u'customer_2', inf],
  [u'plant_13', u'warehouse_2', inf],
  [u'plant_0', u'warehouse_0', inf],
  [u'warehouse_2', u'customer_1', inf],
  [u'warehouse_1', u'customer_8', inf]],
 'commodities': [[u'P2'], [u'P3'], [u'P0'], [u'P1'], [u'P4']],
 'cost': [[u'P2', u'plant_13', u'warehouse_2', 1.0],
  [u'P2', u'warehouse_2', u'customer_8', 1.0],
  [u'P1', u'warehouse_1', u'customer_0', 1.0],
  [u'P3', u'warehouse_0', u'customer_4', 1.0],
  [u'P4', u'warehouse_1', u'customer_3', 1.0],
  [u'P1', u'plant_1', u'warehouse_1', 1.0],
  [u'P2', u'warehouse_2', u'customer_6', 1.0],
  [u'P2', u'plant_4', u'warehouse_2', 1.0],
  [u'P0', u'warehouse_0', u'customer_1', 1.0],
  [u'P1', u'warehouse_1', u'customer_2', 1.0],
  [u'P1', u'plant_6', u'warehouse_1', 1.0],
  [u'P0', u'warehouse_0', u'customer_9', 1.0],
  [u'P1', u'warehouse_1', u'customer_5', 1.0],
  [u'P3', u'warehouse_0', u'customer_7', 1.0],
  [u'P4', u'plant_12', u'warehouse_1', 1.0],
  [u'P4', u'warehouse_1', u'customer_5', 1.0],
  [u'P1', u'warehouse_1', u'customer_7', 1.0],
  [u'P0', u'plant_0', u'warehouse_0', 1.0],
  [u'P0', u'plant_14', u'warehouse_0', 1.0],
  [u'P2', u'warehouse_2', u'customer_3', 1.0],
  [u'P4', u'plant_1', u'warehouse_1', 1.0],
  [u'P3', u'plant_5', u'warehouse_0', 1.0],
  [u'P0', u'warehouse_0', u'customer_6', 1.0],
  [u'P3', u'warehouse_0', u'customer_2', 1.0],
  [u'P3', u'plant_9', u'warehouse_0', 1.0],
  [u'P4', u'warehouse_1', u'customer_0', 1.0],
  [u'P2', u'warehouse_2', u'customer_1', 1.0],
  [u'P0', u'warehouse_0', u'customer_4', 1.0],
  [u'P4', u'warehouse_1', u'customer_8', 1.0],
  [u'P3', u'warehouse_0', u'customer_9', 1.0]],
 'inflow': [[u'P1', u'customer_0', -10.0],
  [u'P0', u'customer_9', -10.0],
  [u'P4', u'plant_1', 20.0],
  [u'P0', u'plant_0', 20.0],
  [u'P1', u'customer_2', -10.0],
  [u'P2', u'customer_1', -10.0],
  [u'P2', u'plant_4', 20.0],
  [u'P2', u'customer_8', -10.0],
  [u'P2', u'customer_3', -10.0],
  [u'P1', u'plant_1', 20.0],
  [u'P1', u'plant_6', 20.0],
  [u'P3', u'customer_9', -10.0],
  [u'P4', u'customer_3', -10.0],
  [u'P3', u'customer_4', -10.0],
  [u'P2', u'plant_13', 20.0],
  [u'P0', u'customer_1', -10.0],
  [u'P4', u'customer_8', -10.0],
  [u'P3', u'plant_5', 20.0],
  [u'P0', u'customer_6', -10.0],
  [u'P1', u'customer_5', -10.0],
  [u'P4', u'customer_5', -10.0],
  [u'P0', u'customer_4', -10.0],
  [u'P1', u'customer_7', -10.0],
  [u'P3', u'customer_7', -10.0],
  [u'P4', u'plant_12', 20.0],
  [u'P3', u'customer_2', -10.0],
  [u'P2', u'customer_6', -10.0],
  [u'P3', u'plant_9', 20.0],
  [u'P4', u'customer_0', -10.0],
  [u'P0', u'plant_14', 20.0]],
 'nodes': [[u'customer_9'],
  [u'customer_8'],
  [u'customer_7'],
  [u'customer_6'],
  [u'customer_5'],
  [u'customer_4'],
  [u'customer_3'],
  [u'customer_2'],
  [u'customer_1'],
  [u'customer_0'],
  [u'warehouse_2'],
  [u'warehouse_1'],
  [u'warehouse_0'],
  [u'plant_9'],
  [u'plant_8'],
  [u'plant_1'],
  [u'plant_0'],
  [u'plant_3'],
  [u'plant_2'],
  [u'plant_5'],
  [u'plant_4'],
  [u'plant_7'],
  [u'plant_6'],
  [u'plant_14'],
  [u'plant_11'],
  [u'plant_10'],
  [u'plant_13'],
  [u'plant_12']]})

Bear in mind the Inflow table isn't fully populated.


In [3]:
len(dat.inflow), len(dat.commodities) * len(dat.nodes)


Out[3]:
(30, 140)

In [4]:
# using the locally installed engine on my computer, comment this out for reproducing
%env PATH = PATH:/Users/XXXXXX/ampl/ampl


env: PATH=PATH:/Users/XXXXX/ampl/ampl

In [5]:
from netflow import solve
sln = solve(dat)


Solution determined by presolve;
objective TotalCost = 400.

In [6]:
sln.parameters


Out[6]:
{'Total Cost': _td:{'Value': 400.0}}