How to define a binary decision variable as upper and lower bond in an optimization function?
古いコメントを表示
Hello experts,
I have an optimization problem that i have to solve using improved particle swarm optimization and i want to define the binary variable (x2) in Matlab as constraint.
x2 = 0 for charge of battery
x2 = 1 for discharge of battery
how can i define it thank you in advance.
回答 (1 件)
Walter Roberson
2021 年 4 月 15 日
編集済み: Walter Roberson
2021 年 4 月 15 日
1 投票
You cannot use integer constraints with the Mathworks provided particle swarm algorithm. You can force the initial positions to match the constraints but the velocity will always be continuous so the first step will move away from the constraints. There is no hook that you can use to confine the range of motion to integers.
6 件のコメント
Usman Taya
2021 年 4 月 15 日
編集済み: Usman Taya
2021 年 4 月 15 日
Walter Roberson
2021 年 4 月 15 日
You might as well use the same mechanism that is used for ga() and some other optimization routines: use lower bound 0, upper bound 1, and have one of your parameters be a list of indices of which variables are subject to integer constraints.
As for implementation:
After a new position has been created, round() the components of the position that are integer constrained, and then apply normal boundary handling to keep it within lb / ub
Usman Taya
2021 年 4 月 15 日
Walter Roberson
2021 年 4 月 15 日
Code without integer constraints:
position = position + velocity;
position = apply_bounds_constraints(positions, constraint_information);
Code with integer constraints:
position = position + velocity;
position(integer_constraint_index) = round(position(integer_constraint_index));
position = apply_bounds_constraints(positions, constraint_information);
Lahiru Ransara
2021 年 6 月 15 日
When I use Walter's code my Best Cost is getting same value for all the iterations. :( What I'm missing?
Walter Roberson
2021 年 6 月 15 日
As this situation was for the case of user-provided code for doing all of the genetic optimization, instead of using MATLAB Library functions, then it is difficult for us to know what is in the rest of the code.
Also, the velocity might come out to be less than +/- 1/2 in each component, so round() might be returning you to the same position.
カテゴリ
ヘルプ センター および File Exchange で Particle Swarm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!