Borrar filtros
Borrar filtros

Error using SumOperator with Optimization Variables

1 visualización (últimos 30 días)
Andra Vartolomei
Andra Vartolomei el 14 de Ag. de 2022
Comentada: Torsten el 14 de Ag. de 2022
I have an Optimization Problem where I created the optim. variable x and the optim. problem linoptim.
Now I am trying to define my constraints and I keep getting an Error
nTasks = 3;
nRess = 2;
maxPT = 50;
x = optimvar('x',nTasks,nRess,maxPT,'Type', 'integer','LowerBound',0,'UpperBound',1);
Constraint1 = sum(x,[2 3]) == ones(nTasks, 1);
"Error in using optim.internal.problemdef.SumOperator
Dimension argument must be a positive integer scalar within indexing range.
If I write the same command and instead of x am using a matrix it works just fine:
sum(rand ([3 2 50]), [2 3])

Respuesta aceptada

Torsten
Torsten el 14 de Ag. de 2022
nTasks = 3;
nRess = 2;
maxPT = 50;
x = optimvar('x',nTasks,nRess,maxPT,'Type', 'integer','LowerBound',0,'UpperBound',1);
Constraint1 = sum(sum(x,2),3) == ones(nTasks,1);
  2 comentarios
Torsten
Torsten el 14 de Ag. de 2022
Little deficits of problem-based programming ...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by