Unique variable values in ga

조회 수: 8 (최근 30일)
B H
B H 2016년 10월 31일
댓글: Siavash Shoja 2018년 2월 27일
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일
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개)

카테고리

Help CenterFile Exchange에서 Direct Search에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by