Created
February 20, 2014 10:19
-
-
Save andreacassioli/9110599 to your computer and use it in GitHub Desktop.
Dual formulation of the minimal sphere enclosing points using MOSEK Fusion API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sphere_enclosing_dual(n,k,p): | |
print('Creating the Fusion optimization model...') | |
start=time.clock() | |
M = Model("minimal sphere enclosing a set of points dual") | |
print('Declaring the variables...') | |
y= M.variable('y',NDSet(k,n+1),Domain.inQCone(k,n+1)) | |
print('done!\n') | |
c=[0. for i in range(n+1)] | |
c[0]=1. | |
print('Defining the constraints...') | |
M.constraint('lin', Expr.mul(DenseMatrix(1,k,1.0), y), Domain.equalsTo(c) ) | |
print('done!\n') | |
print('Defining the objective function...') | |
M.objective('dual',ObjectiveSense.Maximize, Expr.sum(Expr.mulDiag(\ | |
DenseMatrix(p.tolist()),\ | |
y.slice([0,1],[k,n+1]).transpose()))) | |
print('done!\n') | |
print('Model building time: '+ str(time.clock()-start)) | |
M.setLogHandler(sys.stdout) | |
M.solve() | |
print("\nSolution status= "+ str(M.getPrimalSolutionStatus())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment