Assignment Chef icon Assignment Chef
All English tutorials

Programming lesson

Mastering Linear Programming with Xpress: Facility Location, QP, and Production Planning

Learn how to model and solve optimization problems using Xpress, including facility location, quadratic programming with piecewise linear approximation, and production planning. This tutorial covers key concepts from ISYE 6669 homework assignments with timely examples.

linear programming Xpress tutorial facility location problem L1 distance quadratic programming piecewise linear approximation production planning linear programming ISYE 6669 homework solutions Xpress optimization modeling Manhattan distance optimization ℓ1 ball quadratic program DEC production planning model operations research examples supply chain optimization AI optimization for data science Xpress mpvar free variable convex piecewise linear lower envelope cutting plane algorithm nonlinear Xpress mmquad qexp

Introduction to Optimization with Xpress

Optimization is at the heart of operations research and data science. In this tutorial, we explore three classic problems from the ISYE 6669 course: facility location, quadratic programming with piecewise linear approximation, and production planning. Using Xpress, a powerful modeling language, you'll learn to formulate and solve linear and quadratic programs. We'll connect these concepts to real-world scenarios, like how AI companies optimize server placement or how supply chains plan production under constraints.

Facility Location Problem

Problem Setup

Suppose you need to locate two new facilities A and B within a rectangular region (0,900) for x-axis and (0,1500) for y-axis. Existing facilities are at C(300,1200), D(0,600), and E(600,0). The objective is to minimize the sum of Manhattan distances (ℓ1 distances) between A and B, A and C, A and D, B and D, and B and E.

Optimization Model with Absolute Values

Let A = (x1, y1) and B = (x2, y2). The objective function is:

min |x1 - x2| + |y1 - y2| + |x1 - 300| + |y1 - 1200| + |x1 - 0| + |y1 - 600| + |x2 - 0| + |y2 - 600| + |x2 - 600| + |y2 - 0|

Subject to: 0 ≤ x1, x2 ≤ 900, 0 ≤ y1, y2 ≤ 1500.

Linear Programming Reformulation

Replace each absolute value term |a| with a variable and two constraints: a ≤ t, -a ≤ t. For example, for |x1 - x2|, introduce t1 and add:

x1 - x2 ≤ t1, x2 - x1 ≤ t1

Similarly for all terms. The objective becomes min sum of t's.

Xpress Implementation

In Xpress, declare variables as free (since they can be negative in reformulation) and use the is free keyword. Run the model to find optimal locations. Typically, facilities may overlap if cost savings from co-location outweigh distances to existing facilities.

Additional Constraints

Now add: distance from A to C ≤ 500, and from B to E ≤ 700. Using absolute values:

|x1 - 300| + |y1 - 1200| ≤ 500, |x2 - 600| + |y2 - 0| ≤ 700

Reformulate linearly by introducing variables and constraints as before. Modify the Xpress code and solve. Check if facilities overlap again.

Quadratic Programming and Piecewise Linear Approximation

Problem (P)

Minimize f(x) = (x1 - 1.5)^2 + (x2 - 0.8)^2 subject to |x1| + |x2| ≤ 1 (ℓ1 unit ball).

Reformulation as QP

Replace constraint with linear constraints: x1 + x2 ≤ 1, x1 - x2 ≤ 1, -x1 + x2 ≤ 1, -x1 - x2 ≤ 1. This is a quadratic program (QP) with linear constraints.

Piecewise Linear Approximation

Generate 10 feasible points on the boundary of the ℓ1 ball, e.g., (1,0), (0,1), (-1,0), (0,-1), (0.5,0.5), (0.5,-0.5), (-0.5,0.5), (-0.5,-0.5), (0.8,0.2), (0.2,0.8). Construct a convex piecewise linear lower envelope ˆf(x) that equals f at these points and is ≤ f everywhere. This is done by taking the maximum of linear functions (tangents) that support f at each point. For each point x^i, we can use the gradient ∇f(x^i) to form a linear function: f(x^i) + ∇f(x^i)·(x - x^i). Since f is convex, this gives a supporting hyperplane. Then ˆf(x) = max_i [f(x^i) + ∇f(x^i)·(x - x^i)].

LP Formulation

Minimize t subject to t ≥ f(x^i) + ∇f(x^i)·(x - x^i) for all i, and x in ℓ1 ball (linear constraints). This is a linear program.

Implementation in Xpress

Use the code template hw1prob2QP.mos. For the LP, declare variable t, and constraints for each supporting plane. For the QP, use the mmquad module and qexp to define quadratic objective. Compare solutions: the QP gives exact optimum (e.g., x* = (0.9, 0.1) with f ≈ 0.85), while the LP approximation yields a slightly higher objective but is easier to solve.

Production Planning at DEC

Background

In 1988, Digital Equipment Corporation (DEC) faced production planning for new computer systems: GP-1, GP-2, GP-3, WS-1, WS-2. Constraints: CPU supply ≤ 7,000 units, 256K memory boards ≤ 8,000 units. Demand: max GP-1: 1,800; GP-3: 300; GP family total: 3,800; WS family total: 3,200. Also, 500 GP-2, 500 WS-1, 400 WS-2 orders must be fulfilled. Prices: GP-1: $60k, GP-2: $40k, GP-3: $30k, WS-1: $30k, WS-2: $15k. Memory usage: GP-1 uses 4 boards, GP-2: 2, GP-3: 2, WS-1: 2, WS-2: 1.

Linear Programming Model

Let x1,...,x5 (in thousands) be production quantities. Objective: maximize revenue = 60x1 + 40x2 + 30x3 + 30x4 + 15x5 (in $k). Constraints:

  • CPU: x1 + x2 + x3 + x4 + x5 ≤ 7
  • Memory: 4x1 + 2x2 + 2x3 + 2x4 + x5 ≤ 8
  • GP-1 demand: x1 ≤ 1.8
  • GP-3 demand: x3 ≤ 0.3
  • GP family: x1 + x2 + x3 ≤ 3.8
  • WS family: x4 + x5 ≤ 3.2
  • Fulfill orders: x2 ≥ 0.5, x4 ≥ 0.5, x5 ≥ 0.4
  • Non-negativity: xi ≥ 0

Solve in Xpress. Optimal solution typically produces up to demand limits, using memory and CPU fully. This model helped DEC make strategic decisions in a competitive market, similar to how modern tech companies plan production for AI servers or gaming consoles.

Conclusion

These problems illustrate the power of linear and quadratic programming in operations research. By mastering Xpress, you can tackle real-world optimization challenges in logistics, manufacturing, and AI. Practice with variations, such as adding integer constraints or using piecewise linear approximations for nonlinear functions.