The OPTMODEL Procedure

Example 9.9 Geometric Median

This example demonstrates the use of conic transformation to automatically convert a nonlinear problem formulation to conic form for use with the conic solver. See also Example 11.2: Geometric Median, which uses manual transformations with the same model.

Given a set of m fixed sample points p 1 comma p 2 comma ellipsis comma p Subscript m Baseline, with each p Subscript i Baseline element of double struck upper R Superscript n, the geometric median is the point that minimizes the sum of distances to the sample points. Equivalently, the geometric median is the solution of the optimization problem

minimize of sigma summation Underscript i equals 1 Overscript m Endscripts StartMetric x minus p Subscript i Baseline EndMetric Subscript 2 Baseline

The objective is the sum of Euclidean norms and can be automatically transformed. The following code solves the model:

proc optmodel;
   /* let (x, y) be the geometric median */
   var x, y;

   /* sample points */
   num samples{1..3, 1..2} = [0 0, 1 4, 3 2];

   /* minimize the sum of distances */
   minimize f = sum{i in 1..3}sqrt((x-samples[i,1])^2+(y-samples[i,2])^2);
   expand / conic;

   solve with conic;

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

The EXPAND output and optimal solution are displayed in Output 9.9.1. The first three added variables and constraints correspond to the d variables and distance constraints, respectively, in the manually transformed version. The EXPAND statement with the CONIC option also displays the added variables and constraints that are passed to the solver in place of linear expressions that are used as predicate operands.

Output 9.9.1: Geometric Median

Var x                                                                           
Var y                                                                           
Var _ADDED_VAR_[1] >= 0                                                         
Var _ADDED_VAR_[2] >= 0                                                         
Var _ADDED_VAR_[3] >= 0                                                         
Var _ADDED_VAR_[4]                                                              
Var _ADDED_VAR_[5]                                                              
Var _ADDED_VAR_[6]                                                              
Var _ADDED_VAR_[7]                                                              
Minimize f=_ADDED_VAR_[1] + _ADDED_VAR_[2] + _ADDED_VAR_[3]                     
Constraint _ADDED_CON_[1]: SOC(_ADDED_VAR_[1], x y)                             
Constraint _ADDED_CON_[2]: SOC(_ADDED_VAR_[2], _ADDED_VAR_[4] _ADDED_VAR_[5])   
Constraint _ADDED_CON_[3]: SOC(_ADDED_VAR_[3], _ADDED_VAR_[6] _ADDED_VAR_[7])   
Constraint _ADDED_CON_[4]: - _ADDED_VAR_[4] + x = 1                             
Constraint _ADDED_CON_[5]: - _ADDED_VAR_[5] + y = 4                             
Constraint _ADDED_CON_[6]: - _ADDED_VAR_[6] + x = 3                             
Constraint _ADDED_CON_[7]: - _ADDED_VAR_[7] + y = 2                             

xy
1.72382.1853


Last updated: June 22, 2026