Unique variable values in ga

I am trying to write a code to optimise a stack of materials, based on certain parameters.
Currently I have an integer constrained ga optimisation, basically evaluating the objective function for a population of different stacks. However I would like to constrain this optimisation so that it doesn't look at stacks with two identical layers next to each other. Currently I am doing this by putting a big penalty on such structures in the objective function.
I was wondering if there is a way to constrain the ga function such that nearest neighbour variables cannot have the same value, i.e. x1~=x2, but x1 may equal x3.

 採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 31 日
編集済み: Walter Roberson 2016 年 10 月 31 日

0 投票

Expressing x1 ~= x2 could in theory be done as ((x1 - x2) < 0 or (x2 - x1) < 0) . However, you cannot express "or" in inequality constraints or equality constraints: inequality constraints and equality constraints are "and"'d together. ga() does not offer strict inequality either, so the closest you could get would be ((x1 - x2) <= 0 and (x2 - x1) <= 0) and that simplifies to x1 == x2 which is not what you want .
ga() also cannot use equality constraints when there are integer constraints.
So... you are going to have to program this as nonlinear inequality constraints.
all(abs(diff(x)) ~= 1)
would correspond to the condition being met. But that returns logical true, and nonlinear constraints are considered to be satisfied if the output of the expression is <= 0 . So you need that the expression returns false (or negative) when the condition is satisfied, and true (or positive) when the condition is violated. One way of expressing that would be:
nonlcon = @(x) deal(any(abs(diff(x)) == 1), [])
that would return true, a positive number, if there was a constraint violation, which happens to work out; the output of the expression with be 0 if the constraint is not violated, and that is the condition for _continuing. It is confusing, but self-consistent.

2 件のコメント

B H
B H 2016 年 10 月 31 日
Awesome, Thanks.
Siavash Shoja
Siavash Shoja 2018 年 2 月 27 日
Shouldn't it be
nonlcon = @(x) deal(any(abs(diff(x)) ~= 1), [])
instead?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

B H
2016 年 10 月 31 日

コメント済み:

2018 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by