문제

내가 어떤 일과 유전자 알고리즘을 작성한 내 자신의 GA 클래스입니다.이후 GA 할 수 있는 다른 방법을 선택,돌연변이,크로스,이상 생성하는 초기 인구,계산 피트니스 및 종료하는 알고리즘 내가 필요로 하는 방법 플러그인에서 다른 이들의 조합.처음 접근 방식이었다는 추상 클래스는 이러한 모든 방법으로 정의 순수한 가상,그리고 어떤 콘크리트 클래스를 구현하는 그들.하고 싶은 경우에도 두 가지 가스 동일한지만 서로 다른 크로스-이 방법을 예를 들어,내가 가진 것을 추상적이고에서 상속되는 클래스 GeneticAlgorithm 고를 모두 구현하는 방법을 제외하고 십자가 방법을 통해 다음 두 가지 콘크리트 클래스를 상속받는 이 클래스에서만 구현 교차 방법입니다.의 단점은 이에 동의하는 것입니다.원하는 교환하는 방법 또는 두 가지를 시도하고 뭔가 새로운 나를 확인해야 하나 이상의 새로운 클래스입니다.

은 거기에 다른 접근 방법 적용할 수 있는 더 나은 이 문제가?

도움이 되었습니까?

해결책

나는 방식 GA 로의 공동 작업은 많은 개체보다는,하나의 큰 클래스를 캡슐화하는 전체적인 알고리즘이 있습니다.기본적으로,당신은 수 있다는 추상 클래스에 대한 모든 크 점의 변형,그리고 콘크리트 클래스에 대한 모든 구현을 선택할.당신은 다음을 결합한 콘크리트 클래스고 싶으로 많은 품종의 GA.

또한,할 수 있습에 익숙해지 전략 패턴:http://en.wikipedia.org/wiki/Strategy_pattern

다른 팁

GA 프레임 워크를 구현할 때 취한 접근 방식은 다음과 같습니다. 다음 클래스를 만듭니다. GeneticalGorithm GeneticalGorithMadapter GeneticalGorithmParameters 인구 개인

다양한 작업의 전략 패턴을 구현하지는 않았지만 GeneticalGorithm 인스턴스의 매개 변수로 다양한 GA 운영 구현을 작성하는 것이 중요 할 것이라고 확신합니다.

GeneticalGorithm 클래스는 기본 알고리즘을 캡처합니다. 그것은 실제로 다양한 단계 (인구 생성, 개별 무작위 배정, 선택, 교차, 돌연변이 등)를 정의하고 알고리즘이 실행될 때 개인의 집단을 관리합니다. 원한다면 여기에서 다른 작업을 연결할 수 있다고 생각합니다.

진짜 마법은 어댑터에 있습니다. 이것이 문제 영역 (모든 관련 데이터와 함께 개인의 특정 하위 클래스)을 유전자 알고리즘에 적응시키는 것입니다. 나는 여기에서 제네릭을 많이 사용하여 인구, 매개 변수 및 개인의 특정 유형이 구현에 전달되도록합니다. 이것은 어댑터의 구현을 지능적이고 강력한 유형 검사를 제공합니다. 어댑터는 기본적으로 주어진 개체 (및 그 게놈)에 대한 특정 작업을 수행하는 방법을 정의해야합니다. 예를 들어, 어댑터의 인터페이스는 다음과 같습니다.

