From 03fab5f77ca07ac887110502f06a490273090e44 Mon Sep 17 00:00:00 2001 From: Miller Cy Chan Date: Thu, 20 Jun 2024 13:27:10 +0800 Subject: [PATCH] Add files via upload --- GaSchedule.Algorithm/Dlba.cs | 12 ++++++++---- GaSchedule.Algorithm/Fpa.cs | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/GaSchedule.Algorithm/Dlba.cs b/GaSchedule.Algorithm/Dlba.cs index 370ca3b..c8f6f92 100644 --- a/GaSchedule.Algorithm/Dlba.cs +++ b/GaSchedule.Algorithm/Dlba.cs @@ -31,6 +31,10 @@ public class Dlba : NsgaIII where T : Chromosome // Initializes Bat algorithm public Dlba(T prototype, int numberOfCrossoverPoints = 2, int mutationSize = 2, float crossoverProbability = 80, float mutationProbability = 3) : base(prototype, numberOfCrossoverPoints, mutationSize, crossoverProbability, mutationProbability) { + // there should be at least 5 chromosomes in population + if (_populationSize < 5) + _populationSize = 5; + _alpha = 0.9; _pa = .25; } @@ -81,10 +85,10 @@ private void UpdatePositions(List population) { var mean = _loudness.Average(); if(_gBest == null) - _gBest = _position[0]; - var prevBest = _prototype.MakeEmptyFromPrototype(); - prevBest.UpdatePositions(_gBest); - + _gBest = _position[0]; + var prevBest = _prototype.MakeEmptyFromPrototype(); + prevBest.UpdatePositions(_gBest); + for (int i = 0; i < _populationSize; ++i) { var beta = (float) Configuration.Random(); var rand = Configuration.Random(); diff --git a/GaSchedule.Algorithm/Fpa.cs b/GaSchedule.Algorithm/Fpa.cs index 883d7b9..57509d3 100644 --- a/GaSchedule.Algorithm/Fpa.cs +++ b/GaSchedule.Algorithm/Fpa.cs @@ -27,7 +27,11 @@ public class Fpa : NsgaIII where T : Chromosome // Initializes Flower Pollination Algorithm public Fpa(T prototype, int numberOfCrossoverPoints = 2, int mutationSize = 2, float crossoverProbability = 80, float mutationProbability = 3) : base(prototype, numberOfCrossoverPoints, mutationSize, crossoverProbability, mutationProbability) - { + { + // there should be at least 5 chromosomes in population + if (_populationSize < 5) + _populationSize = 5; + _pa = .25; }