How can I set an optimization variable to be an element of a set / categorical?

15 views (last 30 days)
I am building an optimization problem and I am trying to work with problem based programming. I want to define decision variables using optimvar function. How can I set a variable to be an element of a set. For example I want my variable to be 5, 8 or 12.5.

Accepted Answer

Alan Weiss
Alan Weiss on 21 Dec 2017
Set your variable to be an integer, and use the integer value to select from a list of predefined values. For examples, see optimal dispatch or a genetic algorithm example (not in problem-based framework).
Alan Weiss
MATLAB mathematical toolbox documentation
  4 Comments
Kendall Knight
Kendall Knight on 12 Mar 2019
When I attmepted an implementation of you comment Alan I got the error.
"Unable to use a value of type 'optim.problemdef.OptimizationVariable' as an index."
when the following code was run.
v = [1,2,3,4];
po_kl_picker = optimvar('po_kl_picker','LowerBound',1,'UpperBound',4, 'Type', 'integer');
rate_func = func_choice(v(po_kl_picker),shackle_angle,travel);
Ayush Modi
Ayush Modi on 14 Jan 2024
Hi Kendall,
Optimization variables cannot be used as an index to get the value from an array. In the example given by @Alan Weiss, index for variable "v" is 1 and 2 and not x (which is the Optimization variable).

Sign in to comment.

More Answers (0)

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!