Initializing help system before first use

Blend: A model for mineral blending


Type: Blending
Rating: 1 (simple)
Description: 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).
File(s): blend.py, blend2.py
Data file(s): blend_data.py


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

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 = [p.addVariable(ub=AVAIL[o]) for o in ROres]

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

# 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)

p.optimize()

# Print out the solution
print("Solution:\n Objective:", p.attributes.objval)
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, "]")

blend2.py
'''*******************************************************
  * Python Example Problems                             *
  *                                                     *
  * file blend2.py                                      *
  * Example for the use of the Python language          *
  * (Blending problem from XPRESS-MP User Guide)        *
  *                                                     *
  * Data given in the model.                            *
  *                                                     *
  * (c) 2018-2025 Fair Isaac Corporation                *
  *******************************************************'''

import xpress as xp

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

COST = [85.00, 93.00]
AVAIL = [60.00, 45.00]
GRADE = [2.1, 6.3]

x = [p.addVariable(ub=AVAIL[o]) for o in ROres]

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

# 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)

p.optimize()

© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.