/// <summary>
/// The interface for an adapter that adapts a domain problem so that it can be optimised with a genetic algorithm.
    /// It is a strongly typed version of the adapter.
    /// </summary>
    /// <typeparam name="TGA"></typeparam>
    /// <typeparam name="TIndividual"></typeparam>
    /// <typeparam name="TPopulation"></typeparam>
    public interface IGeneticAlgorithmAdapter<TGA, TIndividual, TGeneration, TPopulation> : IGeneticAlgorithmAdapter
        where TGA : IGeneticAlgorithm
        where TIndividual : class, IIndividual, new()
        where TGeneration : class, IGeneration<TIndividual>, new()
        where TPopulation : class, IPopulation<TIndividual, TGeneration>, new()
    {
        /// <summary>
        /// This gets called before the adapter is used for an optimisation.
        /// </summary>
        /// <param name="pso"></param>
        void InitialiseAdapter(TGA ga);

        /// <summary>
        /// This initialises the individual so that it is ready to be used for the genetic algorithm.
        /// It gets randomised in the RandomiseIndividual method.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="individual">The individual to initialise.</param>
        void InitialiseIndividual(TGA ga, TIndividual individual);

        /// <summary>
        /// This initialises the generation so that it is ready to be used for the genetic algorithm.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="generation">The generation to initialise.</param>
        void InitialiseGeneration(TGA ga, TGeneration generation);

        /// <summary>
        /// This initialises the population so that it is ready to be used for the genetic algorithm.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="population">The population to initialise.</param>
        void InitialisePopulation(TGA ga, TPopulation population);

        void RandomiseIndividual(TGA ga, TIndividual individual);

        void BeforeIndividualUpdated(TGA ga, TIndividual individual);
        void AfterIndividualUpdated(TGA ga, TIndividual individual);

        void BeforeGenerationUpdated(TGA ga, TGeneration generation);
        void AfterGenerationUpdated(TGA ga, TGeneration generation);

        void BeforePopulationUpdated(TGA ga, TPopulation population);
        void AfterPopulationUpdated(TGA ga, TPopulation population);

        double CalculateFitness(TGA ga, TIndividual individual);

        void CloneIndividualValues(TIndividual from, TIndividual to);

        /// <summary>
        /// This selects an individual from the population for the given generation.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="generation">The generation to select the individual from.</param>
        /// <returns>The selected individual.</returns>
        TIndividual SelectIndividual(TGA ga, TGeneration generation);

        /// <summary>
        /// This crosses over two parents to create two children.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="parentsGeneration">The generation that the parent individuals belong to.</param>
        /// <param name="childsGeneration">The generation that the child individuals belong to.</param>
        /// <param name="parent1">The first parent to cross over.</param>
        /// <param name="parent2">The second parent to cross over.</param>
        /// <param name="child">The child that must be updated.</param>
        void CrossOver(TGA ga, TGeneration parentsGeneration, TIndividual parent1, TIndividual parent2, TGeneration childsGeneration, TIndividual child);

        /// <summary>
        /// This mutates the given individual.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="generation">The individuals generation.</param>
        /// <param name="individual">The individual to mutate.</param>
        void Mutate(TGA ga, TGeneration generation, TIndividual individual);

        /// <summary>
        /// This gets the size of the next generation to create.
        /// Typically, this is the same size as the current generation.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="currentGeneration">The current generation.</param>
        /// <returns>The size of the next generation to create.</returns>
        int GetNextGenerationSize(TGA ga, TGeneration currentGeneration);


        /// <summary>
        /// This gets whether a cross over should be performed when creating a child from this individual.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="currentGeneration">The current generation.</param>
        /// <param name="individual">The individual to determine whether it needs a cross over.</param>
        /// <returns>True to perform a cross over. False to allow the individual through to the next generation un-altered.</returns>
        bool ShouldPerformCrossOver(TGA ga, TGeneration generation, TIndividual individual);

        /// <summary>
        /// This gets whether a mutation should be performed when creating a child from this individual.
        /// </summary>
        /// <param name="ga">The genetic algorithm that is running.</param>
        /// <param name="currentGeneration">The current generation.</param>
        /// <param name="individual">The individual to determine whether it needs a mutation.</param>
        /// <returns>True to perform a mutation. False to allow the individual through to the next generation un-altered.</returns>
        bool ShouldPerformMutation(TGA ga, TGeneration generation, TIndividual individual);
    }

다른 문제 도메인에 대한 GA 구현을 쉽게 재사용 할 수 있고 적절한 어댑터를 작성하는 것이기 때문에이 접근 방식이 나에게 잘 작동한다는 것을 알았습니다. 다양한 선택, 크로스 오버 또는 돌연변이 구현 측면에서 어댑터는 관심있는 구현을 호출 할 수 있습니다. 일반적으로 수행하는 것은 적절한 전략을 조사하는 동안 어댑터에서 다른 아이디어를 주석하는 것입니다.

도움이 되었기를 바랍니다. 필요한 경우 더 많은 지침을 줄 수 있습니다. 이와 같은 디자인 정의를하기가 어렵습니다.

나는 당신이 당신의 접근 방식에서 물건을 과도하게 복잡하게 생각하고 있다고 생각합니다. 다운로드 할 것을 제안합니다 갈리브 패키지. 문서를 HTML 또는 PDF 형식으로 만 가져 오더라도. 이 libs는 한동안 주변에 있었으며 Galib에서 어떻게 이루어 졌는지 모습을 보지 못하는 방법을 배우게 될 것입니다.

내 부분에서 임의의 비트 :

  • (접근 방식으로) 확인 해야하는 프로젝트는 다음과 같습니다. 시계 제작자
  • 건물 가스의 가장 어려운 부분은 문제에 대한 현명한 유전 적 표현을 찾고 좋은 분포로 체력 기능을 구축하는 것입니다. 적합 주어진 인구에 대해
  • (m) 어려운 제약을 다룰 때, 당신은 역자 클래스 Wich는 (가능한) 정크 DNA와 약간의 성능으로 단단한 제약을 처리합니다.

구현은 a 데코레이터 패턴.

사람들이 말했듯이, 하나의 거대한 수업을 만들지 마십시오. 그것은 끔찍할 것입니다. 다른 클래스에서 동작을 캡슐화합니다. 전략은 해결책입니다.
예제가 필요한 경우 다운로드 소스 및 예제 JGAP. 유전자 프로그래밍 및 유전자 알고리즘을 지원합니다. 당신은 거기에서 멋진 멋진 디자인을 볼 것입니다. 돌연변이, 크로스 오버, 선택, 집단, 유전자 -이 모든 것은 별도의 등급입니다. 사용하려는 구현으로 정의 된 인터페이스를 시작하고 적절한 알고리즘 매개 변수를 전달하면 실행하는 구성 개체를 설정합니다. 실제로 패키지는 거대하고 Javadoc은 훌륭하며 언제든지 소스를 조사하거나 메일 그룹을 확인할 수 있습니다. 내가 GA 패키지를 찾고있을 때 나는 Galib과 다른 사람들을 보았지만 이것은 정말 멋진 디자인으로 가장 완성된다고 생각합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top