Genetic Algorithm in Matlab oop

Hi,
Could anyone tell me the syntax of genetic algorithm in matlab oop?
I would like to have a small example with what should be involved in properties and methods, how to add packages etc.
For example
classdef GA
properties
clsystem % this is the folder where all myclasses and subclasses are included
end
methods (Static)
function
% Here goes my algorithm with fitness function
end
end
end
Could anyone give me a small example of the GA syntax using them.
Thank you

9 个评论

I have not encountered a genetic algorithm classdef .
There is no special syntax for one. You define the class according to the interface you want it to have. What properties and operations do you want it to have?
Do you mean that you want to specify a method of an object as the objective function for a call to the ga function in Global Optimization Toolbox?
Hi guys,
Thankyou for your reply. @Steven Lord yes. I want to know what all should i include in this algoritm. For example, i have to optimize different folders together which are system, goset, path, pmd (all these are the folders). They also have sub folders in them and then they contain classes. I tried to optimize them. SO i would like to know how to do that.
Thankyou.
HI Walter,
Thankyou for your reply. I want to include fit function in it and optimize.
They also have sub folders in them and then they contain classes
Do you mean "classes" in the object-oriented sense? Or do you mean "classes" in the sense of sets of readings that represent similar objects, such as one folder containing a number of pictures of kittens, and another folder containing a number of pictures of kangaroos ?
I want to include fit function in it and optimize.
Why use object oriented programming for that? Why not just call ga() ?
Do you mean that you want to specify a method of an object as the objective function for a call to the ga function
Caution: Methods of an object cannot typically be used directly as the objective function for a call to ga().
ga() calls the function handle it has been supplied, passing in the trial x vector, and expecting the "cost" associated with that vector to be returned. However, methods of an object require that the object itself be passed in as the first parameter, with two exceptions: (1) Object constructors; and (2) "static" methods of a class.
Hi Walter,
Do you mean "classes" in the object-oriented sense?
yes...
I tried doing calling ga() function in main file. however i try I am getting Reference to non-existent field 'lT'. but when i call the function seperately in my main file it is working. i don,t understand what is the problem... i am attaching the files of my main script and fit function class. Please tell me whats wrong in it.
Since my main file has many objects just have alook at the cloptim1 and the object of it at the end of my main file.
Thankyou
The main() you post here does not call ga(). It calls gaoptimize(), which is not a Mathworks supplied function.
different folders together which are system, goset, path, pmd
gaoptimize() happens to be a function used in connection with Genetic Optimization System Engineering Tool (GOSET) from US Naval Academy. https://engineering.purdue.edu/~sudhoff/Software%20Distribution/GOSET%202.3%20manual.pdf
GOSET is not Mathworks supplied code.
Your code does not use any variable or field named IT, so I suspect that error is occuring within gaoptimize()
Thankyou for your explanation. Could you please tell me how to make the field lT to be used by gaoptimize(). The field lT is represented in the cltransformer. How to make use of it. Iam attaching clTransformer file as well.
Could you please tell me how to make the field lT to be used by gaoptimize()
No, I cannot.
You call clTransformer and assign the result to objT, but you never do anything with objT . In order to use the field lT of objT, gaoptimize() would have to evalin('caller') to deliberately look for objT in its calling environment, which would be a bad interface design that would be contrary to the principles of using object oriented design.
Perhaps you should be passing objT in some of the gaoptimize() calls, instead of passing objDS in all of them?

请先登录,再进行评论。

回答(0 个)

类别

标签

Community Treasure Hunt

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

Start Hunting!

Translated by