FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Network problem: transport from depots to customers

Description
Network problem: transport from depots to customers.

Further explanation of this example: 'Xpress Python Reference Manual'

trans_python.zip[download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
trans.py[download]

Data Files





trans.py

'''*******************************************************
  * Python Example Problems                             *
  *                                                     *
  * file trans.py                                       *
  * Example for the use of the Python language          *
  * (Network problem: transport from depots to          *
  *  customers)                                         *
  *                                                     *
  * (c) 2018-2024 Fair Isaac Corporation                *
  *******************************************************'''

import xpress as xp
from Data.trans_data import AVAIL, DEMAND, COST

p = xp.problem()

Suppliers = AVAIL.keys()
Customers = DEMAND.keys()
Pairs = COST.keys()

x = {(i, j): p.addVariable() for i, j in Pairs}

p.setObjective(xp.Sum(COST[i, j] * x[i, j] for i, j in Pairs))

p.addConstraint(xp.Sum([x[s, c] for c in Customers if (s, c) in Pairs])
                <= AVAIL[s] for s in Suppliers)
p.addConstraint(xp.Sum([x[s, c] for s in Suppliers if (s, c) in Pairs])
                >= DEMAND[c] for c in Customers)

p.optimize()

Back to examples browserPrevious exampleNext example