The Conic Optimization Solver

Example 11.3 Euclidean Distance between Sets

This example demonstrates how to solve a quadratically constrained quadratic programming (QCQP) problem. Let script upper A and script upper B be two closed convex sets in double struck upper R Superscript n. The Euclidean distance between them is defined as the smallest distance between one point in script upper A and another point in script upper B. You can find the Euclidean distance between these two sets by solving the following optimization problem:

StartLayout 1st Row 1st Column min 2nd Column StartMetric a minus b EndMetric squared 2nd Row 1st Column normal s normal u normal b normal j normal e normal c normal t normal t normal o 2nd Column a element of script upper A comma b element of script upper B EndLayout

Consider the following Euclidean distance problem. Set script upper A is an ellipse in two-dimensional space. A point in set script upper A is denoted as left parenthesis x 1 comma y 1 right parenthesis. Set script upper B is a polyhedron that is defined by two linear inequalities. A point in set script upper B is denoted as left parenthesis x 2 comma y 2 right parenthesis. The QCQP problem is as follows:

StartLayout 1st Row 1st Column min 2nd Column left parenthesis x 1 minus x 2 right parenthesis squared plus left parenthesis y 1 minus y 2 right parenthesis squared 2nd Row 1st Column normal s normal u normal b normal j normal e normal c normal t normal t normal o 2nd Column 3 left parenthesis x 1 minus 2 right parenthesis squared plus left parenthesis y 1 minus 3 right parenthesis squared plus 2 left parenthesis x 1 minus 2 right parenthesis left parenthesis y 1 minus 3 right parenthesis less than or equals 5 3rd Row 1st Column Blank 2nd Column x 2 plus y 2 less than or equals 1 4th Row 1st Column Blank 2nd Column 2 x 2 plus y 2 less than or equals 0 EndLayout

Use the following SAS statements to solve the problem:

/* example 3: Euclidean distance between sets */
proc optmodel;
   /* let (x, y) be a point in two-dimensional space */
   var x{1..2}, y{1..2};

   /* minimize the distance between two points in different sets */
   minimize f = (x[1] - x[2])^2 + (y[1] - y[2])^2;

   /* set A is an ellipse */
   con ellipse: 3*(x[1] - 2)^2 + (y[1] - 3)^2 + 2*(x[1] - 2)*(y[1] - 3) <= 5;

   /* set B is a polyhedron defined by two linear inequalities */
   con line1: x[2] + y[2] <= 1;
   con line2: 2*x[2] + y[2] <= 0;

   solve with conic;

   /* print the optimal solution */
   print x y;
quit;

The output and optimal solution are displayed in Output 11.3.1.

Output 11.3.1: Euclidean Distance between Sets

The OPTMODEL Procedure

Problem Summary
Objective SenseMinimization
Objective Functionf
Objective TypeQuadratic
  
Number of Variables4
Bounded Above0
Bounded Below0
Bounded Below and Above0
Free4
Fixed0
  
Number of Constraints3
Linear LE (<=)2
Linear EQ (=)0
Linear GE (>=)0
Linear Range0
Nonlinear LE (<=)1
Nonlinear EQ (=)0
Nonlinear GE (>=)0
Nonlinear Range0

Solution Summary
SolverConic
AlgorithmInterior Point
Objective Functionf
Solution StatusOptimal
Objective Value3.631884584
  
Primal Infeasibility1.1715218E-7
Dual Infeasibility3.4277832E-7
Bound Infeasibility0
Duality Gap2.9966075E-8
Complementarity4.8755354E-7
  
Iterations8
Presolve Time0.00
Solution Time0.00

[1]xy
11.086582.0882
2-0.617981.2360


Last updated: September 09, 2026