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

Blend: A model for mineral blending

Several ores are blended to a final product that must have a certain quality ('grade'). We wish to determine the quantity of every ore to be used in the blend with the objective to maximize the total profit (calculated as sales revenues - raw material cost).

Further explanation of this example: 'Xpress Python Reference Manual'[download all files]

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

Data Files

  * Python Example Problems                             *
  *                                                     *
  * file                                       *
  * Example for the use of the Python language          *
  * (Blending problem)                                  *
  *                                                     *
  * Reading data from file.                             *
  *                                                     *
  * (c) 2018-2023 Fair Isaac Corporation                *

from __future__ import print_function
import xpress as xp
from Data.blend_data import COST, AVAIL, GRADE

p = xp.problem()

ROres = range(2)
REV = 125                     # Unit revenue of product
MINGRADE = 4                  # Min permitted grade of product
MAXGRADE = 5                  # Max permitted grade of product

x = [xp.var(ub=AVAIL[o]) for o in ROres]


# Objective: maximize total profit
p.setObjective(xp.Sum((REV - COST[o]) * x[o] for o in ROres),

# Lower and upper bounds on ore quality
p.addConstraint(xp.Sum((GRADE[o] - MINGRADE) * x[o] for o in ROres) >= 0)
p.addConstraint(xp.Sum((MAXGRADE - GRADE[o]) * x[o] for o in ROres) >= 0)


# Print out the solution
print("Solution:\n Objective:", p.getObjVal())
for o in ROres:
    print(" x(", o, "): ", p.getSolution(x[o]))
print("Grade: ", sum(GRADE[o] * p.getSolution(x[o]) for o in ROres)
      / sum(p.getSolution(x[o]) for o in ROres),
      " [min,max]: [", MINGRADE, ",", MAXGRADE, "]")

Back to examples browserPrevious exampleNext example