Optimization problem with Mosek

27 visualizaciones (últimos 30 días)
valentino dardanoni
valentino dardanoni el 20 de Sept. de 2024
Comentada: valentino dardanoni el 10 de Oct. de 2024
I want to solve the following problem: Maximize \sum_{i=1}^{n} \log(v_i) subject to v_i \geq 0 and A' v \leq n 1_m, where A is a n \times m matrix of positive reals, using Mosek in Matlab. This is my code:
n = 10; % Number of variables
m = 20; % Number of constraints
F = rand(n, m)*100; % Example n x m matrix of positive reals
A = F'; % Transpose of F for the constraint matrix
b = n * ones(m, 1); % Right-hand side for constraints
% Optimization problem
prob.c = -ones(n, 1); % Coefficients for the objective function (maximize sum log(v_i))
prob.a = sparse(A); % Constraint matrix A'
prob.blc = -inf(m, 1); % Lower bounds
prob.buc = b; % Upper bounds
% Lower bounds (v >= 0)
prob.blx = zeros(n, 1); % Lower bounds for v
prob.bux = inf(n, 1); % No upper bounds for v
% Exponential cone constraints for log(v_i)
prob.cones.type = 'pexp'; % Type of cone (primal exponential)
prob.cones.sub = (1:n); % Indices of the variables involved in the cone
prob.cones.dim = repmat(3, n, 1); % Each cone has dimensionality 3
% Call MOSEK optimizer to solve the problem
[r, res] = mosekopt('minimize', prob);
I tried a few variants, but so far I always get error 1200. Any help?

Respuesta aceptada

Manikanta Aditya
Manikanta Aditya el 10 de Oct. de 2024
Hello,
I think the error 1200 in Mosek typically indicates an issue with the problem formulation or the input data.
You want to maximize ∑i=1nlog⁡(vi) subject to vi≥0 and A′v≤n1m, where A is an n×m matrix of positive reals.
  1. You are trying to maximize (\sum_{i=1}^{n} \log(v_i)). This is a concave function, so you should be minimizing the negative of this function, which you correctly attempted by setting prob.c = -ones(n, 1). However, looks like MOSEK handles exponential cones in a specific way, which requires setting up the problem to fit within the exponential cone framework.
  2. The logarithm can be represented using exponential cones. The primal exponential cone constraint in MOSEK requires that for each (i), variables ( (x_i, y_i, z_i) ) must satisfy ( y_i \exp(x_i/y_i) \leq z_i ). For your problem, this can be transformed into the cone constraints needed to represent (\log(v_i)).
Try out this, should help you get started:
n = 10; % Number of variables
m = 20; % Number of constraints
F = rand(n, m) * 100; % Example n x m matrix of positive reals
A = F'; % Transpose of F for the constraint matrix
b = n * ones(m, 1); % Right-hand side for constraints
% Initialize the problem structure
prob.c = zeros(3*n, 1); % Objective coefficients
prob.c(2:3:end) = -1; % Coefficients for maximizing log(v_i)
% Constraint matrix
prob.a = sparse([A, zeros(m, 2*n)]); % Augment A with zeros for auxiliary variables
prob.blc = -inf(m, 1); % Lower bounds for linear constraints
prob.buc = b; % Upper bounds for linear constraints
% Bounds for variables
prob.blx = [zeros(n, 1); -inf(2*n, 1)]; % v_i >= 0, no bounds on auxiliary variables
prob.bux = inf(3*n, 1); % No upper bounds
% Exponential cone constraints
prob.cones.type = repmat('PEXP', n, 1); % Type of cone (primal exponential)
prob.cones.sub = reshape(1:3*n, 3, n)'; % Indices for each cone
prob.cones.sub = prob.cones.sub(:); % Flatten to column vector
prob.cones.dim = repmat(3, n, 1); % Each cone has dimension 3
% Call MOSEK optimizer to solve the problem
[r, res] = mosekopt('minimize', prob);
Hope this helps.
  1 comentario
valentino dardanoni
valentino dardanoni el 10 de Oct. de 2024
Thankyou, Manikanta... I tried your code, but still gives the same error....
*** Error(1200): prob.cones
Mosek error: MSK_RES_ERR_IN_ARGUMENT (A function argument is incorrect.)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by