4 variables problem optimization with Genetic Algorithm

조회 수: 3 (최근 30일)
Ali Ghalavand
Ali Ghalavand 2021년 5월 10일
댓글: Ali Ghalavand 2021년 5월 14일
I have a 4 variables nonlinear problem optimization that want to solve it with Genetic Algorithm, my lower bounds are [-100 -100 -3000 -3000] and upper bounds are
[100 100 700 700]. But every time I run the program it gives me the different results for variables and the variables don't converge. How can I fix this problem to get a specific result?

채택된 답변

Alan Weiss
Alan Weiss 2021년 5월 11일
ga is a stochastic algorithm, and is expected to give different results on different runs. You can get reproducible behavior by setting the random seed. For example, run
rng default
before running ga.
A different question: is ga the right solver for you? See Choose a Solver.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 3
Alan Weiss
Alan Weiss 2021년 5월 13일
You can try patternsearch from several initial points randomly chosen within bounds, as described here:
x0 = lb + rand(size(lb)).*(ub - lb);
Write a loop and see what you get.
I don't understand your question "I used the optimization toolbox and I didn't write the GA code, so where I can use the rng function?" Call the rng function before your ga call. If you canot because someone gave you precompiled code somehow, then I don't know how to help you.
Alan Weiss
MATLAB mathematical toolbox documentation
Ali Ghalavand
Ali Ghalavand 2021년 5월 14일
Thank you Alan,
I wrote GA code yesterday and I used rng function then I saw the variables converged and my problem was solved.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